diff options
author | Junio C Hamano <gitster@pobox.com> | 2021-05-14 08:26:06 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-05-14 08:26:06 +0900 |
commit | 65c18913deeba4c5f0ca9488b1d8b6757ffc56e1 (patch) | |
tree | 96d55f99777aa2bc3446587a0a67d2583f5c88c5 | |
parent | The sixteenth batch (diff) | |
parent | word diff: handle zero length matches (diff) | |
download | tgif-65c18913deeba4c5f0ca9488b1d8b6757ffc56e1.tar.xz |
Merge branch 'pw/word-diff-zero-width-matches'
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
-rw-r--r-- | diff.c | 10 | ||||
-rwxr-xr-x | t/t4034-diff-words.sh | 5 |
2 files changed, 12 insertions, 3 deletions
@@ -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, int *begin, int *end) { - if (word_regex && *begin < buffer->size) { + while (word_regex && *begin < buffer->size) { regmatch_t match[1]; if (!regexec_buf(word_regex, buffer->ptr + *begin, buffer->size - *begin, 1, match, 0)) { @@ -2061,9 +2061,13 @@ static int find_word_boundaries(mmfile_t *buffer, regex_t *word_regex, '\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; + if (*begin == *end) + (*begin)++; + else + return *begin > *end; + } else { + return -1; } - return -1; } /* find the next word */ diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh index ee7721ab91..561c582d16 100755 --- a/t/t4034-diff-words.sh +++ b/t/t4034-diff-words.sh @@ -184,6 +184,11 @@ test_expect_success 'word diff with a regular expression' ' 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' ' git config diff.testdriver.wordRegex "[^[:space:]]" && cat <<-\EOF >.gitattributes |