Merge branch 'sb/diff-color-move'
authorJunio C Hamano <gitster@pobox.com>
Tue, 17 Oct 2017 04:29:19 +0000 (13:29 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Oct 2017 04:29:19 +0000 (13:29 +0900)
A recently added "--color-moved" feature of "diff" fell into
infinite loop when ignoring whitespace changes, which has been
fixed.

* sb/diff-color-move:
diff: fix infinite loop with --color-moved --ignore-space-change

diff.c
t/t4015-diff-whitespace.sh
diff --git a/diff.c b/diff.c
index 69f03570adf6cf2c3642aea1fb0dba5011ef966f..d76bb937c1e49bc5cd3ecaf9f498a90543def822 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -712,20 +712,22 @@ static int next_byte(const char **cp, const char **endp,
        if (*cp > *endp)
                return -1;
 
-       if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE_CHANGE)) {
-               while (*cp < *endp && isspace(**cp))
-                       (*cp)++;
-               /*
-                * After skipping a couple of whitespaces, we still have to
-                * account for one space.
-                */
-               return (int)' ';
-       }
+       if (isspace(**cp)) {
+               if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE_CHANGE)) {
+                       while (*cp < *endp && isspace(**cp))
+                               (*cp)++;
+                       /*
+                        * After skipping a couple of whitespaces,
+                        * we still have to account for one space.
+                        */
+                       return (int)' ';
+               }
 
-       if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE)) {
-               while (*cp < *endp && isspace(**cp))
-                       (*cp)++;
-               /* return the first non-ws character via the usual below */
+               if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE)) {
+                       while (*cp < *endp && isspace(**cp))
+                               (*cp)++;
+                       /* return the first non-ws character via the usual below */
+               }
        }
 
        retval = (unsigned char)(**cp);
index bd0f75d9f726c10f561937bb28403d4c8cefb25e..87083f728fed1be9d93d971419ac533ee5314d4f 100755 (executable)
@@ -1530,4 +1530,13 @@ test_expect_success 'move detection with submodules' '
        test_cmp expect decoded_actual
 '
 
+test_expect_success 'move detection with whitespace changes' '
+       test_when_finished "git reset --hard" &&
+       test_seq 10 >test &&
+       git add test &&
+       sed s/3/42/ <test >test.tmp &&
+       mv test.tmp test &&
+       git -c diff.colormoved diff --ignore-space-change -- test
+'
+
 test_done