From: Adrian Ratiu <adrian.ratiu@collabora.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>,
"brian m . carlson" <sandals@crustytoothpaste.net>
Subject: Re: [PATCH v3 4/4] object-file-convert: copy unknown commit headers unchanged
Date: Fri, 04 Dec 2026 23:25:25 +0200 [thread overview]
Message-ID: <874icsg2m2.fsf@collabora.com> (raw)
In-Reply-To: <8733sddjk9.fsf@email.froward.int.ebiederm.org>
Hi Eric,
Really appreciate your review, thanks!
On Fri, 04 Dec 2026, "Eric W. Biederman" <ebiederm@xmission.com> wrote:
> I don't understand what the problem is with the behavior that was
> deliberately added in commit 08a45903cb32 ("object-file-convert: convert
> commits that embed signed tags").
Taking a step back, I'll try to keep this as short & sweet as I can. :)
Jujutsu can use a Git repo as its backend and starting with jj v0.30, it
records its own change ID in every commit it writes by default, as an
extra header after "committer":
change-id <32 characters from jj's k-z alphabet>
(jj's change ID is not an object ID and doesn't refer to anything in the
object store, it's just a random 16-byte value written in reverse hex,
that stays the same when jj rewrites a commit.)
While testing sha1-sha256 interop between Git, Gitoxide and jj, I found
that none of these commits can be converted in a repository with
extensions.compatObjectFormat enabled:
1. git fetch of a jj commit fails: "Failed to convert object from sha256
to sha1" and "unpack-objects failed". So does git hash-object -w.
2. git commit --amend on such a commit succeeds: commit_tree_extended()
converts the extra headers with convert_commit_extra_headers(),
which copies unknown headers. It records a compat ID for the new
commit, but reading that compat ID back fails with the same error.
Basically one path rejects the header and the other accepts it. :)
The repo ends up with compat IDs that Git itself can't read.
Here is an example reproducer with jj v0.47.1 and git 2.56.1:
# A SHA-256 repo with SHA-1 compat IDs
git init -q --object-format=sha256 compat
git -C compat config extensions.compatObjectFormat sha1
git -C compat commit -q --allow-empty -m base
# A jj commit on top of it, in a clone without compat
git clone -q compat plain
(cd plain && jj git init --colocate && jj commit -m 'made by jj')
git -C plain cat-file commit HEAD | grep change-id
# change-id xlzosozsspsklvyrmyztsvykqvkpuyky
# 1. Pulling it fails
git -C compat pull -q ../plain HEAD
# fatal: Failed to convert object from sha256 to sha1
# fatal: unpack-objects failed
# 2. index-pack converts nothing, so this pull works. The amend
# then records a compat ID that can't be read back.
git -C compat -c fetch.unpackLimit=1 pull -q ../plain HEAD
git -C compat commit -q --amend --allow-empty -m amended
c=$(git -C compat rev-parse --output-object-format=sha1 HEAD)
git -C compat cat-file -p $c
# fatal: Failed to convert object from sha256 to sha1
With this series the above works without errors.
> Fundamentally if a header holds a object id the code needs to know about
> the header or the commit can not be converted. Ignoring that
> possibility will result in inconsistent and improper conversions that
> affect the structure of the git tree.
I agree and jj also has such a header: for a commit with unresolved
conflicts (yes, committing conflicts is a jj feature :)), it records the
IDs of the conflicting trees:
jj:trees <tree ID> <tree ID> <tree ID>
Copied unconverted, these IDs are wrong in the compat commit.
Git's own graph isn't affected, though. In either format, Git only
reads object IDs from the tree, parent and mergetag headers. What breaks
is the meaning the other tool gave to the header.
> When git isn't converting commits it doesn't matter so I also don't
> see a problem with the two code paths being different, as the difference
> is in their fundamental responsibilities.
In a compat repo, creating a commit also converts it: git commit writes
the sha256 commit, builds its sha1 version and records that ID. It
builds the sha1 headers with convert_commit_extra_headers() which copies
unknown headers.
So both code paths do the same job: produce the sha1 version of a
commit. When they disagree, git commit records a compat ID that
convert_commit_object() then refuses to produce.
I tried a commit with an "x-related <sha256 commit ID>" header:
1. git hash-object -w refuses it.
2. git commit --amend accepts it, copies the ID unconverted, and
records a compat ID that then can't be read back.
So git commit already produces the commit you're worried about. If we
fail on such headers, both paths have to fail, see my proposal below.
> My sense is that deliberately failing is better than generating a
> garbage commit. I think that should definitely be the default.
I agree that failing is better than writing garbage, but today Git does
both: git commit records a compat ID for such a commit, and
convert_commit_object() then refuses to produce the commit behind it.
You're right, though, that this patch lets more commands accept such a
commit silently (fetch, hash-object, reading by compat ID), where today
they fail loudly.
> Fundamentally the code must be updated whenever someone adds a new
> header that adds additional object ids.
>
> For me the question is how does the code reasonably detect new headers
> with object ids and fail those while allowing the other non-problematic
> cases to work.
>
> The paths I see are whitelisting all headers. Or having something that
> scans the unknown like and causes the conversion to fail if it includes
> anything that looks like an object id.
A whitelist would make Git decide which tools may add headers, which
Patrick argued against in v1 [1]. He was also skeptical of recognizing
IDs automatically, but that was about converting them, here we'd only
refuse them.
I don't have a strong opinion on this and am willing to follow any
guidance/consensus. A scan would be a good solution for me personally,
since in jj the change IDs use letters k-z and never look like hex
object IDs, while commits with conflicts would continue to be refused.
So in v4 I could keep failing on unknown headers, but only on those that
look like they hold an object ID, and copy the rest. Both
convert_commit_object() and convert_commit_extra_headers() would use the
same check, so the two paths can't disagree again.
Would that work for you? I'm open to other suggestions.
> It might make sense to add a warning in the ordinary commit case about
> headers that we don't know how to commit.
With the check above, the ordinary commit case would fail on headers
that look like they hold an object ID, instead of warning.
Warning about all other unknown headers would fire on every jj commit
that git rewrites (e.g. git commit --amend), so I'd rather copy those
silently.
If you'd prefer only a warning for the first kind, the read path would
have to accept the same commits too or we're back to compat IDs that
can't be read.
> How do we prevent creating a corrupt git archive? If there are such
> headers the converted archive will be corrupt when the non-converted
> archive is fine.
For the headers Git knows, the converted graph is complete and fsck is
happy. Unknown headers that hold full object IDs would be refused by the
check above instead of being copied. Abbreviated or otherwise encoded
IDs would still get through so the check can't prevent every case.
To fully prevent it, Git needs to know which headers hold object
IDs. Patrick suggested a well-known header prefix for them,
e.g. "x-obj-foo <oid>" [1], which would also let Git convert them.
I think that's the correct long-term fix, but it's outside the scope for
this series.
[1] https://lore.kernel.org/git/avqypRLPLZZFNqRs@pks.im/
Thanks again,
Adrian
prev parent reply other threads:[~2026-12-04 21:25 UTC|newest]
Thread overview: 32+ 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
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
2026-11-19 14:18 ` [PATCH v2 0/3] compatObjectFormat: fix a BUG(), wrong ID and unknown headers Adrian Ratiu
2026-11-19 14:18 ` [PATCH v2 1/3] setup: reject compatObjectFormat == objectFormat Adrian Ratiu
2026-11-20 22:21 ` Junio C Hamano
2026-11-19 14:18 ` [PATCH v2 2/3] rev-parse: die when --output-object-format cannot map an object Adrian Ratiu
2026-11-20 22:29 ` Junio C Hamano
2026-11-23 16:12 ` Adrian Ratiu
2026-11-19 14:18 ` [PATCH v2 3/3] object-file-convert: copy unknown commit headers unchanged Adrian Ratiu
2026-11-20 22:41 ` Junio C Hamano
2026-11-23 16:41 ` Adrian Ratiu
2026-11-21 0:30 ` Junio C Hamano
2026-11-21 19:08 ` Junio C Hamano
2026-11-23 16:16 ` Adrian Ratiu
2026-11-21 2:59 ` [PATCH v2 0/3] compatObjectFormat: fix a BUG(), wrong ID and unknown headers Junio C Hamano
2026-11-30 13:43 ` [PATCH v3 0/4] " Adrian Ratiu
2026-11-30 13:43 ` [PATCH v3 1/4] setup: reject compatObjectFormat == objectFormat Adrian Ratiu
2026-11-30 13:43 ` [PATCH v3 2/4] rev-parse: die when --output-object-format cannot map an object Adrian Ratiu
2026-11-30 13:43 ` [PATCH v3 3/4] object-file-convert: match tree, parent and mergetag headers by key Adrian Ratiu
2026-12-01 8:15 ` Patrick Steinhardt
2026-12-01 11:29 ` Adrian Ratiu
2026-11-30 13:43 ` [PATCH v3 4/4] object-file-convert: copy unknown commit headers unchanged Adrian Ratiu
2026-12-04 17:47 ` Eric W. Biederman
2026-12-04 21:25 ` Adrian Ratiu [this message]
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=874icsg2m2.fsf@collabora.com \
--to=adrian.ratiu@collabora.com \
--cc=ebiederm@xmission.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ps@pks.im \
--cc=sandals@crustytoothpaste.net \
/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