builtin/blame: add new coloring scheme config
authorStefan Beller <sbeller@google.com>
Tue, 24 Apr 2018 00:09:00 +0000 (17:09 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 24 Apr 2018 02:03:17 +0000 (11:03 +0900)
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>
Documentation/config.txt
builtin/blame.c
t/t8012-blame-colors.sh
index c6aea52e98ad9742dd893e0452e64c860fcd254a..4eb030ed43736959a111d2aa9dc6401a64a75837 100644 (file)
@@ -1240,6 +1240,11 @@ everything older than one year blue, recent changes between one month and
 one year old are kept white, and lines introduced within the last month are
 colored red.
 
+blame.coloring::
+       This determines the coloring scheme to be applied to blame
+       output. It can be 'repeatedLines', 'highlightRecent',
+       or 'none' which is the default.
+
 color.ui::
        This variable determines the default value for variables such
        as `color.diff` and `color.grep` that control the use of color
index 35104e41603942c8ee8b19d528d76dfc16675eab..f95aac746872af820a6c69596207620b80e5793c 100644 (file)
@@ -49,6 +49,7 @@ static int abbrev = -1;
 static int no_whole_file_rename;
 static int show_progress;
 static char repeated_meta_color[COLOR_MAXLEN];
+static int coloring_mode;
 
 static struct date_mode blame_date_mode = { DATE_ISO8601 };
 static size_t blame_date_width;
@@ -702,6 +703,20 @@ static int git_blame_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
+       if (!strcmp(var, "blame.coloring")) {
+               if (!strcmp(value, "repeatedLines")) {
+                       coloring_mode |= OUTPUT_COLOR_LINE;
+               } else if (!strcmp(value, "highlightRecent")) {
+                       coloring_mode |= OUTPUT_SHOW_AGE_WITH_COLOR;
+               } else if (!strcmp(value, "none")) {
+                       coloring_mode &= ~(OUTPUT_COLOR_LINE |
+                                           OUTPUT_SHOW_AGE_WITH_COLOR);
+               } else {
+                       warning(_("invalid value for blame.coloring"));
+                       return 0;
+               }
+       }
+
        if (git_diff_heuristic_config(var, value, cb) < 0)
                return -1;
        if (userdiff_config(var, value) < 0)
@@ -1037,6 +1052,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 
        blame_coalesce(&sb);
 
+       if (!(output_option & (OUTPUT_COLOR_LINE | OUTPUT_SHOW_AGE_WITH_COLOR)))
+               output_option |= coloring_mode;
+
        if (!(output_option & OUTPUT_PORCELAIN)) {
                find_alignment(&sb, &output_option);
                if (!*repeated_meta_color &&
index ae9aa79d4e60dac70d3db42f871546a89f1e2e4d..ed38f74de95c92b358cc9a27d2470e890b9bdbb3 100755 (executable)
@@ -8,6 +8,8 @@ PROG='git blame -c'
 
 test_expect_success 'colored blame colors contiguous lines' '
        git -c color.blame.repeatedLines=yellow blame --color-lines --abbrev=12 hello.c >actual.raw &&
+       git -c color.blame.repeatedLines=yellow -c blame.coloring=repeatedLines blame --abbrev=12 hello.c >actual.raw.2 &&
+       test_cmp actual.raw actual.raw.2 &&
        test_decode_color <actual.raw >actual &&
        grep "<YELLOW>" <actual >darkened &&
        grep "(F" darkened > F.expect &&
@@ -18,6 +20,8 @@ test_expect_success 'colored blame colors contiguous lines' '
 
 test_expect_success 'color by age consistently colors old code' '
        git blame --color-by-age hello.c >actual.raw &&
+       git -c blame.coloring=highlightRecent blame hello.c >actual.raw.2 &&
+       test_cmp actual.raw actual.raw.2 &&
        test_decode_color <actual.raw >actual &&
        grep "<BLUE>" <actual >colored &&
        test_line_count = 10 colored