Skip to content

Commit aa30162

Browse files
Abhra303gitster
authored andcommitted
bitmap: move get commit positions code to bitmap_writer_finish
The `write_selected_commits_v1` function takes care of writing commit positions along with their corresponding bitmaps in the disk. It is OK because this `search commit position of a given commit` algorithm is needed only once here. But in later changes of the `lookup table extension series`, we need same commit positions which means we have to run the above mentioned algorithm one more time. Move the `search commit position of a given commit` algorithm to `bitmap_writer_finish()` and use the `commit_positions` array to get commit positions of their corresponding bitmaps. Signed-off-by: Abhradeep Chakraborty <[email protected]> Reviewed-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e9977b1 commit aa30162

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

pack-bitmap-write.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -650,20 +650,15 @@ static const struct object_id *oid_access(size_t pos, const void *table)
650650

651651
static void write_selected_commits_v1(struct hashfile *f,
652652
struct pack_idx_entry **index,
653-
uint32_t index_nr)
653+
uint32_t index_nr,
654+
uint32_t *commit_positions)
654655
{
655656
int i;
656657

657658
for (i = 0; i < writer.selected_nr; ++i) {
658659
struct bitmapped_commit *stored = &writer.selected[i];
659660

660-
int commit_pos =
661-
oid_pos(&stored->commit->object.oid, index, index_nr, oid_access);
662-
663-
if (commit_pos < 0)
664-
BUG("trying to write commit not in index");
665-
666-
hashwrite_be32(f, commit_pos);
661+
hashwrite_be32(f, commit_positions[i]);
667662
hashwrite_u8(f, stored->xor_offset);
668663
hashwrite_u8(f, stored->flags);
669664

@@ -697,6 +692,8 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
697692
static uint16_t flags = BITMAP_OPT_FULL_DAG;
698693
struct strbuf tmp_file = STRBUF_INIT;
699694
struct hashfile *f;
695+
uint32_t *commit_positions = NULL;
696+
uint32_t i;
700697

701698
struct bitmap_disk_header header;
702699

@@ -715,7 +712,20 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
715712
dump_bitmap(f, writer.trees);
716713
dump_bitmap(f, writer.blobs);
717714
dump_bitmap(f, writer.tags);
718-
write_selected_commits_v1(f, index, index_nr);
715+
716+
ALLOC_ARRAY(commit_positions, writer.selected_nr);
717+
718+
for (i = 0; i < writer.selected_nr; i++) {
719+
struct bitmapped_commit *stored = &writer.selected[i];
720+
int commit_pos = oid_pos(&stored->commit->object.oid, index, index_nr, oid_access);
721+
722+
if (commit_pos < 0)
723+
BUG(_("trying to write commit not in index"));
724+
725+
commit_positions[i] = commit_pos;
726+
}
727+
728+
write_selected_commits_v1(f, index, index_nr, commit_positions);
719729

720730
if (options & BITMAP_OPT_HASH_CACHE)
721731
write_hash_cache(f, index, index_nr);
@@ -730,4 +740,5 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
730740
die_errno("unable to rename temporary bitmap file to '%s'", filename);
731741

732742
strbuf_release(&tmp_file);
743+
free(commit_positions);
733744
}

0 commit comments

Comments
 (0)