Skip to content

Commit 431841b

Browse files
committed
Merge branch 'am/git-blame-ignore-revs-by-default' into seen
Teaches 'git blame' to treat '.git-blame-ignore-revs' as if it were passed as '--ignore-revs-file' by default. * am/git-blame-ignore-revs-by-default: blame: introduce --override-ignore-revs to bypass ignore revisions list blame: respect .git-blame-ignore-revs automatically
2 parents 8e2da43 + 0386bb3 commit 431841b

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

builtin/blame.c

Lines changed: 15 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),
@@ -1105,13 +1107,25 @@ int cmd_blame(int argc,
11051107
add_pending_object(&revs, &head_commit->object, "HEAD");
11061108
}
11071109

1110+
/*
1111+
* By default, add .git-blame-ignore-revs to the list of files
1112+
* containing revisions to ignore if it exists.
1113+
*/
1114+
if (access(".git-blame-ignore-revs", F_OK) == 0) {
1115+
string_list_append(&ignore_revs_file_list, ".git-blame-ignore-revs");
1116+
}
1117+
11081118
init_scoreboard(&sb);
11091119
sb.revs = &revs;
11101120
sb.contents_from = contents_from;
11111121
sb.reverse = reverse;
11121122
sb.repo = the_repository;
11131123
sb.path = path;
1114-
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+
11151129
string_list_clear(&ignore_revs_file_list, 0);
11161130
string_list_clear(&ignore_rev_list, 0);
11171131
setup_scoreboard(&sb, &o);

t/t8015-blame-default-ignore-revs.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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: default-ignore-revs-file' '
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 rev-parse HEAD >ignored-file &&
19+
git blame --ignore-revs-file=ignored-file hello.txt >expect &&
20+
git rev-parse HEAD >.git-blame-ignore-revs &&
21+
git blame hello.txt >actual &&
22+
23+
test_cmp expect actual
24+
'
25+
26+
test_done

t/t8016-blame-override-ignore-revs.sh

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)