Skip to content

Commit 06af3bb

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b5c0cbd commit 06af3bb

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

builtin/pack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,8 @@ static void write_pack_file(void)
879879

880880
if (write_bitmap_index) {
881881
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);
883884
}
884885

885886
finish_tmp_packfile(&tmpname, pack_tmp_name,

pack-bitmap-write.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ void bitmap_writer_show_progress(int show)
4848
/**
4949
* Build the initial type index for the packfile
5050
*/
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,
5253
uint32_t index_nr)
5354
{
5455
uint32_t i;
@@ -57,12 +58,13 @@ void bitmap_writer_build_type_index(struct pack_idx_entry **index,
5758
writer.trees = ewah_new();
5859
writer.blobs = ewah_new();
5960
writer.tags = ewah_new();
61+
ALLOC_ARRAY(to_pack->in_pack_pos, to_pack->nr_objects);
6062

6163
for (i = 0; i < index_nr; ++i) {
6264
struct object_entry *entry = (struct object_entry *)index[i];
6365
enum object_type real_type;
6466

65-
entry->in_pack_pos = i;
67+
oe_set_in_pack_pos(to_pack, entry, i);
6668

6769
switch (oe_type(entry)) {
6870
case OBJ_COMMIT:
@@ -146,7 +148,7 @@ static uint32_t find_object_pos(const unsigned char *sha1)
146148
"(object %s is missing)", sha1_to_hex(sha1));
147149
}
148150

149-
return entry->in_pack_pos;
151+
return oe_in_pack_pos(writer.to_pack, entry);
150152
}
151153

152154
static void show_object(struct object *object, const char *name, void *data)

pack-bitmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ int rebuild_existing_bitmaps(struct packing_data *mapping,
10331033
oe = packlist_find(mapping, sha1, NULL);
10341034

10351035
if (oe)
1036-
reposition[i] = oe->in_pack_pos + 1;
1036+
reposition[i] = oe_in_pack_pos(mapping, oe) + 1;
10371037
}
10381038

10391039
rebuild = bitmap_new();

pack-bitmap.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ int rebuild_existing_bitmaps(struct packing_data *mapping, khash_sha1 *reused_bi
4444

4545
void bitmap_writer_show_progress(int show);
4646
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);
4850
void bitmap_writer_reuse_bitmaps(struct packing_data *to_pack);
4951
void bitmap_writer_select_commits(struct commit **indexed_commits,
5052
unsigned int indexed_commits_nr, int max_bitmaps);

pack-objects.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ struct object_entry {
7979
unsigned in_pack_type:TYPE_BITS; /* could be delta */
8080
unsigned type_valid:1;
8181
uint32_t hash; /* name hint hash */
82-
unsigned int in_pack_pos;
8382
unsigned char in_pack_header_size;
8483
unsigned preferred_base:1; /*
8584
* we do not pack this, but is available
@@ -99,6 +98,8 @@ struct packing_data {
9998

10099
int32_t *index;
101100
uint32_t index_size;
101+
102+
unsigned int *in_pack_pos;
102103
};
103104

104105
struct object_entry *packlist_alloc(struct packing_data *pdata,
@@ -144,4 +145,17 @@ static inline void oe_set_type(struct object_entry *e,
144145
e->type_ = (unsigned)type;
145146
}
146147

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+
147161
#endif

0 commit comments

Comments
 (0)