Skip to content

Commit 0386bb3

Browse files
Ethan0456ttaylorr
authored andcommitted
blame: introduce --override-ignore-revs to bypass ignore revisions list
The git blame command can ignore a list of revisions specified either through the --ignore-revs-file option or the blame.ignoreRevsFile configuration. This feature is useful for excluding irrelevant commits, such as formatting changes or large refactors, from blame annotations. However, users may encounter cases where they need to temporarily override these configurations to inspect all commits, even those excluded by the ignore list. Currently, there is no simple way to bypass all ignore revisions settings in one go. This patch introduces the --override-ignore-revs option (or -O), which allows users to easily bypass the --ignore-revs-file option, --ignore-rev option and the blame.ignoreRevsFile configuration. When this option is used, git blame will completely disregard all configured ignore revisions lists. The motivation behind this feature is to provide users with more flexibility when dealing with large codebases that rely on .git-blame-ignore-revs files for shared configurations, while still allowing them to disable the ignore list when necessary for troubleshooting or deeper inspections. Signed-off-by: Abhijeetsingh Meena <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent eca5438 commit 0386bb3

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

builtin/blame.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static int coloring_mode;
6969
static struct string_list ignore_revs_file_list = STRING_LIST_INIT_DUP;
7070
static int mark_unblamable_lines;
7171
static int mark_ignored_lines;
72+
static int override_ignore_revs = 0;
7273

7374
static struct date_mode blame_date_mode = { DATE_ISO8601 };
7475
static size_t blame_date_width;
@@ -901,6 +902,7 @@ int cmd_blame(int argc,
901902
OPT_BIT('w', NULL, &xdl_opts, N_("ignore whitespace differences"), XDF_IGNORE_WHITESPACE),
902903
OPT_STRING_LIST(0, "ignore-rev", &ignore_rev_list, N_("rev"), N_("ignore <rev> when blaming")),
903904
OPT_STRING_LIST(0, "ignore-revs-file", &ignore_revs_file_list, N_("file"), N_("ignore revisions from <file>")),
905+
OPT_BOOL('O', "override-ignore-revs", &override_ignore_revs, N_("override all configurations that exclude revisions")),
904906
OPT_BIT(0, "color-lines", &output_option, N_("color redundant metadata from previous line differently"), OUTPUT_COLOR_LINE),
905907
OPT_BIT(0, "color-by-age", &output_option, N_("color lines by age"), OUTPUT_SHOW_AGE_WITH_COLOR),
906908
OPT_BIT(0, "minimal", &xdl_opts, N_("spend extra cycles to find better match"), XDF_NEED_MINIMAL),
@@ -1119,7 +1121,11 @@ int cmd_blame(int argc,
11191121
sb.reverse = reverse;
11201122
sb.repo = the_repository;
11211123
sb.path = path;
1122-
build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list);
1124+
1125+
if (!override_ignore_revs) {
1126+
build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list);
1127+
}
1128+
11231129
string_list_clear(&ignore_revs_file_list, 0);
11241130
string_list_clear(&ignore_rev_list, 0);
11251131
setup_scoreboard(&sb, &o);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
test_description='default revisions to ignore when blaming'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
6+
. ./test-lib.sh
7+
8+
test_expect_success 'blame: override-ignore-revs' '
9+
test_commit first-commit hello.txt hello &&
10+
11+
echo world >>hello.txt &&
12+
test_commit second-commit hello.txt &&
13+
14+
sed "1s/hello/hi/" <hello.txt > hello.txt.tmp &&
15+
mv hello.txt.tmp hello.txt &&
16+
test_commit third-commit hello.txt &&
17+
18+
git blame hello.txt >expect &&
19+
git rev-parse HEAD >.git-blame-ignore-revs &&
20+
git blame -O hello.txt >actual &&
21+
22+
test_cmp expect actual
23+
'
24+
25+
test_done

0 commit comments

Comments
 (0)