Skip to content

Commit 6dc5ef7

Browse files
derrickstoleegitster
authored andcommitted
pack-bitmap-write: fill bitmap with commit history
The current implementation of bitmap_writer_build() creates a reachability bitmap for every walked commit. After computing a bitmap for a commit, those bits are pushed to an in-progress bitmap for its children. fill_bitmap_commit() assumes the bits corresponding to objects reachable from the parents of a commit are already set. This means that when visiting a new commit, we only have to walk the objects reachable between it and any of its parents. A future change to bitmap_writer_build() will relax this condition so not all parents have their bits set. Prepare for that by having 'fill_bitmap_commit()' walk parents until reaching commits whose bits are already set. Then, walk the trees for these commits as well. This has no functional change with the current implementation of bitmap_writer_build(). Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 010e5ea commit 6dc5ef7

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

pack-bitmap-write.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "sha1-lookup.h"
1313
#include "pack-objects.h"
1414
#include "commit-reach.h"
15+
#include "prio-queue.h"
1516

1617
struct bitmapped_commit {
1718
struct commit *commit;
@@ -279,17 +280,30 @@ static void fill_bitmap_tree(struct bitmap *bitmap,
279280
}
280281

281282
static void fill_bitmap_commit(struct bb_commit *ent,
282-
struct commit *commit)
283+
struct commit *commit,
284+
struct prio_queue *queue)
283285
{
284286
if (!ent->bitmap)
285287
ent->bitmap = bitmap_new();
286288

287-
/*
288-
* mark ourselves, but do not bother with parents; their values
289-
* will already have been propagated to us
290-
*/
291289
bitmap_set(ent->bitmap, find_object_pos(&commit->object.oid));
292-
fill_bitmap_tree(ent->bitmap, get_commit_tree(commit));
290+
prio_queue_put(queue, commit);
291+
292+
while (queue->nr) {
293+
struct commit_list *p;
294+
struct commit *c = prio_queue_get(queue);
295+
296+
bitmap_set(ent->bitmap, find_object_pos(&c->object.oid));
297+
fill_bitmap_tree(ent->bitmap, get_commit_tree(c));
298+
299+
for (p = c->parents; p; p = p->next) {
300+
int pos = find_object_pos(&p->item->object.oid);
301+
if (!bitmap_get(ent->bitmap, pos)) {
302+
bitmap_set(ent->bitmap, pos);
303+
prio_queue_put(queue, p->item);
304+
}
305+
}
306+
}
293307
}
294308

295309
static void store_selected(struct bb_commit *ent, struct commit *commit)
@@ -319,6 +333,7 @@ void bitmap_writer_build(struct packing_data *to_pack)
319333
struct bitmap_builder bb;
320334
size_t i;
321335
int nr_stored = 0; /* for progress */
336+
struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
322337

323338
writer.bitmaps = kh_init_oid_map();
324339
writer.to_pack = to_pack;
@@ -335,7 +350,7 @@ void bitmap_writer_build(struct packing_data *to_pack)
335350
struct commit *child;
336351
int reused = 0;
337352

338-
fill_bitmap_commit(ent, commit);
353+
fill_bitmap_commit(ent, commit, &queue);
339354

340355
if (ent->selected) {
341356
store_selected(ent, commit);
@@ -360,6 +375,7 @@ void bitmap_writer_build(struct packing_data *to_pack)
360375
bitmap_free(ent->bitmap);
361376
ent->bitmap = NULL;
362377
}
378+
clear_prio_queue(&queue);
363379
bitmap_builder_clear(&bb);
364380

365381
trace2_region_leave("pack-bitmap-write", "building_bitmaps_total",

0 commit comments

Comments
 (0)