threads / rfc / 63734

RFC patchblame: avoid failing if ignoreRevsFile does not exist

Subject: [RFC PATCH] blame: avoid failing if ignoreRevsFile does not exist

## tl;dr

3 messages between Jul 3, 2025 and Jul 3, 2025. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Francesco Nicoletta Puzzillo· Jul 3, 2025, 08:18 UTC · lore

Setting ignoreRevsFile globally makes the blame command fail in repositories that don't have the file present.

Check that the file exists before trying to parse it.
Signed-off-by: Francesco Nicoletta Puzzillo <francesco.nicolettap@amarulasolutions.com>
---
 builtin/blame.c  | 3 ++-
 t/t8002-blame.sh | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
Show changes to 2 files +8 −1

builtin/blame.c, t/t8002-blame.sh

diff --git a/builtin/blame.c b/builtin/blame.c
index 944952e30e..e4236f0ebc 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -868,12 +868,13 @@ static void build_ignorelist(struct blame_scoreboard *sb,
 {
 	struct string_list_item *i;
 	struct object_id oid;
+	struct stat st;
 
 	oidset_init(&sb->ignore_list, 0);
 	for_each_string_list_item(i, ignore_revs_file_list) {
 		if (!strcmp(i->string, ""))
 			oidset_clear(&sb->ignore_list);
-		else
+		else if (!stat(i->string, &st))
 			oidset_parse_file_carefully(&sb->ignore_list, i->string,
 						    the_repository->hash_algo,
 						    peel_to_commit_oid, sb);
diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
index 7822947f02..24010f544c 100755
--- a/t/t8002-blame.sh
+++ b/t/t8002-blame.sh
@@ -173,4 +173,10 @@ test_expect_success 'blame with uncommitted edits in partial clone does not cras
 	git -C client blame file.txt
 '
 
+test_expect_success 'blame with ignoreRevsFile set but not present does not fail' '
+	test_commit A file line1 &&
+	git config --global blame.ignoreRevsFile .git-blame-ignore-revs &&
+	git blame file
+'
+
 test_done

base-commit: 8b6f19ccfc3aefbd0f22f6b7d56ad6a3fc5e4f37
-- 
2.43.0
Kristoffer Haugsbakk· Jul 3, 2025, 08:25 UTC · re: Francesco Nicoletta Puzzillo · lore

Re: [RFC PATCH] blame: avoid failing if ignoreRevsFile does not exist

On Thu, Jul 3, 2025, at 10:18, Francesco Nicoletta Puzzillo wrote:
Show 6 quoted lines
> Setting ignoreRevsFile globally makes the blame command fail in
> repositories that don't have the file present.
>
> Check that the file exists before trying to parse it.
>
> Signed-off-by: Francesco Nicoletta Puzzillo <francesco.nicolettap@amarulasolutions.com>
Relevant thread
https://lore.kernel.org/git/20210807202752.1278672-1-noah.pendleton@gmail.com/
Ben Knoble· Jul 3, 2025, 13:18 UTC · re: Kristoffer Haugsbakk · lore

Re: [RFC PATCH] blame: avoid failing if ignoreRevsFile does not exist

Show 14 quoted lines
> Le 3 juil. 2025 à 04:26, Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com> a écrit :
> 
> On Thu, Jul 3, 2025, at 10:18, Francesco Nicoletta Puzzillo wrote:
>> Setting ignoreRevsFile globally makes the blame command fail in
>> repositories that don't have the file present.
>> 
>> Check that the file exists before trying to parse it.
>> 
>> Signed-off-by: Francesco Nicoletta Puzzillo <francesco.nicolettap@amarulasolutions.com>
> 
> Relevant thread
> 
> https://lore.kernel.org/git/20210807202752.1278672-1-noah.pendleton@gmail.com/
> 
Indeed. IIRC there was some polish to do on Junio’s patches, which I intend to get to unless someone beats me to it ;)

← back to recent threads