Skip to content

Commit

Permalink
pickaxe: hoist empty needle check
Browse files Browse the repository at this point in the history
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 <peff@peff.net>
  • Loading branch information
Jeff King committed Oct 28, 2012
1 parent b1c2f57 commit 8fa4b09
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions diffcore-pickaxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ static unsigned int contains(struct diff_filespec *one, struct diff_options *o,
unsigned int cnt;
unsigned long sz;
const char *data;
if (!o->pickaxe[0])
return 0;
if (diff_populate_filespec(one, 0))
return 0;

Expand Down Expand Up @@ -206,6 +204,9 @@ static unsigned int contains(struct diff_filespec *one, struct diff_options *o,
static int has_changes(struct diff_filepair *p, struct diff_options *o,
regex_t *regexp, kwset_t kws)
{
if (!o->pickaxe[0])
return 0;

if (!DIFF_FILE_VALID(p->one)) {
if (!DIFF_FILE_VALID(p->two))
return 0; /* ignore unmerged */
Expand Down

0 comments on commit 8fa4b09

Please sign in to comment.