Merge branch 'nd/ls-tree-pathspec'
[gitweb.git] / sha1_name.c
index 7098b10e3db0caef02ae2daef8f0624e641aada4..cb88170252a26c37d90f5c03263136439ec60e54 100644 (file)
@@ -372,10 +372,10 @@ const char *find_unique_abbrev(const unsigned char *sha1, int len)
        int status, exists;
        static char hex[41];
 
-       exists = has_sha1_file(sha1);
        memcpy(hex, sha1_to_hex(sha1), 40);
        if (len == 40 || !len)
                return hex;
+       exists = has_sha1_file(sha1);
        while (len < 40) {
                unsigned char sha1_ret[20];
                status = get_short_sha1(hex, len, sha1_ret, GET_SHA1_QUIETLY);
@@ -432,7 +432,8 @@ static inline int upstream_mark(const char *string, int len)
 static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned lookup_flags);
 static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
 
-static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
+static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
+                         unsigned int flags)
 {
        static const char *warn_msg = "refname '%.*s' is ambiguous.";
        static const char *object_name_msg = N_(
@@ -511,7 +512,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
        if (!refs_found)
                return -1;
 
-       if (warn_ambiguous_refs &&
+       if (warn_ambiguous_refs && !(flags & GET_SHA1_QUIETLY) &&
            (refs_found > 1 ||
             !get_short_sha1(str, len, tmp_sha1, GET_SHA1_QUIETLY)))
                warning(warn_msg, len, str);
@@ -545,7 +546,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
                                return -1;
                        }
                }
-               if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
+               if (read_ref_at(real_ref, flags, at_time, nth, sha1, NULL,
                                &co_time, &co_tz, &co_cnt)) {
                        if (!len) {
                                if (starts_with(real_ref, "refs/heads/")) {
@@ -557,11 +558,16 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
                                        len = 4;
                                }
                        }
-                       if (at_time)
-                               warning("Log for '%.*s' only goes "
-                                       "back to %s.", len, str,
-                                       show_date(co_time, co_tz, DATE_RFC2822));
-                       else {
+                       if (at_time) {
+                               if (!(flags & GET_SHA1_QUIETLY)) {
+                                       warning("Log for '%.*s' only goes "
+                                               "back to %s.", len, str,
+                                               show_date(co_time, co_tz, DATE_RFC2822));
+                               }
+                       } else {
+                               if (flags & GET_SHA1_QUIETLY) {
+                                       exit(128);
+                               }
                                die("Log for '%.*s' only has %d entries.",
                                    len, str, co_cnt);
                        }
@@ -801,7 +807,7 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l
        if (!ret)
                return 0;
 
-       ret = get_sha1_basic(name, len, sha1);
+       ret = get_sha1_basic(name, len, sha1, lookup_flags);
        if (!ret)
                return 0;