mirror of
https://github.com/o2sh/onefetch
synced 2024-06-30 22:54:20 +00:00
exclude bot commits from churn when --no-bots
option is used (#1335)
* init * fix * review * early exit in is_bot_commit
This commit is contained in:
parent
2bc5aed55b
commit
1775cc1c32
|
@ -48,6 +48,8 @@ pub fn traverse_commit_graph(
|
||||||
|
|
||||||
let (churn_thread, churn_tx) = get_churn_channel(
|
let (churn_thread, churn_tx) = get_churn_channel(
|
||||||
repo,
|
repo,
|
||||||
|
&mailmap,
|
||||||
|
no_bots.clone(),
|
||||||
&has_commit_graph_traversal_ended,
|
&has_commit_graph_traversal_ended,
|
||||||
&total_number_of_commits,
|
&total_number_of_commits,
|
||||||
max_churn_pool_size,
|
max_churn_pool_size,
|
||||||
|
@ -169,6 +171,8 @@ type ChurnPair = (NumberOfCommitsByFilepath, usize);
|
||||||
|
|
||||||
fn get_churn_channel(
|
fn get_churn_channel(
|
||||||
repo: &gix::Repository,
|
repo: &gix::Repository,
|
||||||
|
mailmap: &gix::mailmap::Snapshot,
|
||||||
|
bot_regex_pattern: Option<MyRegex>,
|
||||||
has_commit_graph_traversal_ended: &Arc<AtomicBool>,
|
has_commit_graph_traversal_ended: &Arc<AtomicBool>,
|
||||||
total_number_of_commits: &Arc<AtomicUsize>,
|
total_number_of_commits: &Arc<AtomicUsize>,
|
||||||
max_churn_pool_size: Option<usize>,
|
max_churn_pool_size: Option<usize>,
|
||||||
|
@ -176,6 +180,8 @@ fn get_churn_channel(
|
||||||
let (tx, rx) = channel::<gix::hash::ObjectId>();
|
let (tx, rx) = channel::<gix::hash::ObjectId>();
|
||||||
let thread = std::thread::spawn({
|
let thread = std::thread::spawn({
|
||||||
let repo = repo.clone();
|
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 has_commit_graph_traversal_ended = has_commit_graph_traversal_ended.clone();
|
||||||
let total_number_of_commits = total_number_of_commits.clone();
|
let total_number_of_commits = total_number_of_commits.clone();
|
||||||
move || -> Result<_> {
|
move || -> Result<_> {
|
||||||
|
@ -183,6 +189,9 @@ fn get_churn_channel(
|
||||||
let mut number_of_diffs_computed = 0;
|
let mut number_of_diffs_computed = 0;
|
||||||
while let Ok(commit_id) = rx.recv() {
|
while let Ok(commit_id) = rx.recv() {
|
||||||
let commit = repo.find_object(commit_id)?.into_commit();
|
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)?;
|
compute_diff_with_parent(&mut number_of_commits_by_file_path, &commit, &repo)?;
|
||||||
number_of_diffs_computed += 1;
|
number_of_diffs_computed += 1;
|
||||||
if should_break(
|
if should_break(
|
||||||
|
@ -272,6 +281,19 @@ fn compute_diff_with_parent(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_bot_commit(
|
||||||
|
commit: &Commit,
|
||||||
|
mailmap: &gix::mailmap::Snapshot,
|
||||||
|
bot_regex_pattern: Option<&MyRegex>,
|
||||||
|
) -> Result<bool> {
|
||||||
|
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 {
|
fn is_bot(author_name: &BString, bot_regex_pattern: Option<&MyRegex>) -> bool {
|
||||||
bot_regex_pattern.map_or(false, |regex| {
|
bot_regex_pattern.map_or(false, |regex| {
|
||||||
regex.0.is_match(author_name.to_str_lossy().as_ref())
|
regex.0.is_match(author_name.to_str_lossy().as_ref())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user