Skip to content

Commit

Permalink
pickaxe: count regex matches only once
Browse files Browse the repository at this point in the history
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 <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Mar 22, 2009
1 parent c0250b6 commit 7ad3c52
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions diffcore-pickaxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ static unsigned int contains(struct diff_filespec *one,
regmatch_t regmatch;
int flags = 0;

assert(data[sz] == '\0');
while (*data && !regexec(regexp, data, 1, &regmatch, flags)) {
flags |= REG_NOTBOL;
data += regmatch.rm_so;
if (*data) data++;
data += regmatch.rm_eo;
if (*data && regmatch.rm_so == regmatch.rm_eo)
data++;
cnt++;
}

Expand Down

0 comments on commit 7ad3c52

Please sign in to comment.