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 <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Apr 23, 2018 at 17:09 UTC
0dc95a4d8a71bcb0c9d0163716bd99c2d785bd10
3 files changed
+27
Documentation/config.txt
+5
@@ -1240,6 +1240,11 @@ everything older than one year blue, recent changes between one month and
1240
one year old are kept white, and lines introduced within the last month are
1241
colored red.
1242
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
+
1248
color.ui::
1249
This variable determines the default value for variables such
1250
as `color.diff` and `color.grep` that control the use of color
builtin/blame.c
+18
@@ -49,6 +49,7 @@ static int abbrev = -1;
49
static int no_whole_file_rename;
50
static int show_progress;
51
static char repeated_meta_color[COLOR_MAXLEN];
52
+static int coloring_mode;
53
54
static struct date_mode blame_date_mode = { DATE_ISO8601 };
55
static size_t blame_date_width;
@@ -702,6 +703,20 @@ static int git_blame_config(const char *var, const char *value, void *cb)
703
return 0;
704
}
705
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
+
720
if (git_diff_heuristic_config(var, value, cb) < 0)
721
return -1;
722
if (userdiff_config(var, value) < 0)
@@ -1037,6 +1052,9 @@ parse_done:
1052
1053
blame_coalesce(&sb);
1054
1055
+ if (!(output_option & (OUTPUT_COLOR_LINE | OUTPUT_SHOW_AGE_WITH_COLOR)))
1056
+ output_option |= coloring_mode;
1057
+
1058
if (!(output_option & OUTPUT_PORCELAIN)) {
1059
find_alignment(&sb, &output_option);
1060
if (!*repeated_meta_color &&
t/t8012-blame-colors.sh
+4
@@ -8,6 +8,8 @@ PROG='git blame -c'
8
9
test_expect_success 'colored blame colors contiguous lines' '
10
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 &&
13
test_decode_color <actual.raw >actual &&
14
grep "<YELLOW>" <actual >darkened &&
15
grep "(F" darkened > F.expect &&
@@ -18,6 +20,8 @@ test_expect_success 'colored blame colors contiguous lines' '
20
21
test_expect_success 'color by age consistently colors old code' '
22
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 &&
25
test_decode_color <actual.raw >actual &&
26
grep "<BLUE>" <actual >colored &&
27
test_line_count = 10 colored