Merge branch 'ph/color-test'
[gitweb.git] / sha1_name.c
index 267ea3f3edc63600bc1591d2115ee85222f3e8c5..2d727d54dc43c23cb2fe19369d58e57e2a020ca9 100644 (file)
@@ -76,8 +76,11 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
 
        prepare_packed_git();
        for (p = packed_git; p && found < 2; p = p->next) {
-               uint32_t num = num_packed_objects(p);
-               uint32_t first = 0, last = num;
+               uint32_t num, last;
+               uint32_t first = 0;
+               open_pack_index(p);
+               num = p->num_objects;
+               last = num;
                while (first < last) {
                        uint32_t mid = (first + last) / 2;
                        const unsigned char *now;
@@ -133,6 +136,7 @@ static int find_unique_short_object(int len, char *canonical,
        int has_unpacked, has_packed;
        unsigned char unpacked_sha1[20], packed_sha1[20];
 
+       prepare_alt_odb();
        has_unpacked = find_short_object_filename(len, canonical, unpacked_sha1);
        has_packed = find_short_packed_object(len, res, packed_sha1);
        if (!has_unpacked && !has_packed)
@@ -366,7 +370,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
                                fprintf(stderr,
                                        "warning: Log for '%.*s' only goes "
                                        "back to %s.\n", len, str,
-                                       show_rfc2822_date(co_time, co_tz));
+                                       show_date(co_time, co_tz, DATE_RFC2822));
                        else
                                fprintf(stderr,
                                        "warning: Log for '%.*s' only has "
@@ -643,12 +647,17 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
  */
 int get_sha1(const char *name, unsigned char *sha1)
 {
-       int ret, bracket_depth;
        unsigned unused;
+       return get_sha1_with_mode(name, sha1, &unused);
+}
+
+int get_sha1_with_mode(const char *name, unsigned char *sha1, unsigned *mode)
+{
+       int ret, bracket_depth;
        int namelen = strlen(name);
        const char *cp;
 
-       prepare_alt_odb();
+       *mode = S_IFINVALID;
        ret = get_sha1_1(name, namelen, sha1);
        if (!ret)
                return ret;
@@ -673,8 +682,6 @@ int get_sha1(const char *name, unsigned char *sha1)
                namelen = namelen - (cp - name);
                if (!active_cache)
                        read_cache();
-               if (active_nr < 0)
-                       return -1;
                pos = cache_name_pos(cp, namelen);
                if (pos < 0)
                        pos = -pos - 1;
@@ -685,6 +692,7 @@ int get_sha1(const char *name, unsigned char *sha1)
                                break;
                        if (ce_stage(ce) == stage) {
                                hashcpy(sha1, ce->sha1);
+                               *mode = ntohl(ce->ce_mode);
                                return 0;
                        }
                        pos++;
@@ -703,7 +711,7 @@ int get_sha1(const char *name, unsigned char *sha1)
                unsigned char tree_sha1[20];
                if (!get_sha1_1(name, cp-name, tree_sha1))
                        return get_tree_entry(tree_sha1, cp+1, sha1,
-                                             &unused);
+                                             mode);
        }
        return ret;
 }