From: Noah Pendleton <noah.pendleton@gmail.com>
To: git@vger.kernel.org
Cc: Noah Pendleton <noah.pendleton@gmail.com>,
Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2] blame: add config `blame.ignoreRevsFileIsOptional`
Date: Sun, 8 Aug 2021 13:48:47 -0400 [thread overview]
Message-ID: <20210808174847.16590-1-noah.pendleton@gmail.com> (raw)
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
next prev parent reply other threads:[~2021-08-08 17:49 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-07 20:27 [PATCH 0/1] blame: Skip missing ignore-revs file Noah Pendleton
2021-08-07 20:58 ` Junio C Hamano
2021-08-07 21:34 ` Noah Pendleton
2021-08-08 5:43 ` Junio C Hamano
2021-08-08 17:50 ` Junio C Hamano
2021-08-08 18:21 ` Noah Pendleton
2021-08-09 15:47 ` Junio C Hamano
2024-10-14 20:44 ` [PATCH 0/3] specifying a file that can optionally exist Junio C Hamano
2024-10-14 20:44 ` [PATCH 1/3] t7500: make each piece more independent Junio C Hamano
2024-10-14 20:44 ` [PATCH 2/3] config: values of pathname type can be prefixed with :(optional) Junio C Hamano
2024-10-14 20:44 ` [PATCH 3/3] parseopt: " Junio C Hamano
2025-05-01 21:40 ` [PATCH 0/3] specifying a file that can optionally exist Junio C Hamano
2025-05-01 21:40 ` [PATCH 1/3] t7500: make each piece more independent Junio C Hamano
2025-05-01 21:40 ` [PATCH 2/3] config: values of pathname type can be prefixed with :(optional) Junio C Hamano
2025-05-02 8:52 ` Patrick Steinhardt
2025-05-02 14:28 ` Phillip Wood
2025-05-02 20:05 ` Junio C Hamano
2025-05-01 21:40 ` [PATCH 3/3] parseopt: " Junio C Hamano
2025-09-28 21:29 ` [PATCH v2 0/3] Support :(optional) filepaths D. Ben Knoble
2025-09-28 21:29 ` [PATCH v2 1/3] t7500: make each piece more independent D. Ben Knoble
2025-09-28 21:29 ` [PATCH v2 2/3] config: values of pathname type can be prefixed with :(optional) D. Ben Knoble
2025-09-30 15:26 ` Phillip Wood
2025-10-06 19:00 ` Junio C Hamano
2025-10-06 19:59 ` Junio C Hamano
2025-10-06 20:21 ` Junio C Hamano
2025-10-06 20:22 ` Junio C Hamano
2025-10-07 12:24 ` Kristoffer Haugsbakk
2025-10-07 17:04 ` Junio C Hamano
2025-11-02 16:20 ` D. Ben Knoble
2025-09-28 21:29 ` [PATCH v2 3/3] parseopt: " D. Ben Knoble
2025-09-30 15:26 ` Phillip Wood
2025-11-02 16:20 ` D. Ben Knoble
2025-11-03 0:10 ` Eric Sunshine
2025-11-04 18:22 ` D. Ben Knoble
2025-09-28 22:40 ` [PATCH v2 0/3] Support :(optional) filepaths Junio C Hamano
2025-09-29 16:42 ` Ben Knoble
2025-10-20 9:40 ` [PATCH] t7500: fix tests with absolute path following ":(optional)" on Windows Johannes Sixt
2025-10-20 13:43 ` Ben Knoble
2025-10-20 17:32 ` Johannes Sixt
2025-10-20 18:06 ` Junio C Hamano
2025-10-20 20:27 ` D. Ben Knoble
2025-10-20 20:27 ` D. Ben Knoble
2025-10-20 17:39 ` Eric Sunshine
2025-10-20 16:17 ` Junio C Hamano
2025-10-20 17:24 ` Johannes Sixt
2022-03-04 9:51 ` [PATCH 0/1] blame: Skip missing ignore-revs file Thranur Andul
2021-08-08 17:48 ` Noah Pendleton [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-04-25 18:41 Feature request: automatically read .git-blame-ignore-revs or allow global optional config Michael Grosser
2025-04-25 19:54 ` Eric Sunshine
2025-05-01 18:00 ` D. Ben Knoble
2025-05-01 18:28 ` Eric Sunshine
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=20210808174847.16590-1-noah.pendleton@gmail.com \
--to=noah.pendleton@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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.