From: Johannes Schindelin Date: Wed, 14 Jan 2009 19:28:33 GMT Subject: Re: [PATCH take 3 0/4] color-words improvements Message-ID: In-Reply-To: <87d4epk96e.fsf@iki.fi> Hi, On Wed, 14 Jan 2009, Teemu Likonen wrote: > Teemu Likonen (2009-01-14 20:54 +0200) wrote: > > > With --color-diff=a+ it looks like > > Obviously I meant --color-words=a+ Heh, I missed that, even... Thanks for the report! -- snipsnap -- [WILL BE SQUASHED INTO 4/4] Fix find_word_boundaries() Since newlines cannot be part of words, we have to stop at newlines even if the regular expression's match contains one. Of course, I fscked up the range where to look for the newline when I changed the function from find_word_boundary(). --- diff.c | 2 +- t/t4034-diff-words.sh | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletions(-) diff --git a/diff.c b/diff.c index d5d7171..1408717 100644 --- a/diff.c +++ b/diff.c @@ -384,7 +384,7 @@ static int find_word_boundaries(mmfile_t *buffer, regex_t *word_regex, regmatch_t match[1]; if (!regexec(word_regex, buffer->ptr + *begin, 1, match, 0)) { char *p = memchr(buffer->ptr + *begin + match[0].rm_so, - '\n', match[0].rm_eo); + '\n', match[0].rm_eo - match[0].rm_so); *end = p ? p - buffer->ptr : match[0].rm_eo + *begin; *begin += match[0].rm_so; return *begin >= *end; diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh index 0ed7e53..1137131 100755 --- a/t/t4034-diff-words.sh +++ b/t/t4034-diff-words.sh @@ -83,4 +83,24 @@ test_expect_success 'word diff with a regular expression' ' ' +echo 'aaa (aaa)' > pre +echo 'aaa (aaa) aaa' > post + +cat > expect <<\EOF +diff --git a/pre b/post +index c29453b..be22f37 100644 +--- a/pre ++++ b/post +@@ -1 +1 @@ +aaa (aaa) aaa +EOF + +test_expect_success "Teemo's example" ' + + test_must_fail git diff --no-index --color-words='a+' pre post > output && + decrypt_color < output > output.decrypted && + test_cmp expect output.decrypted + +' + test_done -- 1.6.1.295.gb16478