builtin/repack.c: use `write_pack_opts` within `write_cruft_pack()`

Similar to the changes made in the previous commit to
`write_filtered_pack()`, teach `write_cruft_pack()` to take a
`write_pack_opts` struct and use that where possible.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
main
Taylor Blau 2025-10-15 18:29:19 -04:00 committed by Junio C Hamano
parent 7a9c81a38d
commit 3d2ac2065e
1 changed files with 14 additions and 13 deletions

View File

@ -221,9 +221,7 @@ static void combine_small_cruft_packs(FILE *in, size_t combine_cruft_below_size,
strbuf_release(&buf); strbuf_release(&buf);
} }


static int write_cruft_pack(const struct pack_objects_args *args, static int write_cruft_pack(const struct write_pack_opts *opts,
const char *destination,
const char *pack_prefix,
const char *cruft_expiration, const char *cruft_expiration,
unsigned long combine_cruft_below_size, unsigned long combine_cruft_below_size,
struct string_list *names, struct string_list *names,
@ -234,9 +232,9 @@ static int write_cruft_pack(const struct pack_objects_args *args,
FILE *in; FILE *in;
int ret; int ret;
const char *scratch; const char *scratch;
int local = skip_prefix(destination, packdir, &scratch); int local = skip_prefix(opts->destination, opts->packdir, &scratch);


prepare_pack_objects(&cmd, args, destination); prepare_pack_objects(&cmd, opts->po_args, opts->destination);


strvec_push(&cmd.args, "--cruft"); strvec_push(&cmd.args, "--cruft");
if (cruft_expiration) if (cruft_expiration)
@ -267,7 +265,7 @@ static int write_cruft_pack(const struct pack_objects_args *args,
*/ */
in = xfdopen(cmd.in, "w"); in = xfdopen(cmd.in, "w");
for_each_string_list_item(item, names) for_each_string_list_item(item, names)
fprintf(in, "%s-%s.pack\n", pack_prefix, item->string); fprintf(in, "%s-%s.pack\n", opts->pack_prefix, item->string);
if (combine_cruft_below_size && !cruft_expiration) { if (combine_cruft_below_size && !cruft_expiration) {
combine_small_cruft_packs(in, combine_cruft_below_size, combine_small_cruft_packs(in, combine_cruft_below_size,
existing); existing);
@ -599,6 +597,13 @@ int cmd_repack(int argc,


if (pack_everything & PACK_CRUFT) { if (pack_everything & PACK_CRUFT) {
const char *pack_prefix = find_pack_prefix(packdir, packtmp); const char *pack_prefix = find_pack_prefix(packdir, packtmp);
struct write_pack_opts opts = {
.po_args = &cruft_po_args,
.destination = packtmp,
.pack_prefix = pack_prefix,
.packtmp = packtmp,
.packdir = packdir,
};


if (!cruft_po_args.window) if (!cruft_po_args.window)
cruft_po_args.window = xstrdup_or_null(po_args.window); cruft_po_args.window = xstrdup_or_null(po_args.window);
@ -615,8 +620,7 @@ int cmd_repack(int argc,
cruft_po_args.quiet = po_args.quiet; cruft_po_args.quiet = po_args.quiet;
cruft_po_args.delta_base_offset = po_args.delta_base_offset; cruft_po_args.delta_base_offset = po_args.delta_base_offset;


ret = write_cruft_pack(&cruft_po_args, packtmp, pack_prefix, ret = write_cruft_pack(&opts, cruft_expiration,
cruft_expiration,
combine_cruft_below_size, &names, combine_cruft_below_size, &names,
&existing); &existing);
if (ret) if (ret)
@ -651,11 +655,8 @@ int cmd_repack(int argc,
* pack, but rather removing all cruft packs from the * pack, but rather removing all cruft packs from the
* main repository regardless of size. * main repository regardless of size.
*/ */
ret = write_cruft_pack(&cruft_po_args, expire_to, opts.destination = expire_to;
pack_prefix, ret = write_cruft_pack(&opts, NULL, 0ul, &names,
NULL,
0ul,
&names,
&existing); &existing);
if (ret) if (ret)
goto cleanup; goto cleanup;