From: Toon Claes <toon@iotcl.com>
To: Patrick Steinhardt <ps@pks.im>, git@vger.kernel.org
Subject: Re: [PATCH 5/8] builtin/clone: move setup of alternates for non-shared local clones
Date: Fri, 28 Aug 2026 16:52:57 +0200 [thread overview]
Message-ID: <874igeuwja.fsf@emacs.iotcl.com> (raw)
In-Reply-To: <20260825-pks-odb-write-alternates-at-creation-time-v1-5-911513ba95c3@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
> Similar as in the preceding commit, move the setup of alternates for
> local clones with "--no-shared" into `collect_alternates()`. With this
> step, the complete setup of alternates is now handled by that function.
>
> Note that besides moving stuff around, it also fixes a bug: previously,
> we did not know to resolve the referenced repository's common directory.
> Consequently, when referencing a worktree we failed to resolve
> alternates. But as `collect_alternates()` already knows to resolve the
> commondir for "--local" we can simply reuse this resolved path for our
> purpose.
>
> Add two tests, the first one of which exercises this bug to avoid future
> regressions. The second patch ensures that we properly handle relative
> alternates for a referenced worktree.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> builtin/clone.c | 34 +++++++++++++++++++++++-----------
> t/t5604-clone-reference.sh | 25 +++++++++++++++++++++++++
> 2 files changed, 48 insertions(+), 11 deletions(-)
>
> diff --git a/builtin/clone.c b/builtin/clone.c
> index 08c8f5a94f..2e3473fddf 100644
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -181,7 +181,7 @@ static int add_one_alternate(struct string_list_item *item, void *cb_data)
> return 0;
> }
>
> -static void copy_alternates(struct strbuf *src, const char *src_repo)
> +static void read_alternates(struct strvec *alternates, const char *src_repo)
> {
> /*
> * Read from the source objects/info/alternates file
> @@ -195,29 +195,41 @@ static void copy_alternates(struct strbuf *src, const char *src_repo)
> * to turn entries with paths relative to the original
> * absolute, so that they can be used in the new repository.
> */
> - FILE *in = xfopen(src->buf, "r");
> + FILE *in;
> + struct strbuf path = STRBUF_INIT;
> struct strbuf line = STRBUF_INIT;
>
> + strbuf_addf(&path, "%s/objects/info/alternates", src_repo);
> +
> + in = fopen(path.buf, "r");
> + if (!in) {
> + if (errno == ENOENT)
> + goto out;
> + die_errno("could not read alternates file '%s'", path.buf);
> + }
> +
> while (strbuf_getline(&line, in) != EOF) {
> char *abs_path;
> if (!line.len || line.buf[0] == '#')
> continue;
> if (is_absolute_path(line.buf)) {
> - odb_add_to_alternates_file(the_repository->objects,
> - line.buf);
> + strvec_push(alternates, line.buf);
> continue;
> }
> abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf);
> if (!normalize_path_copy(abs_path, abs_path))
> - odb_add_to_alternates_file(the_repository->objects,
> - abs_path);
> + strvec_push(alternates, abs_path);
> else
> warning("skipping invalid relative alternate: %s/%s",
> src_repo, line.buf);
> free(abs_path);
> }
> +
> +out:
> + strbuf_release(&path);
> strbuf_release(&line);
> - fclose(in);
> + if (in)
> + fclose(in);
Why not put this before the `out` label and remove the if?
> }
--
Laters,
Toon
next prev parent reply other threads:[~2026-08-28 14:53 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 14:11 [PATCH 0/8] odb: write alternates at creation time Patrick Steinhardt
2026-08-25 14:11 ` [PATCH 1/8] builtin/clone: defer setup of the object database Patrick Steinhardt
2026-08-25 14:11 ` [PATCH 2/8] builtin/clone: move around `setup_reference()` Patrick Steinhardt
2026-08-25 14:11 ` [PATCH 3/8] builtin/clone: refactor handling of "--reference{,-if-able}" Patrick Steinhardt
2026-08-28 14:52 ` Toon Claes
2026-08-25 14:11 ` [PATCH 4/8] builtin/clone: move setup of alternates for shared local clones Patrick Steinhardt
2026-08-28 14:52 ` Toon Claes
2026-08-25 14:11 ` [PATCH 5/8] builtin/clone: move setup of alternates for non-shared " Patrick Steinhardt
2026-08-28 14:52 ` Toon Claes [this message]
2026-08-31 8:13 ` Patrick Steinhardt
2026-08-25 14:11 ` [PATCH 6/8] odb/source: support writing alternates when creating the database Patrick Steinhardt
2026-08-28 14:53 ` Toon Claes
2026-08-31 8:14 ` Patrick Steinhardt
2026-08-28 19:13 ` Junio C Hamano
2026-08-31 8:14 ` Patrick Steinhardt
2026-08-25 14:11 ` [PATCH 7/8] builtin/clone: write alternates via `odb_create_on_disk()` Patrick Steinhardt
2026-08-25 14:11 ` [PATCH 8/8] odb/source: remove the ability to write alternates Patrick Steinhardt
2026-08-28 14:53 ` Toon Claes
2026-08-31 8:14 ` Patrick Steinhardt
2026-08-31 10:02 ` [PATCH v2 0/8] odb: write alternates at creation time Patrick Steinhardt
2026-08-31 10:02 ` [PATCH v2 1/8] builtin/clone: defer setup of the object database Patrick Steinhardt
2026-09-06 16:42 ` Justin Tobler
2026-09-07 7:23 ` Patrick Steinhardt
2026-08-31 10:02 ` [PATCH v2 2/8] builtin/clone: move around `setup_reference()` Patrick Steinhardt
2026-08-31 10:02 ` [PATCH v2 3/8] builtin/clone: refactor handling of "--reference{,-if-able}" Patrick Steinhardt
2026-08-31 10:02 ` [PATCH v2 4/8] builtin/clone: move setup of alternates for shared local clones Patrick Steinhardt
2026-08-31 10:02 ` [PATCH v2 5/8] builtin/clone: move setup of alternates for non-shared " Patrick Steinhardt
2026-08-31 10:02 ` [PATCH v2 6/8] odb/source: support writing alternates when creating the database Patrick Steinhardt
2026-09-06 17:02 ` Justin Tobler
2026-09-07 7:23 ` Patrick Steinhardt
2026-08-31 10:02 ` [PATCH v2 7/8] builtin/clone: write alternates via `odb_create_on_disk()` Patrick Steinhardt
2026-09-06 17:07 ` Justin Tobler
2026-08-31 10:02 ` [PATCH v2 8/8] odb/source: remove the ability to write alternates Patrick Steinhardt
2026-09-01 6:09 ` [PATCH v2 0/8] odb: write alternates at creation time Toon Claes
2026-09-07 8:25 ` [PATCH v3 0/9] " Patrick Steinhardt
2026-09-07 8:25 ` [PATCH v3 1/9] setup: split up concerns of `init_db()` Patrick Steinhardt
2026-09-08 22:12 ` Justin Tobler
2026-09-09 5:48 ` Patrick Steinhardt
2026-09-07 8:25 ` [PATCH v3 2/9] builtin/clone: defer setup of the object database Patrick Steinhardt
2026-09-08 22:20 ` Justin Tobler
2026-09-09 5:48 ` Patrick Steinhardt
2026-09-07 8:25 ` [PATCH v3 3/9] builtin/clone: move around `setup_reference()` Patrick Steinhardt
2026-09-07 8:25 ` [PATCH v3 4/9] builtin/clone: refactor handling of "--reference{,-if-able}" Patrick Steinhardt
2026-09-07 8:25 ` [PATCH v3 5/9] builtin/clone: move setup of alternates for shared local clones Patrick Steinhardt
2026-09-08 22:43 ` Justin Tobler
2026-09-08 22:48 ` Justin Tobler
2026-09-07 8:25 ` [PATCH v3 6/9] builtin/clone: move setup of alternates for non-shared " Patrick Steinhardt
2026-09-07 8:25 ` [PATCH v3 7/9] odb/source: support writing alternates when creating the database Patrick Steinhardt
2026-09-07 8:25 ` [PATCH v3 8/9] builtin/clone: write alternates via `odb_create_on_disk()` Patrick Steinhardt
2026-09-07 8:25 ` [PATCH v3 9/9] odb/source: remove the ability to write alternates Patrick Steinhardt
2026-09-09 5:48 ` [PATCH v4 0/9] odb: write alternates at creation time Patrick Steinhardt
2026-09-09 5:48 ` [PATCH v4 1/9] setup: split up concerns of `init_db()` Patrick Steinhardt
2026-09-10 9:24 ` Karthik Nayak
2026-09-09 5:48 ` [PATCH v4 2/9] builtin/clone: defer setup of the object database Patrick Steinhardt
2026-09-10 9:28 ` Karthik Nayak
2026-09-09 5:48 ` [PATCH v4 3/9] builtin/clone: move around `setup_reference()` Patrick Steinhardt
2026-09-10 9:29 ` Karthik Nayak
2026-09-09 5:48 ` [PATCH v4 4/9] builtin/clone: refactor handling of "--reference{,-if-able}" Patrick Steinhardt
2026-09-10 9:37 ` Karthik Nayak
2026-09-10 14:26 ` Patrick Steinhardt
2026-09-09 5:48 ` [PATCH v4 5/9] builtin/clone: move setup of alternates for shared local clones Patrick Steinhardt
2026-09-10 10:52 ` Karthik Nayak
2026-09-10 10:54 ` Karthik Nayak
2026-09-10 14:26 ` Patrick Steinhardt
2026-09-09 5:48 ` [PATCH v4 6/9] builtin/clone: move setup of alternates for non-shared " Patrick Steinhardt
2026-09-10 11:00 ` Karthik Nayak
2026-09-09 5:48 ` [PATCH v4 7/9] odb/source: support writing alternates when creating the database Patrick Steinhardt
2026-09-10 11:10 ` Karthik Nayak
2026-09-11 5:15 ` Patrick Steinhardt
2026-09-09 5:48 ` [PATCH v4 8/9] builtin/clone: write alternates via `odb_create_on_disk()` Patrick Steinhardt
2026-09-09 5:48 ` [PATCH v4 9/9] odb/source: remove the ability to write alternates Patrick Steinhardt
2026-09-09 18:30 ` [PATCH v4 0/9] odb: write alternates at creation time Justin Tobler
2026-09-10 15:09 ` [PATCH v5 " Patrick Steinhardt
2026-09-10 15:09 ` [PATCH v5 1/9] setup: split up concerns of `init_db()` Patrick Steinhardt
2026-09-10 15:09 ` [PATCH v5 2/9] builtin/clone: defer setup of the object database Patrick Steinhardt
2026-09-10 15:09 ` [PATCH v5 3/9] builtin/clone: move around `setup_reference()` Patrick Steinhardt
2026-09-10 15:09 ` [PATCH v5 4/9] builtin/clone: refactor handling of "--reference{,-if-able}" Patrick Steinhardt
2026-09-10 15:09 ` [PATCH v5 5/9] builtin/clone: move setup of alternates for shared local clones Patrick Steinhardt
2026-09-10 15:09 ` [PATCH v5 6/9] builtin/clone: move setup of alternates for non-shared " Patrick Steinhardt
2026-09-10 15:09 ` [PATCH v5 7/9] odb/source: support writing alternates when creating the database Patrick Steinhardt
2026-09-10 15:09 ` [PATCH v5 8/9] builtin/clone: write alternates via `odb_create_on_disk()` Patrick Steinhardt
2026-09-10 15:09 ` [PATCH v5 9/9] odb/source: remove the ability to write alternates Patrick Steinhardt
2026-09-10 19:53 ` [PATCH v5 0/9] odb: write alternates at creation time Karthik Nayak
2026-09-11 5:15 ` Patrick Steinhardt
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=874igeuwja.fsf@emacs.iotcl.com \
--to=toon@iotcl.com \
--cc=git@vger.kernel.org \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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