From: Stefan Beller <sbeller@google.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
Stefan Beller <sbeller@google.com>
Subject: [PATCH 6/6] diff.c: detect blocks despite whitespace changes
Date: Tue, 27 Jun 2017 17:56:51 -0700 [thread overview]
Message-ID: <20170628005651.8110-7-sbeller@google.com> (raw)
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 <sbeller@google.com>
---
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 &&
+ <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
+ <BOLD>index 734156d..eb89ead 100644<RESET>
+ <BOLD>--- a/lines.txt<RESET>
+ <BOLD>+++ b/lines.txt<RESET>
+ <CYAN>@@ -1,7 +1,7 @@<RESET>
+ <GREEN>+<RESET> <GREEN>line 5<RESET>
+ <GREEN>+<RESET> <GREEN>line 6<RESET>
+ <GREEN>+<RESET> <GREEN>line 7<RESET>
+ line 1<RESET>
+ line 2<RESET>
+ line 3<RESET>
+ line 4<RESET>
+ <RED>-line 5<RESET>
+ <RED>-line 6<RESET>
+ <RED>-line 7<RESET>
+ EOF
+ test_cmp expected actual &&
+
+ git diff HEAD --no-renames -w --color-moved| test_decode_color >actual &&
+ cat <<-\EOF >expected &&
+ <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
+ <BOLD>index 734156d..eb89ead 100644<RESET>
+ <BOLD>--- a/lines.txt<RESET>
+ <BOLD>+++ b/lines.txt<RESET>
+ <CYAN>@@ -1,7 +1,7 @@<RESET>
+ <CYAN>+<RESET> <CYAN>line 5<RESET>
+ <CYAN>+<RESET> <CYAN>line 6<RESET>
+ <CYAN>+<RESET> <CYAN>line 7<RESET>
+ line 1<RESET>
+ line 2<RESET>
+ line 3<RESET>
+ line 4<RESET>
+ <MAGENTA>-line 5<RESET>
+ <MAGENTA>-line 6<RESET>
+ <MAGENTA>-line 7<RESET>
+ 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
next prev parent reply other threads:[~2017-06-28 0:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-28 0:56 [PATCH 0/6] Fixing up sb/diff-color-moved Stefan Beller
2017-06-28 0:56 ` [PATCH 1/6] diff.c: factor out shrinking of potential moved line blocks Stefan Beller
2017-06-28 0:56 ` [PATCH 2/6] diff.c: change the default for move coloring to zebra Stefan Beller
2017-06-28 3:14 ` Junio C Hamano
2017-06-28 19:54 ` Stefan Beller
2017-06-28 0:56 ` [PATCH 3/6] diff.c: better reporting on color.moved bogus configuration Stefan Beller
2017-06-28 0:56 ` [PATCH 4/6] Documentation/diff: reword color moved Stefan Beller
2017-06-28 3:25 ` Junio C Hamano
2017-06-28 0:56 ` [PATCH 5/6] diff.c: omit uninteresting moved lines Stefan Beller
2017-06-28 3:31 ` Junio C Hamano
2017-06-28 20:00 ` Stefan Beller
2017-06-28 0:56 ` Stefan Beller [this message]
2017-06-28 3:41 ` [PATCH 6/6] diff.c: detect blocks despite whitespace changes Junio C Hamano
2017-06-28 5:06 ` Junio C Hamano
2017-06-28 20:36 ` Stefan Beller
2017-06-28 21:16 ` Junio C Hamano
2017-06-29 21:01 ` Stefan Beller
2017-06-29 23:51 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170628005651.8110-7-sbeller@google.com \
--to=sbeller@google.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).