Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>2022-08-14 19:55:07 +0300
committerJunio C Hamano <gitster@pobox.com>2022-08-26 20:13:47 +0300
commitaa30162559ab6c5be0181853cbc07d777675d82a (patch)
tree5fcacc2840ac7ba31b8ef47d64e2798183eb9de8 /pack-bitmap-write.c
parente9977b12fdd64a9c5d7d0aff10709e043181ca7b (diff)
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 <chakrabortyabhradeep79@gmail.com> Reviewed-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pack-bitmap-write.c')
-rw-r--r--pack-bitmap-write.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 4fcfaed428..9b1be59f6d 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -650,20 +650,15 @@ static const struct object_id *oid_access(size_t pos, const void *table)
static void write_selected_commits_v1(struct hashfile *f,
struct pack_idx_entry **index,
- uint32_t index_nr)
+ uint32_t index_nr,
+ uint32_t *commit_positions)
{
int i;
for (i = 0; i < writer.selected_nr; ++i) {
struct bitmapped_commit *stored = &writer.selected[i];
- int commit_pos =
- oid_pos(&stored->commit->object.oid, index, index_nr, oid_access);
-
- if (commit_pos < 0)
- BUG("trying to write commit not in index");
-
- hashwrite_be32(f, commit_pos);
+ hashwrite_be32(f, commit_positions[i]);
hashwrite_u8(f, stored->xor_offset);
hashwrite_u8(f, stored->flags);
@@ -697,6 +692,8 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
static uint16_t flags = BITMAP_OPT_FULL_DAG;
struct strbuf tmp_file = STRBUF_INIT;
struct hashfile *f;
+ uint32_t *commit_positions = NULL;
+ uint32_t i;
struct bitmap_disk_header header;
@@ -715,7 +712,20 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
dump_bitmap(f, writer.trees);
dump_bitmap(f, writer.blobs);
dump_bitmap(f, writer.tags);
- write_selected_commits_v1(f, index, index_nr);
+
+ ALLOC_ARRAY(commit_positions, writer.selected_nr);
+
+ for (i = 0; i < writer.selected_nr; i++) {
+ struct bitmapped_commit *stored = &writer.selected[i];
+ int commit_pos = oid_pos(&stored->commit->object.oid, index, index_nr, oid_access);
+
+ if (commit_pos < 0)
+ BUG(_("trying to write commit not in index"));
+
+ commit_positions[i] = commit_pos;
+ }
+
+ write_selected_commits_v1(f, index, index_nr, commit_positions);
if (options & BITMAP_OPT_HASH_CACHE)
write_hash_cache(f, index, index_nr);
@@ -730,4 +740,5 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
die_errno("unable to rename temporary bitmap file to '%s'", filename);
strbuf_release(&tmp_file);
+ free(commit_positions);
}