diff --git a/src/info/git/mod.rs b/src/info/git/mod.rs index a77018d39..8645b8c0b 100644 --- a/src/info/git/mod.rs +++ b/src/info/git/mod.rs @@ -48,6 +48,8 @@ pub fn traverse_commit_graph( let (churn_thread, churn_tx) = get_churn_channel( repo, + &mailmap, + no_bots.clone(), &has_commit_graph_traversal_ended, &total_number_of_commits, max_churn_pool_size, @@ -169,6 +171,8 @@ type ChurnPair = (NumberOfCommitsByFilepath, usize); fn get_churn_channel( repo: &gix::Repository, + mailmap: &gix::mailmap::Snapshot, + bot_regex_pattern: Option, has_commit_graph_traversal_ended: &Arc, total_number_of_commits: &Arc, max_churn_pool_size: Option, @@ -176,6 +180,8 @@ fn get_churn_channel( let (tx, rx) = channel::(); let thread = std::thread::spawn({ let repo = repo.clone(); + let mailmap = mailmap.clone(); + let bot_regex_pattern = bot_regex_pattern.clone(); let has_commit_graph_traversal_ended = has_commit_graph_traversal_ended.clone(); let total_number_of_commits = total_number_of_commits.clone(); move || -> Result<_> { @@ -183,6 +189,9 @@ fn get_churn_channel( let mut number_of_diffs_computed = 0; while let Ok(commit_id) = rx.recv() { let commit = repo.find_object(commit_id)?.into_commit(); + if is_bot_commit(&commit, &mailmap, bot_regex_pattern.as_ref())? { + continue; + } compute_diff_with_parent(&mut number_of_commits_by_file_path, &commit, &repo)?; number_of_diffs_computed += 1; if should_break( @@ -272,6 +281,19 @@ fn compute_diff_with_parent( Ok(()) } +fn is_bot_commit( + commit: &Commit, + mailmap: &gix::mailmap::Snapshot, + bot_regex_pattern: Option<&MyRegex>, +) -> Result { + if bot_regex_pattern.is_some() { + let sig = mailmap.resolve(commit.author()?); + Ok(is_bot(&sig.name, bot_regex_pattern)) + } else { + Ok(false) + } +} + fn is_bot(author_name: &BString, bot_regex_pattern: Option<&MyRegex>) -> bool { bot_regex_pattern.map_or(false, |regex| { regex.0.is_match(author_name.to_str_lossy().as_ref())