feat: enable full clone
Signed-off-by: Pakin <pakin.t@forth.co.th>
This commit is contained in:
parent
febf91d417
commit
bb3e55eecb
3 changed files with 49 additions and 45 deletions
|
|
@ -735,7 +735,7 @@ pub async fn run(config: gcm::Configure) -> gcm::StandardResult {
|
|||
let state = AppState {
|
||||
// cached_country_names: common::valid_country_name(),
|
||||
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()),
|
||||
)?)),
|
||||
redis: redis_pool.clone(),
|
||||
|
|
|
|||
90
src/git.rs
90
src/git.rs
|
|
@ -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 log::{info};
|
||||
use git2::{Cred, FetchOptions, Progress, RemoteCallbacks, build::RepoBuilder};
|
||||
use log::info;
|
||||
|
||||
use crate::gcm;
|
||||
|
||||
struct GitState {
|
||||
progress: Option<Progress<'static>>,
|
||||
total: usize,
|
||||
current: usize,
|
||||
path: Option<PathBuf>,
|
||||
newline: bool
|
||||
progress: Option<Progress<'static>>,
|
||||
total: usize,
|
||||
current: usize,
|
||||
path: Option<PathBuf>,
|
||||
newline: bool,
|
||||
}
|
||||
|
||||
fn print(state: &mut GitState) {
|
||||
|
|
@ -29,10 +34,11 @@ fn print(state: &mut GitState) {
|
|||
state.newline = true;
|
||||
}
|
||||
|
||||
info!("Resolving deltas {}/{}",
|
||||
stats.indexed_deltas(),
|
||||
stats.total_deltas());
|
||||
|
||||
info!(
|
||||
"Resolving deltas {}/{}",
|
||||
stats.indexed_deltas(),
|
||||
stats.total_deltas()
|
||||
);
|
||||
} else {
|
||||
info!(
|
||||
"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 {
|
||||
let state = RefCell::new(GitState {
|
||||
progress: None,
|
||||
total: 0,
|
||||
current: 0,
|
||||
path: None,
|
||||
newline: true
|
||||
});
|
||||
let state = RefCell::new(GitState {
|
||||
progress: None,
|
||||
total: 0,
|
||||
current: 0,
|
||||
path: None,
|
||||
newline: true,
|
||||
});
|
||||
|
||||
let mut cb = RemoteCallbacks::new();
|
||||
cb.transfer_progress(|stats| {
|
||||
let mut state = state.borrow_mut();
|
||||
state.progress = Some(stats.to_owned());
|
||||
print(&mut state);
|
||||
true
|
||||
});
|
||||
let mut cb = RemoteCallbacks::new();
|
||||
cb.transfer_progress(|stats| {
|
||||
let mut state = state.borrow_mut();
|
||||
state.progress = Some(stats.to_owned());
|
||||
print(&mut state);
|
||||
true
|
||||
});
|
||||
|
||||
cb.credentials(|_,_,_| {
|
||||
Cred::userpass_plaintext(
|
||||
config.get("GIT_REPO_USERNAME").unwrap_or(&"".to_string()),
|
||||
config.get("GIT_REPO_PASSWORD").unwrap_or(&"".to_string())
|
||||
)
|
||||
});
|
||||
cb.credentials(|_, _, _| {
|
||||
Cred::userpass_plaintext(
|
||||
config.get("GIT_REPO_USERNAME").unwrap_or(&"".to_string()),
|
||||
config.get("GIT_REPO_PASSWORD").unwrap_or(&"".to_string()),
|
||||
)
|
||||
});
|
||||
|
||||
let mut fo = FetchOptions::new();
|
||||
fo.remote_callbacks(cb);
|
||||
fo.depth(1);
|
||||
let mut fo = FetchOptions::new();
|
||||
fo.remote_callbacks(cb);
|
||||
|
||||
RepoBuilder::new()
|
||||
.bare(true)
|
||||
.fetch_options(fo)
|
||||
.clone(
|
||||
config.get("GIT_REPO_REMOTE").unwrap_or(&"".to_string()),
|
||||
Path::new(config.get("GIT_REPO_LOCAL_DEST").unwrap()).into()
|
||||
let _ = RepoBuilder::new().bare(false).fetch_options(fo).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(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ pub async fn setup_prebuild_tx_cache(
|
|||
git_repo: &str,
|
||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
// import tx files
|
||||
let repo = match Repository::open_bare(git_repo) {
|
||||
let repo = match Repository::open(git_repo) {
|
||||
Ok(repo) => repo,
|
||||
Err(_) => return Err("cannot open repo".into()),
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue