From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 01/13] odb: fix subtle logic to check whether an alternate is usable
Date: Fri, 24 Oct 2025 09:21:23 -0700 [thread overview]
Message-ID: <xmqqo6pwp8xo.fsf@gitster.g> (raw)
In-Reply-To: <20251024-b4-pks-odb-loose-backend-v1-1-1a4202273c38@pks.im> (Patrick Steinhardt's message of "Fri, 24 Oct 2025 11:56:00 +0200")
Patrick Steinhardt <ps@pks.im> writes:
> +static int alt_odb_usable(struct object_database *o, const char *path,
> + const char *normalized_objdir)
> {
> int r;
>
> /* Detect cases where alternate disappeared */
> - if (!is_directory(path->buf)) {
> + if (!is_directory(path)) {
> error(_("object directory %s does not exist; "
> "check .git/objects/info/alternates"),
> - path->buf);
> + path);
> return 0;
> }
>
> @@ -113,11 +112,14 @@ static int alt_odb_usable(struct object_database *o,
> assert(r == 1); /* never used */
> kh_value(o->source_by_path, p) = o->sources;
> }
> - if (fspatheq(path->buf, normalized_objdir))
> +
> + if (fspatheq(path, normalized_objdir))
> + return 0;
> +
> + if (kh_get_odb_path_map(o->source_by_path, path) < kh_end(o->source_by_path))
> return 0;
> - *pos = kh_put_odb_path_map(o->source_by_path, path->buf, &r);
> - /* r: 0 = exists, 1 = never used, 2 = deleted */
> - return r == 0 ? 0 : 1;
> +
> + return 1;
> }
In other words, when we say "we ask if this is usable", it says "yes
it is usable" or "no it is not", but ...
> @@ -148,6 +150,7 @@ static struct odb_source *link_alt_odb_entry(struct object_database *odb,
> struct strbuf pathbuf = STRBUF_INIT;
> struct strbuf tmp = STRBUF_INIT;
> khiter_t pos;
> + int ret;
>
> if (!is_absolute_path(dir) && relative_base) {
> strbuf_realpath(&pathbuf, relative_base, 1);
> @@ -172,20 +175,21 @@ static struct odb_source *link_alt_odb_entry(struct object_database *odb,
> strbuf_reset(&tmp);
> strbuf_realpath(&tmp, odb->sources->path, 1);
>
> - if (!alt_odb_usable(odb, &pathbuf, tmp.buf, &pos))
> + if (!alt_odb_usable(odb, pathbuf.buf, tmp.buf))
> goto error;
>
> CALLOC_ARRAY(alternate, 1);
> alternate->odb = odb;
> alternate->local = false;
> - /* pathbuf.buf is already in r->objects->source_by_path */
> alternate->path = strbuf_detach(&pathbuf, NULL);
>
> /* add the alternate entry */
> *odb->sources_tail = alternate;
> odb->sources_tail = &(alternate->next);
> - alternate->next = NULL;
> - assert(odb->source_by_path);
> +
> + pos = kh_put_odb_path_map(odb->source_by_path, alternate->path, &ret);
> + if (!ret)
> + BUG("source must not yet exist");
... responding to the answer and saying "ok, if it is usable, then
let's use it" is a responsibility of the caller. Which makes sense.
> kh_value(odb->source_by_path, pos) = alternate;
>
> /* recursively add alternates */
next prev parent reply other threads:[~2025-10-24 16:21 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-24 9:55 [PATCH 00/13] Carve out loose object source Patrick Steinhardt
2025-10-24 9:56 ` [PATCH 01/13] odb: fix subtle logic to check whether an alternate is usable Patrick Steinhardt
2025-10-24 16:21 ` Junio C Hamano [this message]
2025-10-30 10:34 ` Karthik Nayak
2025-10-24 9:56 ` [PATCH 02/13] odb: introduce `odb_source_new()` Patrick Steinhardt
2025-10-24 16:37 ` Junio C Hamano
2025-10-27 11:21 ` Patrick Steinhardt
2025-10-24 9:56 ` [PATCH 03/13] odb: adjust naming to free object sources Patrick Steinhardt
2025-10-30 10:41 ` Karthik Nayak
2025-10-24 9:56 ` [PATCH 04/13] object-file: move `fetch_if_missing` Patrick Steinhardt
2025-10-24 9:56 ` [PATCH 05/13] object-file: introduce `struct odb_loose_source` Patrick Steinhardt
2025-10-30 10:47 ` Karthik Nayak
2025-10-30 11:32 ` Patrick Steinhardt
2025-10-31 6:11 ` Patrick Steinhardt
2025-10-31 16:16 ` Junio C Hamano
2025-11-03 7:19 ` Patrick Steinhardt
2025-10-31 16:10 ` Junio C Hamano
2025-10-24 9:56 ` [PATCH 06/13] object-file: move loose object cache into loose source Patrick Steinhardt
2025-10-24 21:44 ` Junio C Hamano
2025-10-27 11:21 ` Patrick Steinhardt
2025-10-24 9:56 ` [PATCH 07/13] object-file: hide internals when we need to reprepare loose sources Patrick Steinhardt
2025-10-24 9:56 ` [PATCH 08/13] object-file: move loose object map into loose source Patrick Steinhardt
2025-10-24 9:56 ` [PATCH 09/13] object-file: read objects via the loose object source Patrick Steinhardt
2025-10-30 12:19 ` Karthik Nayak
2025-10-24 9:56 ` [PATCH 10/13] object-file: rename `has_loose_object()` Patrick Steinhardt
2025-10-24 9:56 ` [PATCH 11/13] object-file: refactor freshening of objects Patrick Steinhardt
2025-10-24 9:56 ` [PATCH 12/13] object-file: rename `write_object_file()` Patrick Steinhardt
2025-10-24 9:56 ` [PATCH 13/13] object-file: refactor writing objects via a stream Patrick Steinhardt
2025-10-30 12:24 ` [PATCH 00/13] Carve out loose object source Karthik Nayak
2025-10-31 6:12 ` [PATCH v2 " Patrick Steinhardt
2025-10-31 6:12 ` [PATCH v2 01/13] odb: fix subtle logic to check whether an alternate is usable Patrick Steinhardt
2025-10-31 6:12 ` [PATCH v2 02/13] odb: introduce `odb_source_new()` Patrick Steinhardt
2025-10-31 6:12 ` [PATCH v2 03/13] odb: adjust naming to free object sources Patrick Steinhardt
2025-10-31 6:12 ` [PATCH v2 04/13] object-file: move `fetch_if_missing` Patrick Steinhardt
2025-10-31 6:12 ` [PATCH v2 05/13] object-file: introduce `struct odb_loose_source` Patrick Steinhardt
2025-10-31 6:12 ` [PATCH v2 06/13] object-file: move loose object cache into loose source Patrick Steinhardt
2025-10-31 6:12 ` [PATCH v2 07/13] object-file: hide internals when we need to reprepare loose sources Patrick Steinhardt
2025-10-31 6:12 ` [PATCH v2 08/13] object-file: move loose object map into loose source Patrick Steinhardt
2025-10-31 6:12 ` [PATCH v2 09/13] object-file: read objects via the loose object source Patrick Steinhardt
2025-10-31 6:12 ` [PATCH v2 10/13] object-file: rename `has_loose_object()` Patrick Steinhardt
2025-10-31 6:12 ` [PATCH v2 11/13] object-file: refactor freshening of objects Patrick Steinhardt
2025-10-31 6:12 ` [PATCH v2 12/13] object-file: rename `write_object_file()` Patrick Steinhardt
2025-10-31 6:12 ` [PATCH v2 13/13] object-file: refactor writing objects via a stream Patrick Steinhardt
2025-11-03 7:41 ` [PATCH v3 00/13] Carve out loose object source Patrick Steinhardt
2025-11-03 7:41 ` [PATCH v3 01/13] odb: fix subtle logic to check whether an alternate is usable Patrick Steinhardt
2025-11-03 7:41 ` [PATCH v3 02/13] odb: introduce `odb_source_new()` Patrick Steinhardt
2025-11-03 7:41 ` [PATCH v3 03/13] odb: adjust naming to free object sources Patrick Steinhardt
2025-11-03 7:41 ` [PATCH v3 04/13] object-file: move `fetch_if_missing` Patrick Steinhardt
2025-11-03 7:42 ` [PATCH v3 05/13] object-file: introduce `struct odb_source_loose` Patrick Steinhardt
2025-11-03 7:42 ` [PATCH v3 06/13] object-file: move loose object cache into loose source Patrick Steinhardt
2025-11-03 7:42 ` [PATCH v3 07/13] object-file: hide internals when we need to reprepare loose sources Patrick Steinhardt
2025-11-03 7:42 ` [PATCH v3 08/13] object-file: move loose object map into loose source Patrick Steinhardt
2025-11-03 7:42 ` [PATCH v3 09/13] object-file: read objects via the loose object source Patrick Steinhardt
2025-11-03 7:42 ` [PATCH v3 10/13] object-file: rename `has_loose_object()` Patrick Steinhardt
2025-11-03 7:42 ` [PATCH v3 11/13] object-file: refactor freshening of objects Patrick Steinhardt
2025-11-03 7:42 ` [PATCH v3 12/13] object-file: rename `write_object_file()` Patrick Steinhardt
2025-11-03 7:42 ` [PATCH v3 13/13] object-file: refactor writing objects via a stream Patrick Steinhardt
2025-11-03 13:39 ` [PATCH v3 00/13] Carve out loose object source Karthik Nayak
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=xmqqo6pwp8xo.fsf@gitster.g \
--to=gitster@pobox.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;
as well as URLs for NNTP newsgroup(s).