Skip to content

Commit 7ad3c52

Browse files
René Scharfegitster
authored andcommitted
pickaxe: count regex matches only once
When --pickaxe-regex is used, forward past the end of matches instead of advancing to the byte after their start. This way matches count only once, even if the regular expression matches their tail -- like in the fixed-string fork of the code. E.g.: /.*/ used to count the number of bytes instead of the number of lines. /aa/ resulted in a count of two in "aaa" instead of one. Also document the fact that regexec() needs a NUL-terminated string as its second argument by adding an assert(). Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c0250b6 commit 7ad3c52

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

diffcore-pickaxe.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ static unsigned int contains(struct diff_filespec *one,
2525
regmatch_t regmatch;
2626
int flags = 0;
2727

28+
assert(data[sz] == '\0');
2829
while (*data && !regexec(regexp, data, 1, &regmatch, flags)) {
2930
flags |= REG_NOTBOL;
30-
data += regmatch.rm_so;
31-
if (*data) data++;
31+
data += regmatch.rm_eo;
32+
if (*data && regmatch.rm_so == regmatch.rm_eo)
33+
data++;
3234
cnt++;
3335
}
3436

0 commit comments

Comments
 (0)