pickaxe: hoist empty needle check
[gitweb.git] / diffcore-pickaxe.c
index ed23eb4bdda3b595ac956ba65557b1dc7d50426d..61f628c28579a0350065ae0b7725624625e03ba5 100644 (file)
@@ -104,10 +104,10 @@ static int diff_grep(struct diff_filepair *p, struct diff_options *o,
                if (!mf2.ptr)
                        return 0; /* ignore unmerged */
                /* created "two" -- does it have what we are looking for? */
-               hit = !regexec(regexp, p->two->data, 1, &regmatch, 0);
+               hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);
        } else if (!mf2.ptr) {
                /* removed "one" -- did it have what we are looking for? */
-               hit = !regexec(regexp, p->one->data, 1, &regmatch, 0);
+               hit = !regexec(regexp, mf1.ptr, 1, &regmatch, 0);
        } else {
                /*
                 * We have both sides; need to run textual diff and see if
@@ -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 */