Code

grep: micro-optimize hit collection for AND nodes
[git.git] / sha1_name.c
index 38c9f1b19e89401b24204b4daac26f327a8f8d8f..2f75179f4c6c1d05bdd7594b23dcf77007c26751 100644 (file)
@@ -268,16 +268,19 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
                char fullref[PATH_MAX];
                unsigned char sha1_from_ref[20];
                unsigned char *this_result;
+               int flag;
 
                this_result = refs_found ? sha1_from_ref : sha1;
                mksnpath(fullref, sizeof(fullref), *p, len, str);
-               r = resolve_ref(fullref, this_result, 1, NULL);
+               r = resolve_ref(fullref, this_result, 1, &flag);
                if (r) {
                        if (!refs_found++)
                                *ref = xstrdup(r);
                        if (!warn_ambiguous_refs)
                                break;
-               }
+               } else if ((flag & REF_ISSYMREF) &&
+                          (len != 4 || strcmp(str, "HEAD")))
+                       warning("ignoring dangling symref %s.", fullref);
        }
        free(last_branch);
        return refs_found;
@@ -334,7 +337,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
 
        /* basic@{time or number or -number} format to query ref-log */
        reflog_len = at = 0;
-       if (str[len-1] == '}') {
+       if (len && str[len-1] == '}') {
                for (at = len-2; at >= 0; at--) {
                        if (str[at] == '@' && str[at+1] == '{') {
                                reflog_len = (len-1) - (at+2);
@@ -723,17 +726,13 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
 
        if (!prefixcmp(message, "checkout: moving from ")) {
                match = message + strlen("checkout: moving from ");
-               if ((target = strstr(match, " to ")) != NULL)
-                       target += 4;
+               target = strstr(match, " to ");
        }
 
        if (!match || !target)
                return 0;
 
-       len = target - match - 4;
-       if (target[len] == '\n' && !strncmp(match, target, len))
-               return 0;
-
+       len = target - match;
        nth = cb->cnt++ % cb->alloc;
        strbuf_reset(&cb->buf[nth]);
        strbuf_add(&cb->buf[nth], match, len);