Skip to content

Commit 4722e06

Browse files
ttaylorrgitster
authored andcommitted
pack-bitmap: move some initialization to bitmap_writer_init()
The pack-bitmap-writer machinery uses a oidmap (backed by khash.h) to map from commits selected for bitmaps (by OID) to a bitmapped_commit structure (containing the bitmap itself, among other things like its XOR offset, etc.) This map was initialized at the end of `bitmap_writer_build()`. New entries are added in `pack-bitmap-write.c::store_selected()`, which is called by the bitmap_builder machinery (which is responsible for traversing history and generating the actual bitmaps). Reorganize when this field is initialized and when entries are added to it so that we can quickly determine whether a commit is a candidate for pseudo-merge selection, or not (since it was already selected to receive a bitmap, and thus storing it in a pseudo-merge would be redundant). The changes are as follows: - Introduce a new `bitmap_writer_init()` function which initializes the `writer.bitmaps` field (instead of waiting until the end of `bitmap_writer_build()`). - Add map entries in `push_bitmapped_commit()` (which is called via `bitmap_writer_select_commits()`) with OID keys and NULL values to track whether or not we *expect* to write a bitmap for some given commit. - Validate that a NULL entry is found matching the given key when we store a selected bitmap. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 10a96af commit 4722e06

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

builtin/pack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,8 @@ static void write_pack_file(void)
13401340
hash_to_hex(hash));
13411341

13421342
if (write_bitmap_index) {
1343-
bitmap_writer_init(&bitmap_writer);
1343+
bitmap_writer_init(&bitmap_writer,
1344+
the_repository);
13441345
bitmap_writer_set_checksum(&bitmap_writer, hash);
13451346
bitmap_writer_build_type_index(&bitmap_writer,
13461347
&to_pack, written_list, nr_written);

midx-write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ static int write_midx_bitmap(const char *midx_name,
820820
for (i = 0; i < pdata->nr_objects; i++)
821821
index[i] = &pdata->objects[i].idx;
822822

823-
bitmap_writer_init(&writer);
823+
bitmap_writer_init(&writer, the_repository);
824824
bitmap_writer_show_progress(&writer, flags & MIDX_PROGRESS);
825825
bitmap_writer_build_type_index(&writer, pdata, index,
826826
pdata->nr_objects);

pack-bitmap-write.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ struct bitmapped_commit {
2727
uint32_t commit_pos;
2828
};
2929

30-
void bitmap_writer_init(struct bitmap_writer *writer)
30+
void bitmap_writer_init(struct bitmap_writer *writer, struct repository *r)
3131
{
3232
memset(writer, 0, sizeof(struct bitmap_writer));
33+
if (writer->bitmaps)
34+
BUG("bitmap writer already initialized");
35+
writer->bitmaps = kh_init_oid_map();
3336
}
3437

3538
void bitmap_writer_free(struct bitmap_writer *writer)
@@ -128,11 +131,21 @@ void bitmap_writer_build_type_index(struct bitmap_writer *writer,
128131
static inline void push_bitmapped_commit(struct bitmap_writer *writer,
129132
struct commit *commit)
130133
{
134+
int hash_ret;
135+
khiter_t hash_pos;
136+
131137
if (writer->selected_nr >= writer->selected_alloc) {
132138
writer->selected_alloc = (writer->selected_alloc + 32) * 2;
133139
REALLOC_ARRAY(writer->selected, writer->selected_alloc);
134140
}
135141

142+
hash_pos = kh_put_oid_map(writer->bitmaps, commit->object.oid,
143+
&hash_ret);
144+
if (!hash_ret)
145+
die(_("duplicate entry when writing bitmap index: %s"),
146+
oid_to_hex(&commit->object.oid));
147+
kh_value(writer->bitmaps, hash_pos) = NULL;
148+
136149
writer->selected[writer->selected_nr].commit = commit;
137150
writer->selected[writer->selected_nr].bitmap = NULL;
138151
writer->selected[writer->selected_nr].write_as = NULL;
@@ -483,14 +496,14 @@ static void store_selected(struct bitmap_writer *writer,
483496
{
484497
struct bitmapped_commit *stored = &writer->selected[ent->idx];
485498
khiter_t hash_pos;
486-
int hash_ret;
487499

488500
stored->bitmap = bitmap_to_ewah(ent->bitmap);
489501

490-
hash_pos = kh_put_oid_map(writer->bitmaps, commit->object.oid, &hash_ret);
491-
if (hash_ret == 0)
492-
die("Duplicate entry when writing index: %s",
502+
hash_pos = kh_get_oid_map(writer->bitmaps, commit->object.oid);
503+
if (hash_pos == kh_end(writer->bitmaps))
504+
die(_("attempted to store non-selected commit: '%s'"),
493505
oid_to_hex(&commit->object.oid));
506+
494507
kh_value(writer->bitmaps, hash_pos) = stored;
495508
}
496509

@@ -506,7 +519,6 @@ int bitmap_writer_build(struct bitmap_writer *writer,
506519
uint32_t *mapping;
507520
int closed = 1; /* until proven otherwise */
508521

509-
writer->bitmaps = kh_init_oid_map();
510522
writer->to_pack = to_pack;
511523

512524
if (writer->show_progress)

pack-bitmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ struct bitmap_writer {
114114
unsigned char pack_checksum[GIT_MAX_RAWSZ];
115115
};
116116

117-
void bitmap_writer_init(struct bitmap_writer *writer);
117+
void bitmap_writer_init(struct bitmap_writer *writer, struct repository *r);
118118
void bitmap_writer_show_progress(struct bitmap_writer *writer, int show);
119119
void bitmap_writer_set_checksum(struct bitmap_writer *writer,
120120
const unsigned char *sha1);

0 commit comments

Comments
 (0)