]> granicus.if.org Git - git/commitdiff
pack-objects: move in_pack_pos out of struct object_entry
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 14 Apr 2018 15:35:04 +0000 (17:35 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Apr 2018 03:38:58 +0000 (12:38 +0900)
This field is only need for pack-bitmap, which is an optional
feature. Move it to a separate array that is only allocated when
pack-bitmap is used (like objects[], it is not freed, since we need it
until the end of the process)

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pack-objects.c
pack-bitmap-write.c
pack-bitmap.c
pack-bitmap.h
pack-objects.h

index b231e80f17d4c405846ff8a9721c17625d92bfdc..d9c89e87cd29e39e3d647e450c296307ce4750c9 100644 (file)
@@ -879,7 +879,8 @@ static void write_pack_file(void)
 
                        if (write_bitmap_index) {
                                bitmap_writer_set_checksum(oid.hash);
-                               bitmap_writer_build_type_index(written_list, nr_written);
+                               bitmap_writer_build_type_index(
+                                       &to_pack, written_list, nr_written);
                        }
 
                        finish_tmp_packfile(&tmpname, pack_tmp_name,
index 2df7b3e14493b62c097710261a6d81f2c91ecbab..d707fc9ea2fcf0ad3c23028a0383227bb8daaaa6 100644 (file)
@@ -48,7 +48,8 @@ void bitmap_writer_show_progress(int show)
 /**
  * Build the initial type index for the packfile
  */
-void bitmap_writer_build_type_index(struct pack_idx_entry **index,
+void bitmap_writer_build_type_index(struct packing_data *to_pack,
+                                   struct pack_idx_entry **index,
                                    uint32_t index_nr)
 {
        uint32_t i;
@@ -57,12 +58,13 @@ void bitmap_writer_build_type_index(struct pack_idx_entry **index,
        writer.trees = ewah_new();
        writer.blobs = ewah_new();
        writer.tags = ewah_new();
+       ALLOC_ARRAY(to_pack->in_pack_pos, to_pack->nr_objects);
 
        for (i = 0; i < index_nr; ++i) {
                struct object_entry *entry = (struct object_entry *)index[i];
                enum object_type real_type;
 
-               entry->in_pack_pos = i;
+               oe_set_in_pack_pos(to_pack, entry, i);
 
                switch (oe_type(entry)) {
                case OBJ_COMMIT:
@@ -146,7 +148,7 @@ static uint32_t find_object_pos(const unsigned char *sha1)
                        "(object %s is missing)", sha1_to_hex(sha1));
        }
 
-       return entry->in_pack_pos;
+       return oe_in_pack_pos(writer.to_pack, entry);
 }
 
 static void show_object(struct object *object, const char *name, void *data)
index 3f2dab340f6cc05cde659f97dacbd825d8266bc9..c9e90d1bb530cae500fec403cf716c959c74cbcb 100644 (file)
@@ -1033,7 +1033,7 @@ int rebuild_existing_bitmaps(struct packing_data *mapping,
                oe = packlist_find(mapping, sha1, NULL);
 
                if (oe)
-                       reposition[i] = oe->in_pack_pos + 1;
+                       reposition[i] = oe_in_pack_pos(mapping, oe) + 1;
        }
 
        rebuild = bitmap_new();
index 3742a00e14a0d4da335253b2a76f978edb499d35..5ded2f139a6ccdab725ed5e568b1100906f4b736 100644 (file)
@@ -44,7 +44,9 @@ int rebuild_existing_bitmaps(struct packing_data *mapping, khash_sha1 *reused_bi
 
 void bitmap_writer_show_progress(int show);
 void bitmap_writer_set_checksum(unsigned char *sha1);
-void bitmap_writer_build_type_index(struct pack_idx_entry **index, uint32_t index_nr);
+void bitmap_writer_build_type_index(struct packing_data *to_pack,
+                                   struct pack_idx_entry **index,
+                                   uint32_t index_nr);
 void bitmap_writer_reuse_bitmaps(struct packing_data *to_pack);
 void bitmap_writer_select_commits(struct commit **indexed_commits,
                unsigned int indexed_commits_nr, int max_bitmaps);
index cdce1648de99fbc64b27a2980079ddb725d136dc..71ea992c3cd384b34bf3925d70feed1b59c0c8e7 100644 (file)
@@ -79,7 +79,6 @@ struct object_entry {
        unsigned in_pack_type:TYPE_BITS; /* could be delta */
        unsigned type_valid:1;
        uint32_t hash;                  /* name hint hash */
-       unsigned int in_pack_pos;
        unsigned char in_pack_header_size;
        unsigned preferred_base:1; /*
                                    * we do not pack this, but is available
@@ -99,6 +98,8 @@ struct packing_data {
 
        int32_t *index;
        uint32_t index_size;
+
+       unsigned int *in_pack_pos;
 };
 
 struct object_entry *packlist_alloc(struct packing_data *pdata,
@@ -144,4 +145,17 @@ static inline void oe_set_type(struct object_entry *e,
        e->type_ = (unsigned)type;
 }
 
+static inline unsigned int oe_in_pack_pos(const struct packing_data *pack,
+                                         const struct object_entry *e)
+{
+       return pack->in_pack_pos[e - pack->objects];
+}
+
+static inline void oe_set_in_pack_pos(const struct packing_data *pack,
+                                     const struct object_entry *e,
+                                     unsigned int pos)
+{
+       pack->in_pack_pos[e - pack->objects] = pos;
+}
+
 #endif