From: Stefan Beller Date: Wed, 28 Jun 2017 00:56:51 GMT Subject: [PATCH 6/6] diff.c: detect blocks despite whitespace changes Message-ID: <20170628005651.8110-7-sbeller@google.com> In-Reply-To: <20170628005651.8110-1-sbeller@google.com> Reuse the compare function from the hash map instead of calling the compare function directly. Then we pick the correct compare function when told to compare ignoring white space. Signed-off-by: Stefan Beller --- diff.c | 3 +-- t/t4015-diff-whitespace.sh | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/diff.c b/diff.c index 1d93e98e3a..4bcf938e3a 100644 --- a/diff.c +++ b/diff.c @@ -903,8 +903,7 @@ static void mark_color_as_moved(struct diff_options *o, struct moved_entry *p = pmb[i]; struct moved_entry *pnext = (p && p->next_line) ? p->next_line : NULL; - if (pnext && - !emitted_symbol_cmp(pnext->es, l, o)) { + if (pnext && !hm->cmpfn(pnext, match, NULL)) { pmb[i] = p->next_line; } else { pmb[i] = NULL; diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index ae8c686f3c..c3b697411a 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -1317,6 +1317,71 @@ test_expect_success 'no effect from --color-moved with --word-diff' ' test_cmp expect actual ' +test_expect_success 'move detection ignoring whitespace ' ' + git reset --hard && + cat <<\EOF >lines.txt && +line 1 +line 2 +line 3 +line 4 +line 5 +line 6 +line 7 +EOF + git add lines.txt && + git commit -m "add poetry" && + cat <<\EOF >lines.txt && + line 5 + line 6 + line 7 +line 1 +line 2 +line 3 +line 4 +EOF + test_config color.diff.oldMoved "magenta" && + test_config color.diff.newMoved "cyan" && + git diff HEAD --no-renames --color-moved| test_decode_color >actual && + cat <<-\EOF >expected && + diff --git a/lines.txt b/lines.txt + index 734156d..eb89ead 100644 + --- a/lines.txt + +++ b/lines.txt + @@ -1,7 +1,7 @@ + + line 5 + + line 6 + + line 7 + line 1 + line 2 + line 3 + line 4 + -line 5 + -line 6 + -line 7 + EOF + test_cmp expected actual && + + git diff HEAD --no-renames -w --color-moved| test_decode_color >actual && + cat <<-\EOF >expected && + diff --git a/lines.txt b/lines.txt + index 734156d..eb89ead 100644 + --- a/lines.txt + +++ b/lines.txt + @@ -1,7 +1,7 @@ + + line 5 + + line 6 + + line 7 + line 1 + line 2 + line 3 + line 4 + -line 5 + -line 6 + -line 7 + EOF + test_cmp expected actual +' + test_expect_success 'move detection with submodules' ' test_create_repo bananas && echo ripe >bananas/recipe && -- 2.13.0.31.g9b732c453e