Git development
 help / color / mirror / Atom feed
From: Adrian Ratiu <adrian.ratiu@collabora.com>
To: git@vger.kernel.org
Cc: Adrian Ratiu <adrian.ratiu@collabora.com>,
	Junio C Hamano <gitster@pobox.com>,
	Patrick Steinhardt <ps@pks.im>,
	"Eric W . Biederman" <ebiederm@xmission.com>,
	"brian m . carlson" <sandals@crustytoothpaste.net>
Subject: [PATCH v3 0/4] compatObjectFormat: fix a BUG(), wrong ID and unknown headers
Date: Mon, 30 Nov 2026 15:43:21 +0200	[thread overview]
Message-ID: <cover.1795455594.git.adrian.ratiu@collabora.com> (raw)
In-Reply-To: <cover.1794932695.git.adrian.ratiu@collabora.com>

Hello all,

This is v3 of the compatObjectFormat fixes found while testing sha1-sha256
interop between Git, Gitoxide and Jujutsu.

Because patch 4 drops a check that 08a45903cb (object-file-convert: convert
commits that embed signed tags, 2023-10-01) added on purpose, I'd still welcome
a look from Eric or Brian.

Changes in v3:
 * Split the "<" to "<=" change for the "tree ", "parent " and "mergetag "
   headers into its own patch (3/4). (Junio)
 * Reword the note in patch 2 on which rev-parse arguments are covered. (Junio)
 * Simplify building the commit in the "empty mergetag line" test. (Junio)

v2: https://lore.kernel.org/git/cover.1794932695.git.adrian.ratiu@collabora.com/
v1: https://lore.kernel.org/git/20261112195740.2834341-1-adrian.ratiu@collabora.com/

Many thanks,
Adrian

Adrian Ratiu (4):
  setup: reject compatObjectFormat == objectFormat
  rev-parse: die when --output-object-format cannot map an object
  object-file-convert: match tree, parent and mergetag headers by key
  object-file-convert: copy unknown commit headers unchanged

 builtin/rev-parse.c           |  8 +++++---
 object-file-convert.c         | 35 ++++++++++++++++++++++-------------
 setup.c                       |  7 +++++++
 t/t1016-compatObjectFormat.sh | 33 +++++++++++++++++++++++++++++++++
 t/t1302-repo-version.sh       | 14 ++++++++++++++
 t/t1500-rev-parse.sh          | 14 ++++++++++++++
 6 files changed, 95 insertions(+), 16 deletions(-)

Range-diff against v2:
1:  f74a0fd67a = 1:  f74a0fd67a setup: reject compatObjectFormat == objectFormat
2:  5b91372748 ! 2:  5d5527aa40 rev-parse: die when --output-object-format cannot map an object
    @@ Commit message
         Fix it to die with the same message as pack-objects. The other callers
         of repo_oid_to_algop() already check its result.
     
    -    Note that this only covers the case where the user asks for a single
    -    revision, as it is the only case where rev-parse passes 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 it is left for a future patch
    -    series.
    +    Note that this covers every argument that names a single object,
    +    e.g. "git rev-parse --output-object-format=sha1 main next".
    +    Arguments that rev-parse expands into several objects, like the
    +    "A..B" and "A...B" ranges or the "rev^!", "rev^@" and "rev^-"
    +    shorthands, are printed by code that ignores the output format, so
    +    they still print storage IDs. Fixing that would be a bigger change,
    +    so it is left for a future series.
     
         Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
     
-:  ---------- > 3:  ed6dcdd93d object-file-convert: match tree, parent and mergetag headers by key
3:  26080a7a38 ! 4:  366b8c310d object-file-convert: copy unknown commit headers unchanged
    @@ Commit message
         The author, committer, encoding and gpgsig headers were already copied
         the same, so their separate cases are no longer needed.
     
    -    The "tree ", "parent " and "mergetag " cases only matched a line with
    -    something after the space. That didn't matter while all other lines
    -    were rejected, but they would now be copied. For a "mergetag " line
    -    whose tag starts on the next line, the object ID in the tag would be
    -    copied unconverted, even though Git reads that header as a mergetag and
    -    convert_commit_extra_headers() refuses to convert it.
    -
    -    Match these headers by their key alone instead, the way
    -    read_commit_extra_header_lines() does. Such a line with an empty or bad
    -    value is then rejected, as before. A "tree", "parent" or "mergetag"
    -    line without a space is not one of these headers to Git, so it is
    -    copied like any other unknown header, which is also what
    -    convert_commit_extra_headers() does.
    +    The "tree ", "parent " and "mergetag " cases match these headers by
    +    their key alone since the previous commit, so a line with an empty or
    +    bad value is still rejected instead of being copied. A "tree",
    +    "parent" or "mergetag" line without a space is not one of these
    +    headers to Git, so it is copied like any other unknown header, which
    +    is also what convert_commit_extra_headers() does.
     
         Alternatives considered:
     
    @@ Commit message
         Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
     
      ## object-file-convert.c ##
    -@@ object-file-convert.c: static int convert_commit_object(struct repository *repo,
    - 		if (!eol)
    - 			return error(_("bad %s in commit"), "line");
    - 
    --		if (((bufptr + 5) < eol) && !memcmp(bufptr, "tree ", 5))
    -+		if (((bufptr + 5) <= eol) && !memcmp(bufptr, "tree ", 5))
    - 		{
    - 			if (((bufptr + tree_entry_len) != eol) ||
    - 			    parse_oid_hex_algop(bufptr + 5, &oid, &p, from) ||
    -@@ object-file-convert.c: static int convert_commit_object(struct repository *repo,
    - 					     "tree", oid_to_hex(&oid));
    - 			strbuf_addf(out, "tree %s\n", oid_to_hex(&mapped_oid));
    - 		}
    --		else if (((bufptr + 7) < eol) && !memcmp(bufptr, "parent ", 7))
    -+		else if (((bufptr + 7) <= eol) && !memcmp(bufptr, "parent ", 7))
    - 		{
    - 			if (((bufptr + parent_entry_len) != eol) ||
    - 			    parse_oid_hex_algop(bufptr + 7, &oid, &p, from) ||
    -@@ object-file-convert.c: static int convert_commit_object(struct repository *repo,
    - 
    - 			strbuf_addf(out, "parent %s\n", oid_to_hex(&mapped_oid));
    - 		}
    --		else if (((bufptr + 9) < eol) && !memcmp(bufptr, "mergetag ", 9))
    -+		else if (((bufptr + 9) <= eol) && !memcmp(bufptr, "mergetag ", 9))
    - 		{
    - 			struct strbuf tag = STRBUF_INIT, new_tag = STRBUF_INIT;
    - 
     @@ object-file-convert.c: static int convert_commit_object(struct repository *repo,
      			strbuf_release(&tag);
      			strbuf_release(&new_tag);
    @@ t/t1016-compatObjectFormat.sh: do
     +	test_expect_success "reject a $hash commit with an empty mergetag line" '
     +		git cat-file tag committag >../${hash}_committag &&
     +		{
    -+			sed -n "/^committer /q;p" ../${hash}_commit2 &&
    -+			grep "^committer " ../${hash}_commit2 &&
    ++			sed -e "/^committer /q" ../${hash}_commit2 &&
     +			echo "mergetag " &&
     +			sed "s/^/ /" ../${hash}_committag &&
     +			echo &&

base-commit: 1891de46f79dc444a47db1c87bd0c8c76b5463f2
-- 
2.56.1


  parent reply	other threads:[~2026-11-30 13:45 UTC|newest]

Thread overview: 28+ 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   ` Adrian Ratiu [this message]
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-11-30 13:43     ` [PATCH v3 4/4] object-file-convert: copy unknown commit headers unchanged 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=cover.1795455594.git.adrian.ratiu@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