From: Junio C Hamano Date: Wed, 15 Aug 2018 22:08:22 +0000 (-0700) Subject: Merge branch 'es/diff-color-moved-fix' X-Git-Tag: v2.19.0-rc0~80 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=706b0b5e8d683b06e99bdfb2349228b360e4cf03;p=git Merge branch 'es/diff-color-moved-fix' One of the "diff --color-moved" mode "dimmed_zebra" that was named in an unusual way has been deprecated and replaced by "dimmed-zebra". * es/diff-color-moved-fix: diff: --color-moved: rename "dimmed_zebra" to "dimmed-zebra" --- 706b0b5e8d683b06e99bdfb2349228b360e4cf03 diff --cc Documentation/diff-options.txt index f394608b42,cbc05e8a95..0378cd574e --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@@ -276,47 -268,19 +276,48 @@@ plain: that are added somewhere else in the diff. This mode picks up any moved line, but it is not very useful in a review to determine if a block of code was moved without permutation. -zebra:: +blocks:: Blocks of moved text of at least 20 alphanumeric characters are detected greedily. The detected blocks are - painted using either the 'color.diff.{old,new}Moved' color or + painted using either the 'color.diff.{old,new}Moved' color. + Adjacent blocks cannot be told apart. +zebra:: + Blocks of moved text are detected as in 'blocks' mode. The blocks + are painted using either the 'color.diff.{old,new}Moved' color or 'color.diff.{old,new}MovedAlternative'. The change between the two colors indicates that a new block was detected. - dimmed_zebra:: + dimmed-zebra:: Similar to 'zebra', but additional dimming of uninteresting parts of moved code is performed. The bordering lines of two adjacent blocks are considered interesting, the rest is uninteresting. + `dimmed_zebra` is a deprecated synonym. -- +--color-moved-ws=:: + This configures how white spaces are ignored when performing the + move detection for `--color-moved`. +ifdef::git-diff[] + It can be set by the `diff.colorMovedWS` configuration setting. +endif::git-diff[] + These modes can be given as a comma separated list: ++ +-- +ignore-space-at-eol:: + Ignore changes in whitespace at EOL. +ignore-space-change:: + Ignore changes in amount of whitespace. This ignores whitespace + at line end, and considers all other sequences of one or + more whitespace characters to be equivalent. +ignore-all-space:: + Ignore whitespace when comparing lines. This ignores differences + even if one line has whitespace where the other line has none. +allow-indentation-change:: + Initially ignore any white spaces in the move detection, then + group the moved code blocks only into a block if the change in + whitespace is the same per line. This is incompatible with the + other modes. +-- + --word-diff[=]:: Show a word diff, using the to delimit changed words. By default, words are delimited by whitespace; see diff --cc diff.c index 04d044bbb6,717100780d..0746d59fe6 --- a/diff.c +++ b/diff.c @@@ -274,43 -280,7 +276,43 @@@ static int parse_color_moved(const cha else if (!strcmp(arg, "dimmed_zebra")) return COLOR_MOVED_ZEBRA_DIM; else - return error(_("color moved setting must be one of 'no', 'default', 'blocks', 'zebra', 'dimmed_zebra', 'plain'")); - return error(_("color moved setting must be one of 'no', 'default', 'zebra', 'dimmed-zebra', 'plain'")); ++ return error(_("color moved setting must be one of 'no', 'default', 'blocks', 'zebra', 'dimmed-zebra', 'plain'")); +} + +static int parse_color_moved_ws(const char *arg) +{ + int ret = 0; + struct string_list l = STRING_LIST_INIT_DUP; + struct string_list_item *i; + + string_list_split(&l, arg, ',', -1); + + for_each_string_list_item(i, &l) { + struct strbuf sb = STRBUF_INIT; + strbuf_addstr(&sb, i->string); + strbuf_trim(&sb); + + if (!strcmp(sb.buf, "ignore-space-change")) + ret |= XDF_IGNORE_WHITESPACE_CHANGE; + else if (!strcmp(sb.buf, "ignore-space-at-eol")) + ret |= XDF_IGNORE_WHITESPACE_AT_EOL; + else if (!strcmp(sb.buf, "ignore-all-space")) + ret |= XDF_IGNORE_WHITESPACE; + else if (!strcmp(sb.buf, "allow-indentation-change")) + ret |= COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE; + else + error(_("ignoring unknown color-moved-ws mode '%s'"), sb.buf); + + strbuf_release(&sb); + } + + if ((ret & COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) && + (ret & XDF_WHITESPACE_FLAGS)) + die(_("color-moved-ws: allow-indentation-change cannot be combined with other white space modes")); + + string_list_clear(&l, 0); + + return ret; } int git_diff_ui_config(const char *var, const char *value, void *cb) diff --cc t/t4015-diff-whitespace.sh index 41facf7abf,8cdfa225ef..e2dc1895ba --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@@ -1271,52 -1271,9 +1271,52 @@@ test_expect_success 'detect blocks of m test_config color.diff.newMovedDimmed "normal cyan" && test_config color.diff.oldMovedAlternativeDimmed "normal blue" && test_config color.diff.newMovedAlternativeDimmed "normal yellow" && - git diff HEAD --no-renames --color-moved=dimmed-zebra --color | - grep -v "index" | - test_decode_color >actual && + git diff HEAD --no-renames --color-moved=blocks --color >actual.raw && + grep -v "index" actual.raw | test_decode_color >actual && + cat <<-\EOF >expected && + diff --git a/lines.txt b/lines.txt + --- a/lines.txt + +++ b/lines.txt + @@ -1,16 +1,16 @@ + -long line 1 + -long line 2 + -long line 3 + line 4 + line 5 + line 6 + line 7 + line 8 + line 9 + +long line 1 + +long line 2 + +long line 3 + +long line 14 + +long line 15 + +long line 16 + line 10 + line 11 + line 12 + line 13 + -long line 14 + -long line 15 + -long line 16 + EOF + test_cmp expected actual + +' + - test_expect_success 'detect permutations inside moved code -- dimmed_zebra' ' ++test_expect_success 'detect permutations inside moved code -- dimmed-zebra' ' + # reuse setup from test before! + test_config color.diff.oldMoved "magenta" && + test_config color.diff.newMoved "cyan" && + test_config color.diff.oldMovedAlternative "blue" && + test_config color.diff.newMovedAlternative "yellow" && + test_config color.diff.oldMovedDimmed "normal magenta" && + test_config color.diff.newMovedDimmed "normal cyan" && + test_config color.diff.oldMovedAlternativeDimmed "normal blue" && + test_config color.diff.newMovedAlternativeDimmed "normal yellow" && - git diff HEAD --no-renames --color-moved=dimmed_zebra --color >actual.raw && ++ git diff HEAD --no-renames --color-moved=dimmed-zebra --color >actual.raw && + grep -v "index" actual.raw | test_decode_color >actual && cat <<-\EOF >expected && diff --git a/lines.txt b/lines.txt --- a/lines.txt