pack-objects: parameterize pack-reuse routines over a single pack

The routines pack-objects uses to perform verbatim pack-reuse are: - write_reused_pack_one() - write_reused_pack_verbatim() - write_reused_pack() , all of which assume that there is exactly one packfile being reused: the global constant `reuse_packfile`. Prepare for reusing objects from multiple packs by making reuse packfile a parameter of each of the above functions in preparation for calling these functions in a loop with multiple packfiles. Note that we still have the global "reuse_packfile", but pass it through each of the above function's parameter lists, eliminating all but one direct access (the top-level caller in `write_pack_file()`). Even after this series, we will still have a global, but it will hold the array of reusable packfiles, and we'll pass them one at a time to these functions in a loop. Note also that we will eventually need to pass a `bitmapped_pack` instead of a `packed_git` in order to hold onto additional information required for reuse (such as the bit position of the first object belonging to that pack). But that change will be made in a future commit so as to minimize the noise below as much as possible. 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 5e29c3f70749f9f2102185e7450c54a3637fdee0
1 file changed +10 -6
builtin/pack-objects.c
+10 -6
@@ -1013,7 +1013,8 @@ static off_t find_reused_offset(off_t where)
1013 return reused_chunks[lo-1].difference;
1014 }
1015
1016 -static void write_reused_pack_one(size_t pos, struct hashfile *out,
1016 +static void write_reused_pack_one(struct packed_git *reuse_packfile,
1017 + size_t pos, struct hashfile *out,
1018 struct pack_window **w_curs)
1019 {
1020 off_t offset, next, cur;
@@ -1091,7 +1092,8 @@ static void write_reused_pack_one(size_t pos, struct hashfile *out,
1092 copy_pack_data(out, reuse_packfile, w_curs, offset, next - offset);
1093 }
1094
1094 -static size_t write_reused_pack_verbatim(struct hashfile *out,
1095 +static size_t write_reused_pack_verbatim(struct packed_git *reuse_packfile,
1096 + struct hashfile *out,
1097 struct pack_window **w_curs)
1098 {
1099 size_t pos = 0;
@@ -1118,14 +1120,15 @@ static size_t write_reused_pack_verbatim(struct hashfile *out,
1120 return pos;
1121 }
1122
1121 -static void write_reused_pack(struct hashfile *f)
1123 +static void write_reused_pack(struct packed_git *reuse_packfile,
1124 + struct hashfile *f)
1125 {
1126 size_t i = 0;
1127 uint32_t offset;
1128 struct pack_window *w_curs = NULL;
1129
1130 if (allow_ofs_delta)
1128 - i = write_reused_pack_verbatim(f, &w_curs);
1131 + i = write_reused_pack_verbatim(reuse_packfile, f, &w_curs);
1132
1133 for (; i < reuse_packfile_bitmap->word_alloc; ++i) {
1134 eword_t word = reuse_packfile_bitmap->words[i];
@@ -1141,7 +1144,8 @@ static void write_reused_pack(struct hashfile *f)
1144 * bitmaps. See comment in try_partial_reuse()
1145 * for why.
1146 */
1144 - write_reused_pack_one(pos + offset, f, &w_curs);
1147 + write_reused_pack_one(reuse_packfile, pos + offset, f,
1148 + &w_curs);
1149 display_progress(progress_state, ++written);
1150 }
1151 }
@@ -1199,7 +1203,7 @@ static void write_pack_file(void)
1203
1204 if (reuse_packfile) {
1205 assert(pack_to_stdout);
1202 - write_reused_pack(f);
1206 + write_reused_pack(reuse_packfile, f);
1207 offset = hashfile_total(f);
1208 }
1209