Skip to content

Commit

Permalink
pickaxe -S: support content with NULs under --pickaxe-regex
Browse files Browse the repository at this point in the history
Fix a bug in the matching routine powering -S<rx> --pickaxe-regex so
that we won't abort early on content that has NULs in it.

We've had a hard requirement on REG_STARTEND since 2f89522 (regex:
add regexec_buf() that can work on a non NUL-terminated string,
2016-09-21), but this sanity check dates back to d01d8c6 (Support
for pickaxe matching regular expressions, 2006-03-29).

It wasn't needed anymore, and as the now-passing test shows, actively
getting in our way. Since we always require REG_STARTEND support we do
not need to stop at NULs. If we are dealing with a haystack with NUL
in it. The needle may be behind that NUL.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
avar authored and gitster committed May 11, 2021
1 parent 2e197a7 commit 52e011c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions diffcore-pickaxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ static unsigned int contains(mmfile_t *mf, regex_t *regexp, kwset_t kws)
regmatch_t regmatch;
int flags = 0;

while (sz && *data &&
while (sz &&
!regexec_buf(regexp, data, sz, 1, &regmatch, flags)) {
flags |= REG_NOTBOL;
data += regmatch.rm_eo;
sz -= regmatch.rm_eo;
if (sz && *data && regmatch.rm_so == regmatch.rm_eo) {
if (sz && regmatch.rm_so == regmatch.rm_eo) {
data++;
sz--;
}
Expand Down
8 changes: 8 additions & 0 deletions t/t4209-log-pickaxe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,12 @@ test_expect_success 'log -S looks into binary files' '
test_cmp log full-log
'

test_expect_success 'log -S --pickaxe-regex looks into binary files' '
git -C GS-bin-txt log --pickaxe-regex -Sa >log &&
test_cmp log full-log &&
git -C GS-bin-txt log --pickaxe-regex -S"[a]" >log &&
test_cmp log full-log
'

test_done

0 comments on commit 52e011c

Please sign in to comment.