commit: allow associating auxiliary info on-demand
[gitweb.git] / pack-revindex.c
index a8aa2cd6caefe7d37febdf5c3426cec043492b19..77a0465be6f6a79814aa3c009612736770b342a1 100644 (file)
@@ -40,7 +40,7 @@ static int pack_revindex_ix(struct packed_git *p)
        return -1 - i;
 }
 
-void init_pack_revindex(void)
+static void init_pack_revindex(void)
 {
        int num;
        struct packed_git *p;
@@ -118,9 +118,11 @@ struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs)
        struct pack_revindex *rix;
        struct revindex_entry *revindex;
 
+       if (!pack_revindex_hashsz)
+               init_pack_revindex();
        num = pack_revindex_ix(p);
        if (num < 0)
-               die("internal error: pack revindex uninitialized");
+               die("internal error: pack revindex fubar");
 
        rix = &pack_revindex[num];
        if (!rix->revindex)
@@ -138,5 +140,17 @@ struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs)
                else
                        lo = mi + 1;
        } while (lo < hi);
-       die("internal error: pack revindex corrupt");
+       error("bad offset for revindex");
+       return NULL;
+}
+
+void discard_revindex(void)
+{
+       if (pack_revindex_hashsz) {
+               int i;
+               for (i = 0; i < pack_revindex_hashsz; i++)
+                       free(pack_revindex[i].revindex);
+               free(pack_revindex);
+               pack_revindex_hashsz = 0;
+       }
 }