Skip to content

Commit 0dc95a4

Browse files
stefanbellergitster
authored andcommitted
builtin/blame: add new coloring scheme config
Add a config option that allows selecting the default color scheme for blame. The command line still takes precedence over the configuration. It is to be seen, how color.ui will integrate with blame coloring. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 25d5f52 commit 0dc95a4

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

Documentation/config.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,11 @@ everything older than one year blue, recent changes between one month and
12401240
one year old are kept white, and lines introduced within the last month are
12411241
colored red.
12421242

1243+
blame.coloring::
1244+
This determines the coloring scheme to be applied to blame
1245+
output. It can be 'repeatedLines', 'highlightRecent',
1246+
or 'none' which is the default.
1247+
12431248
color.ui::
12441249
This variable determines the default value for variables such
12451250
as `color.diff` and `color.grep` that control the use of color

builtin/blame.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static int abbrev = -1;
4949
static int no_whole_file_rename;
5050
static int show_progress;
5151
static char repeated_meta_color[COLOR_MAXLEN];
52+
static int coloring_mode;
5253

5354
static struct date_mode blame_date_mode = { DATE_ISO8601 };
5455
static size_t blame_date_width;
@@ -702,6 +703,20 @@ static int git_blame_config(const char *var, const char *value, void *cb)
702703
return 0;
703704
}
704705

706+
if (!strcmp(var, "blame.coloring")) {
707+
if (!strcmp(value, "repeatedLines")) {
708+
coloring_mode |= OUTPUT_COLOR_LINE;
709+
} else if (!strcmp(value, "highlightRecent")) {
710+
coloring_mode |= OUTPUT_SHOW_AGE_WITH_COLOR;
711+
} else if (!strcmp(value, "none")) {
712+
coloring_mode &= ~(OUTPUT_COLOR_LINE |
713+
OUTPUT_SHOW_AGE_WITH_COLOR);
714+
} else {
715+
warning(_("invalid value for blame.coloring"));
716+
return 0;
717+
}
718+
}
719+
705720
if (git_diff_heuristic_config(var, value, cb) < 0)
706721
return -1;
707722
if (userdiff_config(var, value) < 0)
@@ -1037,6 +1052,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
10371052

10381053
blame_coalesce(&sb);
10391054

1055+
if (!(output_option & (OUTPUT_COLOR_LINE | OUTPUT_SHOW_AGE_WITH_COLOR)))
1056+
output_option |= coloring_mode;
1057+
10401058
if (!(output_option & OUTPUT_PORCELAIN)) {
10411059
find_alignment(&sb, &output_option);
10421060
if (!*repeated_meta_color &&

t/t8012-blame-colors.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ PROG='git blame -c'
88

99
test_expect_success 'colored blame colors contiguous lines' '
1010
git -c color.blame.repeatedLines=yellow blame --color-lines --abbrev=12 hello.c >actual.raw &&
11+
git -c color.blame.repeatedLines=yellow -c blame.coloring=repeatedLines blame --abbrev=12 hello.c >actual.raw.2 &&
12+
test_cmp actual.raw actual.raw.2 &&
1113
test_decode_color <actual.raw >actual &&
1214
grep "<YELLOW>" <actual >darkened &&
1315
grep "(F" darkened > F.expect &&
@@ -18,6 +20,8 @@ test_expect_success 'colored blame colors contiguous lines' '
1820

1921
test_expect_success 'color by age consistently colors old code' '
2022
git blame --color-by-age hello.c >actual.raw &&
23+
git -c blame.coloring=highlightRecent blame hello.c >actual.raw.2 &&
24+
test_cmp actual.raw actual.raw.2 &&
2125
test_decode_color <actual.raw >actual &&
2226
grep "<BLUE>" <actual >colored &&
2327
test_line_count = 10 colored

0 commit comments

Comments
 (0)