mirror of
https://github.com/git/git.git
synced 2024-05-21 09:16:10 +02:00
Merge branch 'pw/word-diff-zero-width-matches' into next
The word-diff mode has been taught to work better with a word regexp that can match an empty string. * pw/word-diff-zero-width-matches: word diff: handle zero length matches
This commit is contained in:
commit
e5653da568
10
diff.c
10
diff.c
|
@ -2053,7 +2053,7 @@ static void fn_out_diff_words_aux(void *priv,
|
||||||
static int find_word_boundaries(mmfile_t *buffer, regex_t *word_regex,
|
static int find_word_boundaries(mmfile_t *buffer, regex_t *word_regex,
|
||||||
int *begin, int *end)
|
int *begin, int *end)
|
||||||
{
|
{
|
||||||
if (word_regex && *begin < buffer->size) {
|
while (word_regex && *begin < buffer->size) {
|
||||||
regmatch_t match[1];
|
regmatch_t match[1];
|
||||||
if (!regexec_buf(word_regex, buffer->ptr + *begin,
|
if (!regexec_buf(word_regex, buffer->ptr + *begin,
|
||||||
buffer->size - *begin, 1, match, 0)) {
|
buffer->size - *begin, 1, match, 0)) {
|
||||||
|
@ -2061,10 +2061,14 @@ static int find_word_boundaries(mmfile_t *buffer, regex_t *word_regex,
|
||||||
'\n', match[0].rm_eo - match[0].rm_so);
|
'\n', match[0].rm_eo - match[0].rm_so);
|
||||||
*end = p ? p - buffer->ptr : match[0].rm_eo + *begin;
|
*end = p ? p - buffer->ptr : match[0].rm_eo + *begin;
|
||||||
*begin += match[0].rm_so;
|
*begin += match[0].rm_so;
|
||||||
return *begin >= *end;
|
if (*begin == *end)
|
||||||
}
|
(*begin)++;
|
||||||
|
else
|
||||||
|
return *begin > *end;
|
||||||
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* find the next word */
|
/* find the next word */
|
||||||
while (*begin < buffer->size && isspace(buffer->ptr[*begin]))
|
while (*begin < buffer->size && isspace(buffer->ptr[*begin]))
|
||||||
|
|
|
@ -184,6 +184,11 @@ test_expect_success 'word diff with a regular expression' '
|
||||||
word_diff --color-words="[a-z]+"
|
word_diff --color-words="[a-z]+"
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'word diff with zero length matches' '
|
||||||
|
cp expect.letter-runs-are-words expect &&
|
||||||
|
word_diff --color-words="[a-z${LF}]*"
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'set up a diff driver' '
|
test_expect_success 'set up a diff driver' '
|
||||||
git config diff.testdriver.wordRegex "[^[:space:]]" &&
|
git config diff.testdriver.wordRegex "[^[:space:]]" &&
|
||||||
cat <<-\EOF >.gitattributes
|
cat <<-\EOF >.gitattributes
|
||||||
|
|
Loading…
Reference in New Issue