Skip to content

Commit 073b40e

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d1d701e commit 073b40e

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

builtin/pack-objects.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ static int thin;
221221
static int num_preferred_base;
222222
static struct progress *progress_state;
223223

224-
static struct packed_git *reuse_packfile;
224+
static struct bitmapped_pack *reuse_packfiles;
225+
static size_t reuse_packfiles_nr;
225226
static uint32_t reuse_packfile_objects;
226227
static struct bitmap *reuse_packfile_bitmap;
227228

@@ -1094,7 +1095,7 @@ static void write_reused_pack_one(struct packed_git *reuse_packfile,
10941095
copy_pack_data(out, reuse_packfile, w_curs, offset, next - offset);
10951096
}
10961097

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,
10981099
struct hashfile *out,
10991100
off_t pack_start UNUSED,
11001101
struct pack_window **w_curs)
@@ -1109,21 +1110,21 @@ static size_t write_reused_pack_verbatim(struct packed_git *reuse_packfile,
11091110
off_t to_write;
11101111

11111112
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)
11131114
- sizeof(struct pack_header);
11141115

11151116
/* We're recording one chunk, not one object. */
11161117
record_reused_object(sizeof(struct pack_header), 0);
11171118
hashflush(out);
1118-
copy_pack_data(out, reuse_packfile, w_curs,
1119+
copy_pack_data(out, reuse_packfile->p, w_curs,
11191120
sizeof(struct pack_header), to_write);
11201121

11211122
display_progress(progress_state, written);
11221123
}
11231124
return pos;
11241125
}
11251126

1126-
static void write_reused_pack(struct packed_git *reuse_packfile,
1127+
static void write_reused_pack(struct bitmapped_pack *reuse_packfile,
11271128
struct hashfile *f)
11281129
{
11291130
size_t i = 0;
@@ -1149,8 +1150,8 @@ static void write_reused_pack(struct packed_git *reuse_packfile,
11491150
* bitmaps. See comment in try_partial_reuse()
11501151
* for why.
11511152
*/
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);
11541155
display_progress(progress_state, ++written);
11551156
}
11561157
}
@@ -1206,9 +1207,12 @@ static void write_pack_file(void)
12061207

12071208
offset = write_pack_header(f, nr_remaining);
12081209

1209-
if (reuse_packfile) {
1210+
if (reuse_packfiles_nr) {
12101211
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+
}
12121216
offset = hashfile_total(f);
12131217
}
12141218

@@ -3949,19 +3953,16 @@ static int pack_options_allow_reuse(void)
39493953

39503954
static int get_object_list_from_bitmap(struct rev_info *revs)
39513955
{
3952-
struct bitmapped_pack *packs = NULL;
3953-
size_t packs_nr = 0;
3954-
39553956
if (!(bitmap_git = prepare_bitmap_walk(revs, 0)))
39563957
return -1;
39573958

39583959
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,
39613963
&reuse_packfile_bitmap);
39623964

3963-
if (packs) {
3964-
reuse_packfile = packs[0].p;
3965+
if (reuse_packfiles) {
39653966
reuse_packfile_objects = bitmap_popcount(reuse_packfile_bitmap);
39663967
if (!reuse_packfile_objects)
39673968
BUG("expected non-empty reuse bitmap");

0 commit comments

Comments
 (0)