Code

call init_pack_revindex() lazily
authorNicolas Pitre <nico@cam.org>
Tue, 24 Jun 2008 01:22:14 +0000 (21:22 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 24 Jun 2008 04:25:20 +0000 (21:25 -0700)
This makes life much easier for next patch, as well as being more efficient
when the revindex is actually not used.

Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-pack-objects.c
pack-check.c
pack-revindex.c
pack-revindex.h

index 447d492dbbfb578b8903293fa1d2a988eecfefac..827673ce4e81e14e13ae4b41ac89c18f6201ddb6 100644 (file)
@@ -1148,8 +1148,6 @@ static void get_object_details(void)
                sorted_by_offset[i] = objects + i;
        qsort(sorted_by_offset, nr_objects, sizeof(*sorted_by_offset), pack_offset_sort);
 
-       init_pack_revindex();
-
        for (i = 0; i < nr_objects; i++)
                check_object(sorted_by_offset[i]);
 
index f4898732dd8cd8ad2d8599cb13e0d9d96dda753b..b99a9171c023ece7db0a387a49bdb75287bcc06f 100644 (file)
@@ -107,7 +107,6 @@ static void show_pack_info(struct packed_git *p)
 
        nr_objects = p->num_objects;
        memset(chain_histogram, 0, sizeof(chain_histogram));
-       init_pack_revindex();
 
        for (i = 0; i < nr_objects; i++) {
                const unsigned char *sha1;
index a8aa2cd6caefe7d37febdf5c3426cec043492b19..cd300bdff5b524a4d509ba5276e9ef21f443013d 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)
index c3527a75655470b95ab4ba0900e9c1ad6a15a35f..36a514a6cf600e7e77794e50998a9d160e30c8e9 100644 (file)
@@ -6,7 +6,6 @@ struct revindex_entry {
        unsigned int nr;
 };
 
-void init_pack_revindex(void);
 struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs);
 
 #endif