{"thread":{"id":"42807","subject":"[PATCH 1/2] diff: demonstrate a bug with --patience and --ignore-space-at-eol","startedAt":"2016-07-09T07:24:22Z","lastAt":"2016-07-11T19:01:47Z","messageCount":5,"participants":["Johannes Schindelin","Naja Melan","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"291095","messageId":"db5aa5d1f22a22901eb3dd57132e027f462852c5.1468048754.git.johannes.schindelin@gmx.de","threadId":"42807","inReplyTo":"cover.1468048754.git.johannes.schindelin@gmx.de","subject":"[PATCH 1/2] diff: demonstrate a bug with --patience and --ignore-space-at-eol","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-07-09T07:23:50Z","receivedAt":"2016-07-09T07:24:22Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"When a single character is added to a line, the combination of these\ntwo options results in an empty diff.\n\nThis bug was noticed and reported by Naja Melan.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n t/t4033-diff-patience.sh | 8 ++++++++\n 1 file changed, 8 insertions(+)\n\ndiff --git a/t/t4033-diff-patience.sh b/t/t4033-diff-patience.sh\nindex 3c9932e..5f0d0b1 100755\n--- a/t/t4033-diff-patience.sh\n+++ b/t/t4033-diff-patience.sh\n@@ -5,6 +5,14 @@ test_description='patience diff algorithm'\n . ./test-lib.sh\n . \"$TEST_DIRECTORY\"/lib-diff-alternative.sh\n \n+test_expect_failure '--ignore-space-at-eol with a single appended character' '\n+\tprintf \"a\\nb\\nc\\n\" >pre &&\n+\tprintf \"a\\nbX\\nc\\n\" >post &&\n+\ttest_must_fail git diff --no-index \\\n+\t\t--patience --ignore-space-at-eol pre post >diff &&\n+\tgrep \"^+.*X\" diff\n+'\n+\n test_diff_frobnitz \"patience\"\n \n test_diff_unique \"patience\"\n-- \n2.9.0.278.g1caae67\n\n\n"},{"id":"291096","messageId":"cover.1468048754.git.johannes.schindelin@gmx.de","threadId":"42807","inReplyTo":null,"subject":"[PATCH 0/2] Fix xdiff's --ignore-space-at-eol handling","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-07-09T07:23:43Z","receivedAt":"2016-07-09T07:24:25Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"It turns out that I am not the only Git developer capable of producing\nan off-by-one bug ;-)\n\nThis patch series fixes a bug where we ignored single-character changes\nat the end of the lines when trying to ignore white space at the end of\nthe lines.\n\nI split the changes into two patches because the fix turned out to have\na much broader scope than the test (which demonstrates just a symptom):\nthe bug was not in the patience-specific part of the diff code, after all.\n\n\nJohannes Schindelin (2):\n  diff: demonstrate a bug with --patience and --ignore-space-at-eol\n  diff: fix a double off-by-one with --ignore-space-at-eol\n\n t/t4033-diff-patience.sh | 8 ++++++++\n xdiff/xpatience.c        | 2 +-\n xdiff/xutils.c           | 6 ++++--\n 3 files changed, 13 insertions(+), 3 deletions(-)\n\nPublished-As: https://github.com/dscho/git/releases/tag/patience-v1\n-- \n2.9.0.278.g1caae67\n\nbase-commit: 5c589a73de4394ad125a4effac227b3aec856fa1\n"},{"id":"291097","messageId":"daf43539479acdebe1c5799c38f3be75c2399feb.1468048754.git.johannes.schindelin@gmx.de","threadId":"42807","inReplyTo":"cover.1468048754.git.johannes.schindelin@gmx.de","subject":"[PATCH 2/2] diff: fix a double off-by-one with --ignore-space-at-eol","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-07-09T07:23:55Z","receivedAt":"2016-07-09T07:24:26Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"When comparing two lines, ignoring any whitespace at the end, we first\ntry to match as many bytes as possible and break out of the loop only\nupon mismatch, to let the remainder be handled by the code shared with\nthe other whitespace-ignoring code paths.\n\nWhen comparing the bytes, however, we incremented the counters always,\neven if the bytes did not match. And because we fall through to  the\nspace-at-eol handling at that point, it is as if that mismatch never\nhappened.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n t/t4033-diff-patience.sh | 2 +-\n xdiff/xpatience.c        | 2 +-\n xdiff/xutils.c           | 6 ++++--\n 3 files changed, 6 insertions(+), 4 deletions(-)\n\ndiff --git a/t/t4033-diff-patience.sh b/t/t4033-diff-patience.sh\nindex 5f0d0b1..113304d 100755\n--- a/t/t4033-diff-patience.sh\n+++ b/t/t4033-diff-patience.sh\n@@ -5,7 +5,7 @@ test_description='patience diff algorithm'\n . ./test-lib.sh\n . \"$TEST_DIRECTORY\"/lib-diff-alternative.sh\n \n-test_expect_failure '--ignore-space-at-eol with a single appended character' '\n+test_expect_success '--ignore-space-at-eol with a single appended character' '\n \tprintf \"a\\nb\\nc\\n\" >pre &&\n \tprintf \"a\\nbX\\nc\\n\" >post &&\n \ttest_must_fail git diff --no-index \\\ndiff --git a/xdiff/xpatience.c b/xdiff/xpatience.c\nindex 04e1a1a..a613efc 100644\n--- a/xdiff/xpatience.c\n+++ b/xdiff/xpatience.c\n@@ -1,6 +1,6 @@\n /*\n  *  LibXDiff by Davide Libenzi ( File Differential Library )\n- *  Copyright (C) 2003-2009 Davide Libenzi, Johannes E. Schindelin\n+ *  Copyright (C) 2003-2016 Davide Libenzi, Johannes E. Schindelin\n  *\n  *  This library is free software; you can redistribute it and/or\n  *  modify it under the terms of the GNU Lesser General Public\ndiff --git a/xdiff/xutils.c b/xdiff/xutils.c\nindex 62cb23d..027192a 100644\n--- a/xdiff/xutils.c\n+++ b/xdiff/xutils.c\n@@ -200,8 +200,10 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)\n \t\t\t\treturn 0;\n \t\t}\n \t} else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL) {\n-\t\twhile (i1 < s1 && i2 < s2 && l1[i1++] == l2[i2++])\n-\t\t\t; /* keep going */\n+\t\twhile (i1 < s1 && i2 < s2 && l1[i1] == l2[i2]) {\n+\t\t\ti1++;\n+\t\t\ti2++;\n+\t\t}\n \t}\n \n \t/*\n-- \n2.9.0.278.g1caae67\n"},{"id":"291099","messageId":"a72910ab-a396-00c6-6661-46c17e78fd4e@autistici.org","threadId":"42807","inReplyTo":"daf43539479acdebe1c5799c38f3be75c2399feb.1468048754.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH 2/2] diff: fix a double off-by-one with --ignore-space-at-eol","fromName":"Naja Melan","fromEmail":"najamelan@autistici.org","sentAt":"2016-07-09T07:28:00Z","receivedAt":"2016-07-09T07:30:26Z","isPatch":true,"sender":{"key":"najamelan@autistici.org","avatar":"https://gravatar.com/avatar/36a314e8a57b71b7c21efc189fcc9d4ee7d5ba7d0b328362c052f5bb32d613c5?d=mp&s=160"},"body":"Thanks,\n\nyou sure are efficient in bug fixing...\n\ngood day to you\nNaja Melan\n"},{"id":"291193","messageId":"xmqqeg709eya.fsf@gitster.mtv.corp.google.com","threadId":"42807","inReplyTo":"daf43539479acdebe1c5799c38f3be75c2399feb.1468048754.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH 2/2] diff: fix a double off-by-one with --ignore-space-at-eol","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-07-11T19:01:33Z","receivedAt":"2016-07-11T19:01:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <johannes.schindelin@gmx.de> writes:\n\n> diff --git a/xdiff/xutils.c b/xdiff/xutils.c\n> index 62cb23d..027192a 100644\n> --- a/xdiff/xutils.c\n> +++ b/xdiff/xutils.c\n> @@ -200,8 +200,10 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)\n>  \t\t\t\treturn 0;\n>  \t\t}\n>  \t} else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL) {\n> -\t\twhile (i1 < s1 && i2 < s2 && l1[i1++] == l2[i2++])\n> -\t\t\t; /* keep going */\n> +\t\twhile (i1 < s1 && i2 < s2 && l1[i1] == l2[i2]) {\n> +\t\t\ti1++;\n> +\t\t\ti2++;\n> +\t\t}\n>  \t}\n\nWhen we notice l1[i1] and l2[i2] does not match, we want i1 and i2\nto stay pointing at that unmatch.  The code before this fix however\nends up incrementing them before leaving the loop.\n\nThis breakage seems to come from 2344d47f (diff: fix 2 whitespace\nissues, 2006-10-12)?  That's quite old and it is somewhat surprising\nthat nobody complained.\n\nWell spotted.  Will queue.\n\nThanks.\n\n\n\n"}]}