Skip to content

Commit 52e011c

Browse files
avargitster
authored andcommitted
pickaxe -S: support content with NULs under --pickaxe-regex
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2e197a7 commit 52e011c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

diffcore-pickaxe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ static unsigned int contains(mmfile_t *mf, regex_t *regexp, kwset_t kws)
7878
regmatch_t regmatch;
7979
int flags = 0;
8080

81-
while (sz && *data &&
81+
while (sz &&
8282
!regexec_buf(regexp, data, sz, 1, &regmatch, flags)) {
8383
flags |= REG_NOTBOL;
8484
data += regmatch.rm_eo;
8585
sz -= regmatch.rm_eo;
86-
if (sz && *data && regmatch.rm_so == regmatch.rm_eo) {
86+
if (sz && regmatch.rm_so == regmatch.rm_eo) {
8787
data++;
8888
sz--;
8989
}

t/t4209-log-pickaxe.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,12 @@ test_expect_success 'log -S looks into binary files' '
215215
test_cmp log full-log
216216
'
217217

218+
test_expect_success 'log -S --pickaxe-regex looks into binary files' '
219+
git -C GS-bin-txt log --pickaxe-regex -Sa >log &&
220+
test_cmp log full-log &&
221+
222+
git -C GS-bin-txt log --pickaxe-regex -S"[a]" >log &&
223+
test_cmp log full-log
224+
'
225+
218226
test_done

0 commit comments

Comments
 (0)