pack-objects: move in_pack_pos out of struct object_entry
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>
Nguyễn Thái Ngọc Duy committed
Apr 14, 2018 at 17:35 UTC
06af3bba414b832fe9e04fb959daa2b9b678d2d5
5 files changed
+26
-7
builtin/pack-objects.c
+2
-1
@@ -879,7 +879,8 @@ static void write_pack_file(void)
879
880
if (write_bitmap_index) {
881
bitmap_writer_set_checksum(oid.hash);
882
- bitmap_writer_build_type_index(written_list, nr_written);
882
+ bitmap_writer_build_type_index(
883
+ &to_pack, written_list, nr_written);
884
}
885
886
finish_tmp_packfile(&tmpname, pack_tmp_name,
pack-bitmap-write.c
+5
-3
@@ -48,7 +48,8 @@ void bitmap_writer_show_progress(int show)
48
/**
49
* Build the initial type index for the packfile
50
*/
51
-void bitmap_writer_build_type_index(struct pack_idx_entry **index,
51
+void bitmap_writer_build_type_index(struct packing_data *to_pack,
52
+ struct pack_idx_entry **index,
53
uint32_t index_nr)
54
{
55
uint32_t i;
@@ -57,12 +58,13 @@ void bitmap_writer_build_type_index(struct pack_idx_entry **index,
58
writer.trees = ewah_new();
59
writer.blobs = ewah_new();
60
writer.tags = ewah_new();
61
+ ALLOC_ARRAY(to_pack->in_pack_pos, to_pack->nr_objects);
62
63
for (i = 0; i < index_nr; ++i) {
64
struct object_entry *entry = (struct object_entry *)index[i];
65
enum object_type real_type;
66
65
- entry->in_pack_pos = i;
67
+ oe_set_in_pack_pos(to_pack, entry, i);
68
69
switch (oe_type(entry)) {
70
case OBJ_COMMIT:
@@ -146,7 +148,7 @@ static uint32_t find_object_pos(const unsigned char *sha1)
148
"(object %s is missing)", sha1_to_hex(sha1));
149
}
150
149
- return entry->in_pack_pos;
151
+ return oe_in_pack_pos(writer.to_pack, entry);
152
}
153
154
static void show_object(struct object *object, const char *name, void *data)
pack-bitmap.c
+1
-1
@@ -1033,7 +1033,7 @@ int rebuild_existing_bitmaps(struct packing_data *mapping,
1033
oe = packlist_find(mapping, sha1, NULL);
1034
1035
if (oe)
1036
- reposition[i] = oe->in_pack_pos + 1;
1036
+ reposition[i] = oe_in_pack_pos(mapping, oe) + 1;
1037
}
1038
1039
rebuild = bitmap_new();
pack-bitmap.h
+3
-1
@@ -44,7 +44,9 @@ int rebuild_existing_bitmaps(struct packing_data *mapping, khash_sha1 *reused_bi
44
45
void bitmap_writer_show_progress(int show);
46
void bitmap_writer_set_checksum(unsigned char *sha1);
47
-void bitmap_writer_build_type_index(struct pack_idx_entry **index, uint32_t index_nr);
47
+void bitmap_writer_build_type_index(struct packing_data *to_pack,
48
+ struct pack_idx_entry **index,
49
+ uint32_t index_nr);
50
void bitmap_writer_reuse_bitmaps(struct packing_data *to_pack);
51
void bitmap_writer_select_commits(struct commit **indexed_commits,
52
unsigned int indexed_commits_nr, int max_bitmaps);
pack-objects.h
+15
-1
@@ -79,7 +79,6 @@ struct object_entry {
79
unsigned in_pack_type:TYPE_BITS; /* could be delta */
80
unsigned type_valid:1;
81
uint32_t hash; /* name hint hash */
82
- unsigned int in_pack_pos;
82
unsigned char in_pack_header_size;
83
unsigned preferred_base:1; /*
84
* we do not pack this, but is available
@@ -99,6 +98,8 @@ struct packing_data {
98
99
int32_t *index;
100
uint32_t index_size;
101
+
102
+ unsigned int *in_pack_pos;
103
};
104
105
struct object_entry *packlist_alloc(struct packing_data *pdata,
@@ -144,4 +145,17 @@ static inline void oe_set_type(struct object_entry *e,
145
e->type_ = (unsigned)type;
146
}
147
148
+static inline unsigned int oe_in_pack_pos(const struct packing_data *pack,
149
+ const struct object_entry *e)
150
+{
151
+ return pack->in_pack_pos[e - pack->objects];
152
+}
153
+
154
+static inline void oe_set_in_pack_pos(const struct packing_data *pack,
155
+ const struct object_entry *e,
156
+ unsigned int pos)
157
+{
158
+ pack->in_pack_pos[e - pack->objects] = pos;
159
+}
160
+
161
#endif