Skip to content

Commit

Permalink
Allow to limit the logging depth for less cluttered output
Browse files Browse the repository at this point in the history
It's something to cater to, as we shouldn't put too noisy progress
too high up.
  • Loading branch information
Byron committed Jul 2, 2020
1 parent 3b96d18 commit fce7035
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
18 changes: 16 additions & 2 deletions git-features/src/progress/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ pub struct Log {
max: Option<u32>,
unit: Option<&'static str>,
last_set: Option<std::time::SystemTime>,
current_level: usize,
max_level: usize,
}

const EMIT_LOG_EVERY_S: f32 = 0.5;

impl Log {
pub fn new(name: impl Into<String>) -> Self {
pub fn new(name: impl Into<String>, max_level: Option<usize>) -> Self {
Log {
name: name.into(),
current_level: 0,
max_level: max_level.unwrap_or(usize::MAX),
max: None,
unit: None,
last_set: None,
Expand All @@ -25,7 +29,14 @@ impl Progress for Log {
type SubProgress = Log;

fn add_child(&mut self, name: impl Into<String>) -> Self::SubProgress {
Log::new(format!("{}::{}", self.name, Into::<String>::into(name)))
Log {
name: format!("{}::{}", self.name, Into::<String>::into(name)),
current_level: self.current_level + 1,
max_level: self.max_level,
max: None,
unit: None,
last_set: None,
}
}

fn init(&mut self, max: Option<u32>, unit: Option<&'static str>) {
Expand All @@ -34,6 +45,9 @@ impl Progress for Log {
}

fn set(&mut self, step: u32) {
if self.current_level > self.max_level {
return;
}
let now = std::time::SystemTime::now();
if self
.last_set
Expand Down
5 changes: 1 addition & 4 deletions git-odb/src/pack/index/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ impl index::File {
-> Result<Vec<DecodeEntryResult>, ChecksumError> {
progress.init(Some(entries.len() as u32), Some("entries"));
let mut stats = Vec::with_capacity(entries.len());
let progress_every = (entries.len() / 10).max(1);
for (idx, index_entry) in entries.iter().enumerate() {
let pack_entry = pack.entry(index_entry.pack_offset);
let pack_entry_data_offset = pack_entry.data_offset;
Expand Down Expand Up @@ -294,9 +293,7 @@ impl index::File {
});
}
}
if idx % progress_every == 0 {
progress.set(idx as u32);
}
progress.set(idx as u32);
}
Ok(stats)
},
Expand Down
2 changes: 1 addition & 1 deletion src/plumbing/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn main() -> Result<()> {
super::init_env_logger(verbose);
core::verify_pack_or_pack_index(
path,
progress::Log::new("verify-pack").into(),
progress::Log::new("verify-pack", Some(1)).into(),
if statistics {
Some(core::OutputFormat::Human)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn init_progress(
super::init_env_logger(verbose);
match (verbose, progress) {
(false, false) => (None, None),
(true, false) => (None, Some(progress::Either::Left(progress::Log::new(name)))),
(true, false) => (None, Some(progress::Either::Left(progress::Log::new(name, Some(1))))),
(true, true) | (false, true) => {
let progress = prodash::Tree::new();
let sub_progress = progress.add_child(name);
Expand Down

0 comments on commit fce7035

Please sign in to comment.