Skip to content

exclude bot commits from churn when --no-bots option is used - #1335

Merged
o2sh merged 5 commits into
mainfrom
fix/churn-with-no-bots
May 7, 2024
Merged

o2sh merged 5 commits into
mainfrom
fix/churn-with-no-bots

Conversation

@o2sh

@o2sh o2sh commented May 4, 2024

Copy link
Copy Markdown
Owner

Fix for #1334

@o2sh o2sh added the fix label May 4, 2024
@o2sh
o2sh requested a review from Byron May 4, 2024 22:29

@Byron Byron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread src/info/git/mod.rs Outdated
fn get_churn_channel(
repo: &gix::Repository,
mailmap: &gix::mailmap::Snapshot,
bot_regex_pattern: &Option<MyRegex>,

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Collaborator

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>)

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Owner Author

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.

Copy link
Copy Markdown
Owner Author

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

Copy link
Copy Markdown
Owner Author

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

Comment thread src/info/git/mod.rs Outdated

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>> {

Copy link
Copy Markdown
Collaborator

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>>.

Copy link
Copy Markdown
Owner Author

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

Comment thread src/info/git/mod.rs Outdated
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()

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Owner Author

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

@o2sh
o2sh merged commit 1775cc1 into main May 7, 2024
@o2sh
o2sh deleted the fix/churn-with-no-bots branch May 7, 2024 17:07

This branch was successfully deployed

1 active deployment
Preview — 2dc03198 Deployed May 7, 2024 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants