summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2012-10-28 08:34:06 -0400
committerJeff King <peff@peff.net>2012-10-28 08:48:09 -0400
commit8fa4b09fb14339c5d62e65a88fde8b220cb1591b (patch)
treef59014d98e5109d6e5864ca1590de731ae4b13a2
parentb1c2f57db326c43ec286855b396fb16b4890cf2d (diff)
downloadgit-8fa4b09fb14339c5d62e65a88fde8b220cb1591b.tar.gz
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 <peff@peff.net>
-rw-r--r--diffcore-pickaxe.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index a209376354..61f628c285 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -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;
@@ -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 */