From 296f3b6ee29d5e628a19d56db80ba8736223e226 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 28 Oct 2022 10:57:22 +0200 Subject: [PATCH] adapt to changes in `git-diff` for a 2x speedup when calculating line changes --- gitoxide-core/src/hours/mod.rs | 27 ++++++++++----------------- src/plumbing/progress.rs | 4 ++++ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/gitoxide-core/src/hours/mod.rs b/gitoxide-core/src/hours/mod.rs index a92171d951d..cd77aeaa7bb 100644 --- a/gitoxide-core/src/hours/mod.rs +++ b/gitoxide-core/src/hours/mod.rs @@ -228,24 +228,17 @@ where if let Some(Ok(diff)) = is_text_file.then(|| change.event.diff()).flatten() { - use git::diff::lines::similar::ChangeTag::*; let mut nl = 0; - for change in diff - .text(git::diff::lines::Algorithm::Myers) - .iter_all_changes() - { - match change.tag() { - Delete => { - lines.removed += 1; - nl += 1; - } - Insert => { - lines.added += 1; - nl += 1 - } - Equal => {} - } - } + let counts = diff.lines( + git::diff::text::Algorithm::Myers, + |_| { + git::diff::text::imara::sink::Counter::default() + }, + ); + nl += counts.insertions as usize + + counts.removals as usize; + lines.added += counts.insertions as usize; + lines.removed += counts.removals as usize; if let Some(c) = lines_counter.as_ref() { c.fetch_add(nl, Ordering::SeqCst); } diff --git a/src/plumbing/progress.rs b/src/plumbing/progress.rs index a6ae7be2afc..80526e6e5f6 100644 --- a/src/plumbing/progress.rs +++ b/src/plumbing/progress.rs @@ -125,6 +125,10 @@ static GIT_CONFIG: &[Record] = &[ deviation: None, }, }, + Record { + config: "core.eol", + usage: Planned {note: Some("needed for filters, but also for doing diffs correctly")} + }, Record { config: "core.filesRefLockTimeout", usage: InModule {name: "config::cache::access", deviation: None},