Skip to content

Commit e6b0907

Browse files
ttaylorrgitster
authored andcommitted
builtin/repack.c: extract opts struct for 'write_midx_included_packs()'
The function 'write_midx_included_packs()', which is responsible for writing a new MIDX with a given set of included packs, currently takes a list of six arguments. In order to extract this function out of the builtin, we have to pass in a few additional parameters, like 'midx_must_contain_cruft' and 'packdir', which are currently declared as static variables within the builtin/repack.c compilation unit. Instead of adding additional parameters to `write_midx_included_packs()` extract out an "opts" struct that names these parameters, and pass a pointer to that, making it less cumbersome to add additional parameters. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ccb7f82 commit e6b0907

1 file changed

Lines changed: 34 additions & 18 deletions

File tree

builtin/repack.c

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ static int repack_config(const char *var, const char *value,
107107
return git_default_config(var, value, ctx, cb);
108108
}
109109

110+
struct repack_write_midx_opts {
111+
struct string_list *include;
112+
struct pack_geometry *geometry;
113+
struct string_list *names;
114+
const char *refs_snapshot;
115+
const char *packdir;
116+
int show_progress;
117+
int write_bitmaps;
118+
int midx_must_contain_cruft;
119+
};
120+
110121
static int midx_has_unknown_packs(char **midx_pack_names,
111122
size_t midx_pack_names_nr,
112123
struct string_list *include,
@@ -290,19 +301,15 @@ static void midx_included_packs(struct string_list *include,
290301
strbuf_release(&buf);
291302
}
292303

293-
static int write_midx_included_packs(struct string_list *include,
294-
struct pack_geometry *geometry,
295-
struct string_list *names,
296-
const char *refs_snapshot,
297-
int show_progress, int write_bitmaps)
304+
static int write_midx_included_packs(struct repack_write_midx_opts *opts)
298305
{
299306
struct child_process cmd = CHILD_PROCESS_INIT;
300307
struct string_list_item *item;
301-
struct packed_git *preferred = pack_geometry_preferred_pack(geometry);
308+
struct packed_git *preferred = pack_geometry_preferred_pack(opts->geometry);
302309
FILE *in;
303310
int ret;
304311

305-
if (!include->nr)
312+
if (!opts->include->nr)
306313
return 0;
307314

308315
cmd.in = -1;
@@ -311,18 +318,18 @@ static int write_midx_included_packs(struct string_list *include,
311318
strvec_push(&cmd.args, "multi-pack-index");
312319
strvec_pushl(&cmd.args, "write", "--stdin-packs", NULL);
313320

314-
if (show_progress)
321+
if (opts->show_progress)
315322
strvec_push(&cmd.args, "--progress");
316323
else
317324
strvec_push(&cmd.args, "--no-progress");
318325

319-
if (write_bitmaps)
326+
if (opts->write_bitmaps)
320327
strvec_push(&cmd.args, "--bitmap");
321328

322329
if (preferred)
323330
strvec_pushf(&cmd.args, "--preferred-pack=%s",
324331
pack_basename(preferred));
325-
else if (names->nr) {
332+
else if (opts->names->nr) {
326333
/* The largest pack was repacked, meaning that either
327334
* one or two packs exist depending on whether the
328335
* repository has a cruft pack or not.
@@ -335,7 +342,7 @@ static int write_midx_included_packs(struct string_list *include,
335342
* `--max-pack-size` was given, but any one of them
336343
* will suffice, so pick the first one.)
337344
*/
338-
for_each_string_list_item(item, names) {
345+
for_each_string_list_item(item, opts->names) {
339346
struct generated_pack *pack = item->util;
340347
if (generated_pack_has_ext(pack, ".mtimes"))
341348
continue;
@@ -355,15 +362,16 @@ static int write_midx_included_packs(struct string_list *include,
355362
;
356363
}
357364

358-
if (refs_snapshot)
359-
strvec_pushf(&cmd.args, "--refs-snapshot=%s", refs_snapshot);
365+
if (opts->refs_snapshot)
366+
strvec_pushf(&cmd.args, "--refs-snapshot=%s",
367+
opts->refs_snapshot);
360368

361369
ret = start_command(&cmd);
362370
if (ret)
363371
return ret;
364372

365373
in = xfdopen(cmd.in, "w");
366-
for_each_string_list_item(item, include)
374+
for_each_string_list_item(item, opts->include)
367375
fprintf(in, "%s\n", item->string);
368376
fclose(in);
369377

@@ -1001,15 +1009,23 @@ int cmd_repack(int argc,
10011009

10021010
if (write_midx) {
10031011
struct string_list include = STRING_LIST_INIT_DUP;
1012+
struct repack_write_midx_opts opts = {
1013+
.include = &include,
1014+
.geometry = &geometry,
1015+
.names = &names,
1016+
.refs_snapshot = refs_snapshot ? get_tempfile_path(refs_snapshot) : NULL,
1017+
.packdir = packdir,
1018+
.show_progress = show_progress,
1019+
.write_bitmaps = write_bitmaps > 0,
1020+
.midx_must_contain_cruft = midx_must_contain_cruft
1021+
};
10041022
midx_included_packs(&include, &existing, midx_pack_names,
10051023
midx_pack_names_nr, &names, &geometry);
10061024

1007-
ret = write_midx_included_packs(&include, &geometry, &names,
1008-
refs_snapshot ? get_tempfile_path(refs_snapshot) : NULL,
1009-
show_progress, write_bitmaps > 0);
1025+
ret = write_midx_included_packs(&opts);
10101026

10111027
if (!ret && write_bitmaps)
1012-
remove_redundant_bitmaps(&include, packdir);
1028+
remove_redundant_bitmaps(&include, opts.packdir);
10131029

10141030
string_list_clear(&include, 0);
10151031

0 commit comments

Comments
 (0)