Skip to content

Commit fdb2e66

Browse files
committed
Merge branch 'np/blame-ignore-revs-file-may-be-optional' into seen
When the file named by blame.ignoreRevsFile configuration variable does not exist, it causes "git blame" to die. Sometimes, it is useful if the files named by configuration variables can be made optional (it would allow ~/.gitconfig to give a filename, and make it effective only in repositories that have a file with that name). This uses an extra variable that marks that the variable is optional. Yet another alternative is being discussed to define syntax for "optional" filename values, so that the same mechanism can be used for not just blame.ignoreRevsFile but other filenames. Queued just as a reminder of the theme. * np/blame-ignore-revs-file-may-be-optional: blame: add config `blame.ignoreRevsFileIsOptional`
2 parents 7e9cf4a + d44ac73 commit fdb2e66

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

Documentation/blame-options.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ take effect.
134134
`fsck.skipList`. This option may be repeated, and these files will be
135135
processed after any files specified with the `blame.ignoreRevsFile` config
136136
option. An empty file name, `""`, will clear the list of revs from
137-
previously processed files.
137+
previously processed files. If `blame.ignoreRevsFileIsOptional` is true,
138+
missing files will be silently ignored.
138139

139140
-h::
140141
Show help message.

Documentation/config/blame.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ blame.ignoreRevsFile::
2727
file names will reset the list of ignored revisions. This option will
2828
be handled before the command line option `--ignore-revs-file`.
2929

30+
blame.ignoreRevsFileIsOptional::
31+
Silently skip missing files specified by ignoreRevsFile or the command line
32+
option `--ignore-revs-file`. If unset, or set to false, missing files will
33+
cause a nonrecoverable error.
34+
3035
blame.markUnblamableLines::
3136
Mark lines that were changed by an ignored revision that we could not
3237
attribute to another commit with a '*' in the output of

builtin/blame.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static int coloring_mode;
5656
static struct string_list ignore_revs_file_list = STRING_LIST_INIT_NODUP;
5757
static int mark_unblamable_lines;
5858
static int mark_ignored_lines;
59+
static int ignorerevsfileisoptional;
5960

6061
static struct date_mode blame_date_mode = { DATE_ISO8601 };
6162
static size_t blame_date_width;
@@ -715,6 +716,9 @@ static int git_blame_config(const char *var, const char *value, void *cb)
715716
string_list_insert(&ignore_revs_file_list, str);
716717
return 0;
717718
}
719+
if (!strcmp(var, "blame.ignorerevsfileisoptional")) {
720+
ignorerevsfileisoptional = git_config_bool(var, value);
721+
}
718722
if (!strcmp(var, "blame.markunblamablelines")) {
719723
mark_unblamable_lines = git_config_bool(var, value);
720724
return 0;
@@ -835,7 +839,8 @@ static void build_ignorelist(struct blame_scoreboard *sb,
835839
for_each_string_list_item(i, ignore_revs_file_list) {
836840
if (!strcmp(i->string, ""))
837841
oidset_clear(&sb->ignore_list);
838-
else
842+
/* skip non-existent files if ignorerevsfileisoptional is set */
843+
else if (!ignorerevsfileisoptional || file_exists(i->string))
839844
oidset_parse_file_carefully(&sb->ignore_list, i->string,
840845
peel_to_commit_oid, sb);
841846
}

t/t8013-blame-ignore-revs.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,24 @@ test_expect_success override_ignore_revs_file '
127127
grep -E "^[0-9a-f]+ [0-9]+ 2" blame_raw | sed -e "s/ .*//" >actual &&
128128
test_cmp expect actual
129129
'
130-
test_expect_success bad_files_and_revs '
130+
test_expect_success bad_revs '
131131
test_must_fail git blame file --ignore-rev NOREV 2>err &&
132132
test_i18ngrep "cannot find revision NOREV to ignore" err &&
133133
134-
test_must_fail git blame file --ignore-revs-file NOFILE 2>err &&
135-
test_i18ngrep "could not open.*: NOFILE" err &&
136-
137134
echo NOREV >ignore_norev &&
138135
test_must_fail git blame file --ignore-revs-file ignore_norev 2>err &&
139136
test_i18ngrep "invalid object name: NOREV" err
140137
'
141138

139+
# Non-existent ignore-revs-file should fail unless
140+
# blame.ignoreRevsFileIsOptional is set
141+
test_expect_success bad_file '
142+
test_must_fail git blame file --ignore-revs-file NOFILE &&
143+
144+
git config --add blame.ignorerevsfileisoptional true &&
145+
git blame file --ignore-revs-file NOFILE
146+
'
147+
142148
# For ignored revs that have added 'unblamable' lines, mark those lines with a
143149
# '*'
144150
# A--B--X--Y

0 commit comments

Comments
 (0)