{"thread":{"id":"18327","subject":"[PATCH] pickaxe: count regex matches only once","startedAt":"2009-03-16T18:38:42Z","lastAt":"2009-03-16T18:38:42Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"108107","messageId":"49BE9CB2.3090404@lsrfire.ath.cx","threadId":"18327","inReplyTo":null,"subject":"[PATCH] pickaxe: count regex matches only once","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2009-03-16T18:38:42Z","receivedAt":"2009-03-16T18:38:42Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"When --pickaxe-regex is used, forward past the end of matches instead of\nadvancing to the byte after their start.  This way matches count only\nonce, even if the regular expression matches their tail -- like in the\nfixed-string fork of the code.\n\nE.g.: /.*/ used to count the number of bytes instead of the number of\nlines.  /aa/ resulted in a count of two in \"aaa\" instead of one.\n\nAlso document the fact that regexec() needs a NUL-terminated string as\nits second argument by adding an assert().\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n diffcore-pickaxe.c |    6 ++++--\n 1 files changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c\nindex 574b3e8..d0ef839 100644\n--- a/diffcore-pickaxe.c\n+++ b/diffcore-pickaxe.c\n@@ -25,10 +25,12 @@ static unsigned int contains(struct diff_filespec *one,\n \t\tregmatch_t regmatch;\n \t\tint flags = 0;\n \n+\t\tassert(data[sz] == '\\0');\n \t\twhile (*data && !regexec(regexp, data, 1, &regmatch, flags)) {\n \t\t\tflags |= REG_NOTBOL;\n-\t\t\tdata += regmatch.rm_so;\n-\t\t\tif (*data) data++;\n+\t\t\tdata += regmatch.rm_eo;\n+\t\t\tif (*data && regmatch.rm_so == regmatch.rm_eo)\n+\t\t\t\tdata++;\n \t\t\tcnt++;\n \t\t}\n \n-- \n1.6.2.1\n"}]}