path: root/diffcore-pickaxe.c
diff options
authorRené Scharfe <>2009-03-16 18:38:42 (GMT)
committerJunio C Hamano <>2009-03-17 22:10:12 (GMT)
commit50fd6997c60f926efe4b3591f6c0a37568d02185 (patch)
treed46e68d31f209931e6ca0acf90a4521cf7ec532b /diffcore-pickaxe.c
parent01d386121758ac72aedd5f268feb763d53fc3cdf (diff)
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 <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'diffcore-pickaxe.c')
1 files changed, 4 insertions, 2 deletions
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 574b3e8..d0ef839 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -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++;