Repository navigation
exclude bot commits from churn when --no-bots option is used - #1335
Conversation
| fn get_churn_channel( | ||
| repo: &gix::Repository, | ||
| mailmap: &gix::mailmap::Snapshot, | ||
| bot_regex_pattern: &Option<MyRegex>, |
There was a problem hiding this comment.
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.
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.
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.
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.
@Byron @spenserblack 1b682e9 Did I do it right?
There seems to be a little more cloning involved.
|
|
||
| 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.
I believe that this is the same concern as #1335 (comment), and you'd want to make this Option<Option<&T>>.
| 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.
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.
Done, moved the check inside is_bot_commit
Fix for #1334