sha1_file: do not access pack if unneeded
[gitweb.git] / sha1_file.c
index b6bc02f093745dc294db0df2f679ba1f97553c5e..bf6b64ec8f5053d6e705fb887ea1969ef4493fe2 100644 (file)
@@ -2977,12 +2977,16 @@ static int sha1_loose_object_info(const unsigned char *sha1,
 
 int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, unsigned flags)
 {
+       static struct object_info blank_oi = OBJECT_INFO_INIT;
        struct pack_entry e;
        int rtype;
        const unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ?
                                    lookup_replace_object(sha1) :
                                    sha1;
 
+       if (!oi)
+               oi = &blank_oi;
+
        if (!(flags & OBJECT_INFO_SKIP_CACHED)) {
                struct cached_object *co = find_cached_object(real);
                if (co) {
@@ -3020,6 +3024,13 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
                }
        }
 
+       if (oi == &blank_oi)
+               /*
+                * We know that the caller doesn't actually need the
+                * information below, so return early.
+                */
+               return 0;
+
        rtype = packed_object_info(e.p, e.offset, oi);
        if (rtype < 0) {
                mark_bad_packed_object(e.p, real);