From: Patrick Steinhardt <ps@pks.im>
To: Adrian Ratiu <adrian.ratiu@collabora.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
"brian m . carlson" <sandals@crustytoothpaste.net>,
"Eric W . Biederman" <ebiederm@xmission.com>,
Axel Rasmussen <axelrasmussen@google.com>,
Emily Shaffer <emilyshaffer@google.com>,
Josh Steadmon <steadmon@google.com>
Subject: Re: [PATCH 2/3] rev-parse: die when --output-object-format cannot map an object
Date: Mon, 16 Nov 2026 08:37:02 +0100 [thread overview]
Message-ID: <avqynlDKnJpJn6RZ@pks.im> (raw)
In-Reply-To: <20261112195740.2834341-3-adrian.ratiu@collabora.com>
On Thu, Nov 12, 2026 at 09:57:39PM +0200, Adrian Ratiu wrote:
> "git rev-parse --output-object-format=<compat-format>" should print
> an object compat id when extensions.compatObjectFormat is enabled.
>
> Git however doesn't record a compat id for every object, e.g. for
> objects received by a fetch that goes through index-pack.
> For such objects, rev-parse silently prints the wrong id: it prints
> the storage id where the compat id is expected and exits with 0.
Yeah, that's just plain wrong and extremely confusing.
> This happens because rev-parse ignores the repo_oid_to_algop() return
> value. When no mapping is found, that function fails and leaves the
> id unchanged, so the storage id is what gets printed.
>
> Fix it to die with the same message as pack-objects. The other callers
> of repo_oid_to_algop() already check its result.
>
> This only covers a single revision argument, the one case where
> rev-parse converts its output. Other forms, such as "A..B" or "A^@",
> print storage ids whatever --output-object-format says. That is left
> for a separate change.
This paragraph is a bit hard to parse.
Note that this only covers the case where the user asks for a single
revision, as it is the only case where we pass the desired output hash
explicitly. All the other cases, like for example when the user passes
a range, do not use the desired output hash at all. Fixing that would
be a bigger change though, so this is left for a future patch series.
> The test copies a loose object into the repository by hand, so it
> doesn't depend on whether fetch writes compat mappings.
Do we have to do that? I'm mostly asking in the context of the new
object storage format extension, which may change where and how exactly
objects are stored. So all tests that manually modify the object
database will break, and we'll want and need to fix those.
> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
> index d2154eac8d..ab2898ba52 100644
> --- a/builtin/rev-parse.c
> +++ b/builtin/rev-parse.c
> @@ -1171,9 +1171,11 @@ int cmd_rev_parse(int argc,
> }
> if (!repo_get_oid_with_flags(the_repository, name, &oid,
> flags)) {
> - if (output_algo)
> - repo_oid_to_algop(the_repository, &oid,
> - output_algo, &oid);
> + if (output_algo &&
> + repo_oid_to_algop(the_repository, &oid,
> + output_algo, &oid))
> + die(_("cannot map object %s to %s"),
> + oid_to_hex(&oid), output_algo->name);
Makes sense. I would have checked for `< 0`, but that ultimately doesn't
matter much.
> diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
> index 30bf8a4d0a..c15d9953a8 100755
> --- a/t/t1500-rev-parse.sh
> +++ b/t/t1500-rev-parse.sh
> @@ -241,6 +241,24 @@ test_expect_success RUST 'rev-parse --show-object-format in repo with compat mod
> )
> '
>
> +test_expect_success RUST 'rev-parse --output-object-format with unmapped object' '
> + test_when_finished "rm -rf plain compat" &&
> + git init --object-format=sha256 plain &&
> + git init --object-format=sha256 compat &&
> + git -C compat config extensions.compatobjectformat sha1 &&
> + oid=$(echo unmapped | git -C plain hash-object -w --stdin) &&
> + # copy the object by hand, so that no compat mapping is written for it
Instead of copying by hand, wouldn't it be possible to write the object
with the compat object format unset and then set it afterwards? That
should also ensure that we don't have the compat hash.
Patrick
next prev parent reply other threads:[~2026-11-16 7:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 19:57 [PATCH 0/3] compatObjectFormat: fix a BUG(), wrong id and unknown headers Adrian Ratiu
2026-11-12 19:57 ` [PATCH 1/3] setup: reject compatObjectFormat == objectFormat Adrian Ratiu
2026-11-16 7:36 ` Patrick Steinhardt
2026-11-17 10:42 ` Adrian Ratiu
2026-11-12 19:57 ` [PATCH 2/3] rev-parse: die when --output-object-format cannot map an object Adrian Ratiu
2026-11-16 7:37 ` Patrick Steinhardt [this message]
2026-11-17 11:55 ` Adrian Ratiu
2026-11-12 19:57 ` [PATCH 3/3] object-file-convert: copy unknown commit headers unchanged Adrian Ratiu
2026-11-16 7:37 ` Patrick Steinhardt
2026-11-17 15:27 ` Adrian Ratiu
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=avqynlDKnJpJn6RZ@pks.im \
--to=ps@pks.im \
--cc=adrian.ratiu@collabora.com \
--cc=axelrasmussen@google.com \
--cc=ebiederm@xmission.com \
--cc=emilyshaffer@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sandals@crustytoothpaste.net \
--cc=steadmon@google.com \
/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