All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Abhijeetsingh Meena via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Abhijeetsingh Meena <abhijeetsingh.github@gmail.com>,
	Abhijeetsingh Meena <abhijeet040403@gmail.com>
Subject: [PATCH] blame: respect .git-blame-ignore-revs automatically
Date: Tue, 08 Oct 2024 07:01:32 +0000	[thread overview]
Message-ID: <pull.1809.git.1728370892696.gitgitgadget@gmail.com> (raw)

From: Abhijeetsingh Meena <abhijeet040403@gmail.com>

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 <abhijeet040403@gmail.com>
---
    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
-- 
gitgitgadget

             reply	other threads:[~2024-10-08  7:01 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-08  7:01 Abhijeetsingh Meena via GitGitGadget [this message]
2024-10-08  9:07 ` [PATCH] blame: respect .git-blame-ignore-revs automatically Kristoffer Haugsbakk
2024-10-08  9:51 ` Phillip Wood
     [not found] ` <pull.1809.v2.git.1728397437637.gitgitgadget@gmail.com>
     [not found]   ` <CAAirc3j2MfLyiNVnseRmTsDDu6R4gkcms1GXk=9_jAVLvEYaUg@mail.gmail.com>
     [not found]     ` <CAAirc3gX=PBixcyR0NRyRDnrydkeeu8A9or90c8MSUdHQ6uo=w@mail.gmail.com>
2024-10-08 16:12       ` [PREVIEW v2] " Abhijeetsingh Meena
2024-10-08 16:12         ` Abhijeetsingh Meena
2024-10-12  4:37 ` [PATCH v2 0/2] " Abhijeetsingh Meena via GitGitGadget
2024-10-12  4:37   ` [PATCH v2 1/2] " Abhijeetsingh Meena via GitGitGadget
2024-10-12  6:07     ` Eric Sunshine
2024-10-12  6:43       ` Eric Sunshine
2024-10-14 21:08       ` Taylor Blau
2024-10-16  6:04       ` Abhijeetsingh Meena
2024-10-12 13:58     ` Kristoffer Haugsbakk
2024-10-13 15:25       ` Phillip Wood
2024-10-14 21:00         ` Kristoffer Haugsbakk
2024-10-16  6:06       ` Abhijeetsingh Meena
2024-10-13 15:18     ` Phillip Wood
2024-10-16  6:07       ` Abhijeetsingh Meena
2024-10-22  6:49         ` Abhijeetsingh Meena
2024-10-22  7:54           ` Eric Sunshine
2024-10-12  4:37   ` [PATCH v2 2/2] blame: introduce --override-ignore-revs to bypass ignore revisions list Abhijeetsingh Meena via GitGitGadget
2024-10-12  6:24     ` Eric Sunshine
2024-10-12  6:26       ` Eric Sunshine
2024-10-12 14:25     ` Kristoffer Haugsbakk
2024-10-13 15:20     ` Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1809.git.1728370892696.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=abhijeet040403@gmail.com \
    --cc=abhijeetsingh.github@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.