Skip to content

Commit 91ccfb8

Browse files
committed
Merge branch 'sb/diff-color-move'
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
2 parents d1114d8 + fa5ba2c commit 91ccfb8

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

diff.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -712,20 +712,22 @@ static int next_byte(const char **cp, const char **endp,
712712
if (*cp > *endp)
713713
return -1;
714714

715-
if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE_CHANGE)) {
716-
while (*cp < *endp && isspace(**cp))
717-
(*cp)++;
718-
/*
719-
* After skipping a couple of whitespaces, we still have to
720-
* account for one space.
721-
*/
722-
return (int)' ';
723-
}
715+
if (isspace(**cp)) {
716+
if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE_CHANGE)) {
717+
while (*cp < *endp && isspace(**cp))
718+
(*cp)++;
719+
/*
720+
* After skipping a couple of whitespaces,
721+
* we still have to account for one space.
722+
*/
723+
return (int)' ';
724+
}
724725

725-
if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE)) {
726-
while (*cp < *endp && isspace(**cp))
727-
(*cp)++;
728-
/* return the first non-ws character via the usual below */
726+
if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE)) {
727+
while (*cp < *endp && isspace(**cp))
728+
(*cp)++;
729+
/* return the first non-ws character via the usual below */
730+
}
729731
}
730732

731733
retval = (unsigned char)(**cp);

t/t4015-diff-whitespace.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,4 +1530,13 @@ test_expect_success 'move detection with submodules' '
15301530
test_cmp expect decoded_actual
15311531
'
15321532

1533+
test_expect_success 'move detection with whitespace changes' '
1534+
test_when_finished "git reset --hard" &&
1535+
test_seq 10 >test &&
1536+
git add test &&
1537+
sed s/3/42/ <test >test.tmp &&
1538+
mv test.tmp test &&
1539+
git -c diff.colormoved diff --ignore-space-change -- test
1540+
'
1541+
15331542
test_done

0 commit comments

Comments
 (0)