public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Taylor Blau <me@ttaylorr•com>
To: Jeff King <peff@peff•net>
Cc: git@vger•kernel.org, Junio C Hamano <gitster@pobox•com>,
	Elijah Newren <newren@gmail•com>, Patrick Steinhardt <ps@pks•im>,
	Justin Tobler <jltobler@gmail•com>
Subject: Re: [PATCH 44/49] builtin/repack.c: pass `write_pack_opts` to `finish_pack_objects_cmd()`
Date: Wed, 15 Oct 2025 17:35:03 -0400	[thread overview]
Message-ID: <aPAThyMlw4oNEBnJ@nand.local> (raw)
In-Reply-To: <20251015110155.GF2250228@coredump.intra.peff.net>

On Wed, Oct 15, 2025 at 07:01:55AM -0400, Jeff King wrote:
> On Sun, Sep 28, 2025 at 06:10:14PM -0400, Taylor Blau wrote:
>
> >  int cmd_repack(int argc,
> > @@ -294,6 +294,7 @@ int cmd_repack(int argc,
> >  	struct existing_packs existing = EXISTING_PACKS_INIT;
> >  	struct pack_geometry geometry = { 0 };
> >  	struct tempfile *refs_snapshot = NULL;
> > +	struct write_pack_opts opts = { 0 };
> >  	int i, ret;
> >  	int show_progress;
> >
> > @@ -560,7 +561,10 @@ int cmd_repack(int argc,
> >  		fclose(in);
> >  	}
> >
> > -	ret = finish_pack_objects_cmd(repo->hash_algo, &cmd, &names, 1);
> > +	opts.packdir = packdir;
> > +	opts.destination = packdir;
> > +	opts.packtmp = packtmp;
> > +	ret = finish_pack_objects_cmd(repo->hash_algo, &opts, &cmd, &names);
> >  	if (ret)
> >  		goto cleanup;
>
> This looks a bit funny: we are creating a write_pack_opts struct but
> only filling in some of the fields. Notably po_args is NULL. It's
> zero'd, which is good, but as a matter of API design, how can a caller
> know which fields are important for a given function and which are not?
>
> I guess I could have expected cmd_repack() to make a fully fleshed-out
> write_pack_opts up front, and then pass it to all functions which need
> it. Rather than making a custom one for this one function.
>
> But I guess that gets a little weird, because it really has at least
> _two_ such opts: one for the regular pack-objects invocation and one for
> the cruft pack. And really maybe one more, for the filtered pack? And
> the conditional blocks for cruft and filter_options packs shadow the
> "opts" variable. Yuck.

Yeah, it is unfortunate that not all instances where we generate a pack
use the same pack destination, or even the same set of options to
pack-objects.

> I'm not sure if there's a good solution. My inclination is to say that
> po_args should not be in "opts" at all, and that each function should
> take a separate po_args as appropriate. And then we could just have one
> write_pack_opts in cmd_repack(). But there is another snag: we sometimes
> override the "destination" field with "filter_to" or "expire_to".
>
> So the struct really isn't "here are the opts for repacking", but rather
> "let's marshal some arguments into a struct for one function call".
> Which of course is a bit verbose in C, hence these extra shadowed "opts"
> variables.

I think that only solves part of the problem, though. Among the other
spots that call functions which take a `struct write_pack_opts`, not all
of them use the same destination, so we'd still have to create multiple
`struct write_pack_opts` instances in `cmd_repack()`, or pass the
destination separately, which feels equally odd to me.

> So I dunno that I am really asking for any change. This might be the
> least bad way of writing it. I guess if we could avoid the shadowing
> like this:
>
> diff --git a/builtin/repack.c b/builtin/repack.c
> index ad60c4290d..4e4519b180 100644
> --- a/builtin/repack.c
> +++ b/builtin/repack.c
> @@ -108,7 +108,6 @@ int cmd_repack(int argc,
>  	struct existing_packs existing = EXISTING_PACKS_INIT;
>  	struct pack_geometry geometry = { 0 };
>  	struct tempfile *refs_snapshot = NULL;
> -	struct write_pack_opts opts = { 0 };
>  	int i, ret;
>  	int show_progress;
>
> @@ -372,12 +371,15 @@ int cmd_repack(int argc,
>  		fclose(in);
>  	}
>
> -	opts.packdir = packdir;
> -	opts.destination = packdir;
> -	opts.packtmp = packtmp;
> -	ret = finish_pack_objects_cmd(repo->hash_algo, &opts, &cmd, &names);
> -	if (ret)
> -		goto cleanup;
> +	{
> +		struct write_pack_opts opts = { 0 };
> +		opts.packdir = packdir;
> +		opts.destination = packdir;
> +		opts.packtmp = packtmp;
> +		ret = finish_pack_objects_cmd(repo->hash_algo, &opts, &cmd, &names);
> +		if (ret)
> +			goto cleanup;
> +	}
>
>  	if (!names.nr) {
>  		if (!po_args.quiet)

Yeah, I think that is the most reasonable outcome, at least within the
scope of this patch/series.

> That might be nice, but introducing the extra block is kind of ugly. Of
> course you can get really fancy with a compound literal, like:
>
> @@ -372,10 +371,13 @@ int cmd_repack(int argc,
>  		fclose(in);
>  	}
>
> -	opts.packdir = packdir;
> -	opts.destination = packdir;
> -	opts.packtmp = packtmp;
> -	ret = finish_pack_objects_cmd(repo->hash_algo, &opts, &cmd, &names);
> +	ret = finish_pack_objects_cmd(repo->hash_algo,
> +				      &(struct write_pack_opts) {
> +					.packdir = packdir,
> +					.destination = packdir,
> +					.packtmp = packtmp,
> +				      },
> +				      &cmd, &names);
>  	if (ret)
>  		goto cleanup;
>
>
> But that may be a bridge too far.

As much as I'd like to use a compound literal here, 9b2527caa4
(CodingGuidelines: document test balloons in flight, 2025-07-23)
prevents us from adding new instances of them in our codebase for the
time being.

Thanks,
Taylor

  reply	other threads:[~2025-10-15 21:35 UTC|newest]

Thread overview: 163+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-28 22:07 [PATCH 00/49] repack: prepare for incremental MIDX-based repacking Taylor Blau
2025-09-28 22:07 ` [PATCH 01/49] builtin/repack.c: avoid "the_repository" in `cmd_repack()` Taylor Blau
2025-09-28 22:07 ` [PATCH 02/49] builtin/repack.c: avoid "the_repository" in existing packs API Taylor Blau
2025-10-10  5:19   ` Jeff King
2025-10-10 22:48     ` Taylor Blau
2025-09-28 22:07 ` [PATCH 03/49] builtin/repack.c: avoid "the_repository" when taking a ref snapshot Taylor Blau
2025-09-28 22:07 ` [PATCH 04/49] builtin/repack.c: avoid "the_repository" when removing packs Taylor Blau
2025-10-10  5:22   ` Jeff King
2025-10-10 22:49     ` Taylor Blau
2025-09-28 22:07 ` [PATCH 05/49] builtin/repack.c: avoid "the_repository" when repacking promisor objects Taylor Blau
2025-09-28 22:07 ` [PATCH 06/49] builtin/repack.c: avoid "the_hash_algo" when deleting packs Taylor Blau
2025-09-28 22:07 ` [PATCH 07/49] builtin/repack.c: avoid "the_hash_algo" in `write_oid()` Taylor Blau
2025-09-29 23:21   ` Patrick Steinhardt
2025-10-07 20:17     ` Taylor Blau
2025-09-28 22:07 ` [PATCH 08/49] builtin/repack: avoid "the_hash_algo" in `repack_promisor_objects()` Taylor Blau
2025-09-28 22:07 ` [PATCH 09/49] builtin/repack.c: avoid "the_hash_algo" in `finish_pack_objects_cmd()` Taylor Blau
2025-10-10  5:31   ` Jeff King
2025-10-10 22:51     ` Taylor Blau
2025-09-28 22:07 ` [PATCH 10/49] builtin/repack.c: avoid using `hash_to_hex()` in pack geometry Taylor Blau
2025-09-29 23:21   ` Patrick Steinhardt
2025-09-28 22:07 ` [PATCH 11/49] repack: introduce new compilation unit Taylor Blau
2025-10-10  5:48   ` Jeff King
2025-10-10 22:52     ` Taylor Blau
2025-09-28 22:07 ` [PATCH 12/49] builtin/repack.c: pass both pack_objects args to repack_config Taylor Blau
2025-09-29 23:21   ` Patrick Steinhardt
2025-09-28 22:08 ` [PATCH 13/49] repack: move 'delta_base_offset' to 'struct pack_objects_args' Taylor Blau
2025-10-10  5:54   ` Jeff King
2025-10-10 22:54     ` Taylor Blau
2025-09-28 22:08 ` [PATCH 14/49] repack: remove 'prepare_pack_objects' from the builtin Taylor Blau
2025-09-28 22:08 ` [PATCH 15/49] builtin/repack.c: rename many 'struct existing_packs' functions Taylor Blau
2025-09-28 22:08 ` [PATCH 16/49] repack: remove 'remove_redundant_pack' from the builtin Taylor Blau
2025-09-28 22:08 ` [PATCH 17/49] builtin/repack.c: pass "packdir" when removing packs Taylor Blau
2025-09-29 23:21   ` Patrick Steinhardt
2025-10-07 20:23     ` Taylor Blau
2025-10-10  6:04   ` Jeff King
2025-10-10 22:56     ` Taylor Blau
2025-09-28 22:08 ` [PATCH 18/49] builtin/repack.c: avoid unnecessary numeric casts in existing_packs Taylor Blau
2025-09-28 22:08 ` [PATCH 19/49] repack: remove 'existing_packs' API from the builtin Taylor Blau
2025-09-29 23:21   ` Patrick Steinhardt
2025-10-07 20:24     ` Taylor Blau
2025-10-10  6:08   ` Jeff King
2025-10-10 22:57     ` Taylor Blau
2025-09-28 22:08 ` [PATCH 20/49] builtin/repack.c: rename "struct generated_pack_data" Taylor Blau
2025-09-28 22:08 ` [PATCH 21/49] builtin/repack.c: factor our "generated_pack_install" Taylor Blau
2025-09-29 23:21   ` Patrick Steinhardt
2025-10-07 20:26     ` Taylor Blau
2025-10-08  4:28       ` Patrick Steinhardt
2025-10-10  6:14       ` Jeff King
2025-10-10 22:58         ` Taylor Blau
2025-09-28 22:08 ` [PATCH 22/49] builtin/repack.c: pass "packtmp" to `generated_pack_populate()` Taylor Blau
2025-09-29 23:21   ` Patrick Steinhardt
2025-10-07 20:29     ` Taylor Blau
2025-10-08  4:27       ` Patrick Steinhardt
2025-09-28 22:08 ` [PATCH 23/49] builtin/repack.c: provide pack locations to `generated_pack_install()` Taylor Blau
2025-09-28 22:08 ` [PATCH 24/49] repack: remove 'generated_pack' API from the builtin Taylor Blau
2025-09-28 22:08 ` [PATCH 25/49] builtin/repack.c: pass "packtmp" to `repack_promisor_objects()` Taylor Blau
2025-09-28 22:08 ` [PATCH 26/49] builtin/repack.c: remove "repack_promisor_objects()" from the builtin Taylor Blau
2025-09-29 23:21   ` Patrick Steinhardt
2025-10-07 20:36     ` Taylor Blau
2025-09-28 22:08 ` [PATCH 27/49] builtin/repack.c: rename various pack_geometry functions Taylor Blau
2025-09-29 23:22   ` Patrick Steinhardt
2025-10-07 20:38     ` Taylor Blau
2025-10-08  4:26       ` Patrick Steinhardt
2025-10-10 23:00         ` Taylor Blau
2025-09-28 22:08 ` [PATCH 28/49] builtin/repack.c: pass 'pack_kept_objects' to `pack_geometry_init()` Taylor Blau
2025-09-28 22:09 ` [PATCH 29/49] builtin/repack.c: pass 'packdir' to `pack_geometry_remove_redundant()` Taylor Blau
2025-09-28 22:09 ` [PATCH 30/49] repack: remove pack_geometry API from the builtin Taylor Blau
2025-09-28 22:09 ` [PATCH 31/49] builtin/repack.c: remove ref snapshotting from builtin Taylor Blau
2025-09-28 22:09 ` [PATCH 32/49] builtin/repack.c: extract opts struct for 'write_midx_included_packs()' Taylor Blau
2025-09-28 22:09 ` [PATCH 33/49] builtin/repack.c: use a string_list for 'midx_pack_names' Taylor Blau
2025-09-28 22:09 ` [PATCH 34/49] repack: keep track of MIDX pack names using existing_packs Taylor Blau
2025-09-28 22:09 ` [PATCH 35/49] builtin/repack.c: reorder `remove_redundant_bitmaps()` Taylor Blau
2025-09-28 22:09 ` [PATCH 36/49] builtin/repack.c: inline `remove_redundant_bitmaps()` Taylor Blau
2025-09-28 22:09 ` [PATCH 37/49] builtin/repack.c: pass `repack_write_midx_opts` to `midx_included_packs` Taylor Blau
2025-09-28 22:09 ` [PATCH 38/49] builtin/repack.c: inline packs within `write_midx_included_packs()` Taylor Blau
2025-10-10 12:28   ` Patrick Steinhardt
2025-10-10 23:02     ` Taylor Blau
2025-10-15 10:26   ` Jeff King
2025-09-28 22:09 ` [PATCH 39/49] repack: 'write_midx_included_packs' API from the builtin Taylor Blau
2025-09-28 22:09 ` [PATCH 40/49] builtin/repack.c: introduce `struct write_pack_opts` Taylor Blau
2025-10-10 12:28   ` Patrick Steinhardt
2025-10-10 23:13     ` Taylor Blau
2025-10-15 10:28   ` Jeff King
2025-10-15 21:18     ` Taylor Blau
2025-09-28 22:09 ` [PATCH 41/49] builtin/repack.c: use `write_pack_opts` within `write_cruft_pack()` Taylor Blau
2025-10-10 12:28   ` Patrick Steinhardt
2025-10-10 23:13     ` Taylor Blau
2025-10-15 10:29   ` Jeff King
2025-09-28 22:10 ` [PATCH 42/49] repack: move `find_pack_prefix()` out of the builtin Taylor Blau
2025-10-15 10:32   ` Jeff King
2025-10-15 21:19     ` Taylor Blau
2025-09-28 22:10 ` [PATCH 43/49] repack: extract `write_pack_opts_is_local()` Taylor Blau
2025-10-10 12:28   ` Patrick Steinhardt
2025-10-15 21:21     ` Taylor Blau
2025-10-15 10:35   ` Jeff King
2025-10-15 21:25     ` Taylor Blau
2025-09-28 22:10 ` [PATCH 44/49] builtin/repack.c: pass `write_pack_opts` to `finish_pack_objects_cmd()` Taylor Blau
2025-10-15 11:01   ` Jeff King
2025-10-15 21:35     ` Taylor Blau [this message]
2025-09-28 22:10 ` [PATCH 45/49] repack: move `finish_pack_objects_cmd()` out of the builtin Taylor Blau
2025-09-28 22:10 ` [PATCH 46/49] repack: move `pack_kept_objects` to `struct pack_objects_args` Taylor Blau
2025-09-28 22:10 ` [PATCH 47/49] repack: move `write_filtered_pack()` out of the builtin Taylor Blau
2025-09-28 22:10 ` [PATCH 48/49] repack: move `write_cruft_pack()` " Taylor Blau
2025-09-28 22:10 ` [PATCH 49/49] builtin/repack.c: clean up unused `#include`s Taylor Blau
2025-09-28 22:58 ` [PATCH 00/49] repack: prepare for incremental MIDX-based repacking Junio C Hamano
2025-10-07 20:44   ` Taylor Blau
2025-10-10  6:29 ` Jeff King
2025-10-10 23:15   ` Taylor Blau
2025-10-15 11:06     ` Jeff King
2025-10-15 22:26 ` [PATCH v2 " Taylor Blau
2025-10-15 22:27   ` [PATCH v2 01/49] builtin/repack.c: avoid "the_repository" in `cmd_repack()` Taylor Blau
2025-10-15 22:27   ` [PATCH v2 02/49] builtin/repack.c: avoid "the_repository" in existing packs API Taylor Blau
2025-10-15 22:27   ` [PATCH v2 03/49] builtin/repack.c: avoid "the_repository" when taking a ref snapshot Taylor Blau
2025-10-15 22:27   ` [PATCH v2 04/49] builtin/repack.c: avoid "the_repository" when removing packs Taylor Blau
2025-10-15 22:27   ` [PATCH v2 05/49] builtin/repack.c: avoid "the_repository" when repacking promisor objects Taylor Blau
2025-10-15 22:27   ` [PATCH v2 06/49] builtin/repack.c: avoid "the_hash_algo" when deleting packs Taylor Blau
2025-10-15 22:27   ` [PATCH v2 07/49] builtin/repack.c: avoid "the_hash_algo" in `write_oid()` Taylor Blau
2025-10-15 22:27   ` [PATCH v2 08/49] builtin/repack: avoid "the_hash_algo" in `repack_promisor_objects()` Taylor Blau
2025-10-15 22:27   ` [PATCH v2 09/49] builtin/repack.c: avoid "the_hash_algo" in `finish_pack_objects_cmd()` Taylor Blau
2025-10-15 22:27   ` [PATCH v2 10/49] builtin/repack.c: avoid using `hash_to_hex()` in pack geometry Taylor Blau
2025-10-15 22:27   ` [PATCH v2 11/49] repack: introduce new compilation unit Taylor Blau
2025-10-15 22:27   ` [PATCH v2 12/49] builtin/repack.c: pass both pack_objects args to repack_config Taylor Blau
2025-10-15 22:27   ` [PATCH v2 13/49] repack: move 'delta_base_offset' to 'struct pack_objects_args' Taylor Blau
2025-10-15 22:28   ` [PATCH v2 14/49] repack: remove 'prepare_pack_objects' from the builtin Taylor Blau
2025-10-15 22:28   ` [PATCH v2 15/49] builtin/repack.c: rename many 'struct existing_packs' functions Taylor Blau
2025-10-15 22:28   ` [PATCH v2 16/49] repack: remove 'remove_redundant_pack' from the builtin Taylor Blau
2025-10-15 22:28   ` [PATCH v2 17/49] builtin/repack.c: pass "packdir" when removing packs Taylor Blau
2025-10-15 22:28   ` [PATCH v2 18/49] builtin/repack.c: avoid unnecessary numeric casts in existing_packs Taylor Blau
2025-10-15 22:28   ` [PATCH v2 19/49] repack: remove 'existing_packs' API from the builtin Taylor Blau
2025-10-15 22:28   ` [PATCH v2 20/49] builtin/repack.c: rename "struct generated_pack_data" Taylor Blau
2025-10-15 22:28   ` [PATCH v2 21/49] builtin/repack.c: factor out "generated_pack_install" Taylor Blau
2025-10-15 22:28   ` [PATCH v2 22/49] builtin/repack.c: pass "packtmp" to `generated_pack_populate()` Taylor Blau
2025-10-15 22:28   ` [PATCH v2 23/49] builtin/repack.c: provide pack locations to `generated_pack_install()` Taylor Blau
2025-10-15 22:28   ` [PATCH v2 24/49] repack: remove 'generated_pack' API from the builtin Taylor Blau
2025-10-15 22:28   ` [PATCH v2 25/49] builtin/repack.c: pass "packtmp" to `repack_promisor_objects()` Taylor Blau
2025-10-15 22:28   ` [PATCH v2 26/49] builtin/repack.c: remove "repack_promisor_objects()" from the builtin Taylor Blau
2025-10-15 22:28   ` [PATCH v2 27/49] builtin/repack.c: rename various pack_geometry functions Taylor Blau
2025-10-15 22:28   ` [PATCH v2 28/49] builtin/repack.c: pass 'pack_kept_objects' to `pack_geometry_init()` Taylor Blau
2025-10-15 22:28   ` [PATCH v2 29/49] builtin/repack.c: pass 'packdir' to `pack_geometry_remove_redundant()` Taylor Blau
2025-10-15 22:28   ` [PATCH v2 30/49] repack: remove pack_geometry API from the builtin Taylor Blau
2025-10-15 22:28   ` [PATCH v2 31/49] builtin/repack.c: remove ref snapshotting from builtin Taylor Blau
2025-10-15 22:28   ` [PATCH v2 32/49] builtin/repack.c: extract opts struct for 'write_midx_included_packs()' Taylor Blau
2025-10-15 22:28   ` [PATCH v2 33/49] builtin/repack.c: use a string_list for 'midx_pack_names' Taylor Blau
2025-10-15 22:28   ` [PATCH v2 34/49] repack: keep track of MIDX pack names using existing_packs Taylor Blau
2025-10-15 22:29   ` [PATCH v2 35/49] builtin/repack.c: reorder `remove_redundant_bitmaps()` Taylor Blau
2025-10-15 22:29   ` [PATCH v2 36/49] builtin/repack.c: inline `remove_redundant_bitmaps()` Taylor Blau
2025-10-15 22:29   ` [PATCH v2 37/49] builtin/repack.c: pass `repack_write_midx_opts` to `midx_included_packs` Taylor Blau
2025-10-15 22:29   ` [PATCH v2 38/49] builtin/repack.c: inline packs within `write_midx_included_packs()` Taylor Blau
2025-10-15 22:29   ` [PATCH v2 39/49] repack: 'write_midx_included_packs' API from the builtin Taylor Blau
2025-10-15 22:29   ` [PATCH v2 40/49] builtin/repack.c: introduce `struct write_pack_opts` Taylor Blau
2025-10-15 22:29   ` [PATCH v2 41/49] builtin/repack.c: use `write_pack_opts` within `write_cruft_pack()` Taylor Blau
2025-10-15 22:29   ` [PATCH v2 42/49] repack: move `find_pack_prefix()` out of the builtin Taylor Blau
2025-10-15 22:29   ` [PATCH v2 43/49] repack: extract `write_pack_opts_is_local()` Taylor Blau
2025-10-15 22:29   ` [PATCH v2 44/49] builtin/repack.c: pass `write_pack_opts` to `finish_pack_objects_cmd()` Taylor Blau
2025-10-15 22:29   ` [PATCH v2 45/49] repack: move `finish_pack_objects_cmd()` out of the builtin Taylor Blau
2025-10-15 22:29   ` [PATCH v2 46/49] repack: move `pack_kept_objects` to `struct pack_objects_args` Taylor Blau
2025-10-15 22:29   ` [PATCH v2 47/49] repack: move `write_filtered_pack()` out of the builtin Taylor Blau
2025-10-15 22:29   ` [PATCH v2 48/49] repack: move `write_cruft_pack()` " Taylor Blau
2025-10-15 22:29   ` [PATCH v2 49/49] builtin/repack.c: clean up unused `#include`s Taylor Blau
2025-10-16 10:31   ` [PATCH v2 00/49] repack: prepare for incremental MIDX-based repacking Patrick Steinhardt
2025-10-16 17:11     ` Junio C Hamano
2025-10-16 19:56       ` Taylor Blau
2025-10-17  8:40       ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aPAThyMlw4oNEBnJ@nand.local \
    --to=me@ttaylorr$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    --cc=jltobler@gmail$(echo .)com \
    --cc=newren@gmail$(echo .)com \
    --cc=peff@peff$(echo .)net \
    --cc=ps@pks$(echo .)im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox