diff options
author | Junio C Hamano <gitster@pobox.com> | 2022-01-05 14:01:29 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-01-05 14:01:29 -0800 |
commit | 2b755b337134aac9b1386e2d216cf734e1e229d2 (patch) | |
tree | a1ffb96dc36429bc60a9b4b4a53a96b0ed140f42 /t/t4015-diff-whitespace.sh | |
parent | Merge branch 'xw/am-empty' (diff) | |
parent | diff --color-moved: intern strings (diff) | |
download | tgif-2b755b337134aac9b1386e2d216cf734e1e229d2.tar.xz |
Merge branch 'pw/diff-color-moved-fix'
Correctness and performance update to "diff --color-moved" feature.
* pw/diff-color-moved-fix:
diff --color-moved: intern strings
diff: use designated initializers for emitted_diff_symbol
diff --color-moved-ws=allow-indentation-change: improve hash lookups
diff --color-moved: stop clearing potential moved blocks
diff --color-moved: shrink potential moved blocks as we go
diff --color-moved: unify moved block growth functions
diff --color-moved: call comparison function directly
diff --color-moved-ws=allow-indentation-change: simplify and optimize
diff: simplify allow-indentation-change delta calculation
diff --color-moved: avoid false short line matches and bad zebra coloring
diff --color-moved=zebra: fix alternate coloring
diff --color-moved: rewind when discarding pmb
diff --color-moved: factor out function
diff --color-moved: clear all flags on blocks that are too short
diff --color-moved: add perf tests
Diffstat (limited to 't/t4015-diff-whitespace.sh')
-rwxr-xr-x | t/t4015-diff-whitespace.sh | 205 |
1 files changed, 194 insertions, 11 deletions
diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index ca5adabe14..9babf13bc9 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -1442,6 +1442,143 @@ test_expect_success 'detect permutations inside moved code -- dimmed-zebra' ' test_cmp expected actual ' +test_expect_success 'zebra alternate color is only used when necessary' ' + cat >old.txt <<-\EOF && + line 1A should be marked as oldMoved newMovedAlternate + line 1B should be marked as oldMoved newMovedAlternate + unchanged + line 2A should be marked as oldMoved newMovedAlternate + line 2B should be marked as oldMoved newMovedAlternate + line 3A should be marked as oldMovedAlternate newMoved + line 3B should be marked as oldMovedAlternate newMoved + unchanged + line 4A should be marked as oldMoved newMovedAlternate + line 4B should be marked as oldMoved newMovedAlternate + line 5A should be marked as oldMovedAlternate newMoved + line 5B should be marked as oldMovedAlternate newMoved + line 6A should be marked as oldMoved newMoved + line 6B should be marked as oldMoved newMoved + EOF + cat >new.txt <<-\EOF && + line 1A should be marked as oldMoved newMovedAlternate + line 1B should be marked as oldMoved newMovedAlternate + unchanged + line 3A should be marked as oldMovedAlternate newMoved + line 3B should be marked as oldMovedAlternate newMoved + line 2A should be marked as oldMoved newMovedAlternate + line 2B should be marked as oldMoved newMovedAlternate + unchanged + line 6A should be marked as oldMoved newMoved + line 6B should be marked as oldMoved newMoved + line 4A should be marked as oldMoved newMovedAlternate + line 4B should be marked as oldMoved newMovedAlternate + line 5A should be marked as oldMovedAlternate newMoved + line 5B should be marked as oldMovedAlternate newMoved + EOF + test_expect_code 1 git diff --no-index --color --color-moved=zebra \ + --color-moved-ws=allow-indentation-change \ + old.txt new.txt >output && + grep -v index output | test_decode_color >actual && + cat >expected <<-\EOF && + <BOLD>diff --git a/old.txt b/new.txt<RESET> + <BOLD>--- a/old.txt<RESET> + <BOLD>+++ b/new.txt<RESET> + <CYAN>@@ -1,14 +1,14 @@<RESET> + <BOLD;MAGENTA>-line 1A should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;MAGENTA>-line 1B should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 1A should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 1B should be marked as oldMoved newMovedAlternate<RESET> + unchanged<RESET> + <BOLD;MAGENTA>-line 2A should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;MAGENTA>-line 2B should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;BLUE>-line 3A should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;BLUE>-line 3B should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 3A should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 3B should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;YELLOW>+<RESET><BOLD;YELLOW> line 2A should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;YELLOW>+<RESET><BOLD;YELLOW> line 2B should be marked as oldMoved newMovedAlternate<RESET> + unchanged<RESET> + <BOLD;MAGENTA>-line 4A should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;MAGENTA>-line 4B should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;BLUE>-line 5A should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;BLUE>-line 5B should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;MAGENTA>-line 6A should be marked as oldMoved newMoved<RESET> + <BOLD;MAGENTA>-line 6B should be marked as oldMoved newMoved<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 6A should be marked as oldMoved newMoved<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 6B should be marked as oldMoved newMoved<RESET> + <BOLD;YELLOW>+<RESET><BOLD;YELLOW> line 4A should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;YELLOW>+<RESET><BOLD;YELLOW> line 4B should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 5A should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 5B should be marked as oldMovedAlternate newMoved<RESET> + EOF + test_cmp expected actual +' + +test_expect_success 'short lines of opposite sign do not get marked as moved' ' + cat >old.txt <<-\EOF && + this line should be marked as moved + unchanged + unchanged + unchanged + unchanged + too short + this line should be marked as oldMoved newMoved + this line should be marked as oldMovedAlternate newMoved + unchanged 1 + unchanged 2 + unchanged 3 + unchanged 4 + this line should be marked as oldMoved newMoved/newMovedAlternate + EOF + cat >new.txt <<-\EOF && + too short + unchanged + unchanged + this line should be marked as moved + too short + unchanged + unchanged + this line should be marked as oldMoved newMoved/newMovedAlternate + unchanged 1 + unchanged 2 + this line should be marked as oldMovedAlternate newMoved + this line should be marked as oldMoved newMoved/newMovedAlternate + unchanged 3 + this line should be marked as oldMoved newMoved + unchanged 4 + EOF + test_expect_code 1 git diff --no-index --color --color-moved=zebra \ + old.txt new.txt >output && cat output && + grep -v index output | test_decode_color >actual && + cat >expect <<-\EOF && + <BOLD>diff --git a/old.txt b/new.txt<RESET> + <BOLD>--- a/old.txt<RESET> + <BOLD>+++ b/new.txt<RESET> + <CYAN>@@ -1,13 +1,15 @@<RESET> + <BOLD;MAGENTA>-this line should be marked as moved<RESET> + <GREEN>+<RESET><GREEN>too short<RESET> + unchanged<RESET> + unchanged<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>this line should be marked as moved<RESET> + <GREEN>+<RESET><GREEN>too short<RESET> + unchanged<RESET> + unchanged<RESET> + <RED>-too short<RESET> + <BOLD;MAGENTA>-this line should be marked as oldMoved newMoved<RESET> + <BOLD;BLUE>-this line should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>this line should be marked as oldMoved newMoved/newMovedAlternate<RESET> + unchanged 1<RESET> + unchanged 2<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>this line should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;YELLOW>+<RESET><BOLD;YELLOW>this line should be marked as oldMoved newMoved/newMovedAlternate<RESET> + unchanged 3<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>this line should be marked as oldMoved newMoved<RESET> + unchanged 4<RESET> + <BOLD;MAGENTA>-this line should be marked as oldMoved newMoved/newMovedAlternate<RESET> + EOF + test_cmp expect actual +' + test_expect_success 'cmd option assumes configured colored-moved' ' test_config color.diff.oldMoved "magenta" && test_config color.diff.newMoved "cyan" && @@ -1833,6 +1970,52 @@ test_expect_success '--color-moved treats adjacent blocks as separate for MIN_AL test_cmp expected actual ' +test_expect_success '--color-moved rewinds for MIN_ALNUM_COUNT' ' + git reset --hard && + test_write_lines >file \ + A B C one two three four five six seven D E F G H I J && + git add file && + test_write_lines >file \ + one two A B C D E F G H I J two three four five six seven && + git diff --color-moved=zebra -- file && + + git diff --color-moved=zebra --color -- file >actual.raw && + grep -v "index" actual.raw | test_decode_color >actual && + cat >expected <<-\EOF && + <BOLD>diff --git a/file b/file<RESET> + <BOLD>--- a/file<RESET> + <BOLD>+++ b/file<RESET> + <CYAN>@@ -1,13 +1,8 @@<RESET> + <GREEN>+<RESET><GREEN>one<RESET> + <GREEN>+<RESET><GREEN>two<RESET> + A<RESET> + B<RESET> + C<RESET> + <RED>-one<RESET> + <BOLD;MAGENTA>-two<RESET> + <BOLD;MAGENTA>-three<RESET> + <BOLD;MAGENTA>-four<RESET> + <BOLD;MAGENTA>-five<RESET> + <BOLD;MAGENTA>-six<RESET> + <BOLD;MAGENTA>-seven<RESET> + D<RESET> + E<RESET> + F<RESET> + <CYAN>@@ -15,3 +10,9 @@<RESET> <RESET>G<RESET> + H<RESET> + I<RESET> + J<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>two<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>three<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>four<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>five<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>six<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>seven<RESET> + EOF + + test_cmp expected actual +' + test_expect_success 'move detection with submodules' ' test_create_repo bananas && echo ripe >bananas/recipe && @@ -2023,10 +2206,10 @@ EMPTY='' test_expect_success 'compare mixed whitespace delta across moved blocks' ' git reset --hard && - tr Q_ "\t " <<-EOF >text.txt && - ${EMPTY} - ____too short without - ${EMPTY} + tr "^|Q_" "\f\v\t " <<-EOF >text.txt && + ^__ + |____too short without + ^ ___being grouped across blank line ${EMPTY} context @@ -2045,7 +2228,7 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' ' git add text.txt && git commit -m "add text.txt" && - tr Q_ "\t " <<-EOF >text.txt && + tr "^|Q_" "\f\v\t " <<-EOF >text.txt && context lines to @@ -2056,7 +2239,7 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' ' ${EMPTY} QQtoo short without ${EMPTY} - Q_______being grouped across blank line + ^Q_______being grouped across blank line ${EMPTY} Q_QThese two lines have had their indentation reduced by four spaces @@ -2068,16 +2251,16 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' ' -c core.whitespace=space-before-tab \ diff --color --color-moved --ws-error-highlight=all \ --color-moved-ws=allow-indentation-change >actual.raw && - grep -v "index" actual.raw | test_decode_color >actual && + grep -v "index" actual.raw | tr "\f\v" "^|" | test_decode_color >actual && cat <<-\EOF >expected && <BOLD>diff --git a/text.txt b/text.txt<RESET> <BOLD>--- a/text.txt<RESET> <BOLD>+++ b/text.txt<RESET> <CYAN>@@ -1,16 +1,16 @@<RESET> - <BOLD;MAGENTA>-<RESET> - <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA> too short without<RESET> - <BOLD;MAGENTA>-<RESET> + <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA>^<RESET><BRED> <RESET> + <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA>| too short without<RESET> + <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA>^<RESET> <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA> being grouped across blank line<RESET> <BOLD;MAGENTA>-<RESET> <RESET>context<RESET> @@ -2097,7 +2280,7 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' ' <BOLD;YELLOW>+<RESET> <BOLD;YELLOW>+<RESET> <BOLD;YELLOW>too short without<RESET> <BOLD;YELLOW>+<RESET> - <BOLD;YELLOW>+<RESET> <BOLD;YELLOW> being grouped across blank line<RESET> + <BOLD;YELLOW>+<RESET><BOLD;YELLOW>^ being grouped across blank line<RESET> <BOLD;YELLOW>+<RESET> <BOLD;CYAN>+<RESET> <BRED> <RESET> <BOLD;CYAN>These two lines have had their<RESET> <BOLD;CYAN>+<RESET><BOLD;CYAN>indentation reduced by four spaces<RESET> |