Skip to content

Commit 8fa4b09

Browse files
committed
pickaxe: hoist empty needle check
If we are given an empty pickaxe needle like "git log -S ''", it is impossible for us to find anything (because no matter what the content, the count will always be 0). We currently check this at the lowest level of contains(). Let's hoist the logic much earlier to has_changes(), so that it is simpler to return our answer before loading any blob data. Signed-off-by: Jeff King <[email protected]>
1 parent b1c2f57 commit 8fa4b09

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

diffcore-pickaxe.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ static unsigned int contains(struct diff_filespec *one, struct diff_options *o,
163163
unsigned int cnt;
164164
unsigned long sz;
165165
const char *data;
166-
if (!o->pickaxe[0])
167-
return 0;
168166
if (diff_populate_filespec(one, 0))
169167
return 0;
170168

@@ -206,6 +204,9 @@ static unsigned int contains(struct diff_filespec *one, struct diff_options *o,
206204
static int has_changes(struct diff_filepair *p, struct diff_options *o,
207205
regex_t *regexp, kwset_t kws)
208206
{
207+
if (!o->pickaxe[0])
208+
return 0;
209+
209210
if (!DIFF_FILE_VALID(p->one)) {
210211
if (!DIFF_FILE_VALID(p->two))
211212
return 0; /* ignore unmerged */

0 commit comments

Comments
 (0)