pack-bitmap: avoid use of static `bitmap_writer`

The pack-bitmap machinery uses a structure called 'bitmap_writer' to collect the data necessary to write out .bitmap files. Since its introduction in 7cc8f971085 (pack-objects: implement bitmap writing, 2013-12-21), there has been a single static bitmap_writer structure, which is responsible for all bitmap writing-related operations. In practice, this is OK, since we are only ever writing a single .bitmap file in a single process (e.g., `git multi-pack-index write --bitmap`, `git pack-objects --write-bitmap-index`, `git repack -b`, etc.). However, having a single static variable makes issues like data ownership unclear, when to free variables, what has/hasn't been initialized unclear. Refactor this code to be written in terms of a given bitmap_writer structure instead of relying on a static global. Note that this exposes the structure definition of the bitmap_writer at the pack-bitmap.h level. We could work around this by, e.g., forcing callers to declare their writers as: struct bitmap_writer *writer; bitmap_writer_init(&bitmap_writer); and then declaring `bitmap_writer_init()` as taking in a double-pointer like so: void bitmap_writer_init(struct bitmap_writer **writer); which would avoid us having to expose the definition of the structure itself. This patch takes a different approach, since future patches (like for the ongoing pseudo-merge bitmaps work) will want to modify the innards of this structure (in the previous example, via pseudo-merge.c). Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed May 14, 2024 at 15:56 UTC 07647c92ffabbb639436de8b5634244cbdfd6ef2
4 files changed +159 -123
builtin/pack-objects.c
+13 -6
@@ -1245,6 +1245,7 @@ static void write_pack_file(void)
1245 uint32_t nr_remaining = nr_result;
1246 time_t last_mtime = 0;
1247 struct object_entry **write_order;
1248 + struct bitmap_writer bitmap_writer;
1249
1250 if (progress > pack_to_stdout)
1251 progress_state = start_progress(_("Writing objects"), nr_result);
@@ -1339,8 +1340,9 @@ static void write_pack_file(void)
1340 hash_to_hex(hash));
1341
1342 if (write_bitmap_index) {
1342 - bitmap_writer_set_checksum(hash);
1343 - bitmap_writer_build_type_index(
1343 + bitmap_writer_init(&bitmap_writer);
1344 + bitmap_writer_set_checksum(&bitmap_writer, hash);
1345 + bitmap_writer_build_type_index(&bitmap_writer,
1346 &to_pack, written_list, nr_written);
1347 }
1348
@@ -1358,11 +1360,16 @@ static void write_pack_file(void)
1360 strbuf_addstr(&tmpname, "bitmap");
1361 stop_progress(&progress_state);
1362
1361 - bitmap_writer_show_progress(progress);
1362 - bitmap_writer_select_commits(indexed_commits, indexed_commits_nr, -1);
1363 - if (bitmap_writer_build(&to_pack) < 0)
1363 + bitmap_writer_show_progress(&bitmap_writer,
1364 + progress);
1365 + bitmap_writer_select_commits(&bitmap_writer,
1366 + indexed_commits,
1367 + indexed_commits_nr,
1368 + -1);
1369 + if (bitmap_writer_build(&bitmap_writer, &to_pack) < 0)
1370 die(_("failed to write bitmap index"));
1365 - bitmap_writer_finish(written_list, nr_written,
1371 + bitmap_writer_finish(&bitmap_writer,
1372 + written_list, nr_written,
1373 tmpname.buf, write_bitmap_options);
1374 write_bitmap_index = 0;
1375 strbuf_setlen(&tmpname, tmpname_len);
midx-write.c
+10 -6
@@ -798,6 +798,7 @@ static int write_midx_bitmap(const char *midx_name,
798 {
799 int ret, i;
800 uint16_t options = 0;
801 + struct bitmap_writer writer;
802 struct pack_idx_entry **index;
803 char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name,
804 hash_to_hex(midx_hash));
@@ -819,8 +820,10 @@ static int write_midx_bitmap(const char *midx_name,
820 for (i = 0; i < pdata->nr_objects; i++)
821 index[i] = &pdata->objects[i].idx;
822
822 - bitmap_writer_show_progress(flags & MIDX_PROGRESS);
823 - bitmap_writer_build_type_index(pdata, index, pdata->nr_objects);
823 + bitmap_writer_init(&writer);
824 + bitmap_writer_show_progress(&writer, flags & MIDX_PROGRESS);
825 + bitmap_writer_build_type_index(&writer, pdata, index,
826 + pdata->nr_objects);
827
828 /*
829 * bitmap_writer_finish expects objects in lex order, but pack_order
@@ -838,13 +841,14 @@ static int write_midx_bitmap(const char *midx_name,
841 for (i = 0; i < pdata->nr_objects; i++)
842 index[pack_order[i]] = &pdata->objects[i].idx;
843
841 - bitmap_writer_select_commits(commits, commits_nr, -1);
842 - ret = bitmap_writer_build(pdata);
844 + bitmap_writer_select_commits(&writer, commits, commits_nr, -1);
845 + ret = bitmap_writer_build(&writer, pdata);
846 if (ret < 0)
847 goto cleanup;
848
846 - bitmap_writer_set_checksum(midx_hash);
847 - bitmap_writer_finish(index, pdata->nr_objects, bitmap_name, options);
849 + bitmap_writer_set_checksum(&writer, midx_hash);
850 + bitmap_writer_finish(&writer, index, pdata->nr_objects, bitmap_name,
851 + options);
852
853 cleanup:
854 free(index);
pack-bitmap-write.c
+105 -104
@@ -27,43 +27,30 @@ struct bitmapped_commit {
27 uint32_t commit_pos;
28 };
29
30 -struct bitmap_writer {
31 - struct ewah_bitmap *commits;
32 - struct ewah_bitmap *trees;
33 - struct ewah_bitmap *blobs;
34 - struct ewah_bitmap *tags;
35 -
36 - kh_oid_map_t *bitmaps;
37 - struct packing_data *to_pack;
38 -
39 - struct bitmapped_commit *selected;
40 - unsigned int selected_nr, selected_alloc;
41 -
42 - struct progress *progress;
43 - int show_progress;
44 - unsigned char pack_checksum[GIT_MAX_RAWSZ];
45 -};
46 -
47 -static struct bitmap_writer writer;
30 +void bitmap_writer_init(struct bitmap_writer *writer)
31 +{
32 + memset(writer, 0, sizeof(struct bitmap_writer));
33 +}
34
49 -void bitmap_writer_show_progress(int show)
35 +void bitmap_writer_show_progress(struct bitmap_writer *writer, int show)
36 {
51 - writer.show_progress = show;
37 + writer->show_progress = show;
38 }
39
40 /**
41 * Build the initial type index for the packfile or multi-pack-index
42 */
57 -void bitmap_writer_build_type_index(struct packing_data *to_pack,
43 +void bitmap_writer_build_type_index(struct bitmap_writer *writer,
44 + struct packing_data *to_pack,
45 struct pack_idx_entry **index,
46 uint32_t index_nr)
47 {
48 uint32_t i;
49
63 - writer.commits = ewah_new();
64 - writer.trees = ewah_new();
65 - writer.blobs = ewah_new();
66 - writer.tags = ewah_new();
50 + writer->commits = ewah_new();
51 + writer->trees = ewah_new();
52 + writer->blobs = ewah_new();
53 + writer->tags = ewah_new();
54 ALLOC_ARRAY(to_pack->in_pack_pos, to_pack->nr_objects);
55
56 for (i = 0; i < index_nr; ++i) {
@@ -88,19 +75,19 @@ void bitmap_writer_build_type_index(struct packing_data *to_pack,
75
76 switch (real_type) {
77 case OBJ_COMMIT:
91 - ewah_set(writer.commits, i);
78 + ewah_set(writer->commits, i);
79 break;
80
81 case OBJ_TREE:
95 - ewah_set(writer.trees, i);
82 + ewah_set(writer->trees, i);
83 break;
84
85 case OBJ_BLOB:
99 - ewah_set(writer.blobs, i);
86 + ewah_set(writer->blobs, i);
87 break;
88
89 case OBJ_TAG:
103 - ewah_set(writer.tags, i);
90 + ewah_set(writer->tags, i);
91 break;
92
93 default:
@@ -115,23 +102,25 @@ void bitmap_writer_build_type_index(struct packing_data *to_pack,
102 * Compute the actual bitmaps
103 */
104
118 -static inline void push_bitmapped_commit(struct commit *commit)
105 +static inline void push_bitmapped_commit(struct bitmap_writer *writer,
106 + struct commit *commit)
107 {
120 - if (writer.selected_nr >= writer.selected_alloc) {
121 - writer.selected_alloc = (writer.selected_alloc + 32) * 2;
122 - REALLOC_ARRAY(writer.selected, writer.selected_alloc);
108 + if (writer->selected_nr >= writer->selected_alloc) {
109 + writer->selected_alloc = (writer->selected_alloc + 32) * 2;
110 + REALLOC_ARRAY(writer->selected, writer->selected_alloc);
111 }
112
125 - writer.selected[writer.selected_nr].commit = commit;
126 - writer.selected[writer.selected_nr].bitmap = NULL;
127 - writer.selected[writer.selected_nr].flags = 0;
113 + writer->selected[writer->selected_nr].commit = commit;
114 + writer->selected[writer->selected_nr].bitmap = NULL;
115 + writer->selected[writer->selected_nr].flags = 0;
116
129 - writer.selected_nr++;
117 + writer->selected_nr++;
118 }
119
132 -static uint32_t find_object_pos(const struct object_id *oid, int *found)
120 +static uint32_t find_object_pos(struct bitmap_writer *writer,
121 + const struct object_id *oid, int *found)
122 {
134 - struct object_entry *entry = packlist_find(writer.to_pack, oid);
123 + struct object_entry *entry = packlist_find(writer->to_pack, oid);
124
125 if (!entry) {
126 if (found)
@@ -143,17 +132,17 @@ static uint32_t find_object_pos(const struct object_id *oid, int *found)
132
133 if (found)
134 *found = 1;
146 - return oe_in_pack_pos(writer.to_pack, entry);
135 + return oe_in_pack_pos(writer->to_pack, entry);
136 }
137
149 -static void compute_xor_offsets(void)
138 +static void compute_xor_offsets(struct bitmap_writer *writer)
139 {
140 static const int MAX_XOR_OFFSET_SEARCH = 10;
141
142 int i, next = 0;
143
155 - while (next < writer.selected_nr) {
156 - struct bitmapped_commit *stored = &writer.selected[next];
144 + while (next < writer->selected_nr) {
145 + struct bitmapped_commit *stored = &writer->selected[next];
146
147 int best_offset = 0;
148 struct ewah_bitmap *best_bitmap = stored->bitmap;
@@ -166,7 +155,7 @@ static void compute_xor_offsets(void)
155 break;
156
157 test_xor = ewah_pool_new();
169 - ewah_xor(writer.selected[curr].bitmap, stored->bitmap, test_xor);
158 + ewah_xor(writer->selected[curr].bitmap, stored->bitmap, test_xor);
159
160 if (test_xor->buffer_size < best_bitmap->buffer_size) {
161 if (best_bitmap != stored->bitmap)
@@ -348,7 +337,8 @@ static void bitmap_builder_clear(struct bitmap_builder *bb)
337 bb->commits_nr = bb->commits_alloc = 0;
338 }
339
351 -static int fill_bitmap_tree(struct bitmap *bitmap,
340 +static int fill_bitmap_tree(struct bitmap_writer *writer,
341 + struct bitmap *bitmap,
342 struct tree *tree)
343 {
344 int found;
@@ -360,7 +350,7 @@ static int fill_bitmap_tree(struct bitmap *bitmap,
350 * If our bit is already set, then there is nothing to do. Both this
351 * tree and all of its children will be set.
352 */
363 - pos = find_object_pos(&tree->object.oid, &found);
353 + pos = find_object_pos(writer, &tree->object.oid, &found);
354 if (!found)
355 return -1;
356 if (bitmap_get(bitmap, pos))
@@ -375,12 +365,12 @@ static int fill_bitmap_tree(struct bitmap *bitmap,
365 while (tree_entry(&desc, &entry)) {
366 switch (object_type(entry.mode)) {
367 case OBJ_TREE:
378 - if (fill_bitmap_tree(bitmap,
368 + if (fill_bitmap_tree(writer, bitmap,
369 lookup_tree(the_repository, &entry.oid)) < 0)
370 return -1;
371 break;
372 case OBJ_BLOB:
383 - pos = find_object_pos(&entry.oid, &found);
373 + pos = find_object_pos(writer, &entry.oid, &found);
374 if (!found)
375 return -1;
376 bitmap_set(bitmap, pos);
@@ -397,7 +387,8 @@ static int fill_bitmap_tree(struct bitmap *bitmap,
387
388 static int reused_bitmaps_nr;
389
400 -static int fill_bitmap_commit(struct bb_commit *ent,
390 +static int fill_bitmap_commit(struct bitmap_writer *writer,
391 + struct bb_commit *ent,
392 struct commit *commit,
393 struct prio_queue *queue,
394 struct prio_queue *tree_queue,
@@ -436,7 +427,7 @@ static int fill_bitmap_commit(struct bb_commit *ent,
427 * Mark ourselves and queue our tree. The commit
428 * walk ensures we cover all parents.
429 */
439 - pos = find_object_pos(&c->object.oid, &found);
430 + pos = find_object_pos(writer, &c->object.oid, &found);
431 if (!found)
432 return -1;
433 bitmap_set(ent->bitmap, pos);
@@ -444,7 +435,8 @@ static int fill_bitmap_commit(struct bb_commit *ent,
435 repo_get_commit_tree(the_repository, c));
436
437 for (p = c->parents; p; p = p->next) {
447 - pos = find_object_pos(&p->item->object.oid, &found);
438 + pos = find_object_pos(writer, &p->item->object.oid,
439 + &found);
440 if (!found)
441 return -1;
442 if (!bitmap_get(ent->bitmap, pos)) {
@@ -455,29 +447,31 @@ static int fill_bitmap_commit(struct bb_commit *ent,
447 }
448
449 while (tree_queue->nr) {
458 - if (fill_bitmap_tree(ent->bitmap,
450 + if (fill_bitmap_tree(writer, ent->bitmap,
451 prio_queue_get(tree_queue)) < 0)
452 return -1;
453 }
454 return 0;
455 }
456
465 -static void store_selected(struct bb_commit *ent, struct commit *commit)
457 +static void store_selected(struct bitmap_writer *writer,
458 + struct bb_commit *ent, struct commit *commit)
459 {
467 - struct bitmapped_commit *stored = &writer.selected[ent->idx];
460 + struct bitmapped_commit *stored = &writer->selected[ent->idx];
461 khiter_t hash_pos;
462 int hash_ret;
463
464 stored->bitmap = bitmap_to_ewah(ent->bitmap);
465
473 - hash_pos = kh_put_oid_map(writer.bitmaps, commit->object.oid, &hash_ret);
466 + hash_pos = kh_put_oid_map(writer->bitmaps, commit->object.oid, &hash_ret);
467 if (hash_ret == 0)
468 die("Duplicate entry when writing index: %s",
469 oid_to_hex(&commit->object.oid));
477 - kh_value(writer.bitmaps, hash_pos) = stored;
470 + kh_value(writer->bitmaps, hash_pos) = stored;
471 }
472
480 -int bitmap_writer_build(struct packing_data *to_pack)
473 +int bitmap_writer_build(struct bitmap_writer *writer,
474 + struct packing_data *to_pack)
475 {
476 struct bitmap_builder bb;
477 size_t i;
@@ -488,11 +482,12 @@ int bitmap_writer_build(struct packing_data *to_pack)
482 uint32_t *mapping;
483 int closed = 1; /* until proven otherwise */
484
491 - writer.bitmaps = kh_init_oid_map();
492 - writer.to_pack = to_pack;
485 + writer->bitmaps = kh_init_oid_map();
486 + writer->to_pack = to_pack;
487
494 - if (writer.show_progress)
495 - writer.progress = start_progress("Building bitmaps", writer.selected_nr);
488 + if (writer->show_progress)
489 + writer->progress = start_progress("Building bitmaps",
490 + writer->selected_nr);
491 trace2_region_enter("pack-bitmap-write", "building_bitmaps_total",
492 the_repository);
493
@@ -502,23 +497,23 @@ int bitmap_writer_build(struct packing_data *to_pack)
497 else
498 mapping = NULL;
499
505 - bitmap_builder_init(&bb, &writer, old_bitmap);
500 + bitmap_builder_init(&bb, writer, old_bitmap);
501 for (i = bb.commits_nr; i > 0; i--) {
502 struct commit *commit = bb.commits[i-1];
503 struct bb_commit *ent = bb_data_at(&bb.data, commit);
504 struct commit *child;
505 int reused = 0;
506
512 - if (fill_bitmap_commit(ent, commit, &queue, &tree_queue,
507 + if (fill_bitmap_commit(writer, ent, commit, &queue, &tree_queue,
508 old_bitmap, mapping) < 0) {
509 closed = 0;
510 break;
511 }
512
513 if (ent->selected) {
519 - store_selected(ent, commit);
514 + store_selected(writer, ent, commit);
515 nr_stored++;
521 - display_progress(writer.progress, nr_stored);
516 + display_progress(writer->progress, nr_stored);
517 }
518
519 while ((child = pop_commit(&ent->reverse_edges))) {
@@ -549,10 +544,10 @@ int bitmap_writer_build(struct packing_data *to_pack)
544 trace2_data_intmax("pack-bitmap-write", the_repository,
545 "building_bitmaps_reused", reused_bitmaps_nr);
546
552 - stop_progress(&writer.progress);
547 + stop_progress(&writer->progress);
548
549 if (closed)
555 - compute_xor_offsets();
550 + compute_xor_offsets(writer);
551 return closed ? 0 : -1;
552 }
553
@@ -590,7 +585,8 @@ static int date_compare(const void *_a, const void *_b)
585 return (long)b->date - (long)a->date;
586 }
587
593 -void bitmap_writer_select_commits(struct commit **indexed_commits,
588 +void bitmap_writer_select_commits(struct bitmap_writer *writer,
589 + struct commit **indexed_commits,
590 unsigned int indexed_commits_nr,
591 int max_bitmaps)
592 {
@@ -600,12 +596,12 @@ void bitmap_writer_select_commits(struct commit **indexed_commits,
596
597 if (indexed_commits_nr < 100) {
598 for (i = 0; i < indexed_commits_nr; ++i)
603 - push_bitmapped_commit(indexed_commits[i]);
599 + push_bitmapped_commit(writer, indexed_commits[i]);
600 return;
601 }
602
607 - if (writer.show_progress)
608 - writer.progress = start_progress("Selecting bitmap commits", 0);
603 + if (writer->show_progress)
604 + writer->progress = start_progress("Selecting bitmap commits", 0);
605
606 for (;;) {
607 struct commit *chosen = NULL;
@@ -615,8 +611,8 @@ void bitmap_writer_select_commits(struct commit **indexed_commits,
611 if (i + next >= indexed_commits_nr)
612 break;
613
618 - if (max_bitmaps > 0 && writer.selected_nr >= max_bitmaps) {
619 - writer.selected_nr = max_bitmaps;
614 + if (max_bitmaps > 0 && writer->selected_nr >= max_bitmaps) {
615 + writer->selected_nr = max_bitmaps;
616 break;
617 }
618
@@ -638,13 +634,13 @@ void bitmap_writer_select_commits(struct commit **indexed_commits,
634 }
635 }
636
641 - push_bitmapped_commit(chosen);
637 + push_bitmapped_commit(writer, chosen);
638
639 i += next + 1;
644 - display_progress(writer.progress, i);
640 + display_progress(writer->progress, i);
641 }
642
647 - stop_progress(&writer.progress);
643 + stop_progress(&writer->progress);
644 }
645
646
@@ -670,12 +666,13 @@ static const struct object_id *oid_access(size_t pos, const void *table)
666 return &index[pos]->oid;
667 }
668
673 -static void write_selected_commits_v1(struct hashfile *f, off_t *offsets)
669 +static void write_selected_commits_v1(struct bitmap_writer *writer,
670 + struct hashfile *f, off_t *offsets)
671 {
672 int i;
673
677 - for (i = 0; i < writer.selected_nr; ++i) {
678 - struct bitmapped_commit *stored = &writer.selected[i];
674 + for (i = 0; i < writer->selected_nr; ++i) {
675 + struct bitmapped_commit *stored = &writer->selected[i];
676
677 if (offsets)
678 offsets[i] = hashfile_total(f);
@@ -688,10 +685,11 @@ static void write_selected_commits_v1(struct hashfile *f, off_t *offsets)
685 }
686 }
687
691 -static int table_cmp(const void *_va, const void *_vb)
688 +static int table_cmp(const void *_va, const void *_vb, void *_data)
689 {
693 - struct bitmapped_commit *a = &writer.selected[*(uint32_t *)_va];
694 - struct bitmapped_commit *b = &writer.selected[*(uint32_t *)_vb];
690 + struct bitmap_writer *writer = _data;
691 + struct bitmapped_commit *a = &writer->selected[*(uint32_t *)_va];
692 + struct bitmapped_commit *b = &writer->selected[*(uint32_t *)_vb];
693
694 if (a->commit_pos < b->commit_pos)
695 return -1;
@@ -701,15 +699,16 @@ static int table_cmp(const void *_va, const void *_vb)
699 return 0;
700 }
701
704 -static void write_lookup_table(struct hashfile *f, off_t *offsets)
702 +static void write_lookup_table(struct bitmap_writer *writer, struct hashfile *f,
703 + off_t *offsets)
704 {
705 uint32_t i;
706 uint32_t *table, *table_inv;
707
709 - ALLOC_ARRAY(table, writer.selected_nr);
710 - ALLOC_ARRAY(table_inv, writer.selected_nr);
708 + ALLOC_ARRAY(table, writer->selected_nr);
709 + ALLOC_ARRAY(table_inv, writer->selected_nr);
710
712 - for (i = 0; i < writer.selected_nr; i++)
711 + for (i = 0; i < writer->selected_nr; i++)
712 table[i] = i;
713
714 /*
@@ -717,17 +716,17 @@ static void write_lookup_table(struct hashfile *f, off_t *offsets)
716 * bitmap corresponds to j'th bitmapped commit (among the selected
717 * commits) in lex order of OIDs.
718 */
720 - QSORT(table, writer.selected_nr, table_cmp);
719 + QSORT_S(table, writer->selected_nr, table_cmp, writer);
720
721 /* table_inv helps us discover that relationship (i'th bitmap
722 * to j'th commit by j = table_inv[i])
723 */
725 - for (i = 0; i < writer.selected_nr; i++)
724 + for (i = 0; i < writer->selected_nr; i++)
725 table_inv[table[i]] = i;
726
727 trace2_region_enter("pack-bitmap-write", "writing_lookup_table", the_repository);
729 - for (i = 0; i < writer.selected_nr; i++) {
730 - struct bitmapped_commit *selected = &writer.selected[table[i]];
728 + for (i = 0; i < writer->selected_nr; i++) {
729 + struct bitmapped_commit *selected = &writer->selected[table[i]];
730 uint32_t xor_offset = selected->xor_offset;
731 uint32_t xor_row;
732
@@ -748,7 +747,7 @@ static void write_lookup_table(struct hashfile *f, off_t *offsets)
747 xor_row = 0xffffffff;
748 }
749
751 - hashwrite_be32(f, writer.selected[table[i]].commit_pos);
750 + hashwrite_be32(f, writer->selected[table[i]].commit_pos);
751 hashwrite_be64(f, (uint64_t)offsets[table[i]]);
752 hashwrite_be32(f, xor_row);
753 }
@@ -770,12 +769,14 @@ static void write_hash_cache(struct hashfile *f,
769 }
770 }
771
773 -void bitmap_writer_set_checksum(const unsigned char *sha1)
772 +void bitmap_writer_set_checksum(struct bitmap_writer *writer,
773 + const unsigned char *sha1)
774 {
775 - hashcpy(writer.pack_checksum, sha1);
775 + hashcpy(writer->pack_checksum, sha1);
776 }
777
778 -void bitmap_writer_finish(struct pack_idx_entry **index,
778 +void bitmap_writer_finish(struct bitmap_writer *writer,
779 + struct pack_idx_entry **index,
780 uint32_t index_nr,
781 const char *filename,
782 uint16_t options)
@@ -796,20 +797,20 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
797 memcpy(header.magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE));
798 header.version = htons(default_version);
799 header.options = htons(flags | options);
799 - header.entry_count = htonl(writer.selected_nr);
800 - hashcpy(header.checksum, writer.pack_checksum);
800 + header.entry_count = htonl(writer->selected_nr);
801 + hashcpy(header.checksum, writer->pack_checksum);
802
803 hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz);
803 - dump_bitmap(f, writer.commits);
804 - dump_bitmap(f, writer.trees);
805 - dump_bitmap(f, writer.blobs);
806 - dump_bitmap(f, writer.tags);
804 + dump_bitmap(f, writer->commits);
805 + dump_bitmap(f, writer->trees);
806 + dump_bitmap(f, writer->blobs);
807 + dump_bitmap(f, writer->tags);
808
809 if (options & BITMAP_OPT_LOOKUP_TABLE)
810 CALLOC_ARRAY(offsets, index_nr);
811
811 - for (i = 0; i < writer.selected_nr; i++) {
812 - struct bitmapped_commit *stored = &writer.selected[i];
812 + for (i = 0; i < writer->selected_nr; i++) {
813 + struct bitmapped_commit *stored = &writer->selected[i];
814 int commit_pos = oid_pos(&stored->commit->object.oid, index,
815 index_nr, oid_access);
816
@@ -818,10 +819,10 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
819 stored->commit_pos = commit_pos;
820 }
821
821 - write_selected_commits_v1(f, offsets);
822 + write_selected_commits_v1(writer, f, offsets);
823
824 if (options & BITMAP_OPT_LOOKUP_TABLE)
824 - write_lookup_table(f, offsets);
825 + write_lookup_table(writer, f, offsets);
826
827 if (options & BITMAP_OPT_HASH_CACHE)
828 write_hash_cache(f, index, index_nr);
pack-bitmap.h
+31 -7
@@ -97,9 +97,29 @@ int bitmap_has_oid_in_uninteresting(struct bitmap_index *, const struct object_i
97
98 off_t get_disk_usage_from_bitmap(struct bitmap_index *, struct rev_info *);
99
100 -void bitmap_writer_show_progress(int show);
101 -void bitmap_writer_set_checksum(const unsigned char *sha1);
102 -void bitmap_writer_build_type_index(struct packing_data *to_pack,
100 +struct bitmap_writer {
101 + struct ewah_bitmap *commits;
102 + struct ewah_bitmap *trees;
103 + struct ewah_bitmap *blobs;
104 + struct ewah_bitmap *tags;
105 +
106 + kh_oid_map_t *bitmaps;
107 + struct packing_data *to_pack;
108 +
109 + struct bitmapped_commit *selected;
110 + unsigned int selected_nr, selected_alloc;
111 +
112 + struct progress *progress;
113 + int show_progress;
114 + unsigned char pack_checksum[GIT_MAX_RAWSZ];
115 +};
116 +
117 +void bitmap_writer_init(struct bitmap_writer *writer);
118 +void bitmap_writer_show_progress(struct bitmap_writer *writer, int show);
119 +void bitmap_writer_set_checksum(struct bitmap_writer *writer,
120 + const unsigned char *sha1);
121 +void bitmap_writer_build_type_index(struct bitmap_writer *writer,
122 + struct packing_data *to_pack,
123 struct pack_idx_entry **index,
124 uint32_t index_nr);
125 uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,
@@ -109,10 +129,14 @@ int rebuild_bitmap(const uint32_t *reposition,
129 struct bitmap *dest);
130 struct ewah_bitmap *bitmap_for_commit(struct bitmap_index *bitmap_git,
131 struct commit *commit);
112 -void bitmap_writer_select_commits(struct commit **indexed_commits,
113 - unsigned int indexed_commits_nr, int max_bitmaps);
114 -int bitmap_writer_build(struct packing_data *to_pack);
115 -void bitmap_writer_finish(struct pack_idx_entry **index,
132 +void bitmap_writer_select_commits(struct bitmap_writer *writer,
133 + struct commit **indexed_commits,
134 + unsigned int indexed_commits_nr,
135 + int max_bitmaps);
136 +int bitmap_writer_build(struct bitmap_writer *writer,
137 + struct packing_data *to_pack);
138 +void bitmap_writer_finish(struct bitmap_writer *writer,
139 + struct pack_idx_entry **index,
140 uint32_t index_nr,
141 const char *filename,
142 uint16_t options);