Skip to content

Commit f177574

Browse files
ttaylorrgitster
authored andcommitted
builtin/repack.c: inline packs within write_midx_included_packs()
To write a MIDX at the end of a repack operation, 'git repack' presently computes the set of packs to write into the MIDX, before invoking `write_midx_included_packs()` with a `string_list` containing those packs. The logic for computing which packs are supposed to appear in the resulting MIDX is within `midx_included_packs()`, where it is aware of details like which cruft pack(s) were written/combined, if/how we did a geometric repack, etc. Computing this list ourselves before providing it to the sole function to make use of that list `write_midx_included_packs()` is somewhat awkward. In the future, repack will learn how to write incremental MIDXs, which will use a very different pack selection routine. Instead of doing something like: struct string_list included_packs = STRING_LIST_INIT_DUP; if (incremental) { midx_incremental_included_packs(&included_packs, ...): write_midx_incremental_included_packs(&included_packs, ...); } else { midx_included_packs(&included_packs, ...): write_midx_included_packs(&included_packs, ...); } in the future, let's have each function that writes a MIDX be responsible for itself computing the list of included packs. Inline the declaration and initialization of `included_packs` into the `write_midx_included_packs()` function itself, and repeat that pattern in the future when we introduce new ways to write MIDXs. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f07263f commit f177574

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

builtin/repack.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ static int repack_config(const char *var, const char *value,
109109

110110
struct repack_write_midx_opts {
111111
struct existing_packs *existing;
112-
struct string_list *include;
113112
struct pack_geometry *geometry;
114113
struct string_list *names;
115114
const char *refs_snapshot;
@@ -330,12 +329,14 @@ static void remove_redundant_bitmaps(struct string_list *include,
330329
static int write_midx_included_packs(struct repack_write_midx_opts *opts)
331330
{
332331
struct child_process cmd = CHILD_PROCESS_INIT;
332+
struct string_list include = STRING_LIST_INIT_DUP;
333333
struct string_list_item *item;
334334
struct packed_git *preferred = pack_geometry_preferred_pack(opts->geometry);
335335
FILE *in;
336336
int ret = 0;
337337

338-
if (!opts->include->nr)
338+
midx_included_packs(&include, opts);
339+
if (!include.nr)
339340
goto done;
340341

341342
cmd.in = -1;
@@ -397,14 +398,17 @@ static int write_midx_included_packs(struct repack_write_midx_opts *opts)
397398
goto done;
398399

399400
in = xfdopen(cmd.in, "w");
400-
for_each_string_list_item(item, opts->include)
401+
for_each_string_list_item(item, &include)
401402
fprintf(in, "%s\n", item->string);
402403
fclose(in);
403404

404405
ret = finish_command(&cmd);
405406
done:
406407
if (!ret && opts->write_bitmaps)
407-
remove_redundant_bitmaps(opts->include, opts->packdir);
408+
remove_redundant_bitmaps(&include, opts->packdir);
409+
410+
string_list_clear(&include, 0);
411+
408412
return ret;
409413
}
410414

@@ -994,10 +998,8 @@ int cmd_repack(int argc,
994998
existing_packs_mark_for_deletion(&existing, &names);
995999

9961000
if (write_midx) {
997-
struct string_list include = STRING_LIST_INIT_DUP;
9981001
struct repack_write_midx_opts opts = {
9991002
.existing = &existing,
1000-
.include = &include,
10011003
.geometry = &geometry,
10021004
.names = &names,
10031005
.refs_snapshot = refs_snapshot ? get_tempfile_path(refs_snapshot) : NULL,
@@ -1006,12 +1008,9 @@ int cmd_repack(int argc,
10061008
.write_bitmaps = write_bitmaps > 0,
10071009
.midx_must_contain_cruft = midx_must_contain_cruft
10081010
};
1009-
midx_included_packs(&include, &opts);
10101011

10111012
ret = write_midx_included_packs(&opts);
10121013

1013-
string_list_clear(&include, 0);
1014-
10151014
if (ret)
10161015
goto cleanup;
10171016
}

0 commit comments

Comments
 (0)