summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2021-05-13 23:26:06 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-05-13 23:26:06 (GMT)
commit65c18913deeba4c5f0ca9488b1d8b6757ffc56e1 (patch)
tree96d55f99777aa2bc3446587a0a67d2583f5c88c5 /diff.c
parentdf6c4f722c94641d5a9ea5496511f7043433abc2 (diff)
parent0324e8fc6b297c9e61745dc4e7d110780334157d (diff)
downloadgit-65c18913deeba4c5f0ca9488b1d8b6757ffc56e1.zip
git-65c18913deeba4c5f0ca9488b1d8b6757ffc56e1.tar.gz
git-65c18913deeba4c5f0ca9488b1d8b6757ffc56e1.tar.bz2
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
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/diff.c b/diff.c
index 7c730fe..52c7915 100644
--- a/diff.c
+++ b/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,
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 */