-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exclude bot commits from churn when --no-bots
option is used
#1335
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
src/info/git/mod.rs
Outdated
@@ -172,20 +174,29 @@ type ChurnPair = (NumberOfCommitsByFilepath, usize); | |||
|
|||
fn get_churn_channel( | |||
repo: &gix::Repository, | |||
mailmap: &gix::mailmap::Snapshot, | |||
bot_regex_pattern: &Option<MyRegex>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing &Option<T>
isn't idiomatic, but Option<&T>
is. That requires .as_ref()
on the call-site. This is likely the work of an IDE and refactoring tools.
It's a minor detail though and one doesn't have to care, it also seems to be done in other places that aren't touched here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there perhaps a blanket AsRef
implementation that can be used? Something like this?
bot_regex_pattern: impl AsRef<Option<MyRegex>>
(also perhaps MyRegex
should implement AsRef<Regex>
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that adding generics to method signatures would do more than allowing to avoid manual .as_ref()
, which I'd be more than happy to do for clear compiler errors.
But in the end, it's probably Ok the way it is as it's most natural for IDEs. It's surprising clippy is happy with it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH looking at this more it is kind of odd IMO to have functions that don't do anything significant unless that option is Some
.
Basically instead of this
fn foo(ref: &Option<T1>) -> T2 {
if bar(ref) {
do_thing()
} else {
do_other_thing()
}
}
fn bar(ref: &Option<T1>) -> bool {
let thing = do_calculation();
baz(thing, ref)
}
fn baz(thing: Thing, ref: &Option<T1>) -> bool {
ref.as_ref().map_or(false, |t| t.process(thing))
}
I think it should be more like this:
fn foo(ref: &Option<T1>) -> T2 {
if ref.as_ref().unwrap_or(false, bar) {
do_thing()
} else {
do_other_thing()
}
}
fn bar(ref: &T1) -> bool {
let thing = do_calculation();
ref.process(thing)
}
So, like you said, move the .as_ref
call higher up in the "layers" of functions, but while we're at it these function calls could probably use some other cleanup. I think this non-idiomatic usage is partially caused by an overly complex flow of functions getting called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Byron @spenserblack 1b682e9 Did I do it right?
There seems to be a little more cloning involved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, as a follow up #1338
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a second follow up #1340
src/info/git/mod.rs
Outdated
@@ -286,10 +286,10 @@ fn compute_diff_with_parent( | |||
Ok(()) | |||
} | |||
|
|||
fn get_no_bots_regex(no_bots: &Option<Option<MyRegex>>) -> Result<Option<MyRegex>> { | |||
let reg = if let Some(r) = no_bots.clone() { | |||
fn get_no_bots_regex(no_bots: Option<&Option<MyRegex>>) -> Result<Option<MyRegex>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that this is the same concern as #1335 (comment), and you'd want to make this Option<Option<&T>>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no more Option<Option...
cf. #1340
src/info/git/mod.rs
Outdated
let has_commit_graph_traversal_ended = has_commit_graph_traversal_ended.clone(); | ||
let total_number_of_commits = total_number_of_commits.clone(); | ||
move || -> Result<_> { | ||
let mut number_of_commits_by_file_path = NumberOfCommitsByFilepath::new(); | ||
let mut number_of_diffs_computed = 0; | ||
while let Ok(commit_id) = rx.recv() { | ||
let commit = repo.find_object(commit_id)?.into_commit(); | ||
if bot_regex_pattern.is_some() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This extra check shouldn't be needed if is_bot_commit()
would exit early. I agree that all the hassle might go away if is_bot_commit()
would take the regex without an Option
right away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, moved the check inside is_bot_commit
Fix for #1334