pack-objects: pass `bitmapped_pack`'s to pack-reuse functions

Further prepare pack-objects to perform verbatim pack-reuse over multiple packfiles by converting functions that take in a pointer to a `struct packed_git` to instead take in a pointer to a `struct bitmapped_pack`. The additional information found in the bitmapped_pack struct (such as the bit position corresponding to the beginning of the pack) will be necessary in order to perform verbatim pack-reuse. Note that we don't use any of the extra pieces of information contained in the bitmapped_pack struct, so this step is merely preparatory and does not introduce any functional changes. Note further that we do not change the argument type to write_reused_pack_one(). That function is responsible for copying sections of the packfile directly and optionally patching any OFS_DELTAs to account for not reusing sections of the packfile in between a delta and its base. As such, that function is (and should remain) oblivious to multi-pack reuse, and does not require any of the extra pieces of information stored in the bitmapped_pack struct. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Dec 14, 2023 at 17:24 UTC 073b40eba0064ad3bd9bfad89a050208bc033890
1 file changed +17 -16
builtin/pack-objects.c
+17 -16
@@ -221,7 +221,8 @@ static int thin;
221 static int num_preferred_base;
222 static struct progress *progress_state;
223
224 -static struct packed_git *reuse_packfile;
224 +static struct bitmapped_pack *reuse_packfiles;
225 +static size_t reuse_packfiles_nr;
226 static uint32_t reuse_packfile_objects;
227 static struct bitmap *reuse_packfile_bitmap;
228
@@ -1094,7 +1095,7 @@ static void write_reused_pack_one(struct packed_git *reuse_packfile,
1095 copy_pack_data(out, reuse_packfile, w_curs, offset, next - offset);
1096 }
1097
1097 -static size_t write_reused_pack_verbatim(struct packed_git *reuse_packfile,
1098 +static size_t write_reused_pack_verbatim(struct bitmapped_pack *reuse_packfile,
1099 struct hashfile *out,
1100 off_t pack_start UNUSED,
1101 struct pack_window **w_curs)
@@ -1109,13 +1110,13 @@ static size_t write_reused_pack_verbatim(struct packed_git *reuse_packfile,
1110 off_t to_write;
1111
1112 written = (pos * BITS_IN_EWORD);
1112 - to_write = pack_pos_to_offset(reuse_packfile, written)
1113 + to_write = pack_pos_to_offset(reuse_packfile->p, written)
1114 - sizeof(struct pack_header);
1115
1116 /* We're recording one chunk, not one object. */
1117 record_reused_object(sizeof(struct pack_header), 0);
1118 hashflush(out);
1118 - copy_pack_data(out, reuse_packfile, w_curs,
1119 + copy_pack_data(out, reuse_packfile->p, w_curs,
1120 sizeof(struct pack_header), to_write);
1121
1122 display_progress(progress_state, written);
@@ -1123,7 +1124,7 @@ static size_t write_reused_pack_verbatim(struct packed_git *reuse_packfile,
1124 return pos;
1125 }
1126
1126 -static void write_reused_pack(struct packed_git *reuse_packfile,
1127 +static void write_reused_pack(struct bitmapped_pack *reuse_packfile,
1128 struct hashfile *f)
1129 {
1130 size_t i = 0;
@@ -1149,8 +1150,8 @@ static void write_reused_pack(struct packed_git *reuse_packfile,
1150 * bitmaps. See comment in try_partial_reuse()
1151 * for why.
1152 */
1152 - write_reused_pack_one(reuse_packfile, pos + offset, f,
1153 - pack_start, &w_curs);
1153 + write_reused_pack_one(reuse_packfile->p, pos + offset,
1154 + f, pack_start, &w_curs);
1155 display_progress(progress_state, ++written);
1156 }
1157 }
@@ -1206,9 +1207,12 @@ static void write_pack_file(void)
1207
1208 offset = write_pack_header(f, nr_remaining);
1209
1209 - if (reuse_packfile) {
1210 + if (reuse_packfiles_nr) {
1211 assert(pack_to_stdout);
1211 - write_reused_pack(reuse_packfile, f);
1212 + for (j = 0; j < reuse_packfiles_nr; j++) {
1213 + reused_chunks_nr = 0;
1214 + write_reused_pack(&reuse_packfiles[j], f);
1215 + }
1216 offset = hashfile_total(f);
1217 }
1218
@@ -3949,19 +3953,16 @@ static int pack_options_allow_reuse(void)
3953
3954 static int get_object_list_from_bitmap(struct rev_info *revs)
3955 {
3952 - struct bitmapped_pack *packs = NULL;
3953 - size_t packs_nr = 0;
3954 -
3956 if (!(bitmap_git = prepare_bitmap_walk(revs, 0)))
3957 return -1;
3958
3959 if (pack_options_allow_reuse())
3959 - reuse_partial_packfile_from_bitmap(bitmap_git, &packs,
3960 - &packs_nr,
3960 + reuse_partial_packfile_from_bitmap(bitmap_git,
3961 + &reuse_packfiles,
3962 + &reuse_packfiles_nr,
3963 &reuse_packfile_bitmap);
3964
3963 - if (packs) {
3964 - reuse_packfile = packs[0].p;
3965 + if (reuse_packfiles) {
3966 reuse_packfile_objects = bitmap_popcount(reuse_packfile_bitmap);
3967 if (!reuse_packfile_objects)
3968 BUG("expected non-empty reuse bitmap");