{"thread":{"id":"39422","subject":"Mark trailing whitespace error in del lines of diff","startedAt":"2015-05-25T21:11:34Z","lastAt":"2015-05-27T20:53:27Z","messageCount":30,"participants":["Christian Brabandt","brian m. carlson","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"262098","messageId":"9b8e349e223dc9cd871fc5f7915e590548322932.1432585659.git.cb@256bit.org","threadId":"39422","inReplyTo":null,"subject":"Mark trailing whitespace error in del lines of diff","fromName":"Christian Brabandt","fromEmail":"cblists@256bit.org","sentAt":"2015-05-25T21:11:34Z","receivedAt":"2015-05-25T21:11:34Z","isPatch":false,"sender":{"key":"cblists@256bit.org","avatar":null},"body":"Currently git-diff only highlights trailing whitespace in the new lines\n(prefixed with '+'), thus it is not visible in the deleted lines\n(prefixed with '-').\n\nTherefore introduce a new configuration variable for the core.whitespace\nsetting \"blank-at-eol-old\" (default off) that will highlight trailing\nwhitespace in those lines as well.\n\nSigned-off-by: Christian Brabandt <cb@256bit.org>\n---\n\nHi,\nplease be gentle, this is the first time I contribute to the git \ndevelopment.\n\nHere is my use case: I have been working in a team repository, \nreformatting the source and wondered, why my reformatting did introduce \nsome trailing whitespace. I suspected a bug in Vim and started to debug \nit, until I found out, that git-diff simply does not show trailing \nwhitespace in the deleted lines. Therefore, I'd like to have an option, \nto also show trailing whitespace in the deleted lines of a diff. So here \nis the patch.\n\nAs far as I can see, this does not break any tests and also the \nbehaviour of git-diff --check does not change. \n\n Documentation/config.txt | 2 ++\n cache.h                  | 1 +\n diff.c                   | 8 +++++++-\n ws.c                     | 8 ++++++--\n 4 files changed, 16 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 0f668bb..f73f0f7 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -670,6 +670,8 @@ core.whitespace::\n +\n * `blank-at-eol` treats trailing whitespaces at the end of the line\n   as an error (enabled by default).\n+* `blank-at-eol-old` like `blank-at-eol`, but for the deleted lines\n+  of a patch (i.e. those preceeded with a '-') (not enabled by default)\n * `space-before-tab` treats a space character that appears immediately\n   before a tab character in the initial indent part of the line as an\n   error (enabled by default).\ndiff --git a/cache.h b/cache.h\nindex 1f4226b..811b640 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1618,6 +1618,7 @@ void shift_tree_by(const unsigned char *, const unsigned char *, unsigned char *\n #define WS_CR_AT_EOL           01000\n #define WS_BLANK_AT_EOF        02000\n #define WS_TAB_IN_INDENT       04000\n+#define WS_BLANK_AT_EOL_OLD    010000\n #define WS_TRAILING_SPACE      (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF)\n #define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB|8)\n #define WS_TAB_WIDTH_MASK        077\ndiff --git a/diff.c b/diff.c\nindex 7500c55..4245956 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1254,10 +1254,16 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)\n \t\tconst char *color =\n \t\t\tdiff_get_color(ecbdata->color_diff,\n \t\t\t\t       line[0] == '-' ? DIFF_FILE_OLD : DIFF_PLAIN);\n+\t\tconst char *ws = diff_get_color(ecbdata->color_diff, DIFF_WHITESPACE);\n+\n \t\tecbdata->lno_in_preimage++;\n \t\tif (line[0] == ' ')\n \t\t\tecbdata->lno_in_postimage++;\n-\t\temit_line(ecbdata->opt, color, reset, line, len);\n+\t\tif (*ws && ecbdata->ws_rule & WS_BLANK_AT_EOL_OLD)\n+\t\t\tws_check_emit(line, len, ecbdata->ws_rule,\n+\t\t\t\tecbdata->opt->file, color, reset, ws);\n+\t\telse\n+\t\t\temit_line(ecbdata->opt, color, reset, line, len);\n \t} else {\n \t\tecbdata->lno_in_postimage++;\n \t\temit_add_line(reset, ecbdata, line + 1, len - 1);\ndiff --git a/ws.c b/ws.c\nindex ea4b2b1..09e04f0 100644\n--- a/ws.c\n+++ b/ws.c\n@@ -18,6 +18,7 @@ static struct whitespace_rule {\n \t{ \"indent-with-non-tab\", WS_INDENT_WITH_NON_TAB, 0 },\n \t{ \"cr-at-eol\", WS_CR_AT_EOL, 1 },\n \t{ \"blank-at-eol\", WS_BLANK_AT_EOL, 0 },\n+\t{ \"blank-at-eol-del\", WS_BLANK_AT_EOL_OLD, 0, 1 },\n \t{ \"blank-at-eof\", WS_BLANK_AT_EOF, 0 },\n \t{ \"tab-in-indent\", WS_TAB_IN_INDENT, 0, 1 },\n };\n@@ -170,11 +171,14 @@ static unsigned ws_check_emit_1(const char *line, int len, unsigned ws_rule,\n \t}\n \n \t/* Check for trailing whitespace. */\n-\tif (ws_rule & WS_BLANK_AT_EOL) {\n+\tif ((ws_rule & WS_BLANK_AT_EOL) || (ws_rule & WS_BLANK_AT_EOL_OLD)) {\n \t\tfor (i = len - 1; i >= 0; i--) {\n \t\t\tif (isspace(line[i])) {\n \t\t\t\ttrailing_whitespace = i;\n-\t\t\t\tresult |= WS_BLANK_AT_EOL;\n+\t\t\t\tif (ws_rule & WS_BLANK_AT_EOL)\n+\t\t\t\t\tresult |= WS_BLANK_AT_EOL;\n+\t\t\t\telse\n+\t\t\t\t\tresult |= WS_BLANK_AT_EOL_OLD;\n \t\t\t}\n \t\t\telse\n \t\t\t\tbreak;\n"},{"id":"262100","messageId":"20150525222215.GI26436@vauxhall.crustytoothpaste.net","threadId":"39422","inReplyTo":"9b8e349e223dc9cd871fc5f7915e590548322932.1432585659.git.cb@256bit.org","subject":"Re: Mark trailing whitespace error in del lines of diff","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-05-25T22:22:16Z","receivedAt":"2015-05-25T22:22:16Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Mon, May 25, 2015 at 11:11:34PM +0200, Christian Brabandt wrote:\n> Here is my use case: I have been working in a team repository,\n> reformatting the source and wondered, why my reformatting did introduce\n> some trailing whitespace. I suspected a bug in Vim and started to debug\n> it, until I found out, that git-diff simply does not show trailing\n> whitespace in the deleted lines. Therefore, I'd like to have an option,\n> to also show trailing whitespace in the deleted lines of a diff. So here\n> is the patch.\n\nI like this idea.  My use case is determining whether a patch to a\npristine-tar repository introduced trailing whitespace (which is not\nokay) or just left it there (which is okay).\n\n> As far as I can see, this does not break any tests and also the\n> behaviour of git-diff --check does not change.\n\nPerhaps you'd care to implement a test or two to make sure that this\ncontinues to work properly?\n\n>  Documentation/config.txt | 2 ++\n>  cache.h                  | 1 +\n>  diff.c                   | 8 +++++++-\n>  ws.c                     | 8 ++++++--\n>  4 files changed, 16 insertions(+), 3 deletions(-)\n> \n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> index 0f668bb..f73f0f7 100644\n> --- a/Documentation/config.txt\n> +++ b/Documentation/config.txt\n> @@ -670,6 +670,8 @@ core.whitespace::\n>  +\n>  * `blank-at-eol` treats trailing whitespaces at the end of the line\n>    as an error (enabled by default).\n> +* `blank-at-eol-old` like `blank-at-eol`, but for the deleted lines\n\nYou might want to insert \"works\" before \"like\" so that it's a complete\nsentence.\n\n> +  of a patch (i.e. those preceeded with a '-') (not enabled by default)\n\nI believe this should be \"preceded\".\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"},{"id":"262101","messageId":"xmqqbnh89r0z.fsf@gitster.dls.corp.google.com","threadId":"39422","inReplyTo":"20150525222215.GI26436@vauxhall.crustytoothpaste.net","subject":"Re: Mark trailing whitespace error in del lines of diff","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-25T23:27:40Z","receivedAt":"2015-05-25T23:27:40Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> I like this idea.\n\nI don't.\n\n> My use case is determining whether a patch to a pristine-tar\n> repository introduced trailing whitespace (which is not okay) or\n> just left it there (which is okay).\n\nIn your use case, where keeping trailing blank that is otherwise not\nOK is fine only when the breakage was inherited from the preimage,\nwouldn't it be equally fine to keep other kinds of breakages as long\nas they were inherited from the preimage?  E.g. \"The original used\n8-space as leading indent, and you would not use that for your new\nlines, but the breakage was inherited from the preimage\" would want\nto be treated the same way, no?  Why trailing blanks so special?\n\nSo, from that point of view, your \"use case\" does not justify this\nparticular implementation that special-cases trailing blanks on\ndeleted lines and mark them [*1*].\n\nIf the implementation were addition of a new option to check and\nmark all kinds of errors core.whitespace would catch for new lines\nalso for old lines, then it would be a somewhat different story.  I\npersonally do not find such an option interesting, but at least I\ncan understand why some people might find it useful.\n\n\n[Footnote]\n\n*1* To support your use case with the ultimate ease-of-use, it would\nbe best if the new option were to squelch the whitespace error on\nthe new line when it was inherited from the old line, which is\ndifferent from showing and marking the breakage on the old line.\nBut I do not think it can be implemented sanely, so I will not go\nthere.\n"},{"id":"262102","messageId":"20150525235251.GJ26436@vauxhall.crustytoothpaste.net","threadId":"39422","inReplyTo":"xmqqbnh89r0z.fsf@gitster.dls.corp.google.com","subject":"Re: Mark trailing whitespace error in del lines of diff","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-05-25T23:52:52Z","receivedAt":"2015-05-25T23:52:52Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Mon, May 25, 2015 at 04:27:40PM -0700, Junio C Hamano wrote:\n> \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n> > My use case is determining whether a patch to a pristine-tar\n> > repository introduced trailing whitespace (which is not okay) or\n> > just left it there (which is okay).\n> \n> In your use case, where keeping trailing blank that is otherwise not\n> OK is fine only when the breakage was inherited from the preimage,\n> wouldn't it be equally fine to keep other kinds of breakages as long\n> as they were inherited from the preimage?  E.g. \"The original used\n> 8-space as leading indent, and you would not use that for your new\n> lines, but the breakage was inherited from the preimage\" would want\n> to be treated the same way, no?  Why trailing blanks so special?\n\nThe goal is to keep the code as similar as possible to the old code,\nsince this is third-party code.  If you're changing the whitespace\nsignificantly, your changes are too invasive.  If you're inserting\nlines, you shouldn't be adding trailing whitespace, but keeping\nupstream's bizarre indent would be acceptable.\n\nTrailing blanks aren't necessarily special, but they are the most common\nand the easiest to fix (or not introduce) on a piecemeal basis.\n\nI agree that a more generic solution would be better.\n\n> If the implementation were addition of a new option to check and\n> mark all kinds of errors core.whitespace would catch for new lines\n> also for old lines, then it would be a somewhat different story.  I\n> personally do not find such an option interesting, but at least I\n> can understand why some people might find it useful.\n\nThe vast majority of the whitespace errors I see are blank-at-eol, so I\nfelt this change was, if anything, a good first step.  Having read your\nresponse, I agree the generic solution is preferable.\n\n> [Footnote]\n> \n> *1* To support your use case with the ultimate ease-of-use, it would\n> be best if the new option were to squelch the whitespace error on\n> the new line when it was inherited from the old line, which is\n> different from showing and marking the breakage on the old line.\n> But I do not think it can be implemented sanely, so I will not go\n> there.\n\nI'd rather see that there's an error on both so that I have the\nknowledge when reviewing a patch.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"},{"id":"262103","messageId":"xmqq617g9oer.fsf@gitster.dls.corp.google.com","threadId":"39422","inReplyTo":"9b8e349e223dc9cd871fc5f7915e590548322932.1432585659.git.cb@256bit.org","subject":"Re: Mark trailing whitespace error in del lines of diff","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-26T00:24:12Z","receivedAt":"2015-05-26T00:24:12Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Brabandt <cblists@256bit.org>, Christian Brabandt\n<cb@256bit.org> writes:\n\n> As far as I can see, this does not break any tests and also the \n> behaviour of git-diff --check does not change. \n\nEven if this change introduced a bug that changed the behaviour\n(e.g. say, exited with failure status code when only preimage had\nerrors), I wouldn't be surprised if no existing test caught such a\nbreakage.  Because the existing tests were written with the\nassumption that the code to check whitespace breakages would never\nlook at preimage, it is plausible that no preimage line used in the\ntest has any whitespace error in the first place.\n\nIn other words, you'd need to add new tests that change preimage\nlines with various kinds of whitespace errors into postimage lines\nwith and without whitespace errors, and run \"diff\" with various\ncombinations of the existing set of core.whitespace values as well\nas your new one.\n\nBut as I said in the other message, I think that the approach this\npatch takes goes in a wrong direction.  Instead of adding a single\n\"check and highlight this and only kind of breakage on preimage\"\noption as a new kind to existing \"what kind of use of whitespaces\nare errors\" set, it would be more sensible to add a single \"check\nand highlight breakages on preimage lines as well\" option that is\northogonal to the existing ones that specify \"what kind of use of\nwhitespaces are errors\".\n"},{"id":"262136","messageId":"20150526162937.GA24439@256bit.org","threadId":"39422","inReplyTo":"xmqqbnh89r0z.fsf@gitster.dls.corp.google.com","subject":"Re: Mark trailing whitespace error in del lines of diff","fromName":"Christian Brabandt","fromEmail":"cblists@256bit.org","sentAt":"2015-05-26T16:29:37Z","receivedAt":"2015-05-26T16:29:37Z","isPatch":false,"sender":{"key":"cblists@256bit.org","avatar":null},"body":"Hi Junio!\n\nOn Mo, 25 Mai 2015, Junio C Hamano wrote:\n\n> \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n> \n> > I like this idea.\n> \n> I don't.\n> \n> > My use case is determining whether a patch to a pristine-tar\n> > repository introduced trailing whitespace (which is not okay) or\n> > just left it there (which is okay).\n> \n> In your use case, where keeping trailing blank that is otherwise not\n> OK is fine only when the breakage was inherited from the preimage,\n> wouldn't it be equally fine to keep other kinds of breakages as long\n> as they were inherited from the preimage?  E.g. \"The original used\n> 8-space as leading indent, and you would not use that for your new\n> lines, but the breakage was inherited from the preimage\" would want\n> to be treated the same way, no?  Why trailing blanks so special?\n\nIt was the one I am interesting in and also the one that I usually try \nto avoid ;)\n\n(In fact, I thought if the other options would be needed, one could add \nadditional suboptions for core.whitespace as well, so one would be able \nto exactly say, what kind of things one would like to see and which \ncould be different for new lines and old lines).\n\n> \n> So, from that point of view, your \"use case\" does not justify this\n> particular implementation that special-cases trailing blanks on\n> deleted lines and mark them [*1*].\n\n> \n> If the implementation were addition of a new option to check and\n> mark all kinds of errors core.whitespace would catch for new lines\n> also for old lines, then it would be a somewhat different story.  I\n> personally do not find such an option interesting, but at least I\n> can understand why some people might find it useful.\n\nWouldn't that mean, that one couldn't see different kind of whitespace \nmarkings for newlines and deleted lines? I don't know, if one would want \nthat a configuration however.\n\nHowever, as I don't know the codebase very well, I doubt I can implement \nthis.\n\n> [Footnote]\n> \n> *1* To support your use case with the ultimate ease-of-use, it would\n> be best if the new option were to squelch the whitespace error on\n> the new line when it was inherited from the old line, which is\n> different from showing and marking the breakage on the old line.\n> But I do not think it can be implemented sanely, so I will not go\n> there.\n\nAside from the difficulties it would take to do this,\npersonally, I don't like this option. Because I like to see such \nproblems, but just want to know whether a particular patch has \nintroduced the problem or not.\n\nBest,\nChristian\n-- \nIn den Fragen im gemeinen Leben, wie man etwas am besten tun könnte,\nwird ein gewisses Maximum gesucht.\n\t\t-- Georg Christoph Lichtenberg\n"},{"id":"262135","messageId":"20150526163108.GB24439@256bit.org","threadId":"39422","inReplyTo":"xmqq617g9oer.fsf@gitster.dls.corp.google.com","subject":"Re: Mark trailing whitespace error in del lines of diff","fromName":"Christian Brabandt","fromEmail":"cblists@256bit.org","sentAt":"2015-05-26T16:31:08Z","receivedAt":"2015-05-26T16:31:08Z","isPatch":false,"sender":{"key":"cblists@256bit.org","avatar":null},"body":"Hi Junio!\n\nOn Mo, 25 Mai 2015, Junio C Hamano wrote:\n\n> Christian Brabandt <cblists@256bit.org>, Christian Brabandt\n> <cb@256bit.org> writes:\n> \n> > As far as I can see, this does not break any tests and also the \n> > behaviour of git-diff --check does not change. \n> \n> Even if this change introduced a bug that changed the behaviour\n> (e.g. say, exited with failure status code when only preimage had\n> errors), I wouldn't be surprised if no existing test caught such a\n> breakage.  Because the existing tests were written with the\n> assumption that the code to check whitespace breakages would never\n> look at preimage, it is plausible that no preimage line used in the\n> test has any whitespace error in the first place.\n> \n> In other words, you'd need to add new tests that change preimage\n> lines with various kinds of whitespace errors into postimage lines\n> with and without whitespace errors, and run \"diff\" with various\n> combinations of the existing set of core.whitespace values as well\n> as your new one.\n> \n> But as I said in the other message, I think that the approach this\n> patch takes goes in a wrong direction.  Instead of adding a single\n> \"check and highlight this and only kind of breakage on preimage\"\n> option as a new kind to existing \"what kind of use of whitespaces\n> are errors\" set, it would be more sensible to add a single \"check\n> and highlight breakages on preimage lines as well\" option that is\n> orthogonal to the existing ones that specify \"what kind of use of\n> whitespaces are errors\".\n\nOh well, too bad. It sounded like a good idea...\n\nBest,\nChristian\n-- \nUnser Gefühl für Natur gleicht der Empfindung des Kranken für die\nGesundheit.\n\t\t-- Friedrich Johann Christoph Schiller\n"},{"id":"262138","messageId":"xmqqegm3l06u.fsf@gitster.dls.corp.google.com","threadId":"39422","inReplyTo":"20150526162937.GA24439@256bit.org","subject":"Re: Mark trailing whitespace error in del lines of diff","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-26T17:26:33Z","receivedAt":"2015-05-26T17:26:33Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Brabandt <cblists@256bit.org> writes:\n\n> It was the one I am interesting in and also the one that I usually try \n> to avoid ;)\n>\n> (In fact, I thought if the other options would be needed, one could add \n> additional suboptions for core.whitespace as well,...\n\nThat road leads to madness.  Why should we add 2*N options in the\nfirst place?  What valid reason are there, other than \"because we\ncould\", to have \"diff --ws-check-delelted\" and \"diff -R\" paint\nwhitespace breakages differently?\n\nI personally do not think I'd use such an option often, but I do\nrecall running \"diff -R\" and realized that we fixed whitespace\nbreakages in the past, which made me feel good (the reason why I\ngave \"-R\" was not to see whitespace breakages in the preimage,\nthough; it merely was a side effect).\n\nI'll send out two patch series to do the painting part (I didn't\nwant to touch \"--check\", as its utility is even more dubious\ncompared to painting, at least to me).\n\nHere is the first one, a preliminary refactoring.\n\n-- >8 --\nSubject: [PATCH 1/2] diff.c: add emit_del_line() and restructure callers of emit_line_0()\n\nTraditionally, we only had emit_add_line() helper, which knows how\nto find and paint whitespace breakages on the given line, because we\nonly care about whitespace breakages introduced in new lines.  The\ncontext lines and old (i.e. deleted) lines are emitted with a\nsimpler emit_line_0() that paints the entire line in plain or old\ncolors.\n\nSome people may want to paint whitespace breakages on old lines;\nwhen they see a whitespace breakage on a new line, they can spot\nthe same kind of whitespace breakage on the corresponding old line\nand want to say \"Ah, that breakage is there but was inherited from\nthe original, so let's not fix that for now.\"\n\nTo make such a future enhancement easier, introduce emit_del_line()\nand replace direct calls to emit_line_0() with it.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n diff.c | 36 ++++++++++++++++++++++++------------\n 1 file changed, 24 insertions(+), 12 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 7500c55..93c1eb4 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -498,6 +498,15 @@ static void emit_add_line(const char *reset,\n \t}\n }\n \n+static void emit_del_line(const char *reset,\n+\t\t\t  struct emit_callback *ecbdata,\n+\t\t\t  const char *line, int len)\n+{\n+\tconst char *set = diff_get_color(ecbdata->color_diff, DIFF_FILE_OLD);\n+\n+\temit_line_0(ecbdata->opt, set, reset, '-', line, len);\n+}\n+\n static void emit_hunk_header(struct emit_callback *ecbdata,\n \t\t\t     const char *line, int len)\n {\n@@ -603,7 +612,6 @@ static void emit_rewrite_lines(struct emit_callback *ecb,\n {\n \tconst char *endp = NULL;\n \tstatic const char *nneof = \" No newline at end of file\\n\";\n-\tconst char *old = diff_get_color(ecb->color_diff, DIFF_FILE_OLD);\n \tconst char *reset = diff_get_color(ecb->color_diff, DIFF_RESET);\n \n \twhile (0 < size) {\n@@ -613,8 +621,7 @@ static void emit_rewrite_lines(struct emit_callback *ecb,\n \t\tlen = endp ? (endp - data + 1) : size;\n \t\tif (prefix != '+') {\n \t\t\tecb->lno_in_preimage++;\n-\t\t\temit_line_0(ecb->opt, old, reset, '-',\n-\t\t\t\t    data, len);\n+\t\t\temit_del_line(reset, ecb, data, len);\n \t\t} else {\n \t\t\tecb->lno_in_postimage++;\n \t\t\temit_add_line(reset, ecb, data, len);\n@@ -1250,17 +1257,22 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)\n \t\treturn;\n \t}\n \n-\tif (line[0] != '+') {\n-\t\tconst char *color =\n-\t\t\tdiff_get_color(ecbdata->color_diff,\n-\t\t\t\t       line[0] == '-' ? DIFF_FILE_OLD : DIFF_PLAIN);\n-\t\tecbdata->lno_in_preimage++;\n-\t\tif (line[0] == ' ')\n-\t\t\tecbdata->lno_in_postimage++;\n-\t\temit_line(ecbdata->opt, color, reset, line, len);\n-\t} else {\n+\tswitch (line[0]) {\n+\tcase '+':\n \t\tecbdata->lno_in_postimage++;\n \t\temit_add_line(reset, ecbdata, line + 1, len - 1);\n+\t\tbreak;\n+\tcase '-':\n+\t\tecbdata->lno_in_preimage++;\n+\t\temit_del_line(reset, ecbdata, line + 1, len - 1);\n+\t\tbreak;\n+\tdefault: /* both ' ' and incomplete line */\n+\t\tecbdata->lno_in_preimage++;\n+\t\tecbdata->lno_in_postimage++;\n+\t\temit_line(ecbdata->opt,\n+\t\t\t  diff_get_color(ecbdata->color_diff, DIFF_PLAIN),\n+\t\t\t  reset, line, len);\n+\t\tbreak;\n \t}\n }\n \n-- \n2.4.1-511-gc1146d5\n"},{"id":"262139","messageId":"xmqqa8wrkzur.fsf@gitster.dls.corp.google.com","threadId":"39422","inReplyTo":"20150526163108.GB24439@256bit.org","subject":"Re: Mark trailing whitespace error in del lines of diff","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-26T17:33:48Z","receivedAt":"2015-05-26T17:33:48Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Brabandt <cblists@256bit.org> writes:\n\n>> But as I said in the other message, I think that the approach this\n>> patch takes goes in a wrong direction.  Instead of adding a single\n>> \"check and highlight this and only kind of breakage on preimage\"\n>> option as a new kind to existing \"what kind of use of whitespaces\n>> are errors\" set, it would be more sensible to add a single \"check\n>> and highlight breakages on preimage lines as well\" option that is\n>> orthogonal to the existing ones that specify \"what kind of use of\n>> whitespaces are errors\".\n>\n> Oh well, too bad. It sounded like a good idea...\n\nOh, don't get me wrong.  I do not think it is not a good idea\n(i.e. problem and general strategy to solve it).\n\nProblem:\n\n    Sometimes it is desirable to keep existing whitespace breakages\n    while working on fixes and other changes of substance.  The user\n    however gets whitespace errors painted only on new lines in the\n    output from \"git diff\", and this makes it hard to tell if they\n    were introduced by the user's change or came from the original.\n\nStrategy:\n\n    By painting whitespace breakages in the old lines, the user can\n    eyeball and find the corresponding old lines when whitespace\n    errors on new lines are painted.  If the corresponding old lines\n    have the same errors, the user can see they were inherited from\n    the original.\n\nThese may be a pair of reasonable problem to solve and a general\nstrategy to solve it.\n\nWhat I said was *not* good was the particular execution, the\napproach that the patch took.\n"},{"id":"262140","messageId":"xmqq617fkztj.fsf@gitster.dls.corp.google.com","threadId":"39422","inReplyTo":"xmqqegm3l06u.fsf@gitster.dls.corp.google.com","subject":"Re: Mark trailing whitespace error in del lines of diff","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-26T17:34:32Z","receivedAt":"2015-05-26T17:34:32Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> I'll send out two patch series to do the painting part (I didn't\n> want to touch \"--check\", as its utility is even more dubious\n> compared to painting, at least to me).\n\nAnd here is the second one.\n\n-- >8 --\nSubject: [PATCH 2/2] diff.c: --ws-check-deleted option\n\nTraditionally, we only cared about whitespace breakages introduced\nin new lines.  Some people want to paint whitespace breakages on old\nlines, too.  When they see a whitespace breakage on a new line, they\ncan spot the same kind of whitespace breakage on the corresponding\nold line and want to say \"Ah, that breakage is there but was\ninherited from the original, so let's not fix that for now.\"\n\nEnable such use with the new option, \"--ws-check-deleted\".\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/diff-options.txt |  7 +++++++\n diff.c                         | 21 ++++++++++++++++++++-\n diff.h                         |  1 +\n 3 files changed, 28 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex b7c3afe..617cbc6 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -282,6 +282,13 @@ ifndef::git-format-patch[]\n \tinitial indent of the line are considered whitespace errors.\n \tExits with non-zero status if problems are found. Not compatible\n \twith --exit-code.\n+\n+--ws-check-deleted::\n+--no-ws-check-deleted::\n+\tHighlight whitespace errors in deleted lines in the color\n+\tspecified by `color.diff.whitespace`, as well as in added\n+\tlines.\n+\n endif::git-format-patch[]\n \n --full-index::\ndiff --git a/diff.c b/diff.c\nindex 93c1eb4..44cc234 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -503,8 +503,22 @@ static void emit_del_line(const char *reset,\n \t\t\t  const char *line, int len)\n {\n \tconst char *set = diff_get_color(ecbdata->color_diff, DIFF_FILE_OLD);\n+\tconst char *ws = NULL;\n \n-\temit_line_0(ecbdata->opt, set, reset, '-', line, len);\n+\tif (ecbdata->opt->ws_check_deleted) {\n+\t\tws = diff_get_color(ecbdata->color_diff, DIFF_WHITESPACE);\n+\t\tif (!*ws)\n+\t\t\tws = NULL;\n+\t}\n+\n+\tif (!ws)\n+\t\temit_line_0(ecbdata->opt, set, reset, '-', line, len);\n+\telse {\n+\t\t/* Emit just the prefix, then the rest. */\n+\t\temit_line_0(ecbdata->opt, set, reset, '-', \"\", 0);\n+\t\tws_check_emit(line, len, ecbdata->ws_rule,\n+\t\t\t      ecbdata->opt->file, set, reset, ws);\n+\t}\n }\n \n static void emit_hunk_header(struct emit_callback *ecbdata,\n@@ -3819,6 +3833,11 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \telse if (skip_prefix(arg, \"--submodule=\", &arg))\n \t\treturn parse_submodule_opt(options, arg);\n \n+\telse if (!strcmp(arg, \"--ws-check-deleted\"))\n+\t\toptions->ws_check_deleted = 1;\n+\telse if (!strcmp(arg, \"--no-ws-check-deleted\"))\n+\t\toptions->ws_check_deleted = 0;\n+\n \t/* misc options */\n \telse if (!strcmp(arg, \"-z\"))\n \t\toptions->line_termination = 0;\ndiff --git a/diff.h b/diff.h\nindex f6fdf49..baca5ec 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -138,6 +138,7 @@ struct diff_options {\n \tint dirstat_permille;\n \tint setup;\n \tint abbrev;\n+\tint ws_check_deleted;\n \tconst char *prefix;\n \tint prefix_length;\n \tconst char *stat_sep;\n-- \n2.4.1-511-gc1146d5\n"},{"id":"262142","messageId":"20150526173909.GC24439@256bit.org","threadId":"39422","inReplyTo":"xmqq617fkztj.fsf@gitster.dls.corp.google.com","subject":"Re: Mark trailing whitespace error in del lines of diff","fromName":"Christian Brabandt","fromEmail":"cblists@256bit.org","sentAt":"2015-05-26T17:39:10Z","receivedAt":"2015-05-26T17:39:10Z","isPatch":false,"sender":{"key":"cblists@256bit.org","avatar":null},"body":"Hi Junio!\n\nOn Di, 26 Mai 2015, Junio C Hamano wrote:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n> \n> > I'll send out two patch series to do the painting part (I didn't\n> > want to touch \"--check\", as its utility is even more dubious\n> > compared to painting, at least to me).\n> \n> And here is the second one.\n\nWow, great and so fast! I really apologize it.\n\nBest,\nChristian\n"},{"id":"262143","messageId":"xmqq1ti3kz5v.fsf@gitster.dls.corp.google.com","threadId":"39422","inReplyTo":"20150526173909.GC24439@256bit.org","subject":"Re: Mark trailing whitespace error in del lines of diff","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-26T17:48:44Z","receivedAt":"2015-05-26T17:48:44Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Brabandt <cblists@256bit.org> writes:\n\n>> And here is the second one.\n>\n> Wow, great and so fast! I really apologize it.\n\nNo need to apologize, but appreciating would not hurt ;-)\n\nThanks for an interesting idea.  I spotted a buglet in 1/2 so I'll\nqueue a fixed version on 'pu' when I push today's intergration\nresult out.\n"},{"id":"262146","messageId":"20150526182116.GD24439@256bit.org","threadId":"39422","inReplyTo":"xmqq1ti3kz5v.fsf@gitster.dls.corp.google.com","subject":"Re: Mark trailing whitespace error in del lines of diff","fromName":"Christian Brabandt","fromEmail":"cblists@256bit.org","sentAt":"2015-05-26T18:21:16Z","receivedAt":"2015-05-26T18:21:16Z","isPatch":false,"sender":{"key":"cblists@256bit.org","avatar":null},"body":"Hi Junio!\n\nOn Di, 26 Mai 2015, Junio C Hamano wrote:\n\n> No need to apologize, but appreciating would not hurt ;-)\n\nRight. Thanks.\n\nBest,\nChristian\n-- \nTrägt der Bauer rote Socken, will er seinen Bullen schocken.\n"},{"id":"262156","messageId":"1432669584-342-1-git-send-email-gitster@pobox.com","threadId":"39422","inReplyTo":"xmqq1ti3kz5v.fsf@gitster.dls.corp.google.com","subject":"[PATCH v2 0/5] showing existing ws breakage","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-26T19:46:20Z","receivedAt":"2015-05-26T19:46:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"We paint whitespace breakages in new (i.e. added or updated) lines\nwhen showing the \"git diff\" output to help people avoid introducing\nthem with their changes.  The basic premise is that people would\nwant to avoid touching existing lines only to fix whitespace errors\nin a patch that does other changes of substance, and that is why we\ntraditionally did not paint whitespace breakages in existing\n(i.e. deleted or context) lines.\n\nHowever, some people would want to keep existing breakages when they\nare doing other changes of substance; \"new\" lines in such a patch\nwould show existing whitespace breakages painted, and it is not\napparent if the breakages were inherited from the original or newly\nintroduced.\n\nChristian Brabandt had an interesting idea to help users in this\nsituation; why not give them a mode to paint whitespace breakages\nin \"old\" (i.e. deleted or was replaced) lines, too?\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/269912/focus=269956\n\nThis series builds on that idea but with a different implementation\n(Christian's original painted trailing whitespaces only).\n\nThe first three patches are preliminary cleanups.  The last one is\nthe interesting bit.\n\nHaving done this series, I am starting to suspect that painting ws\nbreakages only in deleted lines may not be such a useful thing to\ndo.  In order to decide if fixing ws breakages \"while at it\" is more\nappropriate, you would need to know if such breakages are prevalent\nin the original.  After all, the line you are updating might be one\nof only few lines that the original had breakages, in which case you\nmay want to go back to your editor and fix them all while you are at\nit, or fix only these few ws breakages as a preliminary step.  In\norder to help users do that, the new option may be better not to\nlimit itself to \"deleted\" lines, but \"context and deleted\",\ni.e. \"preimage\" lines.\n\nJunio C Hamano (4):\n  t4015: modernise style\n  t4015: separate common setup and per-test expectation\n  diff.c: add emit_del_line() and update callers of emit_line_0()\n  diff.c: --ws-check-deleted option\n\n Documentation/diff-options.txt |   7 +\n diff.c                         |  58 +++--\n diff.h                         |   1 +\n t/t4015-diff-whitespace.sh     | 474 ++++++++++++++++++++---------------------\n 4 files changed, 290 insertions(+), 250 deletions(-)\n\n-- \n2.4.1-511-gc1146d5\n"},{"id":"262155","messageId":"1432669584-342-2-git-send-email-gitster@pobox.com","threadId":"39422","inReplyTo":"1432669584-342-1-git-send-email-gitster@pobox.com","subject":"[PATCH v2 1/4] t4015: modernise style","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-26T19:46:21Z","receivedAt":"2015-05-26T19:46:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Move the preparatory steps that create the expected output inside\nthe test bodies, remove unnecessary blank lines before and after the\ntest bodies, and drop SP between redirection operator and its target.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n t/t4015-diff-whitespace.sh | 411 +++++++++++++++++++--------------------------\n 1 file changed, 173 insertions(+), 238 deletions(-)\n\ndiff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh\nindex 604a838..0bfc7ff 100755\n--- a/t/t4015-diff-whitespace.sh\n+++ b/t/t4015-diff-whitespace.sh\n@@ -9,138 +9,144 @@ test_description='Test special whitespace in diff engine.\n . ./test-lib.sh\n . \"$TEST_DIRECTORY\"/diff-lib.sh\n \n-# Ray Lehtiniemi's example\n+test_expect_success \"Ray Lehtiniemi's example\" '\n+\tcat <<-\\EOF >x &&\n+\tdo {\n+\t   nothing;\n+\t} while (0);\n+\tEOF\n+\tgit update-index --add x &&\n \n-cat << EOF > x\n-do {\n-   nothing;\n-} while (0);\n-EOF\n+\tcat <<-\\EOF >x &&\n+\tdo\n+\t{\n+\t   nothing;\n+\t}\n+\twhile (0);\n+\tEOF\n \n-git update-index --add x\n+\tcat <<-\\EOF >expect &&\n+\tdiff --git a/x b/x\n+\tindex adf3937..6edc172 100644\n+\t--- a/x\n+\t+++ b/x\n+\t@@ -1,3 +1,5 @@\n+\t-do {\n+\t+do\n+\t+{\n+\t    nothing;\n+\t-} while (0);\n+\t+}\n+\t+while (0);\n+\tEOF\n \n-cat << EOF > x\n-do\n-{\n-   nothing;\n-}\n-while (0);\n-EOF\n+\tgit diff >out &&\n+\ttest_cmp expect out &&\n \n-cat << EOF > expect\n-diff --git a/x b/x\n-index adf3937..6edc172 100644\n---- a/x\n-+++ b/x\n-@@ -1,3 +1,5 @@\n--do {\n-+do\n-+{\n-    nothing;\n--} while (0);\n-+}\n-+while (0);\n-EOF\n+\tgit diff -w >out &&\n+\ttest_cmp expect out &&\n \n-git diff > out\n-test_expect_success \"Ray's example without options\" 'test_cmp expect out'\n+\tgit diff -b >out &&\n+\ttest_cmp expect out\n+'\n \n-git diff -w > out\n-test_expect_success \"Ray's example with -w\" 'test_cmp expect out'\n+test_expect_success 'another test, without options' '\n+\ttr Q \"\\015\" <<-\\EOF >x &&\n+\twhitespace at beginning\n+\twhitespace change\n+\twhitespace in the middle\n+\twhitespace at end\n+\tunchanged line\n+\tCR at endQ\n+\tEOF\n \n-git diff -b > out\n-test_expect_success \"Ray's example with -b\" 'test_cmp expect out'\n+\tgit update-index x &&\n \n-tr 'Q' '\\015' << EOF > x\n-whitespace at beginning\n-whitespace change\n-whitespace in the middle\n-whitespace at end\n-unchanged line\n-CR at endQ\n-EOF\n+\ttr \"_\" \" \" <<-\\EOF >x &&\n+\t_\twhitespace at beginning\n+\twhitespace \t change\n+\twhite space in the middle\n+\twhitespace at end__\n+\tunchanged line\n+\tCR at end\n+\tEOF\n \n-git update-index x\n+\ttr \"Q_\" \"\\015 \" <<-\\EOF >expect &&\n+\tdiff --git a/x b/x\n+\tindex d99af23..22d9f73 100644\n+\t--- a/x\n+\t+++ b/x\n+\t@@ -1,6 +1,6 @@\n+\t-whitespace at beginning\n+\t-whitespace change\n+\t-whitespace in the middle\n+\t-whitespace at end\n+\t+ \twhitespace at beginning\n+\t+whitespace \t change\n+\t+white space in the middle\n+\t+whitespace at end__\n+\t unchanged line\n+\t-CR at endQ\n+\t+CR at end\n+\tEOF\n \n-tr '_' ' ' << EOF > x\n-\twhitespace at beginning\n-whitespace \t change\n-white space in the middle\n-whitespace at end__\n-unchanged line\n-CR at end\n-EOF\n+\tgit diff >out &&\n+\ttest_cmp expect out &&\n \n-tr 'Q_' '\\015 ' << EOF > expect\n-diff --git a/x b/x\n-index d99af23..8b32fb5 100644\n---- a/x\n-+++ b/x\n-@@ -1,6 +1,6 @@\n--whitespace at beginning\n--whitespace change\n--whitespace in the middle\n--whitespace at end\n-+\twhitespace at beginning\n-+whitespace \t change\n-+white space in the middle\n-+whitespace at end__\n- unchanged line\n--CR at endQ\n-+CR at end\n-EOF\n-git diff > out\n-test_expect_success 'another test, without options' 'test_cmp expect out'\n+\t>expect &&\n+\tgit diff -w >out &&\n+\ttest_cmp expect out &&\n+\n+\tgit diff -w -b >out &&\n+\ttest_cmp expect out &&\n+\n+\tgit diff -w --ignore-space-at-eol >out &&\n+\ttest_cmp expect out &&\n+\n+\tgit diff -w -b --ignore-space-at-eol >out &&\n+\ttest_cmp expect out &&\n \n-cat << EOF > expect\n-EOF\n-git diff -w > out\n-test_expect_success 'another test, with -w' 'test_cmp expect out'\n-git diff -w -b > out\n-test_expect_success 'another test, with -w -b' 'test_cmp expect out'\n-git diff -w --ignore-space-at-eol > out\n-test_expect_success 'another test, with -w --ignore-space-at-eol' 'test_cmp expect out'\n-git diff -w -b --ignore-space-at-eol > out\n-test_expect_success 'another test, with -w -b --ignore-space-at-eol' 'test_cmp expect out'\n-\n-tr 'Q_' '\\015 ' << EOF > expect\n-diff --git a/x b/x\n-index d99af23..8b32fb5 100644\n---- a/x\n-+++ b/x\n-@@ -1,6 +1,6 @@\n--whitespace at beginning\n-+\twhitespace at beginning\n- whitespace \t change\n--whitespace in the middle\n-+white space in the middle\n- whitespace at end__\n- unchanged line\n- CR at end\n-EOF\n-git diff -b > out\n-test_expect_success 'another test, with -b' 'test_cmp expect out'\n-git diff -b --ignore-space-at-eol > out\n-test_expect_success 'another test, with -b --ignore-space-at-eol' 'test_cmp expect out'\n-\n-tr 'Q_' '\\015 ' << EOF > expect\n-diff --git a/x b/x\n-index d99af23..8b32fb5 100644\n---- a/x\n-+++ b/x\n-@@ -1,6 +1,6 @@\n--whitespace at beginning\n--whitespace change\n--whitespace in the middle\n-+\twhitespace at beginning\n-+whitespace \t change\n-+white space in the middle\n- whitespace at end__\n- unchanged line\n- CR at end\n-EOF\n-git diff --ignore-space-at-eol > out\n-test_expect_success 'another test, with --ignore-space-at-eol' 'test_cmp expect out'\n+\n+\ttr \"Q_\" \"\\015 \" <<-\\EOF >expect &&\n+\tdiff --git a/x b/x\n+\tindex d99af23..22d9f73 100644\n+\t--- a/x\n+\t+++ b/x\n+\t@@ -1,6 +1,6 @@\n+\t-whitespace at beginning\n+\t+_\twhitespace at beginning\n+\t whitespace \t change\n+\t-whitespace in the middle\n+\t+white space in the middle\n+\t whitespace at end__\n+\t unchanged line\n+\t CR at end\n+\tEOF\n+\tgit diff -b >out &&\n+\ttest_cmp expect out &&\n+\n+\tgit diff -b --ignore-space-at-eol >out &&\n+\ttest_cmp expect out &&\n+\n+\ttr \"Q_\" \"\\015 \" <<-\\EOF >expect &&\n+\tdiff --git a/x b/x\n+\tindex d99af23..22d9f73 100644\n+\t--- a/x\n+\t+++ b/x\n+\t@@ -1,6 +1,6 @@\n+\t-whitespace at beginning\n+\t-whitespace change\n+\t-whitespace in the middle\n+\t+_\twhitespace at beginning\n+\t+whitespace \t change\n+\t+white space in the middle\n+\t whitespace at end__\n+\t unchanged line\n+\t CR at end\n+\tEOF\n+\tgit diff --ignore-space-at-eol >out &&\n+\ttest_cmp expect out\n+'\n \n test_expect_success 'ignore-blank-lines: only new lines' '\n \ttest_seq 5 >x &&\n@@ -489,291 +495,219 @@ test_expect_success 'ignore-blank-lines: mix changes and blank lines' '\n '\n \n test_expect_success 'check mixed spaces and tabs in indent' '\n-\n \t# This is indented with SP HT SP.\n-\techo \" \t foo();\" > x &&\n+\techo \" \t foo();\" >x &&\n \tgit diff --check | grep \"space before tab in indent\"\n-\n '\n \n test_expect_success 'check mixed tabs and spaces in indent' '\n-\n \t# This is indented with HT SP HT.\n-\techo \"\t \tfoo();\" > x &&\n+\techo \"\t \tfoo();\" >x &&\n \tgit diff --check | grep \"space before tab in indent\"\n-\n '\n \n test_expect_success 'check with no whitespace errors' '\n-\n \tgit commit -m \"snapshot\" &&\n-\techo \"foo();\" > x &&\n+\techo \"foo();\" >x &&\n \tgit diff --check\n-\n '\n \n test_expect_success 'check with trailing whitespace' '\n-\n-\techo \"foo(); \" > x &&\n+\techo \"foo(); \" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'check with space before tab in indent' '\n-\n \t# indent has space followed by hard tab\n-\techo \" \tfoo();\" > x &&\n+\techo \" \tfoo();\" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success '--check and --exit-code are not exclusive' '\n-\n \tgit checkout x &&\n \tgit diff --check --exit-code\n-\n '\n \n test_expect_success '--check and --quiet are not exclusive' '\n-\n \tgit diff --check --quiet\n-\n '\n \n test_expect_success 'check staged with no whitespace errors' '\n-\n-\techo \"foo();\" > x &&\n+\techo \"foo();\" >x &&\n \tgit add x &&\n \tgit diff --cached --check\n-\n '\n \n test_expect_success 'check staged with trailing whitespace' '\n-\n-\techo \"foo(); \" > x &&\n+\techo \"foo(); \" >x &&\n \tgit add x &&\n \ttest_must_fail git diff --cached --check\n-\n '\n \n test_expect_success 'check staged with space before tab in indent' '\n-\n \t# indent has space followed by hard tab\n-\techo \" \tfoo();\" > x &&\n+\techo \" \tfoo();\" >x &&\n \tgit add x &&\n \ttest_must_fail git diff --cached --check\n-\n '\n \n test_expect_success 'check with no whitespace errors (diff-index)' '\n-\n-\techo \"foo();\" > x &&\n+\techo \"foo();\" >x &&\n \tgit add x &&\n \tgit diff-index --check HEAD\n-\n '\n \n test_expect_success 'check with trailing whitespace (diff-index)' '\n-\n-\techo \"foo(); \" > x &&\n+\techo \"foo(); \" >x &&\n \tgit add x &&\n \ttest_must_fail git diff-index --check HEAD\n-\n '\n \n test_expect_success 'check with space before tab in indent (diff-index)' '\n-\n \t# indent has space followed by hard tab\n-\techo \" \tfoo();\" > x &&\n+\techo \" \tfoo();\" >x &&\n \tgit add x &&\n \ttest_must_fail git diff-index --check HEAD\n-\n '\n \n test_expect_success 'check staged with no whitespace errors (diff-index)' '\n-\n-\techo \"foo();\" > x &&\n+\techo \"foo();\" >x &&\n \tgit add x &&\n \tgit diff-index --cached --check HEAD\n-\n '\n \n test_expect_success 'check staged with trailing whitespace (diff-index)' '\n-\n-\techo \"foo(); \" > x &&\n+\techo \"foo(); \" >x &&\n \tgit add x &&\n \ttest_must_fail git diff-index --cached --check HEAD\n-\n '\n \n test_expect_success 'check staged with space before tab in indent (diff-index)' '\n-\n \t# indent has space followed by hard tab\n-\techo \" \tfoo();\" > x &&\n+\techo \" \tfoo();\" >x &&\n \tgit add x &&\n \ttest_must_fail git diff-index --cached --check HEAD\n-\n '\n \n test_expect_success 'check with no whitespace errors (diff-tree)' '\n-\n-\techo \"foo();\" > x &&\n+\techo \"foo();\" >x &&\n \tgit commit -m \"new commit\" x &&\n \tgit diff-tree --check HEAD^ HEAD\n-\n '\n \n test_expect_success 'check with trailing whitespace (diff-tree)' '\n-\n-\techo \"foo(); \" > x &&\n+\techo \"foo(); \" >x &&\n \tgit commit -m \"another commit\" x &&\n \ttest_must_fail git diff-tree --check HEAD^ HEAD\n-\n '\n \n test_expect_success 'check with space before tab in indent (diff-tree)' '\n-\n \t# indent has space followed by hard tab\n-\techo \" \tfoo();\" > x &&\n+\techo \" \tfoo();\" >x &&\n \tgit commit -m \"yet another\" x &&\n \ttest_must_fail git diff-tree --check HEAD^ HEAD\n-\n '\n \n test_expect_success 'check trailing whitespace (trailing-space: off)' '\n-\n \tgit config core.whitespace \"-trailing-space\" &&\n-\techo \"foo ();   \" > x &&\n+\techo \"foo ();   \" >x &&\n \tgit diff --check\n-\n '\n \n test_expect_success 'check trailing whitespace (trailing-space: on)' '\n-\n \tgit config core.whitespace \"trailing-space\" &&\n-\techo \"foo ();   \" > x &&\n+\techo \"foo ();   \" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'check space before tab in indent (space-before-tab: off)' '\n-\n \t# indent contains space followed by HT\n \tgit config core.whitespace \"-space-before-tab\" &&\n-\techo \" \tfoo ();\" > x &&\n+\techo \" \tfoo ();\" >x &&\n \tgit diff --check\n-\n '\n \n test_expect_success 'check space before tab in indent (space-before-tab: on)' '\n-\n \t# indent contains space followed by HT\n \tgit config core.whitespace \"space-before-tab\" &&\n-\techo \" \tfoo ();   \" > x &&\n+\techo \" \tfoo ();   \" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'check spaces as indentation (indent-with-non-tab: off)' '\n-\n \tgit config core.whitespace \"-indent-with-non-tab\" &&\n-\techo \"        foo ();\" > x &&\n+\techo \"        foo ();\" >x &&\n \tgit diff --check\n-\n '\n \n test_expect_success 'check spaces as indentation (indent-with-non-tab: on)' '\n-\n \tgit config core.whitespace \"indent-with-non-tab\" &&\n-\techo \"        foo ();\" > x &&\n+\techo \"        foo ();\" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'ditto, but tabwidth=9' '\n-\n \tgit config core.whitespace \"indent-with-non-tab,tabwidth=9\" &&\n \tgit diff --check\n-\n '\n \n test_expect_success 'check tabs and spaces as indentation (indent-with-non-tab: on)' '\n-\n \tgit config core.whitespace \"indent-with-non-tab\" &&\n-\techo \"\t                foo ();\" > x &&\n+\techo \"\t                foo ();\" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'ditto, but tabwidth=10' '\n-\n \tgit config core.whitespace \"indent-with-non-tab,tabwidth=10\" &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'ditto, but tabwidth=20' '\n-\n \tgit config core.whitespace \"indent-with-non-tab,tabwidth=20\" &&\n \tgit diff --check\n-\n '\n \n test_expect_success 'check tabs as indentation (tab-in-indent: off)' '\n-\n \tgit config core.whitespace \"-tab-in-indent\" &&\n-\techo \"\tfoo ();\" > x &&\n+\techo \"\tfoo ();\" >x &&\n \tgit diff --check\n-\n '\n \n test_expect_success 'check tabs as indentation (tab-in-indent: on)' '\n-\n \tgit config core.whitespace \"tab-in-indent\" &&\n-\techo \"\tfoo ();\" > x &&\n+\techo \"\tfoo ();\" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'check tabs and spaces as indentation (tab-in-indent: on)' '\n-\n \tgit config core.whitespace \"tab-in-indent\" &&\n-\techo \"\t                foo ();\" > x &&\n+\techo \"\t                foo ();\" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'ditto, but tabwidth=1 (must be irrelevant)' '\n-\n \tgit config core.whitespace \"tab-in-indent,tabwidth=1\" &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'check tab-in-indent and indent-with-non-tab conflict' '\n-\n \tgit config core.whitespace \"tab-in-indent,indent-with-non-tab\" &&\n-\techo \"foo ();\" > x &&\n+\techo \"foo ();\" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'check tab-in-indent excluded from wildcard whitespace attribute' '\n-\n \tgit config --unset core.whitespace &&\n-\techo \"x whitespace\" > .gitattributes &&\n-\techo \"\t  foo ();\" > x &&\n+\techo \"x whitespace\" >.gitattributes &&\n+\techo \"\t  foo ();\" >x &&\n \tgit diff --check &&\n \trm -f .gitattributes\n-\n '\n \n test_expect_success 'line numbers in --check output are correct' '\n-\n-\techo \"\" > x &&\n-\techo \"foo(); \" >> x &&\n+\techo \"\" >x &&\n+\techo \"foo(); \" >>x &&\n \tgit diff --check | grep \"x:2:\"\n-\n '\n \n test_expect_success 'checkdiff detects new trailing blank lines (1)' '\n@@ -878,26 +812,27 @@ test_expect_success 'setup diff colors' '\n \tgit config color.diff.commit yellow &&\n \tgit config color.diff.whitespace \"normal red\" &&\n \n-\tgit config core.autocrlf false\n+\tgit config core.autocrlf false &&\n+\n+\tcat >expected <<-\\EOF\n+\t<BOLD>diff --git a/x b/x<RESET>\n+\t<BOLD>index 9daeafb..2874b91 100644<RESET>\n+\t<BOLD>--- a/x<RESET>\n+\t<BOLD>+++ b/x<RESET>\n+\t<CYAN>@@ -1 +1,4 @@<RESET>\n+\t test<RESET>\n+\t<GREEN>+<RESET><GREEN>{<RESET>\n+\t<GREEN>+<RESET><BRED>\t<RESET>\n+\t<GREEN>+<RESET><GREEN>}<RESET>\n+\tEOF\n '\n-cat >expected <<\\EOF\n-<BOLD>diff --git a/x b/x<RESET>\n-<BOLD>index 9daeafb..2874b91 100644<RESET>\n-<BOLD>--- a/x<RESET>\n-<BOLD>+++ b/x<RESET>\n-<CYAN>@@ -1 +1,4 @@<RESET>\n- test<RESET>\n-<GREEN>+<RESET><GREEN>{<RESET>\n-<GREEN>+<RESET><BRED>\t<RESET>\n-<GREEN>+<RESET><GREEN>}<RESET>\n-EOF\n \n test_expect_success 'diff that introduces a line with only tabs' '\n \tgit config core.whitespace blank-at-eol &&\n \tgit reset --hard &&\n-\techo \"test\" > x &&\n+\techo \"test\" >x &&\n \tgit commit -m \"initial\" x &&\n-\techo \"{NTN}\" | tr \"NT\" \"\\n\\t\" >> x &&\n+\techo \"{NTN}\" | tr \"NT\" \"\\n\\t\" >>x &&\n \tgit -c color.diff=always diff | test_decode_color >current &&\n \ttest_cmp expected current\n '\n-- \n2.4.1-511-gc1146d5\n"},{"id":"262154","messageId":"1432669584-342-3-git-send-email-gitster@pobox.com","threadId":"39422","inReplyTo":"1432669584-342-1-git-send-email-gitster@pobox.com","subject":"[PATCH v2 2/4] t4015: separate common setup and per-test expectation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-26T19:46:22Z","receivedAt":"2015-05-26T19:46:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The last two tests in the script were to\n\n - set up color.diff.* slots\n - set up an expectation for a single test\n - run that test and check the result\n\nbut split in a wrong way.  It did the first two in the first test\nand the third one in the second test.  The latter two belong to each\nother.  This matters when you plan to add more of these tests that\nshare the common coloring.\n\nWhile at it, make sure we use a color different from old, which is\nalso red.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n t/t4015-diff-whitespace.sh | 25 +++++++++++++------------\n 1 file changed, 13 insertions(+), 12 deletions(-)\n\ndiff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh\nindex 0bfc7ff..4da30e5 100755\n--- a/t/t4015-diff-whitespace.sh\n+++ b/t/t4015-diff-whitespace.sh\n@@ -810,11 +810,20 @@ test_expect_success 'setup diff colors' '\n \tgit config color.diff.old red &&\n \tgit config color.diff.new green &&\n \tgit config color.diff.commit yellow &&\n-\tgit config color.diff.whitespace \"normal red\" &&\n+\tgit config color.diff.whitespace blue &&\n \n-\tgit config core.autocrlf false &&\n+\tgit config core.autocrlf false\n+'\n+\n+test_expect_success 'diff that introduces a line with only tabs' '\n+\tgit config core.whitespace blank-at-eol &&\n+\tgit reset --hard &&\n+\techo \"test\" >x &&\n+\tgit commit -m \"initial\" x &&\n+\techo \"{NTN}\" | tr \"NT\" \"\\n\\t\" >>x &&\n+\tgit -c color.diff=always diff | test_decode_color >current &&\n \n-\tcat >expected <<-\\EOF\n+\tcat >expected <<-\\EOF &&\n \t<BOLD>diff --git a/x b/x<RESET>\n \t<BOLD>index 9daeafb..2874b91 100644<RESET>\n \t<BOLD>--- a/x<RESET>\n@@ -822,18 +831,10 @@ test_expect_success 'setup diff colors' '\n \t<CYAN>@@ -1 +1,4 @@<RESET>\n \t test<RESET>\n \t<GREEN>+<RESET><GREEN>{<RESET>\n-\t<GREEN>+<RESET><BRED>\t<RESET>\n+\t<GREEN>+<RESET><BLUE>\t<RESET>\n \t<GREEN>+<RESET><GREEN>}<RESET>\n \tEOF\n-'\n \n-test_expect_success 'diff that introduces a line with only tabs' '\n-\tgit config core.whitespace blank-at-eol &&\n-\tgit reset --hard &&\n-\techo \"test\" >x &&\n-\tgit commit -m \"initial\" x &&\n-\techo \"{NTN}\" | tr \"NT\" \"\\n\\t\" >>x &&\n-\tgit -c color.diff=always diff | test_decode_color >current &&\n \ttest_cmp expected current\n '\n \n-- \n2.4.1-511-gc1146d5\n"},{"id":"262152","messageId":"1432669584-342-4-git-send-email-gitster@pobox.com","threadId":"39422","inReplyTo":"1432669584-342-1-git-send-email-gitster@pobox.com","subject":"[PATCH v2 3/4] diff.c: add emit_del_line() and update callers of emit_line_0()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-26T19:46:23Z","receivedAt":"2015-05-26T19:46:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Traditionally, we only had emit_add_line() helper, which knows how\nto find and paint whitespace breakages on the given line, because we\nonly care about whitespace breakages introduced in new lines.  The\ncontext lines and old (i.e. deleted) lines are emitted with a\nsimpler emit_line_0() that paints the entire line in plain or old\ncolors.\n\nIdentify callers of emit_line_0() that show deleted lines and\nhave them call a new helper, emit_del_line(), so that we can later\ntweak what is done to deleted lines.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n diff.c | 39 +++++++++++++++++++++++++++------------\n 1 file changed, 27 insertions(+), 12 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex d1bd534..75b1342 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -498,6 +498,15 @@ static void emit_add_line(const char *reset,\n \t}\n }\n \n+static void emit_del_line(const char *reset,\n+\t\t\t  struct emit_callback *ecbdata,\n+\t\t\t  const char *line, int len)\n+{\n+\tconst char *set = diff_get_color(ecbdata->color_diff, DIFF_FILE_OLD);\n+\n+\temit_line_0(ecbdata->opt, set, reset, '-', line, len);\n+}\n+\n static void emit_hunk_header(struct emit_callback *ecbdata,\n \t\t\t     const char *line, int len)\n {\n@@ -603,7 +612,6 @@ static void emit_rewrite_lines(struct emit_callback *ecb,\n {\n \tconst char *endp = NULL;\n \tstatic const char *nneof = \" No newline at end of file\\n\";\n-\tconst char *old = diff_get_color(ecb->color_diff, DIFF_FILE_OLD);\n \tconst char *reset = diff_get_color(ecb->color_diff, DIFF_RESET);\n \n \twhile (0 < size) {\n@@ -613,8 +621,7 @@ static void emit_rewrite_lines(struct emit_callback *ecb,\n \t\tlen = endp ? (endp - data + 1) : size;\n \t\tif (prefix != '+') {\n \t\t\tecb->lno_in_preimage++;\n-\t\t\temit_line_0(ecb->opt, old, reset, '-',\n-\t\t\t\t    data, len);\n+\t\t\temit_del_line(reset, ecb, data, len);\n \t\t} else {\n \t\t\tecb->lno_in_postimage++;\n \t\t\temit_add_line(reset, ecb, data, len);\n@@ -1250,17 +1257,25 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)\n \t\treturn;\n \t}\n \n-\tif (line[0] != '+') {\n-\t\tconst char *color =\n-\t\t\tdiff_get_color(ecbdata->color_diff,\n-\t\t\t\t       line[0] == '-' ? DIFF_FILE_OLD : DIFF_PLAIN);\n-\t\tecbdata->lno_in_preimage++;\n-\t\tif (line[0] == ' ')\n-\t\t\tecbdata->lno_in_postimage++;\n-\t\temit_line(ecbdata->opt, color, reset, line, len);\n-\t} else {\n+\tswitch (line[0]) {\n+\tcase '+':\n \t\tecbdata->lno_in_postimage++;\n \t\temit_add_line(reset, ecbdata, line + 1, len - 1);\n+\t\tbreak;\n+\tcase '-':\n+\t\tecbdata->lno_in_preimage++;\n+\t\temit_del_line(reset, ecbdata, line + 1, len - 1);\n+\t\tbreak;\n+\tcase ' ':\n+\t\tecbdata->lno_in_postimage++;\n+\t\t/* fallthru */\n+\tdefault:\n+\t\t/* ' ' and incomplete line */\n+\t\tecbdata->lno_in_preimage++;\n+\t\temit_line(ecbdata->opt,\n+\t\t\t  diff_get_color(ecbdata->color_diff, DIFF_PLAIN),\n+\t\t\t  reset, line, len);\n+\t\tbreak;\n \t}\n }\n \n-- \n2.4.1-511-gc1146d5\n"},{"id":"262153","messageId":"1432669584-342-5-git-send-email-gitster@pobox.com","threadId":"39422","inReplyTo":"1432669584-342-1-git-send-email-gitster@pobox.com","subject":"[PATCH v2 4/4] diff.c: --ws-check-deleted option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-26T19:46:24Z","receivedAt":"2015-05-26T19:46:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Traditionally, we only cared about whitespace breakages introduced\nin new lines.  Some people want to paint whitespace breakages on old\nlines, too.  When they see a whitespace breakage on a new line, they\ncan spot the same kind of whitespace breakage on the corresponding\nold line and want to say \"Ah, those breakages are there but they\nwere inherited from the original, so let's not touch them for now.\"\n\nEnable such use case with the new option, \"--ws-check-deleted\".\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/diff-options.txt |  7 +++++\n diff.c                         | 21 +++++++++++++-\n diff.h                         |  1 +\n t/t4015-diff-whitespace.sh     | 62 ++++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 90 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex 6cb083a..701c087 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -278,6 +278,13 @@ ifndef::git-format-patch[]\n \tinitial indent of the line are considered whitespace errors.\n \tExits with non-zero status if problems are found. Not compatible\n \twith --exit-code.\n+\n+--ws-check-deleted::\n+--no-ws-check-deleted::\n+\tHighlight whitespace errors in deleted lines in the color\n+\tspecified by `color.diff.whitespace`, as well as in added\n+\tlines.\n+\n endif::git-format-patch[]\n \n --full-index::\ndiff --git a/diff.c b/diff.c\nindex 75b1342..30eeaea 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -503,8 +503,22 @@ static void emit_del_line(const char *reset,\n \t\t\t  const char *line, int len)\n {\n \tconst char *set = diff_get_color(ecbdata->color_diff, DIFF_FILE_OLD);\n+\tconst char *ws = NULL;\n \n-\temit_line_0(ecbdata->opt, set, reset, '-', line, len);\n+\tif (ecbdata->opt->ws_check_deleted) {\n+\t\tws = diff_get_color(ecbdata->color_diff, DIFF_WHITESPACE);\n+\t\tif (!*ws)\n+\t\t\tws = NULL;\n+\t}\n+\n+\tif (!ws)\n+\t\temit_line_0(ecbdata->opt, set, reset, '-', line, len);\n+\telse {\n+\t\t/* Emit just the prefix, then the rest. */\n+\t\temit_line_0(ecbdata->opt, set, reset, '-', \"\", 0);\n+\t\tws_check_emit(line, len, ecbdata->ws_rule,\n+\t\t\t      ecbdata->opt->file, set, reset, ws);\n+\t}\n }\n \n static void emit_hunk_header(struct emit_callback *ecbdata,\n@@ -3823,6 +3837,11 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \telse if (skip_prefix(arg, \"--submodule=\", &arg))\n \t\treturn parse_submodule_opt(options, arg);\n \n+\telse if (!strcmp(arg, \"--ws-check-deleted\"))\n+\t\toptions->ws_check_deleted = 1;\n+\telse if (!strcmp(arg, \"--no-ws-check-deleted\"))\n+\t\toptions->ws_check_deleted = 0;\n+\n \t/* misc options */\n \telse if (!strcmp(arg, \"-z\"))\n \t\toptions->line_termination = 0;\ndiff --git a/diff.h b/diff.h\nindex b4a624d..ba6cf1a 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -137,6 +137,7 @@ struct diff_options {\n \tint dirstat_permille;\n \tint setup;\n \tint abbrev;\n+\tint ws_check_deleted;\n \tconst char *prefix;\n \tint prefix_length;\n \tconst char *stat_sep;\ndiff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh\nindex 4da30e5..8f35475 100755\n--- a/t/t4015-diff-whitespace.sh\n+++ b/t/t4015-diff-whitespace.sh\n@@ -838,4 +838,66 @@ test_expect_success 'diff that introduces a line with only tabs' '\n \ttest_cmp expected current\n '\n \n+test_expect_success 'diff that introduces and removes ws breakages' '\n+\tgit reset --hard &&\n+\t{\n+\t\techo \"0. blank-at-eol \" &&\n+\t\techo \"1. blank-at-eol \"\n+\t} >x &&\n+\tgit commit -a --allow-empty -m preimage &&\n+\t{\n+\t\techo \"0. blank-at-eol \" &&\n+\t\techo \"1. still-blank-at-eol \" &&\n+\t\techo \"2. and a new line \"\n+\t} >x &&\n+\n+\tgit -c color.diff=always diff |\n+\ttest_decode_color >current &&\n+\n+\tcat >expected <<-\\EOF &&\n+\t<BOLD>diff --git a/x b/x<RESET>\n+\t<BOLD>index d0233a2..700886e 100644<RESET>\n+\t<BOLD>--- a/x<RESET>\n+\t<BOLD>+++ b/x<RESET>\n+\t<CYAN>@@ -1,2 +1,3 @@<RESET>\n+\t 0. blank-at-eol <RESET>\n+\t<RED>-1. blank-at-eol <RESET>\n+\t<GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>\n+\t<GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>\n+\tEOF\n+\n+\ttest_cmp expected current\n+'\n+\n+test_expect_success 'the same with --ws-check-deleted' '\n+\tgit reset --hard &&\n+\t{\n+\t\techo \"0. blank-at-eol \" &&\n+\t\techo \"1. blank-at-eol \"\n+\t} >x &&\n+\tgit commit -a --allow-empty -m preimage &&\n+\t{\n+\t\techo \"0. blank-at-eol \" &&\n+\t\techo \"1. still-blank-at-eol \" &&\n+\t\techo \"2. and a new line \"\n+\t} >x &&\n+\n+\tgit -c color.diff=always diff --ws-check-deleted |\n+\ttest_decode_color >current &&\n+\n+\tcat >expected <<-\\EOF &&\n+\t<BOLD>diff --git a/x b/x<RESET>\n+\t<BOLD>index d0233a2..700886e 100644<RESET>\n+\t<BOLD>--- a/x<RESET>\n+\t<BOLD>+++ b/x<RESET>\n+\t<CYAN>@@ -1,2 +1,3 @@<RESET>\n+\t 0. blank-at-eol <RESET>\n+\t<RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>\n+\t<GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>\n+\t<GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>\n+\tEOF\n+\n+\ttest_cmp expected current\n+'\n+\n test_done\n-- \n2.4.1-511-gc1146d5\n"},{"id":"262201","messageId":"1432708232-29892-1-git-send-email-gitster@pobox.com","threadId":"39422","inReplyTo":"1432669584-342-1-git-send-email-gitster@pobox.com","subject":"[PATCH v3 0/4] showing existing ws breakage","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-27T06:30:28Z","receivedAt":"2015-05-27T06:30:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"We paint whitespace breakages in new (i.e. added or updated) lines\nwhen showing the \"git diff\" output to help people avoid introducing\nthem with their changes.  The basic premise is that people would\nwant to avoid touching existing lines only to fix whitespace errors\nin a patch that does other changes of substance, and that is why we\ntraditionally did not paint whitespace breakages in existing\n(i.e. deleted or context) lines.\n\nHowever, some people would want to keep existing breakages when they\nare doing other changes of substance; \"new\" lines in such a patch\nwould show existing whitespace breakages painted, and it is not\napparent if the breakages were inherited from the original or newly\nintroduced.\n\nChristian Brabandt had an interesting idea to help users in this\nsituation; why not give them a mode to paint whitespace breakages\nin \"old\" (i.e. deleted or was replaced) lines, too?\n\n  http://thread.gmane.org/gmane.comp.version-control.git/269912/focus=269956\n\nThis series is a reroll of the previous one\n\n  http://thread.gmane.org/gmane.comp.version-control.git/269972\n\nwhich built on Christian'sidea, but with a different implementation\n(Christian's original painted trailing whitespaces only).\n\nThe first two patches are unchanged since v2; they are preliminary\nclean-ups.\n\nThe third one extends the corresponding patch since v2; not only a\nhelper for \"deleted\" lines but also another helper for \"context\"\nlines is added.\n\nThe fourth one in v2 used a new option \"--[no-]ws-check-deleted\",\nbut in this round a new option \"--ws-error-highlight=<kinds>\" is\ndefined instead.  With that, you can say\n\n\tdiff --ws-error-highlight=new,old\n\nto say \"I want to see whitespace errors on new and old lines\", and\n\n\tdiff --ws-error-highlight=new,old,context\n\tdiff --ws-error-highlight=all\n\t\ncan be used to also see whitespace errors on context lines.  Being\nable to see whitespace errors on context lines, i.e. the ones that\nwere there in the original and you left intact, would help you see\nhow prevalent whitespace errors are in the original and hopefully\nwould make it easier for you to decide if a separate preliminary\nclean-up to only fix these whitespace errors is warranted.\n\nJunio C Hamano (4):\n  t4015: modernise style\n  t4015: separate common setup and per-test expectation\n  diff.c: add emit_del_line() and emit_context_line()\n  diff.c: --ws-error-highlight=<kind> option\n\n Documentation/diff-options.txt |  10 +\n diff.c                         | 122 ++++++++--\n diff.h                         |   5 +\n t/t4015-diff-whitespace.sh     | 508 ++++++++++++++++++++++-------------------\n 4 files changed, 385 insertions(+), 260 deletions(-)\n\n-- \n2.4.2-503-g3e4528a\n"},{"id":"262202","messageId":"1432708232-29892-2-git-send-email-gitster@pobox.com","threadId":"39422","inReplyTo":"1432708232-29892-1-git-send-email-gitster@pobox.com","subject":"[PATCH v3 1/4] t4015: modernise style","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-27T06:30:29Z","receivedAt":"2015-05-27T06:30:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Move the preparatory steps that create the expected output inside\nthe test bodies, remove unnecessary blank lines before and after the\ntest bodies, and drop SP between redirection operator and its target.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n t/t4015-diff-whitespace.sh | 411 +++++++++++++++++++--------------------------\n 1 file changed, 173 insertions(+), 238 deletions(-)\n\ndiff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh\nindex 604a838..0bfc7ff 100755\n--- a/t/t4015-diff-whitespace.sh\n+++ b/t/t4015-diff-whitespace.sh\n@@ -9,138 +9,144 @@ test_description='Test special whitespace in diff engine.\n . ./test-lib.sh\n . \"$TEST_DIRECTORY\"/diff-lib.sh\n \n-# Ray Lehtiniemi's example\n+test_expect_success \"Ray Lehtiniemi's example\" '\n+\tcat <<-\\EOF >x &&\n+\tdo {\n+\t   nothing;\n+\t} while (0);\n+\tEOF\n+\tgit update-index --add x &&\n \n-cat << EOF > x\n-do {\n-   nothing;\n-} while (0);\n-EOF\n+\tcat <<-\\EOF >x &&\n+\tdo\n+\t{\n+\t   nothing;\n+\t}\n+\twhile (0);\n+\tEOF\n \n-git update-index --add x\n+\tcat <<-\\EOF >expect &&\n+\tdiff --git a/x b/x\n+\tindex adf3937..6edc172 100644\n+\t--- a/x\n+\t+++ b/x\n+\t@@ -1,3 +1,5 @@\n+\t-do {\n+\t+do\n+\t+{\n+\t    nothing;\n+\t-} while (0);\n+\t+}\n+\t+while (0);\n+\tEOF\n \n-cat << EOF > x\n-do\n-{\n-   nothing;\n-}\n-while (0);\n-EOF\n+\tgit diff >out &&\n+\ttest_cmp expect out &&\n \n-cat << EOF > expect\n-diff --git a/x b/x\n-index adf3937..6edc172 100644\n---- a/x\n-+++ b/x\n-@@ -1,3 +1,5 @@\n--do {\n-+do\n-+{\n-    nothing;\n--} while (0);\n-+}\n-+while (0);\n-EOF\n+\tgit diff -w >out &&\n+\ttest_cmp expect out &&\n \n-git diff > out\n-test_expect_success \"Ray's example without options\" 'test_cmp expect out'\n+\tgit diff -b >out &&\n+\ttest_cmp expect out\n+'\n \n-git diff -w > out\n-test_expect_success \"Ray's example with -w\" 'test_cmp expect out'\n+test_expect_success 'another test, without options' '\n+\ttr Q \"\\015\" <<-\\EOF >x &&\n+\twhitespace at beginning\n+\twhitespace change\n+\twhitespace in the middle\n+\twhitespace at end\n+\tunchanged line\n+\tCR at endQ\n+\tEOF\n \n-git diff -b > out\n-test_expect_success \"Ray's example with -b\" 'test_cmp expect out'\n+\tgit update-index x &&\n \n-tr 'Q' '\\015' << EOF > x\n-whitespace at beginning\n-whitespace change\n-whitespace in the middle\n-whitespace at end\n-unchanged line\n-CR at endQ\n-EOF\n+\ttr \"_\" \" \" <<-\\EOF >x &&\n+\t_\twhitespace at beginning\n+\twhitespace \t change\n+\twhite space in the middle\n+\twhitespace at end__\n+\tunchanged line\n+\tCR at end\n+\tEOF\n \n-git update-index x\n+\ttr \"Q_\" \"\\015 \" <<-\\EOF >expect &&\n+\tdiff --git a/x b/x\n+\tindex d99af23..22d9f73 100644\n+\t--- a/x\n+\t+++ b/x\n+\t@@ -1,6 +1,6 @@\n+\t-whitespace at beginning\n+\t-whitespace change\n+\t-whitespace in the middle\n+\t-whitespace at end\n+\t+ \twhitespace at beginning\n+\t+whitespace \t change\n+\t+white space in the middle\n+\t+whitespace at end__\n+\t unchanged line\n+\t-CR at endQ\n+\t+CR at end\n+\tEOF\n \n-tr '_' ' ' << EOF > x\n-\twhitespace at beginning\n-whitespace \t change\n-white space in the middle\n-whitespace at end__\n-unchanged line\n-CR at end\n-EOF\n+\tgit diff >out &&\n+\ttest_cmp expect out &&\n \n-tr 'Q_' '\\015 ' << EOF > expect\n-diff --git a/x b/x\n-index d99af23..8b32fb5 100644\n---- a/x\n-+++ b/x\n-@@ -1,6 +1,6 @@\n--whitespace at beginning\n--whitespace change\n--whitespace in the middle\n--whitespace at end\n-+\twhitespace at beginning\n-+whitespace \t change\n-+white space in the middle\n-+whitespace at end__\n- unchanged line\n--CR at endQ\n-+CR at end\n-EOF\n-git diff > out\n-test_expect_success 'another test, without options' 'test_cmp expect out'\n+\t>expect &&\n+\tgit diff -w >out &&\n+\ttest_cmp expect out &&\n+\n+\tgit diff -w -b >out &&\n+\ttest_cmp expect out &&\n+\n+\tgit diff -w --ignore-space-at-eol >out &&\n+\ttest_cmp expect out &&\n+\n+\tgit diff -w -b --ignore-space-at-eol >out &&\n+\ttest_cmp expect out &&\n \n-cat << EOF > expect\n-EOF\n-git diff -w > out\n-test_expect_success 'another test, with -w' 'test_cmp expect out'\n-git diff -w -b > out\n-test_expect_success 'another test, with -w -b' 'test_cmp expect out'\n-git diff -w --ignore-space-at-eol > out\n-test_expect_success 'another test, with -w --ignore-space-at-eol' 'test_cmp expect out'\n-git diff -w -b --ignore-space-at-eol > out\n-test_expect_success 'another test, with -w -b --ignore-space-at-eol' 'test_cmp expect out'\n-\n-tr 'Q_' '\\015 ' << EOF > expect\n-diff --git a/x b/x\n-index d99af23..8b32fb5 100644\n---- a/x\n-+++ b/x\n-@@ -1,6 +1,6 @@\n--whitespace at beginning\n-+\twhitespace at beginning\n- whitespace \t change\n--whitespace in the middle\n-+white space in the middle\n- whitespace at end__\n- unchanged line\n- CR at end\n-EOF\n-git diff -b > out\n-test_expect_success 'another test, with -b' 'test_cmp expect out'\n-git diff -b --ignore-space-at-eol > out\n-test_expect_success 'another test, with -b --ignore-space-at-eol' 'test_cmp expect out'\n-\n-tr 'Q_' '\\015 ' << EOF > expect\n-diff --git a/x b/x\n-index d99af23..8b32fb5 100644\n---- a/x\n-+++ b/x\n-@@ -1,6 +1,6 @@\n--whitespace at beginning\n--whitespace change\n--whitespace in the middle\n-+\twhitespace at beginning\n-+whitespace \t change\n-+white space in the middle\n- whitespace at end__\n- unchanged line\n- CR at end\n-EOF\n-git diff --ignore-space-at-eol > out\n-test_expect_success 'another test, with --ignore-space-at-eol' 'test_cmp expect out'\n+\n+\ttr \"Q_\" \"\\015 \" <<-\\EOF >expect &&\n+\tdiff --git a/x b/x\n+\tindex d99af23..22d9f73 100644\n+\t--- a/x\n+\t+++ b/x\n+\t@@ -1,6 +1,6 @@\n+\t-whitespace at beginning\n+\t+_\twhitespace at beginning\n+\t whitespace \t change\n+\t-whitespace in the middle\n+\t+white space in the middle\n+\t whitespace at end__\n+\t unchanged line\n+\t CR at end\n+\tEOF\n+\tgit diff -b >out &&\n+\ttest_cmp expect out &&\n+\n+\tgit diff -b --ignore-space-at-eol >out &&\n+\ttest_cmp expect out &&\n+\n+\ttr \"Q_\" \"\\015 \" <<-\\EOF >expect &&\n+\tdiff --git a/x b/x\n+\tindex d99af23..22d9f73 100644\n+\t--- a/x\n+\t+++ b/x\n+\t@@ -1,6 +1,6 @@\n+\t-whitespace at beginning\n+\t-whitespace change\n+\t-whitespace in the middle\n+\t+_\twhitespace at beginning\n+\t+whitespace \t change\n+\t+white space in the middle\n+\t whitespace at end__\n+\t unchanged line\n+\t CR at end\n+\tEOF\n+\tgit diff --ignore-space-at-eol >out &&\n+\ttest_cmp expect out\n+'\n \n test_expect_success 'ignore-blank-lines: only new lines' '\n \ttest_seq 5 >x &&\n@@ -489,291 +495,219 @@ test_expect_success 'ignore-blank-lines: mix changes and blank lines' '\n '\n \n test_expect_success 'check mixed spaces and tabs in indent' '\n-\n \t# This is indented with SP HT SP.\n-\techo \" \t foo();\" > x &&\n+\techo \" \t foo();\" >x &&\n \tgit diff --check | grep \"space before tab in indent\"\n-\n '\n \n test_expect_success 'check mixed tabs and spaces in indent' '\n-\n \t# This is indented with HT SP HT.\n-\techo \"\t \tfoo();\" > x &&\n+\techo \"\t \tfoo();\" >x &&\n \tgit diff --check | grep \"space before tab in indent\"\n-\n '\n \n test_expect_success 'check with no whitespace errors' '\n-\n \tgit commit -m \"snapshot\" &&\n-\techo \"foo();\" > x &&\n+\techo \"foo();\" >x &&\n \tgit diff --check\n-\n '\n \n test_expect_success 'check with trailing whitespace' '\n-\n-\techo \"foo(); \" > x &&\n+\techo \"foo(); \" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'check with space before tab in indent' '\n-\n \t# indent has space followed by hard tab\n-\techo \" \tfoo();\" > x &&\n+\techo \" \tfoo();\" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success '--check and --exit-code are not exclusive' '\n-\n \tgit checkout x &&\n \tgit diff --check --exit-code\n-\n '\n \n test_expect_success '--check and --quiet are not exclusive' '\n-\n \tgit diff --check --quiet\n-\n '\n \n test_expect_success 'check staged with no whitespace errors' '\n-\n-\techo \"foo();\" > x &&\n+\techo \"foo();\" >x &&\n \tgit add x &&\n \tgit diff --cached --check\n-\n '\n \n test_expect_success 'check staged with trailing whitespace' '\n-\n-\techo \"foo(); \" > x &&\n+\techo \"foo(); \" >x &&\n \tgit add x &&\n \ttest_must_fail git diff --cached --check\n-\n '\n \n test_expect_success 'check staged with space before tab in indent' '\n-\n \t# indent has space followed by hard tab\n-\techo \" \tfoo();\" > x &&\n+\techo \" \tfoo();\" >x &&\n \tgit add x &&\n \ttest_must_fail git diff --cached --check\n-\n '\n \n test_expect_success 'check with no whitespace errors (diff-index)' '\n-\n-\techo \"foo();\" > x &&\n+\techo \"foo();\" >x &&\n \tgit add x &&\n \tgit diff-index --check HEAD\n-\n '\n \n test_expect_success 'check with trailing whitespace (diff-index)' '\n-\n-\techo \"foo(); \" > x &&\n+\techo \"foo(); \" >x &&\n \tgit add x &&\n \ttest_must_fail git diff-index --check HEAD\n-\n '\n \n test_expect_success 'check with space before tab in indent (diff-index)' '\n-\n \t# indent has space followed by hard tab\n-\techo \" \tfoo();\" > x &&\n+\techo \" \tfoo();\" >x &&\n \tgit add x &&\n \ttest_must_fail git diff-index --check HEAD\n-\n '\n \n test_expect_success 'check staged with no whitespace errors (diff-index)' '\n-\n-\techo \"foo();\" > x &&\n+\techo \"foo();\" >x &&\n \tgit add x &&\n \tgit diff-index --cached --check HEAD\n-\n '\n \n test_expect_success 'check staged with trailing whitespace (diff-index)' '\n-\n-\techo \"foo(); \" > x &&\n+\techo \"foo(); \" >x &&\n \tgit add x &&\n \ttest_must_fail git diff-index --cached --check HEAD\n-\n '\n \n test_expect_success 'check staged with space before tab in indent (diff-index)' '\n-\n \t# indent has space followed by hard tab\n-\techo \" \tfoo();\" > x &&\n+\techo \" \tfoo();\" >x &&\n \tgit add x &&\n \ttest_must_fail git diff-index --cached --check HEAD\n-\n '\n \n test_expect_success 'check with no whitespace errors (diff-tree)' '\n-\n-\techo \"foo();\" > x &&\n+\techo \"foo();\" >x &&\n \tgit commit -m \"new commit\" x &&\n \tgit diff-tree --check HEAD^ HEAD\n-\n '\n \n test_expect_success 'check with trailing whitespace (diff-tree)' '\n-\n-\techo \"foo(); \" > x &&\n+\techo \"foo(); \" >x &&\n \tgit commit -m \"another commit\" x &&\n \ttest_must_fail git diff-tree --check HEAD^ HEAD\n-\n '\n \n test_expect_success 'check with space before tab in indent (diff-tree)' '\n-\n \t# indent has space followed by hard tab\n-\techo \" \tfoo();\" > x &&\n+\techo \" \tfoo();\" >x &&\n \tgit commit -m \"yet another\" x &&\n \ttest_must_fail git diff-tree --check HEAD^ HEAD\n-\n '\n \n test_expect_success 'check trailing whitespace (trailing-space: off)' '\n-\n \tgit config core.whitespace \"-trailing-space\" &&\n-\techo \"foo ();   \" > x &&\n+\techo \"foo ();   \" >x &&\n \tgit diff --check\n-\n '\n \n test_expect_success 'check trailing whitespace (trailing-space: on)' '\n-\n \tgit config core.whitespace \"trailing-space\" &&\n-\techo \"foo ();   \" > x &&\n+\techo \"foo ();   \" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'check space before tab in indent (space-before-tab: off)' '\n-\n \t# indent contains space followed by HT\n \tgit config core.whitespace \"-space-before-tab\" &&\n-\techo \" \tfoo ();\" > x &&\n+\techo \" \tfoo ();\" >x &&\n \tgit diff --check\n-\n '\n \n test_expect_success 'check space before tab in indent (space-before-tab: on)' '\n-\n \t# indent contains space followed by HT\n \tgit config core.whitespace \"space-before-tab\" &&\n-\techo \" \tfoo ();   \" > x &&\n+\techo \" \tfoo ();   \" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'check spaces as indentation (indent-with-non-tab: off)' '\n-\n \tgit config core.whitespace \"-indent-with-non-tab\" &&\n-\techo \"        foo ();\" > x &&\n+\techo \"        foo ();\" >x &&\n \tgit diff --check\n-\n '\n \n test_expect_success 'check spaces as indentation (indent-with-non-tab: on)' '\n-\n \tgit config core.whitespace \"indent-with-non-tab\" &&\n-\techo \"        foo ();\" > x &&\n+\techo \"        foo ();\" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'ditto, but tabwidth=9' '\n-\n \tgit config core.whitespace \"indent-with-non-tab,tabwidth=9\" &&\n \tgit diff --check\n-\n '\n \n test_expect_success 'check tabs and spaces as indentation (indent-with-non-tab: on)' '\n-\n \tgit config core.whitespace \"indent-with-non-tab\" &&\n-\techo \"\t                foo ();\" > x &&\n+\techo \"\t                foo ();\" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'ditto, but tabwidth=10' '\n-\n \tgit config core.whitespace \"indent-with-non-tab,tabwidth=10\" &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'ditto, but tabwidth=20' '\n-\n \tgit config core.whitespace \"indent-with-non-tab,tabwidth=20\" &&\n \tgit diff --check\n-\n '\n \n test_expect_success 'check tabs as indentation (tab-in-indent: off)' '\n-\n \tgit config core.whitespace \"-tab-in-indent\" &&\n-\techo \"\tfoo ();\" > x &&\n+\techo \"\tfoo ();\" >x &&\n \tgit diff --check\n-\n '\n \n test_expect_success 'check tabs as indentation (tab-in-indent: on)' '\n-\n \tgit config core.whitespace \"tab-in-indent\" &&\n-\techo \"\tfoo ();\" > x &&\n+\techo \"\tfoo ();\" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'check tabs and spaces as indentation (tab-in-indent: on)' '\n-\n \tgit config core.whitespace \"tab-in-indent\" &&\n-\techo \"\t                foo ();\" > x &&\n+\techo \"\t                foo ();\" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'ditto, but tabwidth=1 (must be irrelevant)' '\n-\n \tgit config core.whitespace \"tab-in-indent,tabwidth=1\" &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'check tab-in-indent and indent-with-non-tab conflict' '\n-\n \tgit config core.whitespace \"tab-in-indent,indent-with-non-tab\" &&\n-\techo \"foo ();\" > x &&\n+\techo \"foo ();\" >x &&\n \ttest_must_fail git diff --check\n-\n '\n \n test_expect_success 'check tab-in-indent excluded from wildcard whitespace attribute' '\n-\n \tgit config --unset core.whitespace &&\n-\techo \"x whitespace\" > .gitattributes &&\n-\techo \"\t  foo ();\" > x &&\n+\techo \"x whitespace\" >.gitattributes &&\n+\techo \"\t  foo ();\" >x &&\n \tgit diff --check &&\n \trm -f .gitattributes\n-\n '\n \n test_expect_success 'line numbers in --check output are correct' '\n-\n-\techo \"\" > x &&\n-\techo \"foo(); \" >> x &&\n+\techo \"\" >x &&\n+\techo \"foo(); \" >>x &&\n \tgit diff --check | grep \"x:2:\"\n-\n '\n \n test_expect_success 'checkdiff detects new trailing blank lines (1)' '\n@@ -878,26 +812,27 @@ test_expect_success 'setup diff colors' '\n \tgit config color.diff.commit yellow &&\n \tgit config color.diff.whitespace \"normal red\" &&\n \n-\tgit config core.autocrlf false\n+\tgit config core.autocrlf false &&\n+\n+\tcat >expected <<-\\EOF\n+\t<BOLD>diff --git a/x b/x<RESET>\n+\t<BOLD>index 9daeafb..2874b91 100644<RESET>\n+\t<BOLD>--- a/x<RESET>\n+\t<BOLD>+++ b/x<RESET>\n+\t<CYAN>@@ -1 +1,4 @@<RESET>\n+\t test<RESET>\n+\t<GREEN>+<RESET><GREEN>{<RESET>\n+\t<GREEN>+<RESET><BRED>\t<RESET>\n+\t<GREEN>+<RESET><GREEN>}<RESET>\n+\tEOF\n '\n-cat >expected <<\\EOF\n-<BOLD>diff --git a/x b/x<RESET>\n-<BOLD>index 9daeafb..2874b91 100644<RESET>\n-<BOLD>--- a/x<RESET>\n-<BOLD>+++ b/x<RESET>\n-<CYAN>@@ -1 +1,4 @@<RESET>\n- test<RESET>\n-<GREEN>+<RESET><GREEN>{<RESET>\n-<GREEN>+<RESET><BRED>\t<RESET>\n-<GREEN>+<RESET><GREEN>}<RESET>\n-EOF\n \n test_expect_success 'diff that introduces a line with only tabs' '\n \tgit config core.whitespace blank-at-eol &&\n \tgit reset --hard &&\n-\techo \"test\" > x &&\n+\techo \"test\" >x &&\n \tgit commit -m \"initial\" x &&\n-\techo \"{NTN}\" | tr \"NT\" \"\\n\\t\" >> x &&\n+\techo \"{NTN}\" | tr \"NT\" \"\\n\\t\" >>x &&\n \tgit -c color.diff=always diff | test_decode_color >current &&\n \ttest_cmp expected current\n '\n-- \n2.4.2-503-g3e4528a\n"},{"id":"262200","messageId":"1432708232-29892-3-git-send-email-gitster@pobox.com","threadId":"39422","inReplyTo":"1432708232-29892-1-git-send-email-gitster@pobox.com","subject":"[PATCH v3 2/4] t4015: separate common setup and per-test expectation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-27T06:30:30Z","receivedAt":"2015-05-27T06:30:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The last two tests in the script were to\n\n - set up color.diff.* slots\n - set up an expectation for a single test\n - run that test and check the result\n\nbut split in a wrong way.  It did the first two in the first test\nand the third one in the second test.  The latter two belong to each\nother.  This matters when you plan to add more of these tests that\nshare the common coloring.\n\nWhile at it, make sure we use a color different from old, which is\nalso red.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n t/t4015-diff-whitespace.sh | 25 +++++++++++++------------\n 1 file changed, 13 insertions(+), 12 deletions(-)\n\ndiff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh\nindex 0bfc7ff..4da30e5 100755\n--- a/t/t4015-diff-whitespace.sh\n+++ b/t/t4015-diff-whitespace.sh\n@@ -810,11 +810,20 @@ test_expect_success 'setup diff colors' '\n \tgit config color.diff.old red &&\n \tgit config color.diff.new green &&\n \tgit config color.diff.commit yellow &&\n-\tgit config color.diff.whitespace \"normal red\" &&\n+\tgit config color.diff.whitespace blue &&\n \n-\tgit config core.autocrlf false &&\n+\tgit config core.autocrlf false\n+'\n+\n+test_expect_success 'diff that introduces a line with only tabs' '\n+\tgit config core.whitespace blank-at-eol &&\n+\tgit reset --hard &&\n+\techo \"test\" >x &&\n+\tgit commit -m \"initial\" x &&\n+\techo \"{NTN}\" | tr \"NT\" \"\\n\\t\" >>x &&\n+\tgit -c color.diff=always diff | test_decode_color >current &&\n \n-\tcat >expected <<-\\EOF\n+\tcat >expected <<-\\EOF &&\n \t<BOLD>diff --git a/x b/x<RESET>\n \t<BOLD>index 9daeafb..2874b91 100644<RESET>\n \t<BOLD>--- a/x<RESET>\n@@ -822,18 +831,10 @@ test_expect_success 'setup diff colors' '\n \t<CYAN>@@ -1 +1,4 @@<RESET>\n \t test<RESET>\n \t<GREEN>+<RESET><GREEN>{<RESET>\n-\t<GREEN>+<RESET><BRED>\t<RESET>\n+\t<GREEN>+<RESET><BLUE>\t<RESET>\n \t<GREEN>+<RESET><GREEN>}<RESET>\n \tEOF\n-'\n \n-test_expect_success 'diff that introduces a line with only tabs' '\n-\tgit config core.whitespace blank-at-eol &&\n-\tgit reset --hard &&\n-\techo \"test\" >x &&\n-\tgit commit -m \"initial\" x &&\n-\techo \"{NTN}\" | tr \"NT\" \"\\n\\t\" >>x &&\n-\tgit -c color.diff=always diff | test_decode_color >current &&\n \ttest_cmp expected current\n '\n \n-- \n2.4.2-503-g3e4528a\n"},{"id":"262204","messageId":"1432708232-29892-4-git-send-email-gitster@pobox.com","threadId":"39422","inReplyTo":"1432708232-29892-1-git-send-email-gitster@pobox.com","subject":"[PATCH v3 3/4] diff.c: add emit_del_line() and emit_context_line()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-27T06:30:31Z","receivedAt":"2015-05-27T06:30:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Traditionally, we only had emit_add_line() helper, which knows how\nto find and paint whitespace breakages on the given line, because we\nonly care about whitespace breakages introduced in new lines.  The\ncontext lines and old (i.e. deleted) lines are emitted with a\nsimpler emit_line_0() that paints the entire line in plain or old\ncolors.\n\nIdentify callers of emit_line_0() that show deleted lines and\ncontext lines, have them call new helpers, emit_del_line() and\nemit_context_line(), so that we can later tweak what is done to\nthese two classes of lines.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n diff.c | 50 ++++++++++++++++++++++++++++++++++++++------------\n 1 file changed, 38 insertions(+), 12 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex d1bd534..c575c45 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -498,6 +498,24 @@ static void emit_add_line(const char *reset,\n \t}\n }\n \n+static void emit_del_line(const char *reset,\n+\t\t\t  struct emit_callback *ecbdata,\n+\t\t\t  const char *line, int len)\n+{\n+\tconst char *set = diff_get_color(ecbdata->color_diff, DIFF_FILE_OLD);\n+\n+\temit_line_0(ecbdata->opt, set, reset, '-', line, len);\n+}\n+\n+static void emit_context_line(const char *reset,\n+\t\t\t      struct emit_callback *ecbdata,\n+\t\t\t      const char *line, int len)\n+{\n+\tconst char *set = diff_get_color(ecbdata->color_diff, DIFF_PLAIN);\n+\n+\temit_line_0(ecbdata->opt, set, reset, ' ', line, len);\n+}\n+\n static void emit_hunk_header(struct emit_callback *ecbdata,\n \t\t\t     const char *line, int len)\n {\n@@ -603,7 +621,6 @@ static void emit_rewrite_lines(struct emit_callback *ecb,\n {\n \tconst char *endp = NULL;\n \tstatic const char *nneof = \" No newline at end of file\\n\";\n-\tconst char *old = diff_get_color(ecb->color_diff, DIFF_FILE_OLD);\n \tconst char *reset = diff_get_color(ecb->color_diff, DIFF_RESET);\n \n \twhile (0 < size) {\n@@ -613,8 +630,7 @@ static void emit_rewrite_lines(struct emit_callback *ecb,\n \t\tlen = endp ? (endp - data + 1) : size;\n \t\tif (prefix != '+') {\n \t\t\tecb->lno_in_preimage++;\n-\t\t\temit_line_0(ecb->opt, old, reset, '-',\n-\t\t\t\t    data, len);\n+\t\t\temit_del_line(reset, ecb, data, len);\n \t\t} else {\n \t\t\tecb->lno_in_postimage++;\n \t\t\temit_add_line(reset, ecb, data, len);\n@@ -1250,17 +1266,27 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)\n \t\treturn;\n \t}\n \n-\tif (line[0] != '+') {\n-\t\tconst char *color =\n-\t\t\tdiff_get_color(ecbdata->color_diff,\n-\t\t\t\t       line[0] == '-' ? DIFF_FILE_OLD : DIFF_PLAIN);\n-\t\tecbdata->lno_in_preimage++;\n-\t\tif (line[0] == ' ')\n-\t\t\tecbdata->lno_in_postimage++;\n-\t\temit_line(ecbdata->opt, color, reset, line, len);\n-\t} else {\n+\tswitch (line[0]) {\n+\tcase '+':\n \t\tecbdata->lno_in_postimage++;\n \t\temit_add_line(reset, ecbdata, line + 1, len - 1);\n+\t\tbreak;\n+\tcase '-':\n+\t\tecbdata->lno_in_preimage++;\n+\t\temit_del_line(reset, ecbdata, line + 1, len - 1);\n+\t\tbreak;\n+\tcase ' ':\n+\t\tecbdata->lno_in_postimage++;\n+\t\tecbdata->lno_in_preimage++;\n+\t\temit_context_line(reset, ecbdata, line + 1, len - 1);\n+\t\tbreak;\n+\tdefault:\n+\t\t/* incomplete line at the end */\n+\t\tecbdata->lno_in_preimage++;\n+\t\temit_line(ecbdata->opt,\n+\t\t\t  diff_get_color(ecbdata->color_diff, DIFF_PLAIN),\n+\t\t\t  reset, line, len);\n+\t\tbreak;\n \t}\n }\n \n-- \n2.4.2-503-g3e4528a\n"},{"id":"262203","messageId":"1432708232-29892-5-git-send-email-gitster@pobox.com","threadId":"39422","inReplyTo":"1432708232-29892-1-git-send-email-gitster@pobox.com","subject":"[PATCH v3 4/4] diff.c: --ws-error-highlight=<kind> option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-27T06:30:32Z","receivedAt":"2015-05-27T06:30:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Traditionally, we only cared about whitespace breakages introduced\nin new lines.  Some people want to paint whitespace breakages on old\nlines, too.  When they see a whitespace breakage on a new line, they\ncan spot the same kind of whitespace breakage on the corresponding\nold line and want to say \"Ah, those breakages are there but they\nwere inherited from the original, so let's not touch them for now.\"\n\nIntroduce `--ws-error-highlight=<kind>` option, that lets them pass\na comma separated list of `old`, `new`, and `context` to specify\nwhat lines to highlight whitespace errors on.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/diff-options.txt | 10 +++++\n diff.c                         | 84 +++++++++++++++++++++++++++++-------\n diff.h                         |  5 +++\n t/t4015-diff-whitespace.sh     | 96 ++++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 179 insertions(+), 16 deletions(-)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex 6cb083a..85a6547 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -278,6 +278,16 @@ ifndef::git-format-patch[]\n \tinitial indent of the line are considered whitespace errors.\n \tExits with non-zero status if problems are found. Not compatible\n \twith --exit-code.\n+\n+--ws-error-highlight=<kind>::\n+\tHighlight whitespace errors on lines specified by <kind>\n+\tin the color specified by `color.diff.whitespace`.  <kind>\n+\tis a comma separated list of `old`, `new`, `context`.  When\n+\tthis option is not given, only whitespace errors in `new`\n+\tlines are highlighted.  E.g. `--ws-error-highlight=new,old`\n+\thighlights whitespace errors on both deleted and added lines.\n+\t`all` can be used as a short-hand for `old,new,context`.\n+\n endif::git-format-patch[]\n \n --full-index::\ndiff --git a/diff.c b/diff.c\nindex c575c45..34012b4 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -478,42 +478,57 @@ static int new_blank_line_at_eof(struct emit_callback *ecbdata, const char *line\n \treturn ws_blank_line(line, len, ecbdata->ws_rule);\n }\n \n-static void emit_add_line(const char *reset,\n-\t\t\t  struct emit_callback *ecbdata,\n-\t\t\t  const char *line, int len)\n+static void emit_line_checked(const char *reset,\n+\t\t\t      struct emit_callback *ecbdata,\n+\t\t\t      const char *line, int len,\n+\t\t\t      enum color_diff color,\n+\t\t\t      unsigned ws_error_highlight,\n+\t\t\t      char sign)\n {\n-\tconst char *ws = diff_get_color(ecbdata->color_diff, DIFF_WHITESPACE);\n-\tconst char *set = diff_get_color(ecbdata->color_diff, DIFF_FILE_NEW);\n+\tconst char *set = diff_get_color(ecbdata->color_diff, color);\n+\tconst char *ws = NULL;\n \n-\tif (!*ws)\n-\t\temit_line_0(ecbdata->opt, set, reset, '+', line, len);\n-\telse if (new_blank_line_at_eof(ecbdata, line, len))\n+\tif (ecbdata->opt->ws_error_highlight & ws_error_highlight) {\n+\t\tws = diff_get_color(ecbdata->color_diff, DIFF_WHITESPACE);\n+\t\tif (!*ws)\n+\t\t\tws = NULL;\n+\t}\n+\n+\tif (!ws)\n+\t\temit_line_0(ecbdata->opt, set, reset, sign, line, len);\n+\telse if (sign == '+' && new_blank_line_at_eof(ecbdata, line, len))\n \t\t/* Blank line at EOF - paint '+' as well */\n-\t\temit_line_0(ecbdata->opt, ws, reset, '+', line, len);\n+\t\temit_line_0(ecbdata->opt, ws, reset, sign, line, len);\n \telse {\n \t\t/* Emit just the prefix, then the rest. */\n-\t\temit_line_0(ecbdata->opt, set, reset, '+', \"\", 0);\n+\t\temit_line_0(ecbdata->opt, set, reset, sign, \"\", 0);\n \t\tws_check_emit(line, len, ecbdata->ws_rule,\n \t\t\t      ecbdata->opt->file, set, reset, ws);\n \t}\n }\n \n-static void emit_del_line(const char *reset,\n+static void emit_add_line(const char *reset,\n \t\t\t  struct emit_callback *ecbdata,\n \t\t\t  const char *line, int len)\n {\n-\tconst char *set = diff_get_color(ecbdata->color_diff, DIFF_FILE_OLD);\n+\temit_line_checked(reset, ecbdata, line, len,\n+\t\t\t  DIFF_FILE_NEW, WSEH_NEW, '+');\n+}\n \n-\temit_line_0(ecbdata->opt, set, reset, '-', line, len);\n+static void emit_del_line(const char *reset,\n+\t\t\t  struct emit_callback *ecbdata,\n+\t\t\t  const char *line, int len)\n+{\n+\temit_line_checked(reset, ecbdata, line, len,\n+\t\t\t  DIFF_FILE_OLD, WSEH_OLD, '-');\n }\n \n static void emit_context_line(const char *reset,\n \t\t\t      struct emit_callback *ecbdata,\n \t\t\t      const char *line, int len)\n {\n-\tconst char *set = diff_get_color(ecbdata->color_diff, DIFF_PLAIN);\n-\n-\temit_line_0(ecbdata->opt, set, reset, ' ', line, len);\n+\temit_line_checked(reset, ecbdata, line, len,\n+\t\t\t  DIFF_PLAIN, WSEH_CONTEXT, ' ');\n }\n \n static void emit_hunk_header(struct emit_callback *ecbdata,\n@@ -3250,6 +3265,7 @@ void diff_setup(struct diff_options *options)\n \toptions->rename_limit = -1;\n \toptions->dirstat_permille = diff_dirstat_permille_default;\n \toptions->context = diff_context_default;\n+\toptions->ws_error_highlight = WSEH_NEW;\n \tDIFF_OPT_SET(options, RENAME_EMPTY);\n \n \t/* pathchange left =NULL by default */\n@@ -3636,6 +3652,40 @@ static void enable_patch_output(int *fmt) {\n \t*fmt |= DIFF_FORMAT_PATCH;\n }\n \n+static int parse_one_token(const char **arg, const char *token)\n+{\n+\treturn skip_prefix(*arg, token, arg) && (!**arg || **arg == ',');\n+}\n+\n+static int parse_ws_error_highlight(struct diff_options *opt, const char *arg)\n+{\n+\tconst char *orig_arg = arg;\n+\tunsigned val = 0;\n+\twhile (*arg) {\n+\t\tif (parse_one_token(&arg, \"none\"))\n+\t\t\tval = 0;\n+\t\telse if (parse_one_token(&arg, \"default\"))\n+\t\t\tval = WSEH_NEW;\n+\t\telse if (parse_one_token(&arg, \"all\"))\n+\t\t\tval = WSEH_NEW | WSEH_OLD | WSEH_CONTEXT;\n+\t\telse if (parse_one_token(&arg, \"new\"))\n+\t\t\tval |= WSEH_NEW;\n+\t\telse if (parse_one_token(&arg, \"old\"))\n+\t\t\tval |= WSEH_OLD;\n+\t\telse if (parse_one_token(&arg, \"context\"))\n+\t\t\tval |= WSEH_CONTEXT;\n+\t\telse {\n+\t\t\terror(\"unknown value after ws-error-highlight=%.*s\",\n+\t\t\t      (int)(arg - orig_arg), orig_arg);\n+\t\t\treturn 0;\n+\t\t}\n+\t\tif (*arg)\n+\t\t\targ++;\n+\t}\n+\topt->ws_error_highlight = val;\n+\treturn 1;\n+}\n+\n int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n {\n \tconst char *arg = av[0];\n@@ -3833,6 +3883,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \t\tDIFF_OPT_SET(options, SUBMODULE_LOG);\n \telse if (skip_prefix(arg, \"--submodule=\", &arg))\n \t\treturn parse_submodule_opt(options, arg);\n+\telse if (skip_prefix(arg, \"--ws-error-highlight=\", &arg))\n+\t\treturn parse_ws_error_highlight(options, arg);\n \n \t/* misc options */\n \telse if (!strcmp(arg, \"-z\"))\ndiff --git a/diff.h b/diff.h\nindex b4a624d..90c7cd6 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -137,6 +137,11 @@ struct diff_options {\n \tint dirstat_permille;\n \tint setup;\n \tint abbrev;\n+/* white-space error highlighting */\n+#define WSEH_NEW 1\n+#define WSEH_CONTEXT 2\n+#define WSEH_OLD 4\n+\tunsigned ws_error_highlight;\n \tconst char *prefix;\n \tint prefix_length;\n \tconst char *stat_sep;\ndiff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh\nindex 4da30e5..2434157 100755\n--- a/t/t4015-diff-whitespace.sh\n+++ b/t/t4015-diff-whitespace.sh\n@@ -838,4 +838,100 @@ test_expect_success 'diff that introduces a line with only tabs' '\n \ttest_cmp expected current\n '\n \n+test_expect_success 'diff that introduces and removes ws breakages' '\n+\tgit reset --hard &&\n+\t{\n+\t\techo \"0. blank-at-eol \" &&\n+\t\techo \"1. blank-at-eol \"\n+\t} >x &&\n+\tgit commit -a --allow-empty -m preimage &&\n+\t{\n+\t\techo \"0. blank-at-eol \" &&\n+\t\techo \"1. still-blank-at-eol \" &&\n+\t\techo \"2. and a new line \"\n+\t} >x &&\n+\n+\tgit -c color.diff=always diff |\n+\ttest_decode_color >current &&\n+\n+\tcat >expected <<-\\EOF &&\n+\t<BOLD>diff --git a/x b/x<RESET>\n+\t<BOLD>index d0233a2..700886e 100644<RESET>\n+\t<BOLD>--- a/x<RESET>\n+\t<BOLD>+++ b/x<RESET>\n+\t<CYAN>@@ -1,2 +1,3 @@<RESET>\n+\t 0. blank-at-eol <RESET>\n+\t<RED>-1. blank-at-eol <RESET>\n+\t<GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>\n+\t<GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>\n+\tEOF\n+\n+\ttest_cmp expected current\n+'\n+\n+test_expect_success 'the same with --ws-error-highlight' '\n+\tgit reset --hard &&\n+\t{\n+\t\techo \"0. blank-at-eol \" &&\n+\t\techo \"1. blank-at-eol \"\n+\t} >x &&\n+\tgit commit -a --allow-empty -m preimage &&\n+\t{\n+\t\techo \"0. blank-at-eol \" &&\n+\t\techo \"1. still-blank-at-eol \" &&\n+\t\techo \"2. and a new line \"\n+\t} >x &&\n+\n+\tgit -c color.diff=always diff --ws-error-highlight=default,old |\n+\ttest_decode_color >current &&\n+\n+\tcat >expected <<-\\EOF &&\n+\t<BOLD>diff --git a/x b/x<RESET>\n+\t<BOLD>index d0233a2..700886e 100644<RESET>\n+\t<BOLD>--- a/x<RESET>\n+\t<BOLD>+++ b/x<RESET>\n+\t<CYAN>@@ -1,2 +1,3 @@<RESET>\n+\t 0. blank-at-eol <RESET>\n+\t<RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>\n+\t<GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>\n+\t<GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>\n+\tEOF\n+\n+\ttest_cmp expected current &&\n+\n+\tgit -c color.diff=always diff --ws-error-highlight=all |\n+\ttest_decode_color >current &&\n+\n+\tcat >expected <<-\\EOF &&\n+\t<BOLD>diff --git a/x b/x<RESET>\n+\t<BOLD>index d0233a2..700886e 100644<RESET>\n+\t<BOLD>--- a/x<RESET>\n+\t<BOLD>+++ b/x<RESET>\n+\t<CYAN>@@ -1,2 +1,3 @@<RESET>\n+\t <RESET>0. blank-at-eol<RESET><BLUE> <RESET>\n+\t<RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>\n+\t<GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>\n+\t<GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>\n+\tEOF\n+\n+\ttest_cmp expected current &&\n+\n+\tgit -c color.diff=always diff --ws-error-highlight=none |\n+\ttest_decode_color >current &&\n+\n+\tcat >expected <<-\\EOF &&\n+\t<BOLD>diff --git a/x b/x<RESET>\n+\t<BOLD>index d0233a2..700886e 100644<RESET>\n+\t<BOLD>--- a/x<RESET>\n+\t<BOLD>+++ b/x<RESET>\n+\t<CYAN>@@ -1,2 +1,3 @@<RESET>\n+\t 0. blank-at-eol <RESET>\n+\t<RED>-1. blank-at-eol <RESET>\n+\t<GREEN>+1. still-blank-at-eol <RESET>\n+\t<GREEN>+2. and a new line <RESET>\n+\tEOF\n+\n+\ttest_cmp expected current\n+'\n+\n test_done\n-- \n2.4.2-503-g3e4528a\n"},{"id":"262215","messageId":"20150527072218.GB6898@peff.net","threadId":"39422","inReplyTo":"1432708232-29892-1-git-send-email-gitster@pobox.com","subject":"Re: [PATCH v3 0/4] showing existing ws breakage","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-05-27T07:22:19Z","receivedAt":"2015-05-27T07:22:19Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, May 26, 2015 at 11:30:28PM -0700, Junio C Hamano wrote:\n\n> The fourth one in v2 used a new option \"--[no-]ws-check-deleted\",\n> but in this round a new option \"--ws-error-highlight=<kinds>\" is\n> defined instead.  With that, you can say\n> \n> \tdiff --ws-error-highlight=new,old\n> \n> to say \"I want to see whitespace errors on new and old lines\", and\n> \n> \tdiff --ws-error-highlight=new,old,context\n> \tdiff --ws-error-highlight=all\n> \t\n> can be used to also see whitespace errors on context lines.  Being\n> able to see whitespace errors on context lines, i.e. the ones that\n> were there in the original and you left intact, would help you see\n> how prevalent whitespace errors are in the original and hopefully\n> would make it easier for you to decide if a separate preliminary\n> clean-up to only fix these whitespace errors is warranted.\n\nThat makes sense. Neat feature.\n\nIn color.diff.*, these are called \"new\", \"old\", and \"plain\". I am of the\nopinion that \"context\" is a far better name than \"plain\", but perhaps we\nshould support both for consistency.\n\nHere's a patch for the color.diff side, if we want to go that route.\n\n-- >8 --\nSubject: diff: accept color.diff.context as a synonym for \"plain\"\n\nThe term \"plain\" is a bit ambiguous; let's allow the more\nspecific \"context\", but keep \"plain\" around for\ncompatibility.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nI didn't bother mentioning the historical \"plain\" in the documentation.\nI don't know if it's better to (for people who find it in the wild and\nwonder what it means) or if it simply clutters the description. It may\nalso be that people don't find \"plain\" as meaningless as I do, and would\nrather leave it as the primary in the documentation (and accepting\n\"context\" is just a nicety).\n\nI also resisted the urge to refactor every internal variable and enum\nmentioning \"plain\" into \"context\". I guess whether that is a good idea\ndepends on how strongly you agree that \"plain\" is a bad name. :)\n\n Documentation/config.txt | 2 +-\n diff.c                   | 2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 5f76e8c..34ef9fe 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -914,7 +914,7 @@ command line with the `--color[=<when>]` option.\n color.diff.<slot>::\n \tUse customized color for diff colorization.  `<slot>` specifies\n \twhich part of the patch to use the specified color, and is one\n-\tof `plain` (context text), `meta` (metainformation), `frag`\n+\tof `context` (context text), `meta` (metainformation), `frag`\n \t(hunk header), 'func' (function in hunk header), `old` (removed lines),\n \t`new` (added lines), `commit` (commit headers), or `whitespace`\n \t(highlighting whitespace errors).\ndiff --git a/diff.c b/diff.c\nindex 7500c55..27bd371 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -54,7 +54,7 @@ static char diff_colors[][COLOR_MAXLEN] = {\n \n static int parse_diff_color_slot(const char *var)\n {\n-\tif (!strcasecmp(var, \"plain\"))\n+\tif (!strcasecmp(var, \"context\") || !strcasecmp(var, \"plain\"))\n \t\treturn DIFF_PLAIN;\n \tif (!strcasecmp(var, \"meta\"))\n \t\treturn DIFF_METAINFO;\n-- \n2.4.1.552.g6de66a4\n"},{"id":"262245","messageId":"xmqqa8wpn910.fsf@gitster.dls.corp.google.com","threadId":"39422","inReplyTo":"20150527072218.GB6898@peff.net","subject":"Re: [PATCH v3 0/4] showing existing ws breakage","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-27T18:57:15Z","receivedAt":"2015-05-27T18:57:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> In color.diff.*, these are called \"new\", \"old\", and \"plain\". I am of the\n> opinion that \"context\" is a far better name than \"plain\", but perhaps we\n> should support both for consistency.\n>\n> Here's a patch for the color.diff side, if we want to go that route.\n>\n> -- >8 --\n> Subject: diff: accept color.diff.context as a synonym for \"plain\"\n>\n> The term \"plain\" is a bit ambiguous; let's allow the more\n> specific \"context\", but keep \"plain\" around for\n> compatibility.\n>\n> Signed-off-by: Jeff King <peff@peff.net>\n> ---\n> I didn't bother mentioning the historical \"plain\" in the documentation.\n> I don't know if it's better to (for people who find it in the wild and\n> wonder what it means) or if it simply clutters the description.\n\n'plain' does sound a misnomer, as these slot names are about \"what\"\nare painted, not \"how\" they are painted.  The latter is what their\nvalues represent.  Whoever named that slot was confused by the fact\nthat 'context' (i.e. \"what\") lines are by default painted in 'plain'\ncolor without frills (i.e. \"how\").\n\nWe usually try to give a brief mention to historical names primarily\nto silence those who pick up stale information from the Web, get\ncurious, and then complain loudly after finding that we no longer\ndocument them even though we keep accepting them silently, so I am\nsomewhat tempted to do this on top.\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 0a7ffa5..b458590 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -870,7 +870,8 @@ command line with the `--color[=<when>]` option.\n color.diff.<slot>::\n \tUse customized color for diff colorization.  `<slot>` specifies\n \twhich part of the patch to use the specified color, and is one\n-\tof `context` (context text), `meta` (metainformation), `frag`\n+\tof `context` (context text - `plain` is a historical synonym),\n+\t`meta` (metainformation), `frag`\n \t(hunk header), 'func' (function in hunk header), `old` (removed lines),\n \t`new` (added lines), `commit` (commit headers), or `whitespace`\n \t(highlighting whitespace errors). The values of these variables may be\n"},{"id":"262268","messageId":"20150527203648.GE14309@peff.net","threadId":"39422","inReplyTo":"xmqqa8wpn910.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v3 0/4] showing existing ws breakage","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-05-27T20:36:49Z","receivedAt":"2015-05-27T20:36:49Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, May 27, 2015 at 11:57:15AM -0700, Junio C Hamano wrote:\n\n> > -- >8 --\n> > Subject: diff: accept color.diff.context as a synonym for \"plain\"\n> >\n> > The term \"plain\" is a bit ambiguous; let's allow the more\n> > specific \"context\", but keep \"plain\" around for\n> > compatibility.\n> >\n> > Signed-off-by: Jeff King <peff@peff.net>\n> > ---\n> > I didn't bother mentioning the historical \"plain\" in the documentation.\n> > I don't know if it's better to (for people who find it in the wild and\n> > wonder what it means) or if it simply clutters the description.\n> \n> 'plain' does sound a misnomer, as these slot names are about \"what\"\n> are painted, not \"how\" they are painted.  The latter is what their\n> values represent.  Whoever named that slot was confused by the fact\n> that 'context' (i.e. \"what\") lines are by default painted in 'plain'\n> color without frills (i.e. \"how\").\n> \n> We usually try to give a brief mention to historical names primarily\n> to silence those who pick up stale information from the Web, get\n> curious, and then complain loudly after finding that we no longer\n> document them even though we keep accepting them silently, so I am\n> somewhat tempted to do this on top.\n\nYeah, I waffled on doing it myself. If you take the patch, please do\nsquash that in.\n\nDo you want me to also eradicate PLAIN from the code itself? It's a\nrather simple change, but it does touch a lot of places.\n\n-Peff\n"},{"id":"262272","messageId":"xmqqpp5lkau5.fsf@gitster.dls.corp.google.com","threadId":"39422","inReplyTo":"20150527203648.GE14309@peff.net","subject":"Re: [PATCH v3 0/4] showing existing ws breakage","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-27T20:46:26Z","receivedAt":"2015-05-27T20:46:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Do you want me to also eradicate PLAIN from the code itself? It's a\n> rather simple change, but it does touch a lot of places.\n\nNah, that is not user-facing.  We do not do s/cache/index/ in the\ncode, either.\n\nBesides, I actually find plain much easier to type than context ;-)\n"},{"id":"262273","messageId":"20150527204846.GF14309@peff.net","threadId":"39422","inReplyTo":"xmqqpp5lkau5.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v3 0/4] showing existing ws breakage","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-05-27T20:48:46Z","receivedAt":"2015-05-27T20:48:46Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, May 27, 2015 at 01:46:26PM -0700, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > Do you want me to also eradicate PLAIN from the code itself? It's a\n> > rather simple change, but it does touch a lot of places.\n> \n> Nah, that is not user-facing.  We do not do s/cache/index/ in the\n> code, either.\n> \n> Besides, I actually find plain much easier to type than context ;-)\n\nOK. I just did it while our emails were in flight, so here it is just\nfor reference.\n\n-- >8 --\nSubject: diff.h: rename DIFF_PLAIN color slot to DIFF_CONTEXT\n\nThe latter is a much more descriptive name (and we support\n\"color.diff.context\" now). This also updates the name of any\nlocal variables which were used to store the color.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n combine-diff.c |  6 +++---\n diff.c         | 26 +++++++++++++-------------\n diff.h         |  2 +-\n line-log.c     |  6 +++---\n 4 files changed, 20 insertions(+), 20 deletions(-)\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 8eb7278..30c7eb6 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -730,7 +730,7 @@ static void dump_sline(struct sline *sline, const char *line_prefix,\n \tconst char *c_func = diff_get_color(use_color, DIFF_FUNCINFO);\n \tconst char *c_new = diff_get_color(use_color, DIFF_FILE_NEW);\n \tconst char *c_old = diff_get_color(use_color, DIFF_FILE_OLD);\n-\tconst char *c_plain = diff_get_color(use_color, DIFF_PLAIN);\n+\tconst char *c_context = diff_get_color(use_color, DIFF_CONTEXT);\n \tconst char *c_reset = diff_get_color(use_color, DIFF_RESET);\n \n \tif (result_deleted)\n@@ -793,7 +793,7 @@ static void dump_sline(struct sline *sline, const char *line_prefix,\n \t\t\t}\n \t\t\tif (comment_end)\n \t\t\t\tprintf(\"%s%s %s%s\", c_reset,\n-\t\t\t\t\t\t    c_plain, c_reset,\n+\t\t\t\t\t\t    c_context, c_reset,\n \t\t\t\t\t\t    c_func);\n \t\t\tfor (i = 0; i < comment_end; i++)\n \t\t\t\tputchar(hunk_comment[i]);\n@@ -828,7 +828,7 @@ static void dump_sline(struct sline *sline, const char *line_prefix,\n \t\t\t\t */\n \t\t\t\tif (!context)\n \t\t\t\t\tcontinue;\n-\t\t\t\tfputs(c_plain, stdout);\n+\t\t\t\tfputs(c_context, stdout);\n \t\t\t}\n \t\t\telse\n \t\t\t\tfputs(c_new, stdout);\ndiff --git a/diff.c b/diff.c\nindex 27bd371..100773f 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -42,7 +42,7 @@ static long diff_algorithm;\n \n static char diff_colors[][COLOR_MAXLEN] = {\n \tGIT_COLOR_RESET,\n-\tGIT_COLOR_NORMAL,\t/* PLAIN */\n+\tGIT_COLOR_NORMAL,\t/* CONTEXT */\n \tGIT_COLOR_BOLD,\t\t/* METAINFO */\n \tGIT_COLOR_CYAN,\t\t/* FRAGINFO */\n \tGIT_COLOR_RED,\t\t/* OLD */\n@@ -55,7 +55,7 @@ static char diff_colors[][COLOR_MAXLEN] = {\n static int parse_diff_color_slot(const char *var)\n {\n \tif (!strcasecmp(var, \"context\") || !strcasecmp(var, \"plain\"))\n-\t\treturn DIFF_PLAIN;\n+\t\treturn DIFF_CONTEXT;\n \tif (!strcasecmp(var, \"meta\"))\n \t\treturn DIFF_METAINFO;\n \tif (!strcasecmp(var, \"frag\"))\n@@ -501,7 +501,7 @@ static void emit_add_line(const char *reset,\n static void emit_hunk_header(struct emit_callback *ecbdata,\n \t\t\t     const char *line, int len)\n {\n-\tconst char *plain = diff_get_color(ecbdata->color_diff, DIFF_PLAIN);\n+\tconst char *context = diff_get_color(ecbdata->color_diff, DIFF_CONTEXT);\n \tconst char *frag = diff_get_color(ecbdata->color_diff, DIFF_FRAGINFO);\n \tconst char *func = diff_get_color(ecbdata->color_diff, DIFF_FUNCINFO);\n \tconst char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);\n@@ -518,7 +518,7 @@ static void emit_hunk_header(struct emit_callback *ecbdata,\n \tif (len < 10 ||\n \t    memcmp(line, atat, 2) ||\n \t    !(ep = memmem(line + 2, len - 2, atat, 2))) {\n-\t\temit_line(ecbdata->opt, plain, reset, line, len);\n+\t\temit_line(ecbdata->opt, context, reset, line, len);\n \t\treturn;\n \t}\n \tep += 2; /* skip over @@ */\n@@ -540,7 +540,7 @@ static void emit_hunk_header(struct emit_callback *ecbdata,\n \t\tif (*ep != ' ' && *ep != '\\t')\n \t\t\tbreak;\n \tif (ep != cp) {\n-\t\tstrbuf_addstr(&msgbuf, plain);\n+\t\tstrbuf_addstr(&msgbuf, context);\n \t\tstrbuf_add(&msgbuf, cp, ep - cp);\n \t\tstrbuf_addstr(&msgbuf, reset);\n \t}\n@@ -623,10 +623,10 @@ static void emit_rewrite_lines(struct emit_callback *ecb,\n \t\tdata += len;\n \t}\n \tif (!endp) {\n-\t\tconst char *plain = diff_get_color(ecb->color_diff,\n-\t\t\t\t\t\t   DIFF_PLAIN);\n+\t\tconst char *context = diff_get_color(ecb->color_diff,\n+\t\t\t\t\t\t     DIFF_CONTEXT);\n \t\tputc('\\n', ecb->opt->file);\n-\t\temit_line_0(ecb->opt, plain, reset, '\\\\',\n+\t\temit_line_0(ecb->opt, context, reset, '\\\\',\n \t\t\t    nneof, strlen(nneof));\n \t}\n }\n@@ -1086,7 +1086,7 @@ static void init_diff_words_data(struct emit_callback *ecbdata,\n \t\tstruct diff_words_style *st = ecbdata->diff_words->style;\n \t\tst->old.color = diff_get_color_opt(o, DIFF_FILE_OLD);\n \t\tst->new.color = diff_get_color_opt(o, DIFF_FILE_NEW);\n-\t\tst->ctx.color = diff_get_color_opt(o, DIFF_PLAIN);\n+\t\tst->ctx.color = diff_get_color_opt(o, DIFF_CONTEXT);\n \t}\n }\n \n@@ -1162,7 +1162,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)\n {\n \tstruct emit_callback *ecbdata = priv;\n \tconst char *meta = diff_get_color(ecbdata->color_diff, DIFF_METAINFO);\n-\tconst char *plain = diff_get_color(ecbdata->color_diff, DIFF_PLAIN);\n+\tconst char *context = diff_get_color(ecbdata->color_diff, DIFF_CONTEXT);\n \tconst char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);\n \tstruct diff_options *o = ecbdata->opt;\n \tconst char *line_prefix = diff_line_prefix(o);\n@@ -1233,7 +1233,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)\n \t\t}\n \t\tdiff_words_flush(ecbdata);\n \t\tif (ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) {\n-\t\t\temit_line(ecbdata->opt, plain, reset, line, len);\n+\t\t\temit_line(ecbdata->opt, context, reset, line, len);\n \t\t\tfputs(\"~\\n\", ecbdata->opt->file);\n \t\t} else {\n \t\t\t/*\n@@ -1245,7 +1245,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)\n \t\t\t      line++;\n \t\t\t      len--;\n \t\t\t}\n-\t\t\temit_line(ecbdata->opt, plain, reset, line, len);\n+\t\t\temit_line(ecbdata->opt, context, reset, line, len);\n \t\t}\n \t\treturn;\n \t}\n@@ -1253,7 +1253,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)\n \tif (line[0] != '+') {\n \t\tconst char *color =\n \t\t\tdiff_get_color(ecbdata->color_diff,\n-\t\t\t\t       line[0] == '-' ? DIFF_FILE_OLD : DIFF_PLAIN);\n+\t\t\t\t       line[0] == '-' ? DIFF_FILE_OLD : DIFF_CONTEXT);\n \t\tecbdata->lno_in_preimage++;\n \t\tif (line[0] == ' ')\n \t\t\tecbdata->lno_in_postimage++;\ndiff --git a/diff.h b/diff.h\nindex f6fdf49..6115fcb 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -176,7 +176,7 @@ struct diff_options {\n \n enum color_diff {\n \tDIFF_RESET = 0,\n-\tDIFF_PLAIN = 1,\n+\tDIFF_CONTEXT = 1,\n \tDIFF_METAINFO = 2,\n \tDIFF_FRAGINFO = 3,\n \tDIFF_FILE_OLD = 4,\ndiff --git a/line-log.c b/line-log.c\nindex a5ed9e3..c12c69f 100644\n--- a/line-log.c\n+++ b/line-log.c\n@@ -893,7 +893,7 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang\n \tconst char *c_meta = diff_get_color(opt->use_color, DIFF_METAINFO);\n \tconst char *c_old = diff_get_color(opt->use_color, DIFF_FILE_OLD);\n \tconst char *c_new = diff_get_color(opt->use_color, DIFF_FILE_NEW);\n-\tconst char *c_plain = diff_get_color(opt->use_color, DIFF_PLAIN);\n+\tconst char *c_context = diff_get_color(opt->use_color, DIFF_CONTEXT);\n \n \tif (!pair || !diff)\n \t\treturn;\n@@ -957,7 +957,7 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang\n \t\t\tint k;\n \t\t\tfor (; t_cur < diff->target.ranges[j].start; t_cur++)\n \t\t\t\tprint_line(prefix, ' ', t_cur, t_ends, pair->two->data,\n-\t\t\t\t\t   c_plain, c_reset);\n+\t\t\t\t\t   c_context, c_reset);\n \t\t\tfor (k = diff->parent.ranges[j].start; k < diff->parent.ranges[j].end; k++)\n \t\t\t\tprint_line(prefix, '-', k, p_ends, pair->one->data,\n \t\t\t\t\t   c_old, c_reset);\n@@ -968,7 +968,7 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang\n \t\t}\n \t\tfor (; t_cur < t_end; t_cur++)\n \t\t\tprint_line(prefix, ' ', t_cur, t_ends, pair->two->data,\n-\t\t\t\t   c_plain, c_reset);\n+\t\t\t\t   c_context, c_reset);\n \t}\n \n \tfree(p_ends);\n-- \n2.4.2.668.gc3b1ade.dirty\n"},{"id":"262274","messageId":"20150527205144.GA22815@peff.net","threadId":"39422","inReplyTo":"20150527072218.GB6898@peff.net","subject":"Re: [PATCH v3 0/4] showing existing ws breakage","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-05-27T20:51:44Z","receivedAt":"2015-05-27T20:51:44Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, May 27, 2015 at 03:22:18AM -0400, Jeff King wrote:\n\n> In color.diff.*, these are called \"new\", \"old\", and \"plain\". I am of the\n> opinion that \"context\" is a far better name than \"plain\", but perhaps we\n> should support both for consistency.\n> \n> Here's a patch for the color.diff side, if we want to go that route.\n\nSo I had originally thought we would support both names in both places.\nBut since the diff patch we ended up with is basically \"the real name is\ncontext; plain is just a historical anomaly\", I do not see any need to\nsupport \"plain\" in your new whitespace code.\n\nI suspect you came to the same conclusion independently, but I wanted to\nmake sure what I had written before didn't leave anybody confused.\n\n-Peff\n"},{"id":"262275","messageId":"xmqqlhg9kaig.fsf@gitster.dls.corp.google.com","threadId":"39422","inReplyTo":"20150527204846.GF14309@peff.net","subject":"Re: [PATCH v3 0/4] showing existing ws breakage","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-27T20:53:27Z","receivedAt":"2015-05-27T20:53:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Wed, May 27, 2015 at 01:46:26PM -0700, Junio C Hamano wrote:\n>\n>> Jeff King <peff@peff.net> writes:\n>> \n>> > Do you want me to also eradicate PLAIN from the code itself? It's a\n>> > rather simple change, but it does touch a lot of places.\n>> \n>> Nah, that is not user-facing.  We do not do s/cache/index/ in the\n>> code, either.\n>> \n>> Besides, I actually find plain much easier to type than context ;-)\n>\n> OK. I just did it while our emails were in flight, so here it is just\n> for reference.\n\nI actually like that; the changes are fairly isolated and contained.\n\n>\n> -- >8 --\n> Subject: diff.h: rename DIFF_PLAIN color slot to DIFF_CONTEXT\n>\n> The latter is a much more descriptive name (and we support\n> \"color.diff.context\" now). This also updates the name of any\n> local variables which were used to store the color.\n>\n> Signed-off-by: Jeff King <peff@peff.net>\n> ---\n>  combine-diff.c |  6 +++---\n>  diff.c         | 26 +++++++++++++-------------\n>  diff.h         |  2 +-\n>  line-log.c     |  6 +++---\n>  4 files changed, 20 insertions(+), 20 deletions(-)\n>\n> diff --git a/combine-diff.c b/combine-diff.c\n> index 8eb7278..30c7eb6 100644\n> --- a/combine-diff.c\n> +++ b/combine-diff.c\n> @@ -730,7 +730,7 @@ static void dump_sline(struct sline *sline, const char *line_prefix,\n>  \tconst char *c_func = diff_get_color(use_color, DIFF_FUNCINFO);\n>  \tconst char *c_new = diff_get_color(use_color, DIFF_FILE_NEW);\n>  \tconst char *c_old = diff_get_color(use_color, DIFF_FILE_OLD);\n> -\tconst char *c_plain = diff_get_color(use_color, DIFF_PLAIN);\n> +\tconst char *c_context = diff_get_color(use_color, DIFF_CONTEXT);\n>  \tconst char *c_reset = diff_get_color(use_color, DIFF_RESET);\n>  \n>  \tif (result_deleted)\n> @@ -793,7 +793,7 @@ static void dump_sline(struct sline *sline, const char *line_prefix,\n>  \t\t\t}\n>  \t\t\tif (comment_end)\n>  \t\t\t\tprintf(\"%s%s %s%s\", c_reset,\n> -\t\t\t\t\t\t    c_plain, c_reset,\n> +\t\t\t\t\t\t    c_context, c_reset,\n>  \t\t\t\t\t\t    c_func);\n>  \t\t\tfor (i = 0; i < comment_end; i++)\n>  \t\t\t\tputchar(hunk_comment[i]);\n> @@ -828,7 +828,7 @@ static void dump_sline(struct sline *sline, const char *line_prefix,\n>  \t\t\t\t */\n>  \t\t\t\tif (!context)\n>  \t\t\t\t\tcontinue;\n> -\t\t\t\tfputs(c_plain, stdout);\n> +\t\t\t\tfputs(c_context, stdout);\n>  \t\t\t}\n>  \t\t\telse\n>  \t\t\t\tfputs(c_new, stdout);\n> diff --git a/diff.c b/diff.c\n> index 27bd371..100773f 100644\n> --- a/diff.c\n> +++ b/diff.c\n> @@ -42,7 +42,7 @@ static long diff_algorithm;\n>  \n>  static char diff_colors[][COLOR_MAXLEN] = {\n>  \tGIT_COLOR_RESET,\n> -\tGIT_COLOR_NORMAL,\t/* PLAIN */\n> +\tGIT_COLOR_NORMAL,\t/* CONTEXT */\n>  \tGIT_COLOR_BOLD,\t\t/* METAINFO */\n>  \tGIT_COLOR_CYAN,\t\t/* FRAGINFO */\n>  \tGIT_COLOR_RED,\t\t/* OLD */\n> @@ -55,7 +55,7 @@ static char diff_colors[][COLOR_MAXLEN] = {\n>  static int parse_diff_color_slot(const char *var)\n>  {\n>  \tif (!strcasecmp(var, \"context\") || !strcasecmp(var, \"plain\"))\n> -\t\treturn DIFF_PLAIN;\n> +\t\treturn DIFF_CONTEXT;\n>  \tif (!strcasecmp(var, \"meta\"))\n>  \t\treturn DIFF_METAINFO;\n>  \tif (!strcasecmp(var, \"frag\"))\n> @@ -501,7 +501,7 @@ static void emit_add_line(const char *reset,\n>  static void emit_hunk_header(struct emit_callback *ecbdata,\n>  \t\t\t     const char *line, int len)\n>  {\n> -\tconst char *plain = diff_get_color(ecbdata->color_diff, DIFF_PLAIN);\n> +\tconst char *context = diff_get_color(ecbdata->color_diff, DIFF_CONTEXT);\n>  \tconst char *frag = diff_get_color(ecbdata->color_diff, DIFF_FRAGINFO);\n>  \tconst char *func = diff_get_color(ecbdata->color_diff, DIFF_FUNCINFO);\n>  \tconst char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);\n> @@ -518,7 +518,7 @@ static void emit_hunk_header(struct emit_callback *ecbdata,\n>  \tif (len < 10 ||\n>  \t    memcmp(line, atat, 2) ||\n>  \t    !(ep = memmem(line + 2, len - 2, atat, 2))) {\n> -\t\temit_line(ecbdata->opt, plain, reset, line, len);\n> +\t\temit_line(ecbdata->opt, context, reset, line, len);\n>  \t\treturn;\n>  \t}\n>  \tep += 2; /* skip over @@ */\n> @@ -540,7 +540,7 @@ static void emit_hunk_header(struct emit_callback *ecbdata,\n>  \t\tif (*ep != ' ' && *ep != '\\t')\n>  \t\t\tbreak;\n>  \tif (ep != cp) {\n> -\t\tstrbuf_addstr(&msgbuf, plain);\n> +\t\tstrbuf_addstr(&msgbuf, context);\n>  \t\tstrbuf_add(&msgbuf, cp, ep - cp);\n>  \t\tstrbuf_addstr(&msgbuf, reset);\n>  \t}\n> @@ -623,10 +623,10 @@ static void emit_rewrite_lines(struct emit_callback *ecb,\n>  \t\tdata += len;\n>  \t}\n>  \tif (!endp) {\n> -\t\tconst char *plain = diff_get_color(ecb->color_diff,\n> -\t\t\t\t\t\t   DIFF_PLAIN);\n> +\t\tconst char *context = diff_get_color(ecb->color_diff,\n> +\t\t\t\t\t\t     DIFF_CONTEXT);\n>  \t\tputc('\\n', ecb->opt->file);\n> -\t\temit_line_0(ecb->opt, plain, reset, '\\\\',\n> +\t\temit_line_0(ecb->opt, context, reset, '\\\\',\n>  \t\t\t    nneof, strlen(nneof));\n>  \t}\n>  }\n> @@ -1086,7 +1086,7 @@ static void init_diff_words_data(struct emit_callback *ecbdata,\n>  \t\tstruct diff_words_style *st = ecbdata->diff_words->style;\n>  \t\tst->old.color = diff_get_color_opt(o, DIFF_FILE_OLD);\n>  \t\tst->new.color = diff_get_color_opt(o, DIFF_FILE_NEW);\n> -\t\tst->ctx.color = diff_get_color_opt(o, DIFF_PLAIN);\n> +\t\tst->ctx.color = diff_get_color_opt(o, DIFF_CONTEXT);\n>  \t}\n>  }\n>  \n> @@ -1162,7 +1162,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)\n>  {\n>  \tstruct emit_callback *ecbdata = priv;\n>  \tconst char *meta = diff_get_color(ecbdata->color_diff, DIFF_METAINFO);\n> -\tconst char *plain = diff_get_color(ecbdata->color_diff, DIFF_PLAIN);\n> +\tconst char *context = diff_get_color(ecbdata->color_diff, DIFF_CONTEXT);\n>  \tconst char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);\n>  \tstruct diff_options *o = ecbdata->opt;\n>  \tconst char *line_prefix = diff_line_prefix(o);\n> @@ -1233,7 +1233,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)\n>  \t\t}\n>  \t\tdiff_words_flush(ecbdata);\n>  \t\tif (ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) {\n> -\t\t\temit_line(ecbdata->opt, plain, reset, line, len);\n> +\t\t\temit_line(ecbdata->opt, context, reset, line, len);\n>  \t\t\tfputs(\"~\\n\", ecbdata->opt->file);\n>  \t\t} else {\n>  \t\t\t/*\n> @@ -1245,7 +1245,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)\n>  \t\t\t      line++;\n>  \t\t\t      len--;\n>  \t\t\t}\n> -\t\t\temit_line(ecbdata->opt, plain, reset, line, len);\n> +\t\t\temit_line(ecbdata->opt, context, reset, line, len);\n>  \t\t}\n>  \t\treturn;\n>  \t}\n> @@ -1253,7 +1253,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)\n>  \tif (line[0] != '+') {\n>  \t\tconst char *color =\n>  \t\t\tdiff_get_color(ecbdata->color_diff,\n> -\t\t\t\t       line[0] == '-' ? DIFF_FILE_OLD : DIFF_PLAIN);\n> +\t\t\t\t       line[0] == '-' ? DIFF_FILE_OLD : DIFF_CONTEXT);\n>  \t\tecbdata->lno_in_preimage++;\n>  \t\tif (line[0] == ' ')\n>  \t\t\tecbdata->lno_in_postimage++;\n> diff --git a/diff.h b/diff.h\n> index f6fdf49..6115fcb 100644\n> --- a/diff.h\n> +++ b/diff.h\n> @@ -176,7 +176,7 @@ struct diff_options {\n>  \n>  enum color_diff {\n>  \tDIFF_RESET = 0,\n> -\tDIFF_PLAIN = 1,\n> +\tDIFF_CONTEXT = 1,\n>  \tDIFF_METAINFO = 2,\n>  \tDIFF_FRAGINFO = 3,\n>  \tDIFF_FILE_OLD = 4,\n> diff --git a/line-log.c b/line-log.c\n> index a5ed9e3..c12c69f 100644\n> --- a/line-log.c\n> +++ b/line-log.c\n> @@ -893,7 +893,7 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang\n>  \tconst char *c_meta = diff_get_color(opt->use_color, DIFF_METAINFO);\n>  \tconst char *c_old = diff_get_color(opt->use_color, DIFF_FILE_OLD);\n>  \tconst char *c_new = diff_get_color(opt->use_color, DIFF_FILE_NEW);\n> -\tconst char *c_plain = diff_get_color(opt->use_color, DIFF_PLAIN);\n> +\tconst char *c_context = diff_get_color(opt->use_color, DIFF_CONTEXT);\n>  \n>  \tif (!pair || !diff)\n>  \t\treturn;\n> @@ -957,7 +957,7 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang\n>  \t\t\tint k;\n>  \t\t\tfor (; t_cur < diff->target.ranges[j].start; t_cur++)\n>  \t\t\t\tprint_line(prefix, ' ', t_cur, t_ends, pair->two->data,\n> -\t\t\t\t\t   c_plain, c_reset);\n> +\t\t\t\t\t   c_context, c_reset);\n>  \t\t\tfor (k = diff->parent.ranges[j].start; k < diff->parent.ranges[j].end; k++)\n>  \t\t\t\tprint_line(prefix, '-', k, p_ends, pair->one->data,\n>  \t\t\t\t\t   c_old, c_reset);\n> @@ -968,7 +968,7 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang\n>  \t\t}\n>  \t\tfor (; t_cur < t_end; t_cur++)\n>  \t\t\tprint_line(prefix, ' ', t_cur, t_ends, pair->two->data,\n> -\t\t\t\t   c_plain, c_reset);\n> +\t\t\t\t   c_context, c_reset);\n>  \t}\n>  \n>  \tfree(p_ends);\n"}]}