Skip to content
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

blame: respect .git-blame-ignore-revs automatically #1809

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Ethan0456
Copy link

@Ethan0456 Ethan0456 commented Oct 7, 2024

Summary

This patch introduces the ability for git blame to automatically respect the .git-blame-ignore-revs file, which can help users streamline their workflows by ignoring revisions for non-functional changes.

The feature is inspired by similar practices in other projects like Chromium, and it aligns with needs expressed by users in discussions around revision-ignoring mechanisms for git blame.

I have incorporated suggestions provided during the review of patch v1, including improvements to the commit message and addressing how to override ignore revisions using a new option.

Patch Updates and Improvements

Changes since v1

  • Updated the commit message for the first patch. I incorporated Kristoffer’s suggestions by directly using the example he provided, ensuring the commit message aligns with the project's standards.
  • Attempted to use --no-ignore-revs-file to bypass the .git-blame-ignore-revs file, but observed that it did not ignore the specified revisions.
  • Introduced the --override-ignore-revs option (short form: -O) as a straightforward method to override any configured revision ignores, providing users with more control.
  • For the second commit, I applied Kristoffer’s feedback in writing the commit message to ensure consistency and clarity.

cc: "Kristoffer Haugsbakk" [email protected]
cc: Phillip Wood [email protected]
cc: Eric Sunshine [email protected]
cc: Taylor Blau [email protected]

@dscho
Copy link
Member

dscho commented Oct 7, 2024

Is there any reason why #1805 could not be reused? You will need to reuse the same PR when sending multiple iterations to the mailing list, anyway.

@Ethan0456 Ethan0456 closed this Oct 7, 2024
@Ethan0456
Copy link
Author

ohh sorry, I scraped the previous one because I thought adding changes to the that PR will utilize two commit for this small patch which ideally needs a single commit.

@Ethan0456
Copy link
Author

You will need to reuse the same PR when sending multiple iterations to the mailing list, anyway.

Sure, I will reopen that PR again and push the recent changes there.

@dscho
Copy link
Member

dscho commented Oct 7, 2024

adding changes to the that PR will utilize two commit for this small patch which ideally needs a single commit.

Right, but you can squash them and force-push.

@Ethan0456
Copy link
Author

Sorry again, I closed this PR too quickly. I will squash my commits and force push as you suggested.

@Ethan0456
Copy link
Author

Ethan0456 commented Oct 7, 2024

@dscho I reopened this PR as I was unable to reopen the previous PR. The previous PR reads "There is already an open PR request from {my feature branch} to gitgitgadget:master".

I will take care to not scrap and make make multiple PR from the next time.

@dscho
Copy link
Member

dscho commented Oct 7, 2024

@Ethan0456 sounds good!

@Ethan0456
Copy link
Author

/preview

Copy link

gitgitgadget bot commented Oct 8, 2024

Preview email sent as [email protected]

@Ethan0456
Copy link
Author

The preview email looks great!

@Ethan0456
Copy link
Author

/submit

@Ethan0456
Copy link
Author

Thanks @dscho for helping me with my first contribution to git!

Copy link

gitgitgadget bot commented Oct 8, 2024

Submitted as [email protected]

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-1809/Ethan0456/blame-auto-ignore-revs-v1

To fetch this version to local tag pr-1809/Ethan0456/blame-auto-ignore-revs-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-1809/Ethan0456/blame-auto-ignore-revs-v1

Copy link

gitgitgadget bot commented Oct 8, 2024

On the Git mailing list, "Kristoffer Haugsbakk" wrote (reply to this):

Thank you for working on this.  I think an ability to respect a
conventional ignore list would be useful.

I was a bit concerned that there doesn’t seem to be something to turn
off ignore lists.  The man page says that the discussed option exists
but not some `--no` variant.  But then I tested this:

```
git blame --ignore-revs-file=README.md \
    --no-ignore-revs-file README.md
```

And that works without giving errors.  So it’s there.  Just apparently
undocumented?

My assumption then is that, with this change, I could use
`--no-ignore-revs-file` to turn off the default file.

(One can also use the config `blame.ignoreRevsFile` set to the
empty string)

On Tue, Oct 8, 2024, at 09:01, Abhijeetsingh Meena via GitGitGadget wrote:
> From: Abhijeetsingh Meena <[email protected]>
>
> Modify `git blame` to automatically respect a `.git-blame-ignore-revs`
> file if it exists in the repository. This file is used by many projects
> to ignore non-functional changes, such as reformatting or large-scale
> refactoring, when generating blame information.

Nice.

> Before this change, users had to manually specify the file with the
> `--ignore-revs-file` option. This update streamlines the process by
> automatically detecting the `.git-blame-ignore-revs` file, reducing
> manual effort.

(They can also use the `blame.ignoreRevsFile` config in order to not
have to give the option every time)

The project convention is to use the present tense for describing the
current behavior (without this patch).  Like:

    Users that have a standard list of commits to ignore have to use
    `--ignore-revs-file`.

This style often lends itself to this structure:

- (optionally introduce the wider topic)
- Describe the current behavior and why that is a problem
- Say how we’re changing the code (which you already did a good job of in
  your first paragraph).

It might end up something like this:

    git-blame(1) can ignore a list of commits with `--ignore-revs-file`.
    This is useful for marking uninteresting commits like formatting
    changes, refactors and whatever else should not be “blamed”.  Some
    projects even version control this file so that all contributors can
    use it; the conventional name is `.git-blame-ignore-revs`.

    But each user still has to opt-in to the standard ignore list,
    either with this option or with the config `blame.ignoreRevsFile`.
    Let’s teach git-blame(1) to respect this conventional file in order
    to streamline the process.

> This change aligns with the standardized practice in many repositories
> and simplifies the workflow for users.
>
> Signed-off-by: Abhijeetsingh Meena <[email protected]>
> ---
>     blame: respect .git-blame-ignore-revs automatically
>
>
>     Introduction
>     ============
>
>     Hi, I'm Abhijeet (Ethan0456), and this is my first contribution to the
>     Git project. I currently work as an ML Engineer at an early-stage
>     startup, and I’m excited to contribute to this open-source project.
>
>
>     Why the Change?
>     ===============
>
>     I came across this enhancement request on the bug tracker and found it
>     beginner-friendly, making it a great opportunity for me to get familiar
>     with the Git codebase. The ability for git blame to automatically
>     respect the .git-blame-ignore-revs file is something that can streamline
>     workflows for many users, and I felt it would be a valuable addition.

The issue that is referred:

https://github.com/gitgitgadget/git/issues/1494

That issue tracker is unofficial by the way.

>
>
>     Feedback
>     ========
>
>     While I’m confident in the changes made to builtin/blame.c and the new
>     test case in t/t8015-blame-ignore-revs.sh, I welcome any feedback or
>     suggestions to improve both my code and approach. I’m eager to learn
>     from the community and improve where needed.
>
>
>     Community Need
>     ==============
>
>     There is precedent for this functionality in other projects:
>
>      * Chromium
>
> [https://chromium.googlesource.com/chromium/src.git/+/f0596779e57f46fccb115a0fd65f0305894e3031/.git-blame-ignore-revs],
>        which powers many popular browsers, uses .git-blame-ignore-revs
> to
>        simplify the blame process by ignoring non-functional changes.
>      * Rob Allen's blog post
>        [https://akrabat.com/ignoring-revisions-with-git-blame/]
> discusses
>        the need for ignoring revisions with git blame, and a commenter
>        specifically suggests that it would be helpful if Git
> automatically
>        respected .git-blame-ignore-revs.
>
>     I hope this change aligns with community needs and improves the git
>     blame experience for users.

It’s nice that you mention specific projects that use this convention.
Sometimes people just say “this is used by many people/projects”.  But
not what projects.  (Then perhaps it is eventually revealed that “we use
it so therefore it is important” ;) )

> Published-As:
> https://github.com/gitgitgadget/git/releases/tag/pr-1809%2FEthan0456%2Fblame-auto-ignore-revs-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git
> pr-1809/Ethan0456/blame-auto-ignore-revs-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/1809
>
>  builtin/blame.c                      |  8 ++++++++
>  t/t8015-blame-default-ignore-revs.sh | 26 ++++++++++++++++++++++++++
>  2 files changed, 34 insertions(+)
>  create mode 100755 t/t8015-blame-default-ignore-revs.sh
>
> diff --git a/builtin/blame.c b/builtin/blame.c
> index e407a22da3b..1eddabaf60f 100644
> --- a/builtin/blame.c
> +++ b/builtin/blame.c
> @@ -1105,6 +1105,14 @@ parse_done:
>  		add_pending_object(&revs, &head_commit->object, "HEAD");
>  	}
>
> +	/*
> +	* By default, add .git-blame-ignore-revs to the list of files
> +	* containing revisions to ignore if it exists.
> +	*/
> +	if (access(".git-blame-ignore-revs", F_OK) == 0) {
> +		string_list_append(&ignore_revs_file_list, ".git-blame-ignore-revs");
> +	}
> +
>  	init_scoreboard(&sb);
>  	sb.revs = &revs;
>  	sb.contents_from = contents_from;
> diff --git a/t/t8015-blame-default-ignore-revs.sh
> b/t/t8015-blame-default-ignore-revs.sh
> new file mode 100755
> index 00000000000..84e1a9e87e6
> --- /dev/null
> +++ b/t/t8015-blame-default-ignore-revs.sh
> @@ -0,0 +1,26 @@
> +#!/bin/sh
> +
> +test_description='default revisions to ignore when blaming'
> +
> +TEST_PASSES_SANITIZE_LEAK=true
> +. ./test-lib.sh
> +
> +test_expect_success 'blame: default-ignore-revs-file' '
> +    test_commit first-commit hello.txt hello &&
> +
> +    echo world >>hello.txt &&
> +    test_commit second-commit hello.txt &&
> +
> +    sed "1s/hello/hi/" <hello.txt > hello.txt.tmp &&
> +    mv hello.txt.tmp hello.txt &&
> +    test_commit third-commit hello.txt &&
> +
> +    git rev-parse HEAD >ignored-file &&
> +    git blame --ignore-revs-file=ignored-file hello.txt >expect &&
> +    git rev-parse HEAD >.git-blame-ignore-revs &&
> +    git blame hello.txt >actual &&
> +
> +    test_cmp expect actual
> +'
> +
> +test_done
> \ No newline at end of file

There should be a final newline. ;)

>
> base-commit: 777489f9e09c8d0dd6b12f9d90de6376330577a2
> --
> gitgitgadget

Copy link

gitgitgadget bot commented Oct 8, 2024

User "Kristoffer Haugsbakk" <[email protected]> has been added to the cc: list.

Copy link

gitgitgadget bot commented Oct 8, 2024

On the Git mailing list, Phillip Wood wrote (reply to this):

Hi Abhijeetsingh

On 08/10/2024 08:01, Abhijeetsingh Meena via GitGitGadget wrote:
> From: Abhijeetsingh Meena <[email protected]>
> > Modify `git blame` to automatically respect a `.git-blame-ignore-revs`
> file if it exists in the repository. This file is used by many projects
> to ignore non-functional changes, such as reformatting or large-scale
> refactoring, when generating blame information.
> > Before this change, users had to manually specify the file with the
> `--ignore-revs-file` option. This update streamlines the process by
> automatically detecting the `.git-blame-ignore-revs` file, reducing
> manual effort.

As Kristoffer mentioned there is a config option so that the user does not have to specify the file each time. The decision not to support a default file for this feature was deliberate [1,2]. It is possible that we now have enough experience with the feature that we think it would be a good idea but any such change would need to address the concerns about ignoring "cleanup" commits that introduce bugs. If we do decide to support a default file we'd need to work out how it interacted with the config setting and make sure there was an easy way to turn the feature off.

Best Wishes

Phillip

[1] https://lore.kernel.org/git/[email protected]/
[2] https://lore.kernel.org/git/[email protected]/

> This change aligns with the standardized practice in many repositories
> and simplifies the workflow for users.
> > Signed-off-by: Abhijeetsingh Meena <[email protected]>
> ---
>      blame: respect .git-blame-ignore-revs automatically
>      >      >      Introduction
>      ============
>      >      Hi, I'm Abhijeet (Ethan0456), and this is my first contribution to the
>      Git project. I currently work as an ML Engineer at an early-stage
>      startup, and I’m excited to contribute to this open-source project.
>      >      >      Why the Change?
>      ===============
>      >      I came across this enhancement request on the bug tracker and found it
>      beginner-friendly, making it a great opportunity for me to get familiar
>      with the Git codebase. The ability for git blame to automatically
>      respect the .git-blame-ignore-revs file is something that can streamline
>      workflows for many users, and I felt it would be a valuable addition.
>      >      >      Feedback
>      ========
>      >      While I’m confident in the changes made to builtin/blame.c and the new
>      test case in t/t8015-blame-ignore-revs.sh, I welcome any feedback or
>      suggestions to improve both my code and approach. I’m eager to learn
>      from the community and improve where needed.
>      >      >      Community Need
>      ==============
>      >      There is precedent for this functionality in other projects:
>      >       * Chromium
>         [https://chromium.googlesource.com/chromium/src.git/+/f0596779e57f46fccb115a0fd65f0305894e3031/.git-blame-ignore-revs],
>         which powers many popular browsers, uses .git-blame-ignore-revs to
>         simplify the blame process by ignoring non-functional changes.
>       * Rob Allen's blog post
>         [https://akrabat.com/ignoring-revisions-with-git-blame/] discusses
>         the need for ignoring revisions with git blame, and a commenter
>         specifically suggests that it would be helpful if Git automatically
>         respected .git-blame-ignore-revs.
>      >      I hope this change aligns with community needs and improves the git
>      blame experience for users.
> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1809%2FEthan0456%2Fblame-auto-ignore-revs-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1809/Ethan0456/blame-auto-ignore-revs-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/1809
> >   builtin/blame.c                      |  8 ++++++++
>   t/t8015-blame-default-ignore-revs.sh | 26 ++++++++++++++++++++++++++
>   2 files changed, 34 insertions(+)
>   create mode 100755 t/t8015-blame-default-ignore-revs.sh
> > diff --git a/builtin/blame.c b/builtin/blame.c
> index e407a22da3b..1eddabaf60f 100644
> --- a/builtin/blame.c
> +++ b/builtin/blame.c
> @@ -1105,6 +1105,14 @@ parse_done:
>   		add_pending_object(&revs, &head_commit->object, "HEAD");
>   	}
>   > +	/*
> +	* By default, add .git-blame-ignore-revs to the list of files
> +	* containing revisions to ignore if it exists.
> +	*/
> +	if (access(".git-blame-ignore-revs", F_OK) == 0) {
> +		string_list_append(&ignore_revs_file_list, ".git-blame-ignore-revs");
> +	}
> +
>   	init_scoreboard(&sb);
>   	sb.revs = &revs;
>   	sb.contents_from = contents_from;
> diff --git a/t/t8015-blame-default-ignore-revs.sh b/t/t8015-blame-default-ignore-revs.sh
> new file mode 100755
> index 00000000000..84e1a9e87e6
> --- /dev/null
> +++ b/t/t8015-blame-default-ignore-revs.sh
> @@ -0,0 +1,26 @@
> +#!/bin/sh
> +
> +test_description='default revisions to ignore when blaming'
> +
> +TEST_PASSES_SANITIZE_LEAK=true
> +. ./test-lib.sh
> +
> +test_expect_success 'blame: default-ignore-revs-file' '
> +    test_commit first-commit hello.txt hello &&
> +
> +    echo world >>hello.txt &&
> +    test_commit second-commit hello.txt &&
> +
> +    sed "1s/hello/hi/" <hello.txt > hello.txt.tmp &&
> +    mv hello.txt.tmp hello.txt &&
> +    test_commit third-commit hello.txt &&
> +
> +    git rev-parse HEAD >ignored-file &&
> +    git blame --ignore-revs-file=ignored-file hello.txt >expect &&
> +    git rev-parse HEAD >.git-blame-ignore-revs &&
> +    git blame hello.txt >actual &&
> +
> +    test_cmp expect actual
> +'
> +
> +test_done
> \ No newline at end of file
> > base-commit: 777489f9e09c8d0dd6b12f9d90de6376330577a2

Copy link

gitgitgadget bot commented Oct 8, 2024

User Phillip Wood <[email protected]> has been added to the cc: list.

@Ethan0456
Copy link
Author

Ethan0456 commented Oct 8, 2024

Hi Kristoffer,

Thank you so much for your feedback and for taking the time to review my patch. I appreciate your suggestions, particularly regarding the project convention of using the present tense to describe the current behavior, as well as your mention of the --no-ignore-revs-file option and the importance of documenting it.

Regarding your first point:

My assumption then is that, with this change, I could use --no-ignore-revs-file to turn off the default file.

I’ll check how this works in the current setup and get back to you to confirm.

As for your second observation:

git blame --ignore-revs-file=README.md
--no-ignore-revs-file README.md
And that works without giving errors. So it’s there. Just apparently undocumented?

I’ll look into opening an issue and submitting a PR to add documentation for this, as it seems important to address.

I’m excited to refine the patch with these improvements in mind and will continue working on the commit message and necessary documentation in line with your feedback.

Thanks again for your guidance and support!

Best regards,
Abhijeet (Ethan0456)

@Ethan0456
Copy link
Author

/preview

Copy link

gitgitgadget bot commented Oct 8, 2024

Preview email sent as [email protected]

@Ethan0456
Copy link
Author

/submit

Copy link

gitgitgadget bot commented Oct 8, 2024

Error: 6664046 was already submitted

@Ethan0456
Copy link
Author

Hi Phillip,

Thank you for your feedback on my patch. I appreciate your insights regarding the decision not to support a default file for the --ignore-revs-file feature and the concerns related to ignoring "cleanup" commits that could potentially introduce bugs.

I understand that addressing these concerns is crucial. Specifically, I will focus on:

  1. Ensuring there’s a clear and easy way for users to opt out or override the default behavior of ignoring certain commits, especially if they suspect those commits might contain bugs.
  2. Investigating how this new feature could interact with existing configuration options that allow users to specify what should be ignored manually.

I will take these points into consideration as I work on my changes and come up with a solution to address these concerns.

Thank you again for your guidance, and I look forward to your continued feedback!

Best wishes,
Abhijeet (Ethan0456)

Copy link

gitgitgadget bot commented Oct 8, 2024

On the Git mailing list, Abhijeetsingh Meena wrote (reply to this):

Hi Kristoffer,

Thank you so much for your feedback and for taking the time to review
my patch. I appreciate your suggestions, particularly regarding the
project convention of using the present tense to describe the current
behavior, as well as your mention of the --no-ignore-revs-file option
and the importance of documenting it.

Regarding your first point:

> My assumption then is that, with this change, I could use --no-ignore-revs-file to turn off the default file.

I’ll check how this works in the current setup and get back to you to confirm.

As for your second observation:

> git blame --ignore-revs-file=README.md
> --no-ignore-revs-file README.md
> And that works without giving errors. So it’s there. Just apparently undocumented?

I’ll look into opening an issue and submitting a PR to add
documentation for this, as it seems important to address.

I’m excited to refine the patch with these improvements in mind and
will continue working on the commit message and necessary
documentation in line with your feedback.

Thanks again for your guidance and support!

Best regards,
Abhijeet (Ethan0456)

On Tue, Oct 8, 2024 at 8:53 PM Abhijeetsingh Meena
<[email protected]> wrote:
>
> Hi Phillip,
>
> Thank you for your feedback on my patch. I appreciate your insights regarding the decision not to support a default file for the --ignore-revs-file feature and the concerns related to ignoring "cleanup" commits that could potentially introduce bugs.
>
> I understand that addressing these concerns is crucial. Specifically, I will focus on:
>
> 1. Ensuring there’s a clear and easy way for users to opt out or override the default behavior of ignoring certain commits, especially if they suspect those commits might contain bugs.
> 2. Investigating how this new feature could interact with existing configuration options that allow users to specify what should be ignored manually.
>
> I will take these points into consideration as I work on my changes and come up with a solution to address these concerns.
>
> Thank you again for your guidance, and I look forward to your continued feedback!
>
> Best wishes,
> Abhijeet (Ethan0456)
>
> On Tue, Oct 8, 2024 at 8:53 PM Abhijeetsingh Meena <[email protected]> wrote:
>>
>> Hi Kristoffer,
>>
>> Thank you so much for your feedback and for taking the time to review my patch. I appreciate your suggestions, particularly regarding the project convention of using the present tense to describe the current behavior, as well as your mention of the --no-ignore-revs-file option and the importance of documenting it.
>>
>> Regarding your first point:
>>
>> > My assumption then is that, with this change, I could use --no-ignore-revs-file to turn off the default file.
>>
>> I’ll check how this works in the current setup and get back to you to confirm.
>>
>> As for your second observation:
>>
>> > git blame --ignore-revs-file=README.md
>> > --no-ignore-revs-file README.md
>> > And that works without giving errors. So it’s there. Just apparently undocumented?
>>
>> I’ll look into opening an issue and submitting a PR to add documentation for this, as it seems important to address.
>>
>> I’m excited to refine the patch with these improvements in mind and will continue working on the commit message and necessary documentation in line with your feedback.
>>
>> Thanks again for your guidance and support!
>>
>> Best regards,
>> Abhijeet (Ethan0456)
>>
>> On Tue, Oct 8, 2024 at 7:54 PM Abhijeetsingh Meena via GitGitGadget <[email protected]> wrote:
>>>
>>> From: Abhijeetsingh Meena <[email protected]>
>>>
>>> Modify `git blame` to automatically respect a `.git-blame-ignore-revs`
>>> file if it exists in the repository. This file is used by many projects
>>> to ignore non-functional changes, such as reformatting or large-scale
>>> refactoring, when generating blame information.
>>>
>>> Before this change, users had to manually specify the file with the
>>> `--ignore-revs-file` option. This update streamlines the process by
>>> automatically detecting the `.git-blame-ignore-revs` file, reducing
>>> manual effort.
>>>
>>> This change aligns with the standardized practice in many repositories
>>> and simplifies the workflow for users.
>>>
>>> Signed-off-by: Abhijeetsingh Meena <[email protected]>
>>> ---
>>>     blame: respect .git-blame-ignore-revs automatically
>>>
>>>
>>>     Introduction
>>>     ============
>>>
>>>     Hi, I'm Abhijeet (Ethan0456), and this is my first contribution to the
>>>     Git project. I currently work as an ML Engineer at an early-stage
>>>     startup, and I’m excited to contribute to this open-source project.
>>>
>>>
>>>     Why the Change?
>>>     ===============
>>>
>>>     I came across this enhancement request on the bug tracker and found it
>>>     beginner-friendly, making it a great opportunity for me to get familiar
>>>     with the Git codebase. The ability for git blame to automatically
>>>     respect the .git-blame-ignore-revs file is something that can streamline
>>>     workflows for many users, and I felt it would be a valuable addition.
>>>
>>>
>>>     Feedback
>>>     ========
>>>
>>>     While I’m confident in the changes made to builtin/blame.c and the new
>>>     test case in t/t8015-blame-ignore-revs.sh, I welcome any feedback or
>>>     suggestions to improve both my code and approach. I’m eager to learn
>>>     from the community and improve where needed.
>>>
>>>
>>>     Community Need
>>>     ==============
>>>
>>>     There is precedent for this functionality in other projects:
>>>
>>>      * Chromium
>>>        [https://chromium.googlesource.com/chromium/src.git/+/f0596779e57f46fccb115a0fd65f0305894e3031/.git-blame-ignore-revs],
>>>        which powers many popular browsers, uses .git-blame-ignore-revs to
>>>        simplify the blame process by ignoring non-functional changes.
>>>      * Rob Allen's blog post
>>>        [https://akrabat.com/ignoring-revisions-with-git-blame/] discusses
>>>        the need for ignoring revisions with git blame, and a commenter
>>>        specifically suggests that it would be helpful if Git automatically
>>>        respected .git-blame-ignore-revs.
>>>
>>>     I hope this change aligns with community needs and improves the git
>>>     blame experience for users.
>>>
>>> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1809%2FEthan0456%2Fblame-auto-ignore-revs-v2
>>> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1809/Ethan0456/blame-auto-ignore-revs-v2
>>> Pull-Request: https://github.com/gitgitgadget/git/pull/1809
>>>
>>> Range-diff vs v1:
>>>
>>>  1:  666404681d9 = 1:  666404681d9 blame: respect .git-blame-ignore-revs automatically
>>>
>>>
>>>  builtin/blame.c                      |  8 ++++++++
>>>  t/t8015-blame-default-ignore-revs.sh | 26 ++++++++++++++++++++++++++
>>>  2 files changed, 34 insertions(+)
>>>  create mode 100755 t/t8015-blame-default-ignore-revs.sh
>>>
>>> diff --git a/builtin/blame.c b/builtin/blame.c
>>> index e407a22da3b..1eddabaf60f 100644
>>> --- a/builtin/blame.c
>>> +++ b/builtin/blame.c
>>> @@ -1105,6 +1105,14 @@ parse_done:
>>>                 add_pending_object(&revs, &head_commit->object, "HEAD");
>>>         }
>>>
>>> +       /*
>>> +       * By default, add .git-blame-ignore-revs to the list of files
>>> +       * containing revisions to ignore if it exists.
>>> +       */
>>> +       if (access(".git-blame-ignore-revs", F_OK) == 0) {
>>> +               string_list_append(&ignore_revs_file_list, ".git-blame-ignore-revs");
>>> +       }
>>> +
>>>         init_scoreboard(&sb);
>>>         sb.revs = &revs;
>>>         sb.contents_from = contents_from;
>>> diff --git a/t/t8015-blame-default-ignore-revs.sh b/t/t8015-blame-default-ignore-revs.sh
>>> new file mode 100755
>>> index 00000000000..84e1a9e87e6
>>> --- /dev/null
>>> +++ b/t/t8015-blame-default-ignore-revs.sh
>>> @@ -0,0 +1,26 @@
>>> +#!/bin/sh
>>> +
>>> +test_description='default revisions to ignore when blaming'
>>> +
>>> +TEST_PASSES_SANITIZE_LEAK=true
>>> +. ./test-lib.sh
>>> +
>>> +test_expect_success 'blame: default-ignore-revs-file' '
>>> +    test_commit first-commit hello.txt hello &&
>>> +
>>> +    echo world >>hello.txt &&
>>> +    test_commit second-commit hello.txt &&
>>> +
>>> +    sed "1s/hello/hi/" <hello.txt > hello.txt.tmp &&
>>> +    mv hello.txt.tmp hello.txt &&
>>> +    test_commit third-commit hello.txt &&
>>> +
>>> +    git rev-parse HEAD >ignored-file &&
>>> +    git blame --ignore-revs-file=ignored-file hello.txt >expect &&
>>> +    git rev-parse HEAD >.git-blame-ignore-revs &&
>>> +    git blame hello.txt >actual &&
>>> +
>>> +    test_cmp expect actual
>>> +'
>>> +
>>> +test_done
>>> \ No newline at end of file
>>>
>>> base-commit: 777489f9e09c8d0dd6b12f9d90de6376330577a2
>>> --
>>> gitgitgadget

Copy link

gitgitgadget bot commented Oct 8, 2024

On the Git mailing list, Abhijeetsingh Meena wrote (reply to this):

Hi Phillip,

Thank you for your feedback on my patch. I appreciate your insights
regarding the decision not to support a default file for the
--ignore-revs-file feature and the concerns related to ignoring
"cleanup" commits that could potentially introduce bugs.

I understand that addressing these concerns is crucial. Specifically,
I will focus on:

1. Ensuring there’s a clear and easy way for users to opt out or
override the default behavior of ignoring certain commits, especially
if they suspect those commits might contain bugs.
2. Investigating how this new feature could interact with existing
configuration options that allow users to specify what should be
ignored manually.

I will take these points into consideration as I work on my changes
and come up with a solution to address these concerns.

Thank you again for your guidance, and I look forward to your
continued feedback!

Best wishes,
Abhijeet (Ethan0456)

On Tue, Oct 8, 2024 at 9:42 PM Abhijeetsingh Meena
<[email protected]> wrote:
>
> Hi Kristoffer,
>
> Thank you so much for your feedback and for taking the time to review
> my patch. I appreciate your suggestions, particularly regarding the
> project convention of using the present tense to describe the current
> behavior, as well as your mention of the --no-ignore-revs-file option
> and the importance of documenting it.
>
> Regarding your first point:
>
> > My assumption then is that, with this change, I could use --no-ignore-revs-file to turn off the default file.
>
> I’ll check how this works in the current setup and get back to you to confirm.
>
> As for your second observation:
>
> > git blame --ignore-revs-file=README.md
> > --no-ignore-revs-file README.md
> > And that works without giving errors. So it’s there. Just apparently undocumented?
>
> I’ll look into opening an issue and submitting a PR to add
> documentation for this, as it seems important to address.
>
> I’m excited to refine the patch with these improvements in mind and
> will continue working on the commit message and necessary
> documentation in line with your feedback.
>
> Thanks again for your guidance and support!
>
> Best regards,
> Abhijeet (Ethan0456)
>
> On Tue, Oct 8, 2024 at 8:53 PM Abhijeetsingh Meena
> <[email protected]> wrote:
> >
> > Hi Phillip,
> >
> > Thank you for your feedback on my patch. I appreciate your insights regarding the decision not to support a default file for the --ignore-revs-file feature and the concerns related to ignoring "cleanup" commits that could potentially introduce bugs.
> >
> > I understand that addressing these concerns is crucial. Specifically, I will focus on:
> >
> > 1. Ensuring there’s a clear and easy way for users to opt out or override the default behavior of ignoring certain commits, especially if they suspect those commits might contain bugs.
> > 2. Investigating how this new feature could interact with existing configuration options that allow users to specify what should be ignored manually.
> >
> > I will take these points into consideration as I work on my changes and come up with a solution to address these concerns.
> >
> > Thank you again for your guidance, and I look forward to your continued feedback!
> >
> > Best wishes,
> > Abhijeet (Ethan0456)
> >
> > On Tue, Oct 8, 2024 at 8:53 PM Abhijeetsingh Meena <[email protected]> wrote:
> >>
> >> Hi Kristoffer,
> >>
> >> Thank you so much for your feedback and for taking the time to review my patch. I appreciate your suggestions, particularly regarding the project convention of using the present tense to describe the current behavior, as well as your mention of the --no-ignore-revs-file option and the importance of documenting it.
> >>
> >> Regarding your first point:
> >>
> >> > My assumption then is that, with this change, I could use --no-ignore-revs-file to turn off the default file.
> >>
> >> I’ll check how this works in the current setup and get back to you to confirm.
> >>
> >> As for your second observation:
> >>
> >> > git blame --ignore-revs-file=README.md
> >> > --no-ignore-revs-file README.md
> >> > And that works without giving errors. So it’s there. Just apparently undocumented?
> >>
> >> I’ll look into opening an issue and submitting a PR to add documentation for this, as it seems important to address.
> >>
> >> I’m excited to refine the patch with these improvements in mind and will continue working on the commit message and necessary documentation in line with your feedback.
> >>
> >> Thanks again for your guidance and support!
> >>
> >> Best regards,
> >> Abhijeet (Ethan0456)
> >>
> >> On Tue, Oct 8, 2024 at 7:54 PM Abhijeetsingh Meena via GitGitGadget <[email protected]> wrote:
> >>>
> >>> From: Abhijeetsingh Meena <[email protected]>
> >>>
> >>> Modify `git blame` to automatically respect a `.git-blame-ignore-revs`
> >>> file if it exists in the repository. This file is used by many projects
> >>> to ignore non-functional changes, such as reformatting or large-scale
> >>> refactoring, when generating blame information.
> >>>
> >>> Before this change, users had to manually specify the file with the
> >>> `--ignore-revs-file` option. This update streamlines the process by
> >>> automatically detecting the `.git-blame-ignore-revs` file, reducing
> >>> manual effort.
> >>>
> >>> This change aligns with the standardized practice in many repositories
> >>> and simplifies the workflow for users.
> >>>
> >>> Signed-off-by: Abhijeetsingh Meena <[email protected]>
> >>> ---
> >>>     blame: respect .git-blame-ignore-revs automatically
> >>>
> >>>
> >>>     Introduction
> >>>     ============
> >>>
> >>>     Hi, I'm Abhijeet (Ethan0456), and this is my first contribution to the
> >>>     Git project. I currently work as an ML Engineer at an early-stage
> >>>     startup, and I’m excited to contribute to this open-source project.
> >>>
> >>>
> >>>     Why the Change?
> >>>     ===============
> >>>
> >>>     I came across this enhancement request on the bug tracker and found it
> >>>     beginner-friendly, making it a great opportunity for me to get familiar
> >>>     with the Git codebase. The ability for git blame to automatically
> >>>     respect the .git-blame-ignore-revs file is something that can streamline
> >>>     workflows for many users, and I felt it would be a valuable addition.
> >>>
> >>>
> >>>     Feedback
> >>>     ========
> >>>
> >>>     While I’m confident in the changes made to builtin/blame.c and the new
> >>>     test case in t/t8015-blame-ignore-revs.sh, I welcome any feedback or
> >>>     suggestions to improve both my code and approach. I’m eager to learn
> >>>     from the community and improve where needed.
> >>>
> >>>
> >>>     Community Need
> >>>     ==============
> >>>
> >>>     There is precedent for this functionality in other projects:
> >>>
> >>>      * Chromium
> >>>        [https://chromium.googlesource.com/chromium/src.git/+/f0596779e57f46fccb115a0fd65f0305894e3031/.git-blame-ignore-revs],
> >>>        which powers many popular browsers, uses .git-blame-ignore-revs to
> >>>        simplify the blame process by ignoring non-functional changes.
> >>>      * Rob Allen's blog post
> >>>        [https://akrabat.com/ignoring-revisions-with-git-blame/] discusses
> >>>        the need for ignoring revisions with git blame, and a commenter
> >>>        specifically suggests that it would be helpful if Git automatically
> >>>        respected .git-blame-ignore-revs.
> >>>
> >>>     I hope this change aligns with community needs and improves the git
> >>>     blame experience for users.
> >>>
> >>> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1809%2FEthan0456%2Fblame-auto-ignore-revs-v2
> >>> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1809/Ethan0456/blame-auto-ignore-revs-v2
> >>> Pull-Request: https://github.com/gitgitgadget/git/pull/1809
> >>>
> >>> Range-diff vs v1:
> >>>
> >>>  1:  666404681d9 = 1:  666404681d9 blame: respect .git-blame-ignore-revs automatically
> >>>
> >>>
> >>>  builtin/blame.c                      |  8 ++++++++
> >>>  t/t8015-blame-default-ignore-revs.sh | 26 ++++++++++++++++++++++++++
> >>>  2 files changed, 34 insertions(+)
> >>>  create mode 100755 t/t8015-blame-default-ignore-revs.sh
> >>>
> >>> diff --git a/builtin/blame.c b/builtin/blame.c
> >>> index e407a22da3b..1eddabaf60f 100644
> >>> --- a/builtin/blame.c
> >>> +++ b/builtin/blame.c
> >>> @@ -1105,6 +1105,14 @@ parse_done:
> >>>                 add_pending_object(&revs, &head_commit->object, "HEAD");
> >>>         }
> >>>
> >>> +       /*
> >>> +       * By default, add .git-blame-ignore-revs to the list of files
> >>> +       * containing revisions to ignore if it exists.
> >>> +       */
> >>> +       if (access(".git-blame-ignore-revs", F_OK) == 0) {
> >>> +               string_list_append(&ignore_revs_file_list, ".git-blame-ignore-revs");
> >>> +       }
> >>> +
> >>>         init_scoreboard(&sb);
> >>>         sb.revs = &revs;
> >>>         sb.contents_from = contents_from;
> >>> diff --git a/t/t8015-blame-default-ignore-revs.sh b/t/t8015-blame-default-ignore-revs.sh
> >>> new file mode 100755
> >>> index 00000000000..84e1a9e87e6
> >>> --- /dev/null
> >>> +++ b/t/t8015-blame-default-ignore-revs.sh
> >>> @@ -0,0 +1,26 @@
> >>> +#!/bin/sh
> >>> +
> >>> +test_description='default revisions to ignore when blaming'
> >>> +
> >>> +TEST_PASSES_SANITIZE_LEAK=true
> >>> +. ./test-lib.sh
> >>> +
> >>> +test_expect_success 'blame: default-ignore-revs-file' '
> >>> +    test_commit first-commit hello.txt hello &&
> >>> +
> >>> +    echo world >>hello.txt &&
> >>> +    test_commit second-commit hello.txt &&
> >>> +
> >>> +    sed "1s/hello/hi/" <hello.txt > hello.txt.tmp &&
> >>> +    mv hello.txt.tmp hello.txt &&
> >>> +    test_commit third-commit hello.txt &&
> >>> +
> >>> +    git rev-parse HEAD >ignored-file &&
> >>> +    git blame --ignore-revs-file=ignored-file hello.txt >expect &&
> >>> +    git rev-parse HEAD >.git-blame-ignore-revs &&
> >>> +    git blame hello.txt >actual &&
> >>> +
> >>> +    test_cmp expect actual
> >>> +'
> >>> +
> >>> +test_done
> >>> \ No newline at end of file
> >>>
> >>> base-commit: 777489f9e09c8d0dd6b12f9d90de6376330577a2
> >>> --
> >>> gitgitgadget

git-blame(1) can ignore a list of commits with `--ignore-revs-file`.
This is useful for marking uninteresting commits like formatting
changes, refactors and whatever else should not be “blamed”.  Some
projects even version control this file so that all contributors can
use it; the conventional name is `.git-blame-ignore-revs`.

But each user still has to opt-in to the standard ignore list,
either with this option or with the config `blame.ignoreRevsFile`.
Let’s teach git-blame(1) to respect this conventional file in order
to streamline the process.

Signed-off-by: Abhijeetsingh Meena <[email protected]>
The git blame command can ignore a list of revisions specified either
through the --ignore-revs-file option or the blame.ignoreRevsFile
configuration. This feature is useful for excluding irrelevant
commits, such as formatting changes or large refactors, from blame
annotations.

However, users may encounter cases where they need to
temporarily override these configurations to inspect all commits,
even those excluded by the ignore list. Currently, there is no
simple way to bypass all ignore revisions settings in one go.

This patch introduces the --override-ignore-revs option (or -O),
which allows users to easily bypass the --ignore-revs-file
option, --ignore-rev option and the blame.ignoreRevsFile
configuration. When this option is used, git blame will completely
disregard all configured ignore revisions lists.

The motivation behind this feature is to provide users with more
flexibility when dealing with large codebases that rely on
.git-blame-ignore-revs files for shared configurations, while
still allowing them to disable the ignore list when necessary
for troubleshooting or deeper inspections.

Signed-off-by: Abhijeetsingh Meena <[email protected]>
Copy link

gitgitgadget bot commented Oct 12, 2024

User Eric Sunshine <[email protected]> has been added to the cc: list.

@@ -69,6 +69,7 @@ static int coloring_mode;
static struct string_list ignore_revs_file_list = STRING_LIST_INIT_DUP;
Copy link

Choose a reason for hiding this comment

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

On the Git mailing list, Eric Sunshine wrote (reply to this):

On Sat, Oct 12, 2024 at 12:38 AM Abhijeetsingh Meena via GitGitGadget
<[email protected]> wrote:
> The git blame command can ignore a list of revisions specified either
> through the --ignore-revs-file option or the blame.ignoreRevsFile
> configuration. This feature is useful for excluding irrelevant
> commits, such as formatting changes or large refactors, from blame
> annotations.
>
> However, users may encounter cases where they need to
> temporarily override these configurations to inspect all commits,
> even those excluded by the ignore list. Currently, there is no
> simple way to bypass all ignore revisions settings in one go.
>
> This patch introduces the --override-ignore-revs option (or -O),
> which allows users to easily bypass the --ignore-revs-file
> option, --ignore-rev option and the blame.ignoreRevsFile
> configuration. When this option is used, git blame will completely
> disregard all configured ignore revisions lists.

It's not clear from this description whether ".git-blame-ignore-revs"
is also ignored by --override-ignore-revs. Looking at the
implementation, it appears that it is, but it would be good to state
so here.

> The motivation behind this feature is to provide users with more
> flexibility when dealing with large codebases that rely on
> .git-blame-ignore-revs files for shared configurations, while
> still allowing them to disable the ignore list when necessary
> for troubleshooting or deeper inspections.
>
> Signed-off-by: Abhijeetsingh Meena <[email protected]>
> ---
> diff --git a/builtin/blame.c b/builtin/blame.c
> @@ -901,6 +902,7 @@ int cmd_blame(int argc,
>                 OPT_STRING_LIST(0, "ignore-rev", &ignore_rev_list, N_("rev"), N_("ignore <rev> when blaming")),
>                 OPT_STRING_LIST(0, "ignore-revs-file", &ignore_revs_file_list, N_("file"), N_("ignore revisions from <file>")),
> +               OPT_BOOL('O', "override-ignore-revs", &override_ignore_revs, N_("override all configurations that exclude revisions")),

We don't normally allocate a short option name ("-O" in this case)
when introducing a new option since short option names are considered
a valuable and limited resource. A short option name may be added
*later* if experience shows that the option is popular enough that the
convenience of the short option name is warranted.

> @@ -1119,7 +1121,11 @@ parse_done:
> -       build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list);
> +
> +       if (!override_ignore_revs) {
> +               build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list);
> +       }

A style nit and questions and observations...

nit: drop the braces around the one-line `if` body

Is the all-or-nothing behavior implemented by this patch desirable? If
so, should the command warn or error out if the user gives conflicting
options like --ignore-revs-file and --override-ignore-revs together?

A common behavior of many Git commands when dealing with options is
"last wins", and following that precedent could make this new option
even much more useful by allowing the user to ignore project-supplied
ignore-revs but still take advantage of the feature with a different
set of ignore-revs that make sense to the local user. For instance:

    git blame --override-ignore-revs --ignore-revs-file=my-ignore-revs ...

> diff --git a/t/t8016-blame-override-ignore-revs.sh b/t/t8016-blame-override-ignore-revs.sh
> new file mode 100755

Let's avoid allocating a new test number just for this single new
test. Instead, the existing t8013-blame-ignore-revs.sh would probably
be a good home for this new test.

> @@ -0,0 +1,25 @@
> +test_expect_success 'blame: override-ignore-revs' '
> +    test_commit first-commit hello.txt hello &&
> +
> +    echo world >>hello.txt &&
> +    test_commit second-commit hello.txt &&
> +
> +    sed "1s/hello/hi/" <hello.txt > hello.txt.tmp &&

style: drop space after redirection operator

    sed "1s/hello/hi/" <hello.txt >hello.txt.tmp &&

> +    mv hello.txt.tmp hello.txt &&
> +    test_commit third-commit hello.txt &&
> +
> +    git blame hello.txt >expect &&
> +    git rev-parse HEAD >.git-blame-ignore-revs &&
> +    git blame -O hello.txt >actual &&
> +
> +    test_cmp expect actual
> +'

What is this test actually checking? It doesn't seem to use
--override-ignore-revs at all.

Copy link

Choose a reason for hiding this comment

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

On the Git mailing list, Eric Sunshine wrote (reply to this):

On Sat, Oct 12, 2024 at 2:24 AM Eric Sunshine <[email protected]> wrote:
> On Sat, Oct 12, 2024 at 12:38 AM Abhijeetsingh Meena via GitGitGadget
> <[email protected]> wrote:
> > [...]
> > This patch introduces the --override-ignore-revs option (or -O),
> > which allows users to easily bypass the --ignore-revs-file
> > option, --ignore-rev option and the blame.ignoreRevsFile
> > configuration. When this option is used, git blame will completely
> > disregard all configured ignore revisions lists.
> > +               OPT_BOOL('O', "override-ignore-revs", &override_ignore_revs, N_("override all configurations that exclude revisions")),
>
> We don't normally allocate a short option name ("-O" in this case)
> when introducing a new option since short option names are considered
> a valuable and limited resource. A short option name may be added
> *later* if experience shows that the option is popular enough that the
> convenience of the short option name is warranted.

I forgot to mention that this patch also deserves a documentation
update; otherwise how are users going to know that the new option
exists?

@@ -1105,6 +1105,14 @@ int cmd_blame(int argc,
add_pending_object(&revs, &head_commit->object, "HEAD");
Copy link

Choose a reason for hiding this comment

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

On the Git mailing list, "Kristoffer Haugsbakk" wrote (reply to this):

Hi Abhijeetsingh

For what it’s worth here’s how I imagine this feature could work
conceptually:

Before this feature/change, the effective config for Git use looks like this:

```
[blame]
```

No `blame.ignoreRevsFile`.

But with/after it:

```
[blame]
	ignoreRevsFile=.git-blame-ignore-revs
```

This is the effective config.  Not what the user has typed out.

If the user types out this:

```
[blame]
	ignoreRevsFile=.git-blame-more-revs
```

Then this becomes their effective config:

```
[blame]
	ignoreRevsFile=.git-blame-ignore-revs
	ignoreRevsFile=.git-blame-more-revs
```

Now there are two files: the default one and the user-supplied one (this
config variable is documented as being multi-valued: “This option may be
repeated multiple times.”).

§ How to ignore this new default §§§

Considering users who do not want this new default:

```
[blame]
	ignoreRevsFile=
```

This is the change they would have to make.  Because a blank/empty
resets/empties the list of files.

On Sat, Oct 12, 2024, at 06:37, Abhijeetsingh Meena via GitGitGadget wrote:
> From: Abhijeetsingh Meena <[email protected]>
>
> git-blame(1) can ignore a list of commits with `--ignore-revs-file`.
> This is useful for marking uninteresting commits like formatting
> changes, refactors and whatever else should not be “blamed”.  Some
> projects even version control this file so that all contributors can
> use it; the conventional name is `.git-blame-ignore-revs`.
>
> But each user still has to opt-in to the standard ignore list,
> either with this option or with the config `blame.ignoreRevsFile`.
> Let’s teach git-blame(1) to respect this conventional file in order
> to streamline the process.
>
> Signed-off-by: Abhijeetsingh Meena <[email protected]>
> ---
>  builtin/blame.c                      |  8 ++++++++
>  t/t8015-blame-default-ignore-revs.sh | 26 ++++++++++++++++++++++++++
>  2 files changed, 34 insertions(+)
>  create mode 100755 t/t8015-blame-default-ignore-revs.sh
>
> diff --git a/builtin/blame.c b/builtin/blame.c
> index e407a22da3b..1eddabaf60f 100644
> --- a/builtin/blame.c
> +++ b/builtin/blame.c
> @@ -1105,6 +1105,14 @@ parse_done:
>  		add_pending_object(&revs, &head_commit->object, "HEAD");
>  	}
>
> +	/*
> +	* By default, add .git-blame-ignore-revs to the list of files
> +	* containing revisions to ignore if it exists.
> +	*/
> +	if (access(".git-blame-ignore-revs", F_OK) == 0) {
> +		string_list_append(&ignore_revs_file_list, ".git-blame-ignore-revs");
> +	}
> +

I have not tested these patches.  But I see why you check for file access/existence.  Because with this config:

```
[blame]
	ignoreRevsFile=.git-blame-ignore-revs
```

I get this warning in repositories that don’t have the file:

```
fatal: could not open object name list: .git-blame-ignore-revs
```

Which is just noise.

I get the same thing with Git Notes namespace configurations.  I need to
configure them for certain repositories (like `amlog` in this project),
but then I get warnings about them when using the relevant commands in a
project that does not have them.

Maybe this is totally off-topic but I think it would make more sense if
`blame.ignoreRevsFile` just didn’t say anything if it didn’t find the
file.  Because the point of the config might be to opt-in to this file
for those projects that does have it.

>  	init_scoreboard(&sb);
>  	sb.revs = &revs;
>  	sb.contents_from = contents_from;
> diff --git a/t/t8015-blame-default-ignore-revs.sh
> b/t/t8015-blame-default-ignore-revs.sh
> new file mode 100755
> index 00000000000..d4ab686f14d
> --- /dev/null
> +++ b/t/t8015-blame-default-ignore-revs.sh
> @@ -0,0 +1,26 @@
> +#!/bin/sh
> +
> +test_description='default revisions to ignore when blaming'
> +
> +TEST_PASSES_SANITIZE_LEAK=true
> +. ./test-lib.sh
> +
> +test_expect_success 'blame: default-ignore-revs-file' '
> +    test_commit first-commit hello.txt hello &&
> +
> +    echo world >>hello.txt &&
> +    test_commit second-commit hello.txt &&
> +
> +    sed "1s/hello/hi/" <hello.txt > hello.txt.tmp &&
> +    mv hello.txt.tmp hello.txt &&
> +    test_commit third-commit hello.txt &&
> +
> +    git rev-parse HEAD >ignored-file &&
> +    git blame --ignore-revs-file=ignored-file hello.txt >expect &&
> +    git rev-parse HEAD >.git-blame-ignore-revs &&
> +    git blame hello.txt >actual &&
> +
> +    test_cmp expect actual
> +'
> +
> +test_done
> --
> gitgitgadget

-- 
Kristoffer

Copy link

Choose a reason for hiding this comment

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

On the Git mailing list, Phillip Wood wrote (reply to this):

Hi Kristoffer

On 12/10/2024 14:58, Kristoffer Haugsbakk wrote:
> Hi Abhijeetsingh
> > Maybe this is totally off-topic but I think it would make more sense if
> `blame.ignoreRevsFile` just didn’t say anything if it didn’t find the
> file.  Because the point of the config might be to opt-in to this file
> for those projects that does have it.

See https://lore.kernel.org/git/[email protected]/ for some discussion about this

Best Wishes

Phillip

Copy link

Choose a reason for hiding this comment

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

On the Git mailing list, "Kristoffer Haugsbakk" wrote (reply to this):

On Sun, Oct 13, 2024, at 17:25, Phillip Wood wrote:
> Hi Kristoffer
>> […]
>
> See https://lore.kernel.org/git/[email protected]/ for some
> discussion about this
>
> Best Wishes
>
> Phillip

Thanks!  That was an interesting read.  And an interesting idea.

And then today we got this:

https://lore.kernel.org/git/[email protected]/T/#mce170a493a7b324c585124a9124356a0f87c77a6

-- 
Kristoffer

Copy link

Choose a reason for hiding this comment

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

On the Git mailing list, Abhijeetsingh Meena wrote (reply to this):

Hi Kristoffer,

Thank you for reviewing the v2 of my patch. I appreciate your
thoughtful feedback.
Before proceeding with v3, I’d like to address some of your questions
and suggestions.

> Hi Abhijeetsingh
>
> For what it’s worth here’s how I imagine this feature could work
> conceptually:
>
> Before this feature/change, the effective config for Git use looks like this:
>
> ```
> [blame]
> ```
>
> No `blame.ignoreRevsFile`.
>
> But with/after it:
>
> ```
> [blame]
>         ignoreRevsFile=.git-blame-ignore-revs
> ```
>
> This is the effective config.  Not what the user has typed out.
>
> If the user types out this:
>
> ```
> [blame]
>         ignoreRevsFile=.git-blame-more-revs
> ```
>
> Then this becomes their effective config:
>
> ```
> [blame]
>         ignoreRevsFile=.git-blame-ignore-revs
>         ignoreRevsFile=.git-blame-more-revs
> ```
>
> Now there are two files: the default one and the user-supplied one (this
> config variable is documented as being multi-valued: “This option may be
> repeated multiple times.”).
>
> § How to ignore this new default §§§
>
> Considering users who do not want this new default:
>
> ```
> [blame]
>         ignoreRevsFile=
> ```
>
> This is the change they would have to make.  Because a blank/empty
> resets/empties the list of files.

Thanks, Kristoffer. Your conceptual explanation gave me a new
perspective on how this
feature can be implemented using the existing configuration flow
without disrupting
other settings. It has helped shape the solution, as I described in my
response to Eric earlier.

Based on Phillip's clue of exploring how this feature would interact
with existing configuration
settings and your conceptual workflow, I explored git_config_set and
used it to set the
blame.ignoreRevsFile configuration. This approach fits well with the
existing configuration
logic and provides greater flexibility.

With git_config_set to set blame.ignoreRevsFile:

git blame hello.txt
would consult the default .git-blame-ignore-revs file.

git blame --no-ignore-revs-file hello.txt
would disable the default ignore file.

git blame --no-ignore-revs-file --ignore-revs-file=ignore-list hello.txt
would allow the user to specify a custom ignore list while bypassing
the global list,
offering the flexibility you suggested.

This would maintain consistency with Git’s existing behavior, allowing
users to modify
configurations with a “last-wins” approach and enabling both global
and custom ignore
lists as needed.


> I have not tested these patches.  But I see why you check for file access/existence.  Because with this config:
>
> ```
> [blame]
>         ignoreRevsFile=.git-blame-ignore-revs
> ```
>
> I get this warning in repositories that don’t have the file:
>
> ```
> fatal: could not open object name list: .git-blame-ignore-revs
> ```
>
> Which is just noise.
>
> I get the same thing with Git Notes namespace configurations.  I need to
> configure them for certain repositories (like `amlog` in this project),
> but then I get warnings about them when using the relevant commands in a
> project that does not have them.
>
> Maybe this is totally off-topic but I think it would make more sense if
> `blame.ignoreRevsFile` just didn’t say anything if it didn’t find the
> file.  Because the point of the config might be to opt-in to this file
> for those projects that does have it.

Yes, I agree. For a default ignore file, we shouldn't raise a fatal
error if the file is missing, especially if it’s not present in every
repository.
Suppressing the warning for the default file would improve user experience
and prevent unnecessary noise.


> > However, users may encounter cases where they need to
> > temporarily override these configurations to inspect all commits,
> > even those excluded by the ignore list. Currently, there is no
> > simple way to bypass all ignore revisions settings in one go.
>
> “No simple way” gives me pause.  But there are those options/methods
> that we discussed before:
>
> • `--no-ignore-rev`
> • `--no-ignore-revs-file`
>
> These are not documented but I can provide these options and get a
> different output from git-blame(1).
>
> `builtin/blame.c` uses `parse-options.h` which provides automatic
> negated options.  I just looked at the code today (so it’s new to me)
> but it seems like it will empty the lists that are associated with these
> options.  See `parse-options-cb.c:parse_opt_string_list`.
>
> So I think this should be sufficient to reset all “ignore” options:
>
> ```
> git blame --no-ignore-rev --no-ignore-revs-file
> ```
>
> However I tested with this:
>
> ```
> git blame --ignore-revs-file=.git-blame-ignore-revs --no-ignore-revs
> ```
>
> And the output suggests to me that `--no-ignore-revs` affect the result
> of the before-mentioned list of files.  Even though these are two
> different lists.  I can’t make sense of that from the code.  But I’m not
> a C programmer so this might just be a me-problem.

Yes, --no-ignore-revs-file and --no-ignore-rev flags work as intended
to bypass the configuration that ignores revisions. They are separate lists, so
--no-ignore-revs shouldn’t affect the --ignore-revs-file list. My previous
 testing post v1 had some issues in test setup, which led me to believe that
the --no-ignore flags don’t work and I worked on --override-ignore-revs.


> > which allows users to easily bypass the --ignore-revs-file
> > option, --ignore-rev option and the blame.ignoreRevsFile
>
> I can see no precedence for the name “override” for an option in this
> project.  The convention is `--[no-]option`.
>
> Like Eric Sunshine discussed: a common convention is to let the user
> activate and negate options according to the last-wins rule.  This is
> pretty useful in my opinion.  Because I can then make an alias which
> displays some Git Note:
>
> ```
> timber = log [options] --notes=results
> ```
>
> But then what if I don’t want any notes for a specific invocation?  I
> don’t have to copy the whole alias and modify it.  I can just:
>
> ```
> git timber --no-notes
> ```
>
> And the same goes for an alias which disables notes:
>
> ```
> timber = log [options] --no-notes
> ```
>
> Because then I can use `git timber --notes=results`.

I agree that the override option is unnecessary, as both
--no-ignore-rev and --no-ignore-revs-file
already allow users to bypass the ignore configurations. Also, the
“last-wins” approach is more
useful and aligns with how Git typically handles configurations. It’s
flexible and user-friendly,
allowing for easy toggling within aliases or individual commands.
Implementing this using the
existing configuration method, such as git_config_set, would be a
clean and effective solution
to ensure that users can quickly modify or negate options as needed.


> > configuration. When this option is used, git blame will completely
> > disregard all configured ignore revisions lists.
> >> The motivation behind this feature is to provide users with more
> > flexibility when dealing with large codebases that rely on
> > .git-blame-ignore-revs files for shared configurations, while
> > still allowing them to disable the ignore list when necessary
> > for troubleshooting or deeper inspections.
>
> You might be able to achieve the same thing with the existing negated
> options.
>
> If you *cannot* disable all “ignore” config and options in one negated
> one then you might want an option like `--no-ignores` which acts like:
>
> ```
> git blame --no-ignore-rev --no-ignore-revs-file
> ```

Yes, the override option isn’t necessary since the existing flags work
as intended.
If needed in the future, we can add a single flag to reset both lists, or as you
mentioned it can be an alias too.


> > + if (!override_ignore_revs) {
> > + build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list);
> > + }
> > +
>
> This demonstrates the more limited behavior: you either override
> (discard) the ignores or you don’t.  With the negated options you build
> up and reset/empty those lists before you get to this point.  That ends
> up being more flexible for the user.

Yes, this approach was more limited, we can follow the approach
described earlier that uses git_config_set to handle ignoring
revisions and revision lists more flexibly.


Thanks again for your detailed feedback. I hope this approach is
better than my previous approach.
I’ll incorporate these changes and move forward with v3. Looking
forward to your further thoughts!

Best regards,
Abhijeetsingh

On Sat, Oct 12, 2024 at 7:28 PM Kristoffer Haugsbakk
<[email protected]> wrote:
>
> Hi Abhijeetsingh
>
> For what it’s worth here’s how I imagine this feature could work
> conceptually:
>
> Before this feature/change, the effective config for Git use looks like this:
>
> ```
> [blame]
> ```
>
> No `blame.ignoreRevsFile`.
>
> But with/after it:
>
> ```
> [blame]
>         ignoreRevsFile=.git-blame-ignore-revs
> ```
>
> This is the effective config.  Not what the user has typed out.
>
> If the user types out this:
>
> ```
> [blame]
>         ignoreRevsFile=.git-blame-more-revs
> ```
>
> Then this becomes their effective config:
>
> ```
> [blame]
>         ignoreRevsFile=.git-blame-ignore-revs
>         ignoreRevsFile=.git-blame-more-revs
> ```
>
> Now there are two files: the default one and the user-supplied one (this
> config variable is documented as being multi-valued: “This option may be
> repeated multiple times.”).
>
> § How to ignore this new default §§§
>
> Considering users who do not want this new default:
>
> ```
> [blame]
>         ignoreRevsFile=
> ```
>
> This is the change they would have to make.  Because a blank/empty
> resets/empties the list of files.
>
> On Sat, Oct 12, 2024, at 06:37, Abhijeetsingh Meena via GitGitGadget wrote:
> > From: Abhijeetsingh Meena <[email protected]>
> >
> > git-blame(1) can ignore a list of commits with `--ignore-revs-file`.
> > This is useful for marking uninteresting commits like formatting
> > changes, refactors and whatever else should not be “blamed”.  Some
> > projects even version control this file so that all contributors can
> > use it; the conventional name is `.git-blame-ignore-revs`.
> >
> > But each user still has to opt-in to the standard ignore list,
> > either with this option or with the config `blame.ignoreRevsFile`.
> > Let’s teach git-blame(1) to respect this conventional file in order
> > to streamline the process.
> >
> > Signed-off-by: Abhijeetsingh Meena <[email protected]>
> > ---
> >  builtin/blame.c                      |  8 ++++++++
> >  t/t8015-blame-default-ignore-revs.sh | 26 ++++++++++++++++++++++++++
> >  2 files changed, 34 insertions(+)
> >  create mode 100755 t/t8015-blame-default-ignore-revs.sh
> >
> > diff --git a/builtin/blame.c b/builtin/blame.c
> > index e407a22da3b..1eddabaf60f 100644
> > --- a/builtin/blame.c
> > +++ b/builtin/blame.c
> > @@ -1105,6 +1105,14 @@ parse_done:
> >               add_pending_object(&revs, &head_commit->object, "HEAD");
> >       }
> >
> > +     /*
> > +     * By default, add .git-blame-ignore-revs to the list of files
> > +     * containing revisions to ignore if it exists.
> > +     */
> > +     if (access(".git-blame-ignore-revs", F_OK) == 0) {
> > +             string_list_append(&ignore_revs_file_list, ".git-blame-ignore-revs");
> > +     }
> > +
>
> I have not tested these patches.  But I see why you check for file access/existence.  Because with this config:
>
> ```
> [blame]
>         ignoreRevsFile=.git-blame-ignore-revs
> ```
>
> I get this warning in repositories that don’t have the file:
>
> ```
> fatal: could not open object name list: .git-blame-ignore-revs
> ```
>
> Which is just noise.
>
> I get the same thing with Git Notes namespace configurations.  I need to
> configure them for certain repositories (like `amlog` in this project),
> but then I get warnings about them when using the relevant commands in a
> project that does not have them.
>
> Maybe this is totally off-topic but I think it would make more sense if
> `blame.ignoreRevsFile` just didn’t say anything if it didn’t find the
> file.  Because the point of the config might be to opt-in to this file
> for those projects that does have it.
>
> >       init_scoreboard(&sb);
> >       sb.revs = &revs;
> >       sb.contents_from = contents_from;
> > diff --git a/t/t8015-blame-default-ignore-revs.sh
> > b/t/t8015-blame-default-ignore-revs.sh
> > new file mode 100755
> > index 00000000000..d4ab686f14d
> > --- /dev/null
> > +++ b/t/t8015-blame-default-ignore-revs.sh
> > @@ -0,0 +1,26 @@
> > +#!/bin/sh
> > +
> > +test_description='default revisions to ignore when blaming'
> > +
> > +TEST_PASSES_SANITIZE_LEAK=true
> > +. ./test-lib.sh
> > +
> > +test_expect_success 'blame: default-ignore-revs-file' '
> > +    test_commit first-commit hello.txt hello &&
> > +
> > +    echo world >>hello.txt &&
> > +    test_commit second-commit hello.txt &&
> > +
> > +    sed "1s/hello/hi/" <hello.txt > hello.txt.tmp &&
> > +    mv hello.txt.tmp hello.txt &&
> > +    test_commit third-commit hello.txt &&
> > +
> > +    git rev-parse HEAD >ignored-file &&
> > +    git blame --ignore-revs-file=ignored-file hello.txt >expect &&
> > +    git rev-parse HEAD >.git-blame-ignore-revs &&
> > +    git blame hello.txt >actual &&
> > +
> > +    test_cmp expect actual
> > +'
> > +
> > +test_done
> > --
> > gitgitgadget
>
> --
> Kristoffer

@@ -69,6 +69,7 @@ static int coloring_mode;
static struct string_list ignore_revs_file_list = STRING_LIST_INIT_DUP;
Copy link

Choose a reason for hiding this comment

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

On the Git mailing list, "Kristoffer Haugsbakk" wrote (reply to this):

On Sat, Oct 12, 2024, at 06:37, Abhijeetsingh Meena via GitGitGadget wrote:
> From: Abhijeetsingh Meena <[email protected]>
>
> The git blame command can ignore a list of revisions specified either
> through the --ignore-revs-file option or the blame.ignoreRevsFile
> configuration. This feature is useful for excluding irrelevant
> commits, such as formatting changes or large refactors, from blame
> annotations.

In a later paragraph you mention `--ignore-rev` but not here.

> However, users may encounter cases where they need to
> temporarily override these configurations to inspect all commits,
> even those excluded by the ignore list. Currently, there is no
> simple way to bypass all ignore revisions settings in one go.

“No simple way” gives me pause.  But there are those options/methods
that we discussed before:

• `--no-ignore-rev`
• `--no-ignore-revs-file`

These are not documented but I can provide these options and get a
different output from git-blame(1).

`builtin/blame.c` uses `parse-options.h` which provides automatic
negated options.  I just looked at the code today (so it’s new to me)
but it seems like it will empty the lists that are associated with these
options.  See `parse-options-cb.c:parse_opt_string_list`.

So I think this should be sufficient to reset all “ignore” options:

```
git blame --no-ignore-rev --no-ignore-revs-file
```

However I tested with this:

```
git blame --ignore-revs-file=.git-blame-ignore-revs --no-ignore-revs
```

And the output suggests to me that `--no-ignore-revs` affect the result
of the before-mentioned list of files.  Even though these are two
different lists.  I can’t make sense of that from the code.  But I’m not
a C programmer so this might just be a me-problem.

>
> This patch introduces the --override-ignore-revs option (or -O),

Phrases like “this patch” is discouraged compared to the imperative mood
style of commanding the code base to change (so to speak).  See
`imperative-mood` in Documentation/SubmittingPatches.

> which allows users to easily bypass the --ignore-revs-file
> option, --ignore-rev option and the blame.ignoreRevsFile

I can see no precedence for the name “override” for an option in this
project.  The convention is `--[no-]option`.

Like Eric Sunshine discussed: a common convention is to let the user
activate and negate options according to the last-wins rule.  This is
pretty useful in my opinion.  Because I can then make an alias which
displays some Git Note:

```
timber = log [options] --notes=results
```

But then what if I don’t want any notes for a specific invocation?  I
don’t have to copy the whole alias and modify it.  I can just:

```
git timber --no-notes
```

And the same goes for an alias which disables notes:

```
timber = log [options] --no-notes
```

Because then I can use `git timber --notes=results`.

> configuration. When this option is used, git blame will completely
> disregard all configured ignore revisions lists.
>
> The motivation behind this feature is to provide users with more
> flexibility when dealing with large codebases that rely on
> .git-blame-ignore-revs files for shared configurations, while
> still allowing them to disable the ignore list when necessary
> for troubleshooting or deeper inspections.

You might be able to achieve the same thing with the existing negated
options.

If you *cannot* disable all “ignore” config and options in one negated
one then you might want an option like `--no-ignores` which acts like:

```
git blame --no-ignore-rev --no-ignore-revs-file
```

>
> Signed-off-by: Abhijeetsingh Meena <[email protected]>
> ---
>  builtin/blame.c                       |  8 +++++++-
>  t/t8016-blame-override-ignore-revs.sh | 25 +++++++++++++++++++++++++
>  2 files changed, 32 insertions(+), 1 deletion(-)
>  create mode 100755 t/t8016-blame-override-ignore-revs.sh
>
> diff --git a/builtin/blame.c b/builtin/blame.c
> index 1eddabaf60f..956520edcd9 100644
> --- a/builtin/blame.c
> +++ b/builtin/blame.c
> @@ -69,6 +69,7 @@ static int coloring_mode;
>  static struct string_list ignore_revs_file_list = STRING_LIST_INIT_DUP;
>  static int mark_unblamable_lines;
>  static int mark_ignored_lines;
> +static int override_ignore_revs = 0;
>
>  static struct date_mode blame_date_mode = { DATE_ISO8601 };
>  static size_t blame_date_width;
> @@ -901,6 +902,7 @@ int cmd_blame(int argc,
>  		OPT_BIT('w', NULL, &xdl_opts, N_("ignore whitespace differences"),
> XDF_IGNORE_WHITESPACE),
>  		OPT_STRING_LIST(0, "ignore-rev", &ignore_rev_list, N_("rev"),
> N_("ignore <rev> when blaming")),
>  		OPT_STRING_LIST(0, "ignore-revs-file", &ignore_revs_file_list,
> N_("file"), N_("ignore revisions from <file>")),
> +		OPT_BOOL('O', "override-ignore-revs", &override_ignore_revs,
> N_("override all configurations that exclude revisions")),
>  		OPT_BIT(0, "color-lines", &output_option, N_("color redundant
> metadata from previous line differently"), OUTPUT_COLOR_LINE),
>  		OPT_BIT(0, "color-by-age", &output_option, N_("color lines by age"),
> OUTPUT_SHOW_AGE_WITH_COLOR),
>  		OPT_BIT(0, "minimal", &xdl_opts, N_("spend extra cycles to find
> better match"), XDF_NEED_MINIMAL),
> @@ -1119,7 +1121,11 @@ parse_done:
>  	sb.reverse = reverse;
>  	sb.repo = the_repository;
>  	sb.path = path;
> -	build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list);
> +
> +	if (!override_ignore_revs) {
> +		build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list);
> +	}
> +

This demonstrates the more limited behavior: you either override
(discard) the ignores or you don’t.  With the negated options you build
up and reset/empty those lists before you get to this point.  That ends
up being more flexible for the user.

>  	string_list_clear(&ignore_revs_file_list, 0);
>  	string_list_clear(&ignore_rev_list, 0);
>  	setup_scoreboard(&sb, &o);
> diff --git a/t/t8016-blame-override-ignore-revs.sh
> b/t/t8016-blame-override-ignore-revs.sh
> new file mode 100755
> index 00000000000..b5899729f8e
> --- /dev/null
> +++ b/t/t8016-blame-override-ignore-revs.sh
> @@ -0,0 +1,25 @@
> +#!/bin/sh
> +
> +test_description='default revisions to ignore when blaming'
> +
> +TEST_PASSES_SANITIZE_LEAK=true
> +. ./test-lib.sh
> +
> +test_expect_success 'blame: override-ignore-revs' '
> +    test_commit first-commit hello.txt hello &&
> +
> +    echo world >>hello.txt &&
> +    test_commit second-commit hello.txt &&
> +
> +    sed "1s/hello/hi/" <hello.txt > hello.txt.tmp &&
> +    mv hello.txt.tmp hello.txt &&
> +    test_commit third-commit hello.txt &&
> +
> +    git blame hello.txt >expect &&
> +    git rev-parse HEAD >.git-blame-ignore-revs &&
> +    git blame -O hello.txt >actual &&
> +
> +    test_cmp expect actual
> +'
> +
> +test_done
> --
> gitgitgadget

@@ -1105,6 +1105,14 @@ int cmd_blame(int argc,
add_pending_object(&revs, &head_commit->object, "HEAD");
Copy link

Choose a reason for hiding this comment

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

On the Git mailing list, Phillip Wood wrote (reply to this):

Hi Abhijeetsingh

On 12/10/2024 05:37, Abhijeetsingh Meena via GitGitGadget wrote:
> From: Abhijeetsingh Meena <[email protected]>
> > git-blame(1) can ignore a list of commits with `--ignore-revs-file`.
> This is useful for marking uninteresting commits like formatting
> changes, refactors and whatever else should not be “blamed”.  Some
> projects even version control this file so that all contributors can
> use it; the conventional name is `.git-blame-ignore-revs`.
> > But each user still has to opt-in to the standard ignore list,
> either with this option or with the config `blame.ignoreRevsFile`.
> Let’s teach git-blame(1) to respect this conventional file in order
> to streamline the process.

It's good that the commit message now mentions the config setting. It would be helpful to explain why the original implementation deliberately decided not to implement a default file and explain why it is now a good idea to do so. Supporting a default file in addition to the files listed in blame.ignoreRevsFile config setting leaves us in an odd position compared to other settings which use a fixed name like .gitignore or have a default that can be overridden by a config setting like core.excludesFile or require a config setting to enable the feature like diff.orderFile.

I've left a couple of code comments below but really the most important things are to come up with a convincing reason for changing the behavior and figuring out how the default file should interact with the config setting.

> +	/*
> +	* By default, add .git-blame-ignore-revs to the list of files
> +	* containing revisions to ignore if it exists.
> +	*/
> +	if (access(".git-blame-ignore-revs", F_OK) == 0) {

There are some uses of "access(.., F_OK)" in our code base but it is more usual to call file_exists() these days.

> +		string_list_append(&ignore_revs_file_list, ".git-blame-ignore-revs");

If the user already has this path in their config we'll waste time parsing it twice. We could avoid that by using a "struct strset" rather than a "struct string_list". I don't think we have OPT_STRSET but it should be easy to add one by copying OPT_STRING_LIST.

> +    echo world >>hello.txt &&
> +    test_commit second-commit hello.txt &&

test_commit overwrites the file it is committing so you need to use the --printf option

	test_commit --printf second-commit hello.txt "hello\nworld\n"

> +    git rev-parse HEAD >ignored-file &&
> +    git blame --ignore-revs-file=ignored-file hello.txt >expect &&
> +    git rev-parse HEAD >.git-blame-ignore-revs &&
> +    git blame hello.txt >actual &&
> +    test_cmp expect actual

I have mixed feelings about this sort of differential testing, comparing the actual output of git blame to what we expect makes it unambiguous that the test is checking what we want it to.

Best Wishes

Phillip

Copy link

Choose a reason for hiding this comment

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

On the Git mailing list, Abhijeetsingh Meena wrote (reply to this):

Hi Phillip,
Thank you for reviewing the patch and providing valuable feedback.
I’d like to address some of your points below:


> Supporting a default file in addition to the files listed in
> blame.ignoreRevsFile config setting leaves us in an odd position
> compared to other settings which use a fixed name like .gitignore
> or have a default that can be overridden by a config setting like
> core.excludesFile or require a config setting to enable the feature
> like diff.orderFile.

Yes, I now understand that we can solve this by using the existing method for
interacting with configurations, as suggested by you and Kristoffer. We can work
with the existing configuration method like git_config_set to set ignore
revisions file. This (I hope) will also keep it consistent with how
other settings like .gitignore
and core.excludesFile work, making the interaction more predictable for users.


> I've left a couple of code comments below but really
> the most important things are to come up with a convincing
> reason for changing the behavior and figuring out how
> the default file should interact with the config setting.

I agree. After revisiting the use case and the flow, I see now that
the solution can be
more straightforward with git_config_set than my previous approach. This
behavior allows for interaction through the configuration system
without the need to
introduce new options. Kristoffer’s suggestion clarified that handling
.git-blame-ignore-revs
 a default file and allowing it to be overridden or disabled via
--no-ignore-revs-file is sufficient.


> As Kristoffer has pointed out --no-ignore-revs-file should
> be sufficient to disable the default file. If it isn't we
> should fix it so that it is, not add a new option.

Absolutely, you're right. After revisiting my earlier testing issues,
I realized that the
--no-ignore-revs-file and --no-ignore-rev flag works as intended. My
previous confusion was due to a mistake in my test setup. I agree with your
suggestion that we should not add a new option and instead focus on ensuring
 that the current flag behavior is clear and functions correctly.


Thanks again for your review. I hope this approach is better than my
previous approach.
I’ll make sure the changes are implemented correctly in v3
and test the interaction between the default file and config settings
more thoroughly.
Looking forward to your further thoughts!

Best regards,
Abhijeetsingh

On Sun, Oct 13, 2024 at 8:48 PM Phillip Wood <[email protected]> wrote:
>
> Hi Abhijeetsingh
>
> On 12/10/2024 05:37, Abhijeetsingh Meena via GitGitGadget wrote:
> > From: Abhijeetsingh Meena <[email protected]>
> >
> > git-blame(1) can ignore a list of commits with `--ignore-revs-file`.
> > This is useful for marking uninteresting commits like formatting
> > changes, refactors and whatever else should not be “blamed”.  Some
> > projects even version control this file so that all contributors can
> > use it; the conventional name is `.git-blame-ignore-revs`.
> >
> > But each user still has to opt-in to the standard ignore list,
> > either with this option or with the config `blame.ignoreRevsFile`.
> > Let’s teach git-blame(1) to respect this conventional file in order
> > to streamline the process.
>
> It's good that the commit message now mentions the config setting. It
> would be helpful to explain why the original implementation deliberately
> decided not to implement a default file and explain why it is now a good
> idea to do so. Supporting a default file in addition to the files listed
> in blame.ignoreRevsFile config setting leaves us in an odd position
> compared to other settings which use a fixed name like .gitignore or
> have a default that can be overridden by a config setting like
> core.excludesFile or require a config setting to enable the feature like
> diff.orderFile.
>
> I've left a couple of code comments below but really the most important
> things are to come up with a convincing reason for changing the behavior
> and figuring out how the default file should interact with the config
> setting.
>
> > +     /*
> > +     * By default, add .git-blame-ignore-revs to the list of files
> > +     * containing revisions to ignore if it exists.
> > +     */
> > +     if (access(".git-blame-ignore-revs", F_OK) == 0) {
>
> There are some uses of "access(.., F_OK)" in our code base but it is
> more usual to call file_exists() these days.
>
> > +             string_list_append(&ignore_revs_file_list, ".git-blame-ignore-revs");
>
> If the user already has this path in their config we'll waste time
> parsing it twice. We could avoid that by using a "struct strset" rather
> than a "struct string_list". I don't think we have OPT_STRSET but it
> should be easy to add one by copying OPT_STRING_LIST.
>
> > +    echo world >>hello.txt &&
> > +    test_commit second-commit hello.txt &&
>
> test_commit overwrites the file it is committing so you need to use the
> --printf option
>
>         test_commit --printf second-commit hello.txt "hello\nworld\n"
>
> > +    git rev-parse HEAD >ignored-file &&
> > +    git blame --ignore-revs-file=ignored-file hello.txt >expect &&
> > +    git rev-parse HEAD >.git-blame-ignore-revs &&
> > +    git blame hello.txt >actual &&
> > +    test_cmp expect actual
>
> I have mixed feelings about this sort of differential testing, comparing
> the actual output of git blame to what we expect makes it unambiguous
> that the test is checking what we want it to.
>
> Best Wishes
>
> Phillip
>

Copy link

Choose a reason for hiding this comment

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

On the Git mailing list, Abhijeetsingh Meena wrote (reply to this):

Hi Eric, Kristoffer, and Phillip,

Thank you for reviewing the v2 of my patch. I appreciate your
thoughtful feedback.

A few days ago, I sent a detailed email addressing each of your
questions and suggestions individually. Before proceeding with v3,
I’d like to consolidate my thoughts on the next possible approach
to respect '.git-blame-ignore-revs' based on Kristoffer's conceptual
explanation.

> Hi Abhijeetsingh
>
> For what it’s worth here’s how I imagine this feature could work
> conceptually:
>
> Before this feature/change, the effective config for Git use looks like this:
>
> ```
> [blame]
> ```
>
> No `blame.ignoreRevsFile`.
>
> But with/after it:
>
> ```
> [blame]
>         ignoreRevsFile=.git-blame-ignore-revs
> ```
>
> This is the effective config.  Not what the user has typed out.
>
> If the user types out this:
>
> ```
> [blame]
>         ignoreRevsFile=.git-blame-more-revs
> ```
>
> Then this becomes their effective config:
>
> ```
> [blame]
>         ignoreRevsFile=.git-blame-ignore-revs
>         ignoreRevsFile=.git-blame-more-revs
> ```
>
> Now there are two files: the default one and the user-supplied one (this
> config variable is documented as being multi-valued: “This option may be
> repeated multiple times.”).
>
> § How to ignore this new default §§§
>
> Considering users who do not want this new default:
>
> ```
> [blame]
>         ignoreRevsFile=
> ```
>
> This is the change they would have to make.  Because a blank/empty
> resets/empties the list of files.

Thanks, Kristoffer. Your conceptual explanation gave me a new
perspective on how this feature can be implemented using the
existing configuration flow without disrupting other settings.

Based on Phillip's clue of exploring how this feature would interact
with existing configuration settings and your conceptual workflow,
I explored git_config_set and used it to set the
blame.ignoreRevsFile configuration. This approach aligns well with
the existing configuration logic and provides greater flexibility.

With git_config_set to set blame.ignoreRevsFile:

git blame hello.txt
would consult the default .git-blame-ignore-revs file.

git blame --no-ignore-revs-file hello.txt
would disable the default ignore file.

git blame --no-ignore-revs-file --ignore-revs-file=ignore-list hello.txt
would allow the user to specify a custom ignore list while bypassing
the global list, offering the flexibility you suggested.

This would maintain consistency with Git’s existing behavior, allowing
users to modify configurations with a “last-wins” approach and enabling
both global and custom ignore lists as needed.

I hope this approach is better than my previous one. I look forward to
your thoughts!

Best Regards,
Abhijeetsingh

On Wed, Oct 16, 2024 at 11:37 AM Abhijeetsingh Meena
<[email protected]> wrote:
>
> Hi Phillip,
> Thank you for reviewing the patch and providing valuable feedback.
> I’d like to address some of your points below:
>
>
> > Supporting a default file in addition to the files listed in
> > blame.ignoreRevsFile config setting leaves us in an odd position
> > compared to other settings which use a fixed name like .gitignore
> > or have a default that can be overridden by a config setting like
> > core.excludesFile or require a config setting to enable the feature
> > like diff.orderFile.
>
> Yes, I now understand that we can solve this by using the existing method for
> interacting with configurations, as suggested by you and Kristoffer. We can work
> with the existing configuration method like git_config_set to set ignore
> revisions file. This (I hope) will also keep it consistent with how
> other settings like .gitignore
> and core.excludesFile work, making the interaction more predictable for users.
>
>
> > I've left a couple of code comments below but really
> > the most important things are to come up with a convincing
> > reason for changing the behavior and figuring out how
> > the default file should interact with the config setting.
>
> I agree. After revisiting the use case and the flow, I see now that
> the solution can be
> more straightforward with git_config_set than my previous approach. This
> behavior allows for interaction through the configuration system
> without the need to
> introduce new options. Kristoffer’s suggestion clarified that handling
> .git-blame-ignore-revs
>  a default file and allowing it to be overridden or disabled via
> --no-ignore-revs-file is sufficient.
>
>
> > As Kristoffer has pointed out --no-ignore-revs-file should
> > be sufficient to disable the default file. If it isn't we
> > should fix it so that it is, not add a new option.
>
> Absolutely, you're right. After revisiting my earlier testing issues,
> I realized that the
> --no-ignore-revs-file and --no-ignore-rev flag works as intended. My
> previous confusion was due to a mistake in my test setup. I agree with your
> suggestion that we should not add a new option and instead focus on ensuring
>  that the current flag behavior is clear and functions correctly.
>
>
> Thanks again for your review. I hope this approach is better than my
> previous approach.
> I’ll make sure the changes are implemented correctly in v3
> and test the interaction between the default file and config settings
> more thoroughly.
> Looking forward to your further thoughts!
>
> Best regards,
> Abhijeetsingh
>
> On Sun, Oct 13, 2024 at 8:48 PM Phillip Wood <[email protected]> wrote:
> >
> > Hi Abhijeetsingh
> >
> > On 12/10/2024 05:37, Abhijeetsingh Meena via GitGitGadget wrote:
> > > From: Abhijeetsingh Meena <[email protected]>
> > >
> > > git-blame(1) can ignore a list of commits with `--ignore-revs-file`.
> > > This is useful for marking uninteresting commits like formatting
> > > changes, refactors and whatever else should not be “blamed”.  Some
> > > projects even version control this file so that all contributors can
> > > use it; the conventional name is `.git-blame-ignore-revs`.
> > >
> > > But each user still has to opt-in to the standard ignore list,
> > > either with this option or with the config `blame.ignoreRevsFile`.
> > > Let’s teach git-blame(1) to respect this conventional file in order
> > > to streamline the process.
> >
> > It's good that the commit message now mentions the config setting. It
> > would be helpful to explain why the original implementation deliberately
> > decided not to implement a default file and explain why it is now a good
> > idea to do so. Supporting a default file in addition to the files listed
> > in blame.ignoreRevsFile config setting leaves us in an odd position
> > compared to other settings which use a fixed name like .gitignore or
> > have a default that can be overridden by a config setting like
> > core.excludesFile or require a config setting to enable the feature like
> > diff.orderFile.
> >
> > I've left a couple of code comments below but really the most important
> > things are to come up with a convincing reason for changing the behavior
> > and figuring out how the default file should interact with the config
> > setting.
> >
> > > +     /*
> > > +     * By default, add .git-blame-ignore-revs to the list of files
> > > +     * containing revisions to ignore if it exists.
> > > +     */
> > > +     if (access(".git-blame-ignore-revs", F_OK) == 0) {
> >
> > There are some uses of "access(.., F_OK)" in our code base but it is
> > more usual to call file_exists() these days.
> >
> > > +             string_list_append(&ignore_revs_file_list, ".git-blame-ignore-revs");
> >
> > If the user already has this path in their config we'll waste time
> > parsing it twice. We could avoid that by using a "struct strset" rather
> > than a "struct string_list". I don't think we have OPT_STRSET but it
> > should be easy to add one by copying OPT_STRING_LIST.
> >
> > > +    echo world >>hello.txt &&
> > > +    test_commit second-commit hello.txt &&
> >
> > test_commit overwrites the file it is committing so you need to use the
> > --printf option
> >
> >         test_commit --printf second-commit hello.txt "hello\nworld\n"
> >
> > > +    git rev-parse HEAD >ignored-file &&
> > > +    git blame --ignore-revs-file=ignored-file hello.txt >expect &&
> > > +    git rev-parse HEAD >.git-blame-ignore-revs &&
> > > +    git blame hello.txt >actual &&
> > > +    test_cmp expect actual
> >
> > I have mixed feelings about this sort of differential testing, comparing
> > the actual output of git blame to what we expect makes it unambiguous
> > that the test is checking what we want it to.
> >
> > Best Wishes
> >
> > Phillip
> >

Copy link

Choose a reason for hiding this comment

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

On the Git mailing list, Eric Sunshine wrote (reply to this):

On Tue, Oct 22, 2024 at 2:49 AM Abhijeetsingh Meena
<[email protected]> wrote:
> Hi Eric, Kristoffer, and Phillip,
>
> A few days ago, I sent a detailed email addressing each of your
> questions and suggestions individually. Before proceeding with v3,
> I’d like to consolidate my thoughts on the next possible approach
> to respect '.git-blame-ignore-revs' based on Kristoffer's conceptual
> explanation.

Although I asked several questions (which popped into my head) during
my review of the patch, I don't have much to add to the discussion
since I don't use this feature and either wasn't aware of it or forgot
about it until your patch arrived.

Phillip is off-list through the end of the month, so it is unlikely
that he will respond before then.

The general idea of implementing this new behavior via config-list may
indeed be a reasonable way to make it more well-integrated with the
existing methods of specifying ignore-revs. However, that's also an
implementation detail which seems less important presently than these
possible open concerns (unless they've been answered elsewhere), all
of which have to do with forward and backward compatibility...

* Will automatic reading of top-level .git-blame-ignore-revs cause any
unexpected behaviors for existing users who (presumably) are using it
via configuration? It seems unlikely, but the implementation ought to
be careful to process .git-blame-ignore-revs only once.

* Will automatic reading of .git-blame-ignore-revs cause unexpected
behavior for people who have not set up the configuration? In other
words, maybe some projects have a .git-blame-ignore-revs but some
users don't want it consulted by default, thus avoid setting the
configuration.

* It sounds like you want to punt on the idea of cumulatively
processing .git-blame-ignore-revs files from the current subdirectory
up to the project root (as .gitignore works), but can this be done in
such a way that we don't break user's expectations or automations if
such behavior is eventually implemented?

@@ -69,6 +69,7 @@ static int coloring_mode;
static struct string_list ignore_revs_file_list = STRING_LIST_INIT_DUP;
Copy link

Choose a reason for hiding this comment

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

On the Git mailing list, Phillip Wood wrote (reply to this):

Hi Abhijeetsingh

On 12/10/2024 05:37, Abhijeetsingh Meena via GitGitGadget wrote:
> From: Abhijeetsingh Meena <[email protected]>
> > The git blame command can ignore a list of revisions specified either
> through the --ignore-revs-file option or the blame.ignoreRevsFile
> configuration. This feature is useful for excluding irrelevant
> commits, such as formatting changes or large refactors, from blame
> annotations.
> > However, users may encounter cases where they need to
> temporarily override these configurations to inspect all commits,
> even those excluded by the ignore list. Currently, there is no
> simple way to bypass all ignore revisions settings in one go.

As Kristoffer has pointed out --no-ignore-revs-file should be sufficient to disable the default file. If it isn't we should fix it so that it is, not add a new option.

Best Wishes

Phillip

> This patch introduces the --override-ignore-revs option (or -O),
> which allows users to easily bypass the --ignore-revs-file
> option, --ignore-rev option and the blame.ignoreRevsFile
> configuration. When this option is used, git blame will completely
> disregard all configured ignore revisions lists.
> > The motivation behind this feature is to provide users with more
> flexibility when dealing with large codebases that rely on
> .git-blame-ignore-revs files for shared configurations, while
> still allowing them to disable the ignore list when necessary
> for troubleshooting or deeper inspections.
> > Signed-off-by: Abhijeetsingh Meena <[email protected]>
> ---
>   builtin/blame.c                       |  8 +++++++-
>   t/t8016-blame-override-ignore-revs.sh | 25 +++++++++++++++++++++++++
>   2 files changed, 32 insertions(+), 1 deletion(-)
>   create mode 100755 t/t8016-blame-override-ignore-revs.sh
> > diff --git a/builtin/blame.c b/builtin/blame.c
> index 1eddabaf60f..956520edcd9 100644
> --- a/builtin/blame.c
> +++ b/builtin/blame.c
> @@ -69,6 +69,7 @@ static int coloring_mode;
>   static struct string_list ignore_revs_file_list = STRING_LIST_INIT_DUP;
>   static int mark_unblamable_lines;
>   static int mark_ignored_lines;
> +static int override_ignore_revs = 0;
>   >   static struct date_mode blame_date_mode = { DATE_ISO8601 };
>   static size_t blame_date_width;
> @@ -901,6 +902,7 @@ int cmd_blame(int argc,
>   		OPT_BIT('w', NULL, &xdl_opts, N_("ignore whitespace differences"), XDF_IGNORE_WHITESPACE),
>   		OPT_STRING_LIST(0, "ignore-rev", &ignore_rev_list, N_("rev"), N_("ignore <rev> when blaming")),
>   		OPT_STRING_LIST(0, "ignore-revs-file", &ignore_revs_file_list, N_("file"), N_("ignore revisions from <file>")),
> +		OPT_BOOL('O', "override-ignore-revs", &override_ignore_revs, N_("override all configurations that exclude revisions")),
>   		OPT_BIT(0, "color-lines", &output_option, N_("color redundant metadata from previous line differently"), OUTPUT_COLOR_LINE),
>   		OPT_BIT(0, "color-by-age", &output_option, N_("color lines by age"), OUTPUT_SHOW_AGE_WITH_COLOR),
>   		OPT_BIT(0, "minimal", &xdl_opts, N_("spend extra cycles to find better match"), XDF_NEED_MINIMAL),
> @@ -1119,7 +1121,11 @@ parse_done:
>   	sb.reverse = reverse;
>   	sb.repo = the_repository;
>   	sb.path = path;
> -	build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list);
> +
> +	if (!override_ignore_revs) {
> +		build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list);
> +	}
> +
>   	string_list_clear(&ignore_revs_file_list, 0);
>   	string_list_clear(&ignore_rev_list, 0);
>   	setup_scoreboard(&sb, &o);
> diff --git a/t/t8016-blame-override-ignore-revs.sh b/t/t8016-blame-override-ignore-revs.sh
> new file mode 100755
> index 00000000000..b5899729f8e
> --- /dev/null
> +++ b/t/t8016-blame-override-ignore-revs.sh
> @@ -0,0 +1,25 @@
> +#!/bin/sh
> +
> +test_description='default revisions to ignore when blaming'
> +
> +TEST_PASSES_SANITIZE_LEAK=true
> +. ./test-lib.sh
> +
> +test_expect_success 'blame: override-ignore-revs' '
> +    test_commit first-commit hello.txt hello &&
> +
> +    echo world >>hello.txt &&
> +    test_commit second-commit hello.txt &&
> +
> +    sed "1s/hello/hi/" <hello.txt > hello.txt.tmp &&
> +    mv hello.txt.tmp hello.txt &&
> +    test_commit third-commit hello.txt &&
> +
> +    git blame hello.txt >expect &&
> +    git rev-parse HEAD >.git-blame-ignore-revs &&
> +    git blame -O hello.txt >actual &&
> +
> +    test_cmp expect actual
> +'
> +
> +test_done

Copy link

gitgitgadget bot commented Oct 14, 2024

This patch series was integrated into seen via git@bd95564.

@gitgitgadget gitgitgadget bot added the seen label Oct 14, 2024
Copy link

gitgitgadget bot commented Oct 14, 2024

User Taylor Blau <[email protected]> has been added to the cc: list.

Copy link

gitgitgadget bot commented Oct 14, 2024

This patch series was integrated into seen via git@40acc6e.

Copy link

gitgitgadget bot commented Oct 16, 2024

This patch series was integrated into seen via git@9d605a9.

Copy link

gitgitgadget bot commented Oct 18, 2024

This patch series was integrated into seen via git@a118669.

Copy link

gitgitgadget bot commented Oct 18, 2024

This patch series was integrated into seen via git@14b9447.

Copy link

gitgitgadget bot commented Oct 21, 2024

This patch series was integrated into seen via git@ffafd0e.

Copy link

gitgitgadget bot commented Oct 22, 2024

This patch series was integrated into seen via git@3e5d15c.

Copy link

gitgitgadget bot commented Oct 23, 2024

This patch series was integrated into seen via git@5f4c7ae.

Copy link

gitgitgadget bot commented Oct 25, 2024

This patch series was integrated into seen via git@336ef88.

Copy link

gitgitgadget bot commented Oct 25, 2024

This patch series was integrated into seen via git@547be3b.

Copy link

gitgitgadget bot commented Oct 28, 2024

This patch series was integrated into seen via git@b51e1c4.

Copy link

gitgitgadget bot commented Oct 28, 2024

This patch series was integrated into seen via git@d0c2789.

Copy link

gitgitgadget bot commented Oct 29, 2024

This patch series was integrated into seen via git@431841b.

Copy link

gitgitgadget bot commented Oct 30, 2024

This patch series was integrated into seen via git@7faec07.

Copy link

gitgitgadget bot commented Oct 30, 2024

This patch series was integrated into seen via git@3fed5af.

Copy link

gitgitgadget bot commented Oct 31, 2024

This patch series was integrated into seen via git@b12f540.

Copy link

gitgitgadget bot commented Nov 1, 2024

This patch series was integrated into seen via git@e8f888d.

Copy link

gitgitgadget bot commented Nov 1, 2024

This patch series was integrated into seen via git@9a6b9ff.

Copy link

gitgitgadget bot commented Nov 1, 2024

This patch series was integrated into seen via git@1de92e6.

Copy link

gitgitgadget bot commented Nov 4, 2024

This patch series was integrated into seen via git@37ed6aa.

@dscho
Copy link
Member

dscho commented Nov 5, 2024

Hi Kristoffer,

Thank you so much for your feedback and for taking the time to review my patch. I appreciate your suggestions, particularly regarding the project convention of using the present tense to describe the current behavior, as well as your mention of the --no-ignore-revs-file option and the importance of documenting it.

Regarding your first point:

My assumption then is that, with this change, I could use --no-ignore-revs-file to turn off the default file.

I’ll check how this works in the current setup and get back to you to confirm.

As for your second observation:

git blame --ignore-revs-file=README.md
--no-ignore-revs-file README.md
And that works without giving errors. So it’s there. Just apparently undocumented?

I’ll look into opening an issue and submitting a PR to add documentation for this, as it seems important to address.

I’m excited to refine the patch with these improvements in mind and will continue working on the commit message and necessary documentation in line with your feedback.

Thanks again for your guidance and support!

Best regards, Abhijeet (Ethan0456)

@Ethan0456 sadly, these PR comments are not mirrored to the Git mailing list. You will need to follow the guidance provided via "Reply to this" in the comment to which you wanted to reply to. Same problem with this PR comment.

@Ethan0456
Copy link
Author

Thanks @dscho for the heads-up! I figured it out and have been using Gmail for the subsequent emails to the reviewers.

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.

2 participants