Skip to content

Commit

Permalink
prettiffy with indcatif. Issue on multi/concurrent display
Browse files Browse the repository at this point in the history
  • Loading branch information
shadawck committed May 1, 2024
1 parent 3d8b8cf commit df187d3
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 112 deletions.
29 changes: 3 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions glit-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "glit-cli"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["shadawck <[email protected]>"]
description = "Cli - Retrieve all mail related to a git repository, user, or organization"
Expand All @@ -22,7 +22,8 @@ reqwest = { version = "0.11.18", default-features = false, features = [
] }
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }

glit-core = "0.2.0"
#glit-core = "0.2.0"
glit-core = { path = '../glit-core' }

clap = { version = "4.3", features = ["cargo"] }
colored = "2.0.4"
Expand Down
6 changes: 3 additions & 3 deletions glit-cli/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Exporter<Repository> {
let json_value = serde_json::to_string_pretty(&data.branch_data).unwrap();
fs::write(path.as_path(), json_value).unwrap();

println!("File -> {}", path.to_str().unwrap().yellow());
println!("\nResult written in {}", path.to_str().unwrap().yellow());
}
}
}
Expand All @@ -50,7 +50,7 @@ impl Exporter<User> {
let json_value = serde_json::to_string_pretty(data).unwrap();
fs::write(path.as_path(), json_value).unwrap();

println!("File -> {}", path.to_str().unwrap().yellow());
println!("\nResult written in {}", path.to_str().unwrap().yellow());
}
}
}
Expand All @@ -69,7 +69,7 @@ impl Exporter<Org> {
let json_value = serde_json::to_string_pretty(data).unwrap();
fs::write(path.as_path(), json_value).unwrap();

println!("File -> {}", path.to_str().unwrap().yellow());
println!("\nResult written in {}", path.to_str().unwrap().yellow());
}
}
}
16 changes: 9 additions & 7 deletions glit-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use colored::Colorize;
use exporter::Exporter;
use glit_core::{
org::{Org, OrgFactory},
repo::RepositoryFactory,
repo::{Repository, RepositoryFactory},
user::{User, UserFactory},
Logger,
};
Expand All @@ -29,6 +29,8 @@ use reqwest::ClientBuilder;

use user_command_handler::UserCommandHandler;

use crate::printer::Printer;

#[tokio::main]
async fn main() {
let matches = Command::new("glit")
Expand Down Expand Up @@ -145,8 +147,8 @@ async fn main() {
let repository = RepositoryFactory::with_config(repository_config).create(mpb);
let repo_extraction = repository.extract_log();

//let printer = Printer::<Repository>::new(global_config.clone());
//printer.print_repo(&repo_extraction);
let printer = Printer::<Repository>::new(global_config.clone());
printer.print_repo(&repo_extraction);

let exporter = Exporter::new(global_config);
exporter.export_repo(&repo_extraction);
Expand All @@ -162,8 +164,8 @@ async fn main() {

let user_with_log = Logger::log_for(user, &client).await;

//let printer = Printer::new(global_config.clone());
//printer.print_user(&user_with_log);
let printer = Printer::new(global_config.clone());
printer.print_user(&user_with_log);

let exporter = Exporter::new(global_config.clone());
exporter.export_user(&user_with_log);
Expand All @@ -180,8 +182,8 @@ async fn main() {

let org_with_log = Logger::log_for(org, &client).await;

//let printer = Printer::new(global_config.clone());
//printer.print_org(&org_with_log);
let printer = Printer::new(global_config.clone());
printer.print_org(&org_with_log);

let exporter = Exporter::new(global_config.clone());
exporter.export_org(&org_with_log);
Expand Down
2 changes: 1 addition & 1 deletion glit-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "glit-core"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["shadawck <[email protected]>"]
description = "Core - Retrieve all mail related to a git repository, user, or organization"
Expand Down
12 changes: 6 additions & 6 deletions glit-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ pub trait ExtractLog {
let repo_name_key = RepoName(repo.name.clone());
dash.insert(repo_name_key, data);
atomic_count.fetch_add(1, Ordering::Relaxed);
println!(
"Repository {} handled : {}/{}",
repo.name,
atomic_count.load(Ordering::Relaxed),
repo_count
);
//println!(
// "Repository {} handled : {}/{}",
// repo.name,
// atomic_count.load(Ordering::Relaxed),
// repo_count
//);
})
}
dash
Expand Down
22 changes: 11 additions & 11 deletions glit-core/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ impl Log {

let walk: Vec<Oid> = revwalk.map(|id| id.unwrap()).collect();

//let pb = ProgressBar::new(walk.len().try_into().unwrap());
//pb.set_message(format!("[{}][{}]", repo_name, branch));
//let style = ProgressStyle::with_template(
// "🏃 REVWALKING {msg}{spinner:.green}[{elapsed_precise}] [{wide_bar:.cyan/blue}] {human_pos}/{human_len} ",
//)
//.unwrap()
//.progress_chars("#>-");
let pb = ProgressBar::new(walk.len().try_into().unwrap());
pb.set_message(format!("[{}][{}]", repo_name, branch));
let style = ProgressStyle::with_template(
"🏃 REVWALKING {msg}{spinner:.green}[{elapsed_precise}] [{wide_bar:.cyan/blue}] {human_pos}/{human_len} ",
)
.unwrap()
.progress_chars("#>-");

//pb.set_style(style);
pb.set_style(style);

for (i, commit_id) in walk.into_iter().enumerate() {
//pb.set_position(i.try_into().unwrap());
pb.set_position(i.try_into().unwrap());
repo_data.update(&repo, commit_id);
}

//pb.finish_with_message(format!("[{} ✅][{} ✅]", repo_name, branch));
//pb.finish_and_clear();
pb.finish_with_message(format!("[{} ✅][{} ✅]", repo_name, branch));
pb.finish_and_clear();
repo_data
}
}
112 changes: 56 additions & 56 deletions glit-core/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,26 @@ impl RepositoryFactory {
path: &Path,
//mpb: Arc<Mutex<MultiProgress>>,
) -> Result<git2::Repository, git2::Error> {
//let pb_clone = ProgressBar::new(0);
//let pb_delta = ProgressBar::new(0);
let pb_clone = ProgressBar::new(0);
let pb_delta = ProgressBar::new(0);

//mpb.lock().unwrap().add(pb_clone.clone());

//let style_clone = ProgressStyle::with_template(
// "🚧 CLONING {msg}[{elapsed_precise}] [{wide_bar:.cyan/blue}] {human_pos}/{human_len} ",
//)
//.unwrap()
//.progress_chars("#>-");
//
//let style_delta = ProgressStyle::with_template(
// "🚀 RESOLVING {msg}[{elapsed_precise}] [{wide_bar:.cyan/blue}] {human_pos}/{human_len} ",
//)
//.unwrap()
//.progress_chars("#>-");
//
//pb_clone.set_style(style_clone);
//pb_delta.set_style(style_delta);
let cb = create_multi_callback(repo_name, "default".to_string()); // pb_clone, pb_delta , mpb
let style_clone = ProgressStyle::with_template(
"🚧 CLONING {msg}[{elapsed_precise}] [{wide_bar:.cyan/blue}] {human_pos}/{human_len} ",
)
.unwrap()
.progress_chars("#>-");

let style_delta = ProgressStyle::with_template(
"🚀 RESOLVING {msg}[{elapsed_precise}] [{wide_bar:.cyan/blue}] {human_pos}/{human_len} ",
)
.unwrap()
.progress_chars("#>-");

pb_clone.set_style(style_clone);
pb_delta.set_style(style_delta);
let cb = create_multi_callback(repo_name, "default".to_string(), pb_clone, pb_delta ); // , mpb

let mut fo = FetchOptions::new();
fo.remote_callbacks(cb);
Expand Down Expand Up @@ -164,28 +164,28 @@ impl RepositoryFactory {

let branch_clone_path = PathBuf::from_str(&path).unwrap();

//let pb_clone = ProgressBar::new(0);
//let pb_delta = ProgressBar::new(0);

//let style_clone = ProgressStyle::with_template(
// "🚧 CLONING {msg}[{elapsed_precise}] [{wide_bar:.cyan/blue}] {human_pos}/{human_len} ",
//)
//.unwrap()
//.progress_chars("#>-");
//
//let style_delta = ProgressStyle::with_template(
// "🚀 RESOLVING {msg}[{elapsed_precise}] [{wide_bar:.cyan/blue}] {human_pos}/{human_len} ",
//)
//.unwrap()
//.progress_chars("#>-");
//
//pb_clone.set_style(style_clone);
//pb_delta.set_style(style_delta);
let pb_clone = ProgressBar::new(0);
let pb_delta = ProgressBar::new(0);

let style_clone = ProgressStyle::with_template(
"🚧 CLONING {msg}[{elapsed_precise}] [{wide_bar:.cyan/blue}] {human_pos}/{human_len} ",
)
.unwrap()
.progress_chars("#>-");

let style_delta = ProgressStyle::with_template(
"🚀 RESOLVING {msg}[{elapsed_precise}] [{wide_bar:.cyan/blue}] {human_pos}/{human_len} ",
)
.unwrap()
.progress_chars("#>-");

pb_clone.set_style(style_clone);
pb_delta.set_style(style_delta);
let cb = create_multi_callback(
repo_name.clone(),
branch.to_string(),
//pb_clone,
//pb_delta,
pb_clone,
pb_delta,
); //,mpb

let mut fo = FetchOptions::new();
Expand Down Expand Up @@ -396,8 +396,8 @@ impl Committers {
fn create_multi_callback(
repo_name: String,
branch_name: String,
//pb_clone: ProgressBar,
//pb_delta: ProgressBar,
pb_clone: ProgressBar,
pb_delta: ProgressBar,
) -> RemoteCallbacks<'static> {
let mut cb = RemoteCallbacks::new();

Expand All @@ -407,26 +407,26 @@ fn create_multi_callback(

cb.transfer_progress(move |stats| {
if stats.received_objects() == 0 {
//pb_clone.set_message(format!("[{}][{}]", repo_name, branch_name));
//pb_clone.set_length(stats.total_objects().try_into().unwrap());
pb_clone.set_message(format!("[{}][{}]", repo_name, branch_name));
pb_clone.set_length(stats.total_objects().try_into().unwrap());
}

if stats.indexed_deltas() > 0 && !delta_length_is_set {
//pb_delta.set_message(format!("[{}][{}]", repo_name, branch_name));
//pb_delta.set_length(stats.total_deltas().try_into().unwrap());
pb_delta.set_message(format!("[{}][{}]", repo_name, branch_name));
pb_delta.set_length(stats.total_deltas().try_into().unwrap());
delta_length_is_set = true;
}

if (stats.received_objects() <= stats.total_objects()) && !is_clone_finished {
//pb_clone.set_position(stats.received_objects().try_into().unwrap());
//pb_clone.tick();
pb_clone.set_position(stats.received_objects().try_into().unwrap());
pb_clone.tick();
if stats.received_objects() == stats.total_objects() {
//pb_clone.finish_with_message(format!(
// "[{} ✅][{} ✅]",
// repo_name.clone(),
// branch_name.clone()
//));
//pb_clone.finish_and_clear();
pb_clone.finish_with_message(format!(
"[{} ✅][{} ✅]",
repo_name.clone(),
branch_name.clone()
));
pb_clone.finish_and_clear();
is_clone_finished = true;
}
}
Expand All @@ -436,14 +436,14 @@ fn create_multi_callback(
&& is_clone_finished
&& !is_delta_finished
{
//pb_delta.set_position(stats.indexed_deltas().try_into().unwrap());
pb_delta.set_position(stats.indexed_deltas().try_into().unwrap());

if stats.indexed_deltas() == stats.total_deltas() {
//pb_delta.finish_with_message(format!(
// "[{} ✅][{} ✅]",
// repo_name.clone(),
// branch_name.clone()
//));
pb_delta.finish_with_message(format!(
"[{} ✅][{} ✅]",
repo_name.clone(),
branch_name.clone()
));
is_delta_finished = true;
}
}
Expand Down

0 comments on commit df187d3

Please sign in to comment.