From: Justin Tobler Date: Tue, 08 Sep 2026 22:43:00 GMT Subject: Re: [PATCH v3 5/9] builtin/clone: move setup of alternates for shared local clones Message-ID: In-Reply-To: <20260907-pks-odb-write-alternates-at-creation-time-v3-5-735d0b5b3e00@pks.im> On 26/09/07 10:25AM, Patrick Steinhardt wrote: > When cloning a local repository with "--shared" we add that repository > to the new repository's alternates. This is done in `clone_local()`, > which is responsible for performing local clones. > > Move the logic into `collect_alternates()` to unify our setup of > alternates. Furthermore, this will allow us to set up alternates right > at creation time of the object database. > > Note that the logic for cloning a local repository with "--no-shared" is > not yet part of `collect_alternates()`. This will be handled in the next > commit. > > Signed-off-by: Patrick Steinhardt > --- > builtin/clone.c | 23 ++++++++++++++--------- > 1 file changed, 14 insertions(+), 9 deletions(-) > > diff --git a/builtin/clone.c b/builtin/clone.c > index 8786a49332..011fc867c8 100644 > --- a/builtin/clone.c > +++ b/builtin/clone.c > @@ -220,7 +220,8 @@ static void copy_alternates(struct strbuf *src, const char *src_repo) > fclose(in); > } > > -static void collect_alternates(struct strvec *alternates) > +static void collect_alternates(struct strvec *alternates, > + const char *src_repo, bool is_local) > { > if (option_required_reference.nr || option_optional_reference.nr) { > struct add_one_alternate_data data = { > @@ -234,6 +235,16 @@ static void collect_alternates(struct strvec *alternates) > for_each_string_list(&option_optional_reference, > add_one_alternate, &data); > } > + > + if (is_local) { Could this condtional instead be: if (is_local && option_shared) > + struct strbuf commondir = STRBUF_INIT; > + > + get_common_dir(&commondir, src_repo); > + if (option_shared) > + strvec_pushf(alternates, "%s/objects", commondir.buf); > + > + strbuf_release(&commondir); > + } -Justin