From: Junio C Hamano Date: Thu, 11 Jun 2015 16:29:53 +0000 (-0700) Subject: Merge branch 'jk/color-diff-plain-is-context' X-Git-Tag: v2.5.0-rc0~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=db65170ee5558b47355e7f9f111aecb5b152d4d9;p=thirdparty%2Fgit.git Merge branch 'jk/color-diff-plain-is-context' "color.diff.plain" was a misnomer; give it 'color.diff.context' as a more logical synonym. * jk/color-diff-plain-is-context: diff.h: rename DIFF_PLAIN color slot to DIFF_CONTEXT diff: accept color.diff.context as a synonym for "plain" --- db65170ee5558b47355e7f9f111aecb5b152d4d9 diff --cc Documentation/config.txt index 4d21ce1647,b458590f26..43bb53c047 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@@ -914,10 -870,12 +914,11 @@@ command line with the `--color[=] color.diff.:: Use customized color for diff colorization. `` specifies which part of the patch to use the specified color, and is one - of `plain` (context text), `meta` (metainformation), `frag` + of `context` (context text - `plain` is a historical synonym), + `meta` (metainformation), `frag` (hunk header), 'func' (function in hunk header), `old` (removed lines), `new` (added lines), `commit` (commit headers), or `whitespace` - (highlighting whitespace errors). The values of these variables may be - specified as in color.branch.. + (highlighting whitespace errors). color.decorate.:: Use customized color for 'git log --decorate' output. `` is one diff --cc diff.c index 324be1d959,ff68a70b1b..87b16d5613 --- a/diff.c +++ b/diff.c @@@ -507,30 -498,6 +507,30 @@@ static void emit_line_checked(const cha } } +static void emit_add_line(const char *reset, + struct emit_callback *ecbdata, + const char *line, int len) +{ + emit_line_checked(reset, ecbdata, line, len, + DIFF_FILE_NEW, WSEH_NEW, '+'); +} + +static void emit_del_line(const char *reset, + struct emit_callback *ecbdata, + const char *line, int len) +{ + emit_line_checked(reset, ecbdata, line, len, + DIFF_FILE_OLD, WSEH_OLD, '-'); +} + +static void emit_context_line(const char *reset, + struct emit_callback *ecbdata, + const char *line, int len) +{ + emit_line_checked(reset, ecbdata, line, len, - DIFF_PLAIN, WSEH_CONTEXT, ' '); ++ DIFF_CONTEXT, WSEH_CONTEXT, ' '); +} + static void emit_hunk_header(struct emit_callback *ecbdata, const char *line, int len) { @@@ -1281,27 -1250,17 +1281,27 @@@ static void fn_out_consume(void *priv, return; } - if (line[0] != '+') { - const char *color = - diff_get_color(ecbdata->color_diff, - line[0] == '-' ? DIFF_FILE_OLD : DIFF_CONTEXT); - ecbdata->lno_in_preimage++; - if (line[0] == ' ') - ecbdata->lno_in_postimage++; - emit_line(ecbdata->opt, color, reset, line, len); - } else { + switch (line[0]) { + case '+': ecbdata->lno_in_postimage++; emit_add_line(reset, ecbdata, line + 1, len - 1); + break; + case '-': + ecbdata->lno_in_preimage++; + emit_del_line(reset, ecbdata, line + 1, len - 1); + break; + case ' ': + ecbdata->lno_in_postimage++; + ecbdata->lno_in_preimage++; + emit_context_line(reset, ecbdata, line + 1, len - 1); + break; + default: + /* incomplete line at the end */ + ecbdata->lno_in_preimage++; + emit_line(ecbdata->opt, - diff_get_color(ecbdata->color_diff, DIFF_PLAIN), ++ diff_get_color(ecbdata->color_diff, DIFF_CONTEXT), + reset, line, len); + break; } }