summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c0250b6)
raw | patch | inline | side by side (parent: c0250b6)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Mon, 16 Mar 2009 18:38:42 +0000 (19:38 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 22 Mar 2009 06:18:53 +0000 (23:18 -0700) |
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>
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>
diffcore-pickaxe.c | patch | blob | history |
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 574b3e833711fe3794636b86dbf2b9d9deb5e151..d0ef8397008824fb5139680856e3229ecf2c4eb1 100644 (file)
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
regmatch_t regmatch;
int flags = 0;
+ assert(data[sz] == '\0');
while (*data && !regexec(regexp, data, 1, ®match, 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++;
}