git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] blame: add config `blame.ignoreRevsFileIsOptional`

From
Noah Pendleton <noah.pendleton@gmail.com>
Date
Aug 8, 2021, 17:48 UTC
Message-ID
<20210808174847.16590-1-noah.pendleton@gmail.com>
In-Reply-To
<20210807202752.1278672-1-noah.pendleton@gmail.com>

Setting the config option `blame.ignoreRevsFile` globally to eg `.git-blame-ignore-revs` causes `git blame` to error when the file doesn't exist in the current repository:

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

Add a new config option, `blame.ignoreRevsFileIsOptional`, that when set to true, `git blame` will silently ignore any missing ignoreRevsFile's.

Signed-off-by: Noah Pendleton <noah.pendleton@gmail.com>
---
Reworked this patch to add a new config
`blame.ignoreRevsFileIsOptional`, which controls whether missing
files specified by ignoreRevsFile cause an error or are silently
ignored.
Updated tests and docs to match.
 Documentation/blame-options.txt |  3 ++-
 Documentation/config/blame.txt  |  5 +++++
 builtin/blame.c                 |  7 ++++++-
 t/t8013-blame-ignore-revs.sh    | 14 ++++++++++----
 4 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt
index 117f4cf806..199a28ab79 100644
--- a/Documentation/blame-options.txt
+++ b/Documentation/blame-options.txt
@@ -134,7 +134,8 @@ take effect.
 	`fsck.skipList`.  This option may be repeated, and these files will be
 	processed after any files specified with the `blame.ignoreRevsFile` config
 	option.  An empty file name, `""`, will clear the list of revs from
-	previously processed files.
+	previously processed files. If `blame.ignoreRevsFileIsOptional` is true,
+	missing files will be silently ignored.
 
 -h::
 	Show help message.
diff --git a/Documentation/config/blame.txt b/Documentation/config/blame.txt
index 4d047c1790..2aae851e4b 100644
--- a/Documentation/config/blame.txt
+++ b/Documentation/config/blame.txt
@@ -27,6 +27,11 @@ blame.ignoreRevsFile::
 	file names will reset the list of ignored revisions.  This option will
 	be handled before the command line option `--ignore-revs-file`.
 
+blame.ignoreRevsFileIsOptional::
+	Silently skip missing files specified by ignoreRevsFile or the command line
+	option `--ignore-revs-file`. If unset, or set to false, missing files will
+	cause a nonrecoverable error.
+
 blame.markUnblamableLines::
 	Mark lines that were changed by an ignored revision that we could not
 	attribute to another commit with a '*' in the output of
diff --git a/builtin/blame.c b/builtin/blame.c
index 641523ff9a..df132b34ce 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -56,6 +56,7 @@ static int coloring_mode;
 static struct string_list ignore_revs_file_list = STRING_LIST_INIT_NODUP;
 static int mark_unblamable_lines;
 static int mark_ignored_lines;
+static int ignorerevsfileisoptional;
 
 static struct date_mode blame_date_mode = { DATE_ISO8601 };
 static size_t blame_date_width;
@@ -715,6 +716,9 @@ static int git_blame_config(const char *var, const char *value, void *cb)
 		string_list_insert(&ignore_revs_file_list, str);
 		return 0;
 	}
+	if (!strcmp(var, "blame.ignorerevsfileisoptional")) {
+		ignorerevsfileisoptional = git_config_bool(var, value);
+	}
 	if (!strcmp(var, "blame.markunblamablelines")) {
 		mark_unblamable_lines = git_config_bool(var, value);
 		return 0;
@@ -835,7 +839,8 @@ static void build_ignorelist(struct blame_scoreboard *sb,
 	for_each_string_list_item(i, ignore_revs_file_list) {
 		if (!strcmp(i->string, ""))
 			oidset_clear(&sb->ignore_list);
-		else
+		/* skip non-existent files if ignorerevsfileisoptional is set */
+		else if (!ignorerevsfileisoptional || file_exists(i->string))
 			oidset_parse_file_carefully(&sb->ignore_list, i->string,
 						    peel_to_commit_oid, sb);
 	}
diff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh
index b18633dee1..f789426cbf 100755
--- a/t/t8013-blame-ignore-revs.sh
+++ b/t/t8013-blame-ignore-revs.sh
@@ -127,18 +127,24 @@ test_expect_success override_ignore_revs_file '
 	grep -E "^[0-9a-f]+ [0-9]+ 2" blame_raw | sed -e "s/ .*//" >actual &&
 	test_cmp expect actual
 	'
-test_expect_success bad_files_and_revs '
+test_expect_success bad_revs '
 	test_must_fail git blame file --ignore-rev NOREV 2>err &&
 	test_i18ngrep "cannot find revision NOREV to ignore" err &&
 
-	test_must_fail git blame file --ignore-revs-file NOFILE 2>err &&
-	test_i18ngrep "could not open.*: NOFILE" err &&
-
 	echo NOREV >ignore_norev &&
 	test_must_fail git blame file --ignore-revs-file ignore_norev 2>err &&
 	test_i18ngrep "invalid object name: NOREV" err
 '
 
+# Non-existent ignore-revs-file should fail unless
+# blame.ignoreRevsFileIsOptional is set
+test_expect_success bad_file '
+	test_must_fail git blame file --ignore-revs-file NOFILE &&
+
+	git config --add blame.ignorerevsfileisoptional true &&
+	git blame file --ignore-revs-file NOFILE
+'
+
 # For ignored revs that have added 'unblamable' lines, mark those lines with a
 # '*'
 # 	A--B--X--Y
-- 
2.32.0
Previous: Thranur Andul
Message 47 of 47 in “blame: Skip missing ignore-revs file”
  1. 0/1 blame: Skip missing ignore-revs fileNoah Pendleton, Aug 7, 2021
  2. Junio C HamanoAug 7, 2021
  3. Noah PendletonAug 7, 2021
  4. Junio C HamanoAug 8, 2021
  5. Junio C HamanoAug 8, 2021
  6. Noah PendletonAug 8, 2021
  7. Junio C HamanoAug 9, 2021
  8. 0/3 specifying a file that can optionally existJunio C Hamano, Oct 14, 2024
  9. 1/3 t7500: make each piece more independentJunio C Hamano, Oct 14, 2024
  10. 2/3 config: values of pathname type can be prefixed with :(optional)Junio C Hamano, Oct 14, 2024
  11. 3/3 parseopt: values of pathname type can be prefixed with :(optional)Junio C Hamano, Oct 14, 2024
  12. 0/3 specifying a file that can optionally existJunio C Hamano, May 1, 2025
  13. 1/3 t7500: make each piece more independentJunio C Hamano, May 1, 2025
  14. 2/3 config: values of pathname type can be prefixed with :(optional)Junio C Hamano, May 1, 2025
  15. Patrick SteinhardtMay 2, 2025
  16. Phillip WoodMay 2, 2025
  17. Junio C HamanoMay 2, 2025
  18. 3/3 parseopt: values of pathname type can be prefixed with :(optional)Junio C Hamano, May 1, 2025
  19. 0/3 Support :(optional) filepathsD. Ben Knoble, Sep 28, 2025
  20. 1/3 t7500: make each piece more independentD. Ben Knoble, Sep 28, 2025
  21. 2/3 config: values of pathname type can be prefixed with :(optional)D. Ben Knoble, Sep 28, 2025
  22. Phillip WoodSep 30, 2025
  23. Junio C HamanoOct 6, 2025
  24. Junio C HamanoOct 6, 2025
  25. Junio C HamanoOct 6, 2025
  26. Junio C HamanoOct 6, 2025
  27. Kristoffer HaugsbakkOct 7, 2025
  28. Junio C HamanoOct 7, 2025
  29. D. Ben KnobleNov 2, 2025
  30. 3/3 parseopt: values of pathname type can be prefixed with :(optional)D. Ben Knoble, Sep 28, 2025
  31. Phillip WoodSep 30, 2025
  32. D. Ben KnobleNov 2, 2025
  33. Eric SunshineNov 3, 2025
  34. D. Ben KnobleNov 4, 2025
  35. Junio C HamanoSep 28, 2025
  36. Ben KnobleSep 29, 2025
  37. t7500: fix tests with absolute path following ":(optional)" on WindowsJohannes Sixt, Oct 20, 2025
  38. Ben KnobleOct 20, 2025
  39. Johannes SixtOct 20, 2025
  40. Junio C HamanoOct 20, 2025
  41. D. Ben KnobleOct 20, 2025
  42. D. Ben KnobleOct 20, 2025
  43. Eric SunshineOct 20, 2025
  44. Junio C HamanoOct 20, 2025
  45. Johannes SixtOct 20, 2025
  46. Thranur AndulMar 4, 2022
  47. blame: add config `blame.ignoreRevsFileIsOptional`Noah Pendleton, Aug 8, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.