feat: enable full clone

Signed-off-by: Pakin <pakin.t@forth.co.th>
This commit is contained in:
Pakin 2026-03-24 10:21:02 +07:00
parent febf91d417
commit bb3e55eecb
3 changed files with 49 additions and 45 deletions

View file

@ -735,7 +735,7 @@ pub async fn run(config: gcm::Configure) -> gcm::StandardResult {
let state = AppState { let state = AppState {
// cached_country_names: common::valid_country_name(), // cached_country_names: common::valid_country_name(),
configures: config.clone(), configures: config.clone(),
repo: Arc::new(Mutex::new(Repository::open_bare( repo: Arc::new(Mutex::new(Repository::open(
config.get("GIT_REPO_LOCAL_DEST").unwrap_or(&"".to_string()), config.get("GIT_REPO_LOCAL_DEST").unwrap_or(&"".to_string()),
)?)), )?)),
redis: redis_pool.clone(), redis: redis_pool.clone(),

View file

@ -1,16 +1,21 @@
use std::{cell::RefCell, collections::HashMap, io::{self, Write}, path::{Path, PathBuf}}; use std::{
cell::RefCell,
collections::HashMap,
io::{self, Write},
path::{Path, PathBuf},
};
use git2::{build::RepoBuilder, Cred, FetchOptions, Progress, RemoteCallbacks}; use git2::{Cred, FetchOptions, Progress, RemoteCallbacks, build::RepoBuilder};
use log::{info}; use log::info;
use crate::gcm; use crate::gcm;
struct GitState { struct GitState {
progress: Option<Progress<'static>>, progress: Option<Progress<'static>>,
total: usize, total: usize,
current: usize, current: usize,
path: Option<PathBuf>, path: Option<PathBuf>,
newline: bool newline: bool,
} }
fn print(state: &mut GitState) { fn print(state: &mut GitState) {
@ -29,10 +34,11 @@ fn print(state: &mut GitState) {
state.newline = true; state.newline = true;
} }
info!("Resolving deltas {}/{}", info!(
stats.indexed_deltas(), "Resolving deltas {}/{}",
stats.total_deltas()); stats.indexed_deltas(),
stats.total_deltas()
);
} else { } else {
info!( info!(
"net {:3}% ({:4} kb, {:5}/{:5}) / idx {:3}% ({:5}/{:5}) \ "net {:3}% ({:4} kb, {:5}/{:5}) / idx {:3}% ({:5}/{:5}) \
@ -58,40 +64,38 @@ fn print(state: &mut GitState) {
} }
pub fn setup_git_repo(config: HashMap<String, String>) -> gcm::StandardResult { pub fn setup_git_repo(config: HashMap<String, String>) -> gcm::StandardResult {
let state = RefCell::new(GitState { let state = RefCell::new(GitState {
progress: None, progress: None,
total: 0, total: 0,
current: 0, current: 0,
path: None, path: None,
newline: true newline: true,
}); });
let mut cb = RemoteCallbacks::new(); let mut cb = RemoteCallbacks::new();
cb.transfer_progress(|stats| { cb.transfer_progress(|stats| {
let mut state = state.borrow_mut(); let mut state = state.borrow_mut();
state.progress = Some(stats.to_owned()); state.progress = Some(stats.to_owned());
print(&mut state); print(&mut state);
true true
}); });
cb.credentials(|_,_,_| { cb.credentials(|_, _, _| {
Cred::userpass_plaintext( Cred::userpass_plaintext(
config.get("GIT_REPO_USERNAME").unwrap_or(&"".to_string()), config.get("GIT_REPO_USERNAME").unwrap_or(&"".to_string()),
config.get("GIT_REPO_PASSWORD").unwrap_or(&"".to_string()) config.get("GIT_REPO_PASSWORD").unwrap_or(&"".to_string()),
) )
}); });
let mut fo = FetchOptions::new(); let mut fo = FetchOptions::new();
fo.remote_callbacks(cb); fo.remote_callbacks(cb);
fo.depth(1);
RepoBuilder::new() let _ = RepoBuilder::new().bare(false).fetch_options(fo).clone(
.bare(true) config.get("GIT_REPO_REMOTE").unwrap_or(&"".to_string()),
.fetch_options(fo) Path::new(config.get("GIT_REPO_LOCAL_DEST").unwrap()).into(),
.clone(
config.get("GIT_REPO_REMOTE").unwrap_or(&"".to_string()),
Path::new(config.get("GIT_REPO_LOCAL_DEST").unwrap()).into()
)?; )?;
Ok(()) println!("clone completed !");
Ok(())
} }

View file

@ -107,7 +107,7 @@ pub async fn setup_prebuild_tx_cache(
git_repo: &str, git_repo: &str,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> { ) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// import tx files // import tx files
let repo = match Repository::open_bare(git_repo) { let repo = match Repository::open(git_repo) {
Ok(repo) => repo, Ok(repo) => repo,
Err(_) => return Err("cannot open repo".into()), Err(_) => return Err("cannot open repo".into()),
}; };