🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.git
20 messages
20 total messages Started by Adrian Ratiu Thu, 12 Nov 2026 19:57
[PATCH 0/3] compatObjectFormat: fix a BUG(), wrong id and unknown headers
#3041
Author: Adrian Ratiu
Date: Thu, 12 Nov 2026 19:57
37 lines
10499 bytes
Hello all,

I've been continuing my three-way Git, Gitoxide and Jujutsu sha1-sha256
interop testing and uncovered three more bugs, this time in Git's
compatObjectFormat.

I'm reasonably confident in the first two patches.

The last patch needs careful review, because there are two conflicting
behaviors: Git copies unknown commit headers when it creates commits,
but rejects them when converting existing ones.

I made both copy them, which removes a check added on purpose in
08a45903cb (object-file-convert: convert commits that embed signed tags,
2023-10-01) and I'm not 100% sure it's the right direction.

More details in the commit messages.

Many thanks,
Adrian

Adrian Ratiu (3):
  setup: reject compatObjectFormat == objectFormat
  rev-parse: die when --output-object-format cannot map an object
  object-file-convert: copy unknown commit headers unchanged

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

-- 
2.56.1
[PATCH v2 0/3] compatObjectFormat: fix a BUG(), wrong ID and unknown headers
#3389
Author: Adrian Ratiu
Date: Thu, 19 Nov 2026 14:18
330 lines
26257 bytes
Hello all,

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

Because patch 3 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 v2:
 * Check repo_oid_to_algop() for "< 0" and reword the note on which
   rev-parse forms are covered. The test now writes the object before
   enabling compat instead of copying it into the object directory by
   hand. (Patrick)
 * Match the "tree ", "parent " and "mergetag " headers by their key,
   like read_commit_extra_header_lines() does. (Patrick)
 * Minor casing, spacing, doc and commit msg fixes (Patrick)

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

Many thanks,
Adrian

Adrian Ratiu (3):
  setup: reject compatObjectFormat == objectFormat
  rev-parse: die when --output-object-format cannot map an object
  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 | 34 ++++++++++++++++++++++++++++++++++
 t/t1302-repo-version.sh       | 14 ++++++++++++++
 t/t1500-rev-parse.sh          | 14 ++++++++++++++
 6 files changed, 96 insertions(+), 16 deletions(-)

Range-diff against v1:
1:  53c814a1e1 ! 1:  f74a0fd67a setup: reject compatObjectFormat == objectFormat
    @@ setup.c: int verify_repository_format(const struct repository_format *format,
      
     +	if (format->compat_hash_algo == format->hash_algo) {
     +		strbuf_addf(err, _("'%s' is '%s', the same as the object format"),
    -+			    "extensions.compatobjectformat",
    ++			    "extensions.compatObjectFormat",
     +			    hash_algos[format->hash_algo].name);
     +		return -1;
     +	}
    @@ t/t1302-repo-version.sh: abort 0 noop-v1
     +	test_expect_success "compatObjectFormat equal to objectFormat $hash" "
     +		test_when_finished 'rm -rf same' &&
     +		git init --object-format=$hash same &&
    -+		git -C same config core.repositoryformatversion 1 &&
    -+		git -C same config extensions.compatObjectFormat $hash &&
    ++		git -C same config set core.repositoryformatversion 1 &&
    ++		git -C same config set extensions.compatObjectFormat $hash &&
     +		test_must_fail git -C same rev-parse --git-dir 2>err &&
    -+		test_grep \"'extensions.compatobjectformat' is '$hash', the same as the object format\" err &&
    -+		git config --file=same/.git/config --unset extensions.compatObjectFormat &&
    ++		test_grep \"'extensions.compatObjectFormat' is '$hash', the same as the object format\" err &&
    ++		git config unset --file=same/.git/config extensions.compatObjectFormat &&
     +		git -C same rev-parse --git-dir
     +	"
     +done
2:  066fc59207 ! 2:  5b91372748 rev-parse: die when --output-object-format cannot map an object
    @@ Commit message
         rev-parse: die when --output-object-format cannot map an object
     
         "git rev-parse --output-object-format=<compat-format>" should print
    -    an object compat id when extensions.compatObjectFormat is enabled.
    +    the compat ID of an object when extensions.compatObjectFormat is
    +    enabled.
     
    -    Git however doesn't record a compat id for every object, e.g. for
    +    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.
    +    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.
     
         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.
    +    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.
    -
    -    The test copies a loose object into the repository by hand, so it
    -    doesn't depend on whether fetch writes compat mappings.
    +    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.
     
         Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
     
    @@ builtin/rev-parse.c: int cmd_rev_parse(int argc,
     -						  output_algo, &oid);
     +			if (output_algo &&
     +			    repo_oid_to_algop(the_repository, &oid,
    -+					      output_algo, &oid))
    ++					      output_algo, &oid) < 0)
     +				die(_("cannot map object %s to %s"),
     +				    oid_to_hex(&oid), output_algo->name);
      			if (verify)
    @@ t/t1500-rev-parse.sh: test_expect_success RUST 'rev-parse --show-object-format i
      '
      
     +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
    -+	path=$(test_oid_to_path $oid) &&
    -+	mkdir compat/.git/objects/${path%/*} &&
    -+	cp plain/.git/objects/$path compat/.git/objects/$path &&
    ++	test_when_finished "rm -rf unmapped" &&
    ++	git init --object-format=sha256 unmapped &&
    ++	# write the object before enabling compat, so it gets no compat mapping
    ++	oid=$(echo unmapped | git -C unmapped hash-object -w --stdin) &&
    ++	git -C unmapped config set extensions.compatObjectFormat sha1 &&
     +	echo $oid >expect &&
    -+	git -C compat rev-parse --output-object-format=sha256 $oid >actual &&
    ++	git -C unmapped rev-parse --output-object-format=sha256 $oid >actual &&
     +	test_cmp expect actual &&
    -+	test_must_fail git -C compat rev-parse --output-object-format=sha1 $oid >actual 2>err &&
    ++	test_must_fail git -C unmapped rev-parse --output-object-format=sha1 $oid >actual 2>err &&
     +	test_must_be_empty actual &&
     +	test_grep "cannot map object $oid to sha1" err
     +'
3:  a171e86b54 ! 3:  26080a7a38 object-file-convert: copy unknown commit headers unchanged
    @@ Commit message
         don't know:
     
         1. When a commit is created with commit_tree_extended(), as
    -       "git commit" does, convert_commit_extra_headers() copies unknown
    +       git-commit(1) does, convert_commit_extra_headers() copies unknown
            headers unchanged.
     
    -    2. When an existing commit object is converted (git hash-object -w)
    -       or when it's read by its compat id, convert_commit_object() fails
    +    2. When an existing commit object is converted (git-hash-object(1) -w)
    +       or when it's read by its compat ID, convert_commit_object() fails
            on them instead.
     
    -    So git hash-object refuses such a commit, while git commit --amend
    -    records a compat id for it that can't be read back:
    +    So git-hash-object(1) refuses such a commit, while "git commit --amend"
    +    records a compat ID for it that can't be read back:
            "Failed to convert object from sha256 to sha1".
     
         The rejection was added in 08a45903cb (object-file-convert: convert
         commits that embed signed tags, 2023-10-01). Git can't know what an
    -    unknown header holds. It might hold an object id that needs
    +    unknown header holds. It might hold an object ID that needs
         converting, so convert_commit_object() rejects all of them.
     
         Some tools rely on such headers though. Jujutsu, for example, writes
    @@ Commit message
         converted.
     
         Make convert_commit_object() copy unknown headers and their
    -    continuation lines unchanged, just like convert_commit_extra_headers()
    +    continuation lines unchanged, just like convert_commit_extra_headers(),
         so both give the same compat object.
     
         The author, committer, encoding and gpgsig headers were already copied
         the same, so their separate cases are no longer needed.
     
    -    A "tree", "parent" or "mergetag" line with nothing after the keyword
    -    used to be rejected as unknown and is now copied as well. Such a
    -    commit is malformed in both formats anyway.
    +    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.
     
         Alternatives considered:
     
    @@ Commit message
            Both paths would then agree, but commits from tools that add
            their own headers could not be used in a compat repo.
     
    -     - Copy only headers known to hold no object ids. Every tool would
    +     - Copy only headers known to hold no object IDs. Every tool would
            first need to get its headers added to that list.
     
    -    The test writes a commit with an unknown header with "git hash-object",
    -    amends it with "git commit", and checks that both commits map to the
    -    same objects in the SHA-1 and the SHA-256 repo.
    +     - Convert values that look like object IDs. Any other hex string
    +       could be taken for one, and Git shouldn't interpret headers it
    +       doesn't know.
    +
    +     - Also reject lines that don't look like "<key> <value>". This would
    +       make the two paths disagree again, because
    +       convert_commit_extra_headers() copies such lines, so
    +       "git commit --amend" would record compat IDs that can't be read
    +       back.
     
         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);
    @@ object-file-convert.c: static int convert_commit_object(struct repository *repo,
     -			/* Unknown line fail it might embed an oid */
     -			return -1;
     +			/*
    -+			 * Copy all other headers unchanged. author, committer, encoding and gpgsig
    -+			 * hold no object ids. For unknown headers we can't tell, so copy them too,
    -+			 * like convert_commit_extra_headers() does when the commit is written. Both
    -+			 * must give the same compat object.
    ++			 * Copy all other headers unchanged. author, committer,
    ++			 * encoding and gpgsig hold no object IDs. For unknown
    ++			 * headers we can't tell, so copy them too, like
    ++			 * convert_commit_extra_headers() does when the commit
    ++			 * is written. Both must give the same compat object.
    ++			 *
    ++			 * This means that a header holding object IDs is
    ++			 * copied without converting them. Any such header added
    ++			 * to Git needs its own case above, like parent or
    ++			 * mergetag, and the same conversion in
    ++			 * convert_commit_extra_headers().
     +			 *
    -+			 * This means that a header holding object ids is copied without converting
    -+			 * them. Any such header added to Git needs its own case above, like parent
    -+			 * or mergetag, and the same conversion in convert_commit_extra_headers().
    ++			 * The cases above match a header by its key alone, as
    ++			 * read_commit_extra_header_lines() does, so that e.g. a
    ++			 * "mergetag " line with nothing after the space is
    ++			 * still handled as a mergetag instead of being copied.
     +			 */
     +			strbuf_add(out, bufptr, (eol - bufptr) + 1);
      		}
    @@ object-file-convert.c: static int convert_commit_object(struct repository *repo,
     
      ## t/t1016-compatObjectFormat.sh ##
     @@ t/t1016-compatObjectFormat.sh: do
    - 		eval signedtag3_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag3) &&
      		eval signedtag4_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag4)
      	'
    + 
     +	test_expect_success "create a $hash commit with an unknown header" '
     +		git cat-file commit $(commit2_oid $hash) >../${hash}_commit2 &&
     +		awk "{ print } /^committer / { print \"x-unknown one\"; print \" two\" }" \
    @@ t/t1016-compatObjectFormat.sh: do
     +		eval unknownheader_${hash}_oid=$oid &&
     +		git branch unknownheader $oid
     +	'
    ++
     +	test_expect_success "amend a $hash commit with an unknown header" '
     +		git checkout unknownheader &&
     +		git commit --amend -m "Amend a commit with an unknown header" &&
    @@ t/t1016-compatObjectFormat.sh: do
     +		oid=$(git rev-parse HEAD) &&
     +		eval unknownheader2_${hash}_oid=$oid
     +	'
    - 
    ++
    ++	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 &&
    ++			echo "mergetag " &&
    ++			sed "s/^/ /" ../${hash}_committag &&
    ++			echo &&
    ++			echo message
    ++		} >../${hash}_emptymergetag &&
    ++		test_must_fail git hash-object -t commit -w ../${hash}_emptymergetag 2>err &&
    ++		test_grep "Failed to convert object" err
    ++	'
    ++
      	test_expect_success 'rev-parse maps oid of object borrowed from alternate' '
      		for repo in alt borrow
    + 		do
     @@ t/t1016-compatObjectFormat.sh: compare_oids 'blob' more "$more_sha1_oid" "$more_sha256_oid"
      compare_oids 'blob' another "$another_sha1_oid" "$another_sha256_oid"
      compare_oids 'tree' tree2 "$tree2_sha1_oid" "$tree2_sha256_oid"
-- 
2.56.1
[PATCH v2 1/3] setup: reject compatObjectFormat == objectFormat
#3392
Author: Adrian Ratiu
Date: Thu, 19 Nov 2026 14:18
68 lines
11729 bytes
When extensions.compatObjectFormat sets the same hash as the repo
object format, every command in a build with Rust aborts with:

  BUG: repository.c:204: hash_algo and compat_hash_algo match

This includes "git config", so the bad value can't be removed with
Git. It also happens with no extensions.objectFormat at all, when
compatObjectFormat is set to the default object format.

Check for this in verify_repository_format(), next to the other
repo format checks, and return an error instead.

The check runs before any of the Rust-only code. Builds without
Rust, which so far died because compatObjectFormat requires Rust,
now get the same error, so the test needs no RUST prereq.

Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
---
 setup.c                 |  7 +++++++
 t/t1302-repo-version.sh | 14 ++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/setup.c b/setup.c
index 186815c780..a97280cafe 100644
--- a/setup.c
+++ b/setup.c
@@ -918,6 +918,13 @@ int verify_repository_format(const struct repository_format *format,
 		return -1;
 	}
 
+	if (format->compat_hash_algo == format->hash_algo) {
+		strbuf_addf(err, _("'%s' is '%s', the same as the object format"),
+			    "extensions.compatObjectFormat",
+			    hash_algos[format->hash_algo].name);
+		return -1;
+	}
+
 	return 0;
 }
 
diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh
index 69723b88ff..718dafc95c 100755
--- a/t/t1302-repo-version.sh
+++ b/t/t1302-repo-version.sh
@@ -98,6 +98,20 @@ abort 0 noop-v1
 allow 1 noop-v1
 EOF
 
+for hash in sha1 sha256
+do
+	test_expect_success "compatObjectFormat equal to objectFormat $hash" "
+		test_when_finished 'rm -rf same' &&
+		git init --object-format=$hash same &&
+		git -C same config set core.repositoryformatversion 1 &&
+		git -C same config set extensions.compatObjectFormat $hash &&
+		test_must_fail git -C same rev-parse --git-dir 2>err &&
+		test_grep \"'extensions.compatObjectFormat' is '$hash', the same as the object format\" err &&
+		git config unset --file=same/.git/config extensions.compatObjectFormat &&
+		git -C same rev-parse --git-dir
+	"
+done
+
 test_expect_success 'precious-objects allowed' '
 	git config core.repositoryFormatVersion 1 &&
 	git config extensions.preciousObjects 1 &&
-- 
2.56.1
[PATCH v2 2/3] rev-parse: die when --output-object-format cannot map an object
#3391
Author: Adrian Ratiu
Date: Thu, 19 Nov 2026 14:18
76 lines
12460 bytes
"git rev-parse --output-object-format=<compat-format>" should print
the compat ID of an object 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.

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.

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.

Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
---
 builtin/rev-parse.c  |  8 +++++---
 t/t1500-rev-parse.sh | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index d2154eac8d..f4b5a31aff 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) < 0)
+				die(_("cannot map object %s to %s"),
+				    oid_to_hex(&oid), output_algo->name);
 			if (verify)
 				revs_count++;
 			else
diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index 30bf8a4d0a..a945f421da 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -241,6 +241,20 @@ 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 unmapped" &&
+	git init --object-format=sha256 unmapped &&
+	# write the object before enabling compat, so it gets no compat mapping
+	oid=$(echo unmapped | git -C unmapped hash-object -w --stdin) &&
+	git -C unmapped config set extensions.compatObjectFormat sha1 &&
+	echo $oid >expect &&
+	git -C unmapped rev-parse --output-object-format=sha256 $oid >actual &&
+	test_cmp expect actual &&
+	test_must_fail git -C unmapped rev-parse --output-object-format=sha1 $oid >actual 2>err &&
+	test_must_be_empty actual &&
+	test_grep "cannot map object $oid to sha1" err
+'
+
 test_expect_success 'rev-parse --show-ref-storage-format' '
 	test_detect_ref_format >expect &&
 	git rev-parse --show-ref-storage-format >actual &&
-- 
2.56.1
[PATCH v2 3/3] object-file-convert: copy unknown commit headers unchanged
#3390
Author: Adrian Ratiu
Date: Thu, 19 Nov 2026 14:18
194 lines
18009 bytes
In a repo with extensions.compatObjectFormat, Git converts commits
to the compat format in two places which disagree about headers they
don't know:

1. When a commit is created with commit_tree_extended(), as
   git-commit(1) does, convert_commit_extra_headers() copies unknown
   headers unchanged.

2. When an existing commit object is converted (git-hash-object(1) -w)
   or when it's read by its compat ID, convert_commit_object() fails
   on them instead.

So git-hash-object(1) refuses such a commit, while "git commit --amend"
records a compat ID for it that can't be read back:
   "Failed to convert object from sha256 to sha1".

The rejection was added in 08a45903cb (object-file-convert: convert
commits that embed signed tags, 2023-10-01). Git can't know what an
unknown header holds. It might hold an object ID that needs
converting, so convert_commit_object() rejects all of them.

Some tools rely on such headers though. Jujutsu, for example, writes
a "change-id" header in every commit, so none of its commits can be
converted.

Make convert_commit_object() copy unknown headers and their
continuation lines unchanged, just like convert_commit_extra_headers(),
so both give the same compat object.

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.

Alternatives considered:

 - Reject unknown headers in convert_commit_extra_headers() too.
   Both paths would then agree, but commits from tools that add
   their own headers could not be used in a compat repo.

 - Copy only headers known to hold no object IDs. Every tool would
   first need to get its headers added to that list.

 - Convert values that look like object IDs. Any other hex string
   could be taken for one, and Git shouldn't interpret headers it
   doesn't know.

 - Also reject lines that don't look like "<key> <value>". This would
   make the two paths disagree again, because
   convert_commit_extra_headers() copies such lines, so
   "git commit --amend" would record compat IDs that can't be read
   back.

Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
---
 object-file-convert.c         | 35 ++++++++++++++++++++++-------------
 t/t1016-compatObjectFormat.sh | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 13 deletions(-)

diff --git a/object-file-convert.c b/object-file-convert.c
index 63ee18630b..ae21eedc3d 100644
--- a/object-file-convert.c
+++ b/object-file-convert.c
@@ -167,7 +167,7 @@ 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) ||
@@ -179,7 +179,7 @@ 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) ||
@@ -192,7 +192,7 @@ 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;
 
@@ -223,17 +223,26 @@ static int convert_commit_object(struct repository *repo,
 			strbuf_release(&tag);
 			strbuf_release(&new_tag);
 		}
-		else if (((bufptr + 7) < tail) && !memcmp(bufptr, "author ", 7))
-			strbuf_add(out, bufptr, (eol - bufptr) + 1);
-		else if (((bufptr + 10) < tail) && !memcmp(bufptr, "committer ", 10))
-			strbuf_add(out, bufptr, (eol - bufptr) + 1);
-		else if (((bufptr + 9) < tail) && !memcmp(bufptr, "encoding ", 9))
-			strbuf_add(out, bufptr, (eol - bufptr) + 1);
-		else if (((bufptr + 6) < tail) && !memcmp(bufptr, "gpgsig", 6))
-			strbuf_add(out, bufptr, (eol - bufptr) + 1);
 		else {
-			/* Unknown line fail it might embed an oid */
-			return -1;
+			/*
+			 * Copy all other headers unchanged. author, committer,
+			 * encoding and gpgsig hold no object IDs. For unknown
+			 * headers we can't tell, so copy them too, like
+			 * convert_commit_extra_headers() does when the commit
+			 * is written. Both must give the same compat object.
+			 *
+			 * This means that a header holding object IDs is
+			 * copied without converting them. Any such header added
+			 * to Git needs its own case above, like parent or
+			 * mergetag, and the same conversion in
+			 * convert_commit_extra_headers().
+			 *
+			 * The cases above match a header by its key alone, as
+			 * read_commit_extra_header_lines() does, so that e.g. a
+			 * "mergetag " line with nothing after the space is
+			 * still handled as a mergetag instead of being copied.
+			 */
+			strbuf_add(out, bufptr, (eol - bufptr) + 1);
 		}
 		/* Consume any trailing continuation lines */
 		bufptr = eol + 1;
diff --git a/t/t1016-compatObjectFormat.sh b/t/t1016-compatObjectFormat.sh
index 9cafcee509..fdb882c686 100755
--- a/t/t1016-compatObjectFormat.sh
+++ b/t/t1016-compatObjectFormat.sh
@@ -188,6 +188,38 @@ do
 		eval signedtag4_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag4)
 	'
 
+	test_expect_success "create a $hash commit with an unknown header" '
+		git cat-file commit $(commit2_oid $hash) >../${hash}_commit2 &&
+		awk "{ print } /^committer / { print \"x-unknown one\"; print \" two\" }" \
+			<../${hash}_commit2 >../${hash}_unknownheader &&
+		oid=$(git hash-object -t commit -w ../${hash}_unknownheader) &&
+		eval unknownheader_${hash}_oid=$oid &&
+		git branch unknownheader $oid
+	'
+
+	test_expect_success "amend a $hash commit with an unknown header" '
+		git checkout unknownheader &&
+		git commit --amend -m "Amend a commit with an unknown header" &&
+		git cat-file commit HEAD >actual &&
+		test_grep "^x-unknown one$" actual &&
+		oid=$(git rev-parse HEAD) &&
+		eval unknownheader2_${hash}_oid=$oid
+	'
+
+	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 &&
+			echo "mergetag " &&
+			sed "s/^/ /" ../${hash}_committag &&
+			echo &&
+			echo message
+		} >../${hash}_emptymergetag &&
+		test_must_fail git hash-object -t commit -w ../${hash}_emptymergetag 2>err &&
+		test_grep "Failed to convert object" err
+	'
+
 	test_expect_success 'rev-parse maps oid of object borrowed from alternate' '
 		for repo in alt borrow
 		do
@@ -298,6 +330,8 @@ compare_oids 'blob' more "$more_sha1_oid" "$more_sha256_oid"
 compare_oids 'blob' another "$another_sha1_oid" "$another_sha256_oid"
 compare_oids 'tree' tree2 "$tree2_sha1_oid" "$tree2_sha256_oid"
 compare_oids 'commit' commit2 "$commit2_sha1_oid" "$commit2_sha256_oid"
+compare_oids 'commit' unknownheader "$unknownheader_sha1_oid" "$unknownheader_sha256_oid"
+compare_oids 'commit' unknownheader2 "$unknownheader2_sha1_oid" "$unknownheader2_sha256_oid"
 compare_oids GPG2 'tag' signedtag2 "$signedtag2_sha1_oid" "$signedtag2_sha256_oid"
 compare_oids GPG2 'commit' signedcommit2 "$signedcommit2_sha1_oid" "$signedcommit2_sha256_oid"
 compare_oids GPG2 'commit' signedcommit3 "$signedcommit3_sha1_oid" "$signedcommit3_sha256_oid"
-- 
2.56.1
Re: [PATCH v2 1/3] setup: reject compatObjectFormat == objectFormat
#3499
Author: Junio C Hamano
Date: Fri, 20 Nov 2026 22:21
72 lines
15430 bytes
Adrian Ratiu <adrian.ratiu@collabora.com> writes:

> When extensions.compatObjectFormat sets the same hash as the repo
> object format, every command in a build with Rust aborts with:
>
>   BUG: repository.c:204: hash_algo and compat_hash_algo match
>
> This includes "git config", so the bad value can't be removed with
> Git. It also happens with no extensions.objectFormat at all, when
> compatObjectFormat is set to the default object format.
>
> Check for this in verify_repository_format(), next to the other
> repo format checks, and return an error instead.
>
> The check runs before any of the Rust-only code. Builds without
> Rust, which so far died because compatObjectFormat requires Rust,
> now get the same error, so the test needs no RUST prereq.

And the condition that triggers this response is not a BUG() but a
repository that is incorrectly configured, so an error message is
much more appropriate.  Makes sense.

> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
> ---
>  setup.c                 |  7 +++++++
>  t/t1302-repo-version.sh | 14 ++++++++++++++
>  2 files changed, 21 insertions(+)
>
> diff --git a/setup.c b/setup.c
> index 186815c780..a97280cafe 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -918,6 +918,13 @@ int verify_repository_format(const struct repository_format *format,
>  		return -1;
>  	}
>  
> +	if (format->compat_hash_algo == format->hash_algo) {
> +		strbuf_addf(err, _("'%s' is '%s', the same as the object format"),
> +			    "extensions.compatObjectFormat",
> +			    hash_algos[format->hash_algo].name);
> +		return -1;
> +	}
> +
>  	return 0;
>  }
>  
> diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh
> index 69723b88ff..718dafc95c 100755
> --- a/t/t1302-repo-version.sh
> +++ b/t/t1302-repo-version.sh
> @@ -98,6 +98,20 @@ abort 0 noop-v1
>  allow 1 noop-v1
>  EOF
>  
> +for hash in sha1 sha256
> +do
> +	test_expect_success "compatObjectFormat equal to objectFormat $hash" "
> +		test_when_finished 'rm -rf same' &&
> +		git init --object-format=$hash same &&
> +		git -C same config set core.repositoryformatversion 1 &&
> +		git -C same config set extensions.compatObjectFormat $hash &&
> +		test_must_fail git -C same rev-parse --git-dir 2>err &&
> +		test_grep \"'extensions.compatObjectFormat' is '$hash', the same as the object format\" err &&
> +		git config unset --file=same/.git/config extensions.compatObjectFormat &&
> +		git -C same rev-parse --git-dir
> +	"
> +done
> +
>  test_expect_success 'precious-objects allowed' '
>  	git config core.repositoryFormatVersion 1 &&
>  	git config extensions.preciousObjects 1 &&
Re: [PATCH v2 2/3] rev-parse: die when --output-object-format cannot map an object
#3501
Author: Junio C Hamano
Date: Fri, 20 Nov 2026 22:29
44 lines
14511 bytes
Adrian Ratiu <adrian.ratiu@collabora.com> writes:

> Fix it to die with the same message as pack-objects. The other callers
> of repo_oid_to_algop() already check its result.

Mimicking precedent is always a good thing to do.

> 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.

I cannot offer a better rephrasing, but the above is slightly
ambiguous and excludes "git rev-parse --ooformat=sha1 main next"
(i.e., two single revision requests are made at the same time),
which may not be your intention.

> 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.

OK.

> +test_expect_success RUST 'rev-parse --output-object-format with unmapped object' '
> +	test_when_finished "rm -rf unmapped" &&
> +	git init --object-format=sha256 unmapped &&
> +	# write the object before enabling compat, so it gets no compat mapping

clever and clean ;-)

> +	oid=$(echo unmapped | git -C unmapped hash-object -w --stdin) &&
> +	git -C unmapped config set extensions.compatObjectFormat sha1 &&
> +	echo $oid >expect &&
> +	git -C unmapped rev-parse --output-object-format=sha256 $oid >actual &&
> +	test_cmp expect actual &&
> +	test_must_fail git -C unmapped rev-parse --output-object-format=sha1 $oid >actual 2>err &&
> +	test_must_be_empty actual &&
> +	test_grep "cannot map object $oid to sha1" err
> +'
> +
>  test_expect_success 'rev-parse --show-ref-storage-format' '
>  	test_detect_ref_format >expect &&
>  	git rev-parse --show-ref-storage-format >actual &&
Re: [PATCH v2 3/3] object-file-convert: copy unknown commit headers unchanged
#3503
Author: Junio C Hamano
Date: Fri, 20 Nov 2026 22:41
73 lines
16096 bytes
Adrian Ratiu <adrian.ratiu@collabora.com> writes:

> Make convert_commit_object() copy unknown headers and their
> continuation lines unchanged, just like convert_commit_extra_headers(),
> so both give the same compat object.
>
> The author, committer, encoding and gpgsig headers were already copied
> the same, so their separate cases are no longer needed.

In other words, we note the headers that carry object names on them
and make sure we convert these object names, and pass all the other
headers intact, since we do not have to even know about them.  Which
makes sense.

> diff --git a/object-file-convert.c b/object-file-convert.c
> index 63ee18630b..ae21eedc3d 100644
> --- a/object-file-convert.c
> +++ b/object-file-convert.c
> @@ -167,7 +167,7 @@ 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) ||
> @@ -179,7 +179,7 @@ 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) ||
> @@ -192,7 +192,7 @@ 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;

The explanation in the proposed log message did mention these three
headers, but I do not think it sufficiently explained why comparison
started to include the equality case.  It said:

> The "tree ", "parent " and "mergetag " cases only matched a line with
> something after the space.

I do not recall the details of "mergetag", but I fail to see why it
makes sense to start copying a line that is "parent \n" now.  If it
is not "parent [0-9a-f]{algo->rawsz*2}\n", do we still want to pass
it to parse_oid_hex_algop() in the body of this "else if"?

> @@ -223,17 +223,26 @@ static int convert_commit_object(struct repository *repo,
>  			strbuf_release(&tag);
>  			strbuf_release(&new_tag);
>  		}
> -		else if (((bufptr + 7) < tail) && !memcmp(bufptr, "author ", 7))
> -			strbuf_add(out, bufptr, (eol - bufptr) + 1);
> -		else if (((bufptr + 10) < tail) && !memcmp(bufptr, "committer ", 10))
> -			strbuf_add(out, bufptr, (eol - bufptr) + 1);
> -		else if (((bufptr + 9) < tail) && !memcmp(bufptr, "encoding ", 9))
> -			strbuf_add(out, bufptr, (eol - bufptr) + 1);
> -		else if (((bufptr + 6) < tail) && !memcmp(bufptr, "gpgsig", 6))
> -			strbuf_add(out, bufptr, (eol - bufptr) + 1);

These are "headers we know about, but our knowledge on them do not
matter as we are copying the bits verbatim" cases.
Re: [PATCH v2 3/3] object-file-convert: copy unknown commit headers unchanged
#3508
Author: Junio C Hamano
Date: Sat, 21 Nov 2026 00:30
37 lines
14282 bytes
Adrian Ratiu <adrian.ratiu@collabora.com> writes:

> diff --git a/t/t1016-compatObjectFormat.sh b/t/t1016-compatObjectFormat.sh
> index 9cafcee509..fdb882c686 100755
> --- a/t/t1016-compatObjectFormat.sh
> +++ b/t/t1016-compatObjectFormat.sh
> @@ -188,6 +188,38 @@ do
>  		eval signedtag4_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag4)
>  	'
>  
> +	test_expect_success "create a $hash commit with an unknown header" '
> +		git cat-file commit $(commit2_oid $hash) >../${hash}_commit2 &&
> +		awk "{ print } /^committer / { print \"x-unknown one\"; print \" two\" }" \
> +			<../${hash}_commit2 >../${hash}_unknownheader &&
> +		oid=$(git hash-object -t commit -w ../${hash}_unknownheader) &&
> +		eval unknownheader_${hash}_oid=$oid &&
> +		git branch unknownheader $oid
> +	'
> +
> +	test_expect_success "amend a $hash commit with an unknown header" '
> +		git checkout unknownheader &&
> +		git commit --amend -m "Amend a commit with an unknown header" &&
> +		git cat-file commit HEAD >actual &&
> +		test_grep "^x-unknown one$" actual &&
> +		oid=$(git rev-parse HEAD) &&
> +		eval unknownheader2_${hash}_oid=$oid
> +	'
> +
> +	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 &&

This "grep" used for validation will be flagged by test-chainlint.
Use test_grep just like the previous test perhaps?
Re: [PATCH v2 0/3] compatObjectFormat: fix a BUG(), wrong ID and unknown headers
#3513
Author: Junio C Hamano
Date: Sat, 21 Nov 2026 02:59
21 lines
13524 bytes
Adrian Ratiu <adrian.ratiu@collabora.com> writes:

> This is v2 of the compatObjectFormat fixes found while testing sha1-sha256
> interop between Git, Gitoxide and Jujutsu.
>
> Because patch 3 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 v2:
>  * Check repo_oid_to_algop() for "< 0" and reword the note on which
>    rev-parse forms are covered. The test now writes the object before
>    enabling compat instead of copying it into the object directory by
>    hand. (Patrick)
>  * Match the "tree ", "parent " and "mergetag " headers by their key,
>    like read_commit_extra_header_lines() does. (Patrick)
>  * Minor casing, spacing, doc and commit msg fixes (Patrick)

I am neither of these people, but the changes looked reasonable to me.
Thanks.
Re: [PATCH v2 3/3] object-file-convert: copy unknown commit headers unchanged
#3543
Author: Junio C Hamano
Date: Sat, 21 Nov 2026 19:08
25 lines
13709 bytes
Junio C Hamano <gitster@pobox.com> writes:

> Adrian Ratiu <adrian.ratiu@collabora.com> writes:
> ...
>> +			sed -n "/^committer /q;p" ../${hash}_commit2 &&
>> +			grep "^committer " ../${hash}_commit2 &&
>
> This "grep" used for validation will be flagged by test-chainlint.
> Use test_grep just like the previous test perhaps?

Sorry, I misread what this block is doing.  Your "grep" is not an
assertion.  It is filtering the data.

Your first "sed" stops before showing the first line that begins
with "committer ", but otherwise prints all the lines it sees (in
other words, it shows all lines before the first "committer " line).
And then you append to the output all the lines that begin with
"committer ".  Which I suspect is slightly looser for general case,
but presumably it is a good enough assumption that the input file
contains such a line only once?

If so, wouldn't this be equivalent to these two lines?

	sed -e "/^committer /q" ../${hash}_commit2 &&
Re: [PATCH v2 2/3] rev-parse: die when --output-object-format cannot map an object
#3634
Author: Adrian Ratiu
Date: Mon, 23 Nov 2026 16:12
33 lines
10535 bytes
On Fri, 20 Nov 2026, Junio C Hamano <gitster@pobox.com> wrote:
> Adrian Ratiu <adrian.ratiu@collabora.com> writes:
>
>> Fix it to die with the same message as pack-objects. The other callers
>> of repo_oid_to_algop() already check its result.
>
> Mimicking precedent is always a good thing to do.
>
>> 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.
>
> I cannot offer a better rephrasing, but the above is slightly
> ambiguous and excludes "git rev-parse --ooformat=sha1 main next"
> (i.e., two single revision requests are made at the same time),
> which may not be your intention.

Correct, that is not what I meant and "main next" is covered.

What is not covered are the arguments rev-parse expands itself like
"A..B" or "A...B" ranges or shorthands like "rev^!" and others.

I'll clarify this in v3, thanks!

>> +test_expect_success RUST 'rev-parse --output-object-format with unmapped object' '
>> +	test_when_finished "rm -rf unmapped" &&
>> +	git init --object-format=sha256 unmapped &&
>> +	# write the object before enabling compat, so it gets no compat mapping
>
> clever and clean ;-)

Credit goes to Patrick. :)
Re: [PATCH v2 3/3] object-file-convert: copy unknown commit headers unchanged
#3636
Author: Adrian Ratiu
Date: Mon, 23 Nov 2026 16:16
28 lines
10490 bytes
On Sat, 21 Nov 2026, Junio C Hamano <gitster@pobox.com> wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Adrian Ratiu <adrian.ratiu@collabora.com> writes:
>> ...
>>> +			sed -n "/^committer /q;p" ../${hash}_commit2 &&
>>> +			grep "^committer " ../${hash}_commit2 &&
>>
>> This "grep" used for validation will be flagged by test-chainlint.
>> Use test_grep just like the previous test perhaps?
>
> Sorry, I misread what this block is doing.  Your "grep" is not an
> assertion.  It is filtering the data.
>
> Your first "sed" stops before showing the first line that begins
> with "committer ", but otherwise prints all the lines it sees (in
> other words, it shows all lines before the first "committer " line).
> And then you append to the output all the lines that begin with
> "committer ".  Which I suspect is slightly looser for general case,
> but presumably it is a good enough assumption that the input file
> contains such a line only once?
>
> If so, wouldn't this be equivalent to these two lines?
>
> 	sed -e "/^committer /q" ../${hash}_commit2 &&

Yes and it's simpler. I'll use this in v3, thanks!
Re: [PATCH v2 3/3] object-file-convert: copy unknown commit headers unchanged
#3639
Author: Adrian Ratiu
Date: Mon, 23 Nov 2026 16:41
55 lines
11746 bytes
On Fri, 20 Nov 2026, Junio C Hamano <gitster@pobox.com> wrote:
> Adrian Ratiu <adrian.ratiu@collabora.com> writes:
>> diff --git a/object-file-convert.c b/object-file-convert.c
>> index 63ee18630b..ae21eedc3d 100644
>> --- a/object-file-convert.c
>> +++ b/object-file-convert.c
>> @@ -167,7 +167,7 @@ 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) ||
>> @@ -179,7 +179,7 @@ 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) ||
>> @@ -192,7 +192,7 @@ 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;
>
> The explanation in the proposed log message did mention these three
> headers, but I do not think it sufficiently explained why comparison
> started to include the equality case.  It said:
>
>> The "tree ", "parent " and "mergetag " cases only matched a line with
>> something after the space.
>
> I do not recall the details of "mergetag", but I fail to see why it
> makes sense to start copying a line that is "parent \n" now.  If it
> is not "parent [0-9a-f]{algo->rawsz*2}\n", do we still want to pass
> it to parse_oid_hex_algop() in the body of this "else if"?

It is the other way around: the "<=" is what keeps "parent \n" from
being copied. :)

This came out of my discussion with Patrick on v1, but you're 100%
correct that it's hard to follow and I'll split it into a separate
preparatory patch in v3.

Then this patch will only be about the unknown headers because they're
two different things, one uncovered by the other.
[PATCH v3 0/4] compatObjectFormat: fix a BUG(), wrong ID and unknown headers
#4112
Author: Adrian Ratiu
Date: Mon, 30 Nov 2026 13:43
135 lines
15962 bytes
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
[PATCH v3 1/4] setup: reject compatObjectFormat == objectFormat
#4110
Author: Adrian Ratiu
Date: Mon, 30 Nov 2026 13:43
68 lines
11695 bytes
When extensions.compatObjectFormat sets the same hash as the repo
object format, every command in a build with Rust aborts with:

  BUG: repository.c:204: hash_algo and compat_hash_algo match

This includes "git config", so the bad value can't be removed with
Git. It also happens with no extensions.objectFormat at all, when
compatObjectFormat is set to the default object format.

Check for this in verify_repository_format(), next to the other
repo format checks, and return an error instead.

The check runs before any of the Rust-only code. Builds without
Rust, which so far died because compatObjectFormat requires Rust,
now get the same error, so the test needs no RUST prereq.

Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
---
 setup.c                 |  7 +++++++
 t/t1302-repo-version.sh | 14 ++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/setup.c b/setup.c
index 186815c780..a97280cafe 100644
--- a/setup.c
+++ b/setup.c
@@ -918,6 +918,13 @@ int verify_repository_format(const struct repository_format *format,
 		return -1;
 	}
 
+	if (format->compat_hash_algo == format->hash_algo) {
+		strbuf_addf(err, _("'%s' is '%s', the same as the object format"),
+			    "extensions.compatObjectFormat",
+			    hash_algos[format->hash_algo].name);
+		return -1;
+	}
+
 	return 0;
 }
 
diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh
index 69723b88ff..718dafc95c 100755
--- a/t/t1302-repo-version.sh
+++ b/t/t1302-repo-version.sh
@@ -98,6 +98,20 @@ abort 0 noop-v1
 allow 1 noop-v1
 EOF
 
+for hash in sha1 sha256
+do
+	test_expect_success "compatObjectFormat equal to objectFormat $hash" "
+		test_when_finished 'rm -rf same' &&
+		git init --object-format=$hash same &&
+		git -C same config set core.repositoryformatversion 1 &&
+		git -C same config set extensions.compatObjectFormat $hash &&
+		test_must_fail git -C same rev-parse --git-dir 2>err &&
+		test_grep \"'extensions.compatObjectFormat' is '$hash', the same as the object format\" err &&
+		git config unset --file=same/.git/config extensions.compatObjectFormat &&
+		git -C same rev-parse --git-dir
+	"
+done
+
 test_expect_success 'precious-objects allowed' '
 	git config core.repositoryFormatVersion 1 &&
 	git config extensions.preciousObjects 1 &&
-- 
2.56.1
[PATCH v3 2/4] rev-parse: die when --output-object-format cannot map an object
#4109
Author: Adrian Ratiu
Date: Mon, 30 Nov 2026 13:43
77 lines
12490 bytes
"git rev-parse --output-object-format=<compat-format>" should print
the compat ID of an object 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.

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.

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>
---
 builtin/rev-parse.c  |  8 +++++---
 t/t1500-rev-parse.sh | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index d2154eac8d..f4b5a31aff 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) < 0)
+				die(_("cannot map object %s to %s"),
+				    oid_to_hex(&oid), output_algo->name);
 			if (verify)
 				revs_count++;
 			else
diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index 30bf8a4d0a..a945f421da 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -241,6 +241,20 @@ 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 unmapped" &&
+	git init --object-format=sha256 unmapped &&
+	# write the object before enabling compat, so it gets no compat mapping
+	oid=$(echo unmapped | git -C unmapped hash-object -w --stdin) &&
+	git -C unmapped config set extensions.compatObjectFormat sha1 &&
+	echo $oid >expect &&
+	git -C unmapped rev-parse --output-object-format=sha256 $oid >actual &&
+	test_cmp expect actual &&
+	test_must_fail git -C unmapped rev-parse --output-object-format=sha1 $oid >actual 2>err &&
+	test_must_be_empty actual &&
+	test_grep "cannot map object $oid to sha1" err
+'
+
 test_expect_success 'rev-parse --show-ref-storage-format' '
 	test_detect_ref_format >expect &&
 	git rev-parse --show-ref-storage-format >actual &&
-- 
2.56.1
[PATCH v3 3/4] object-file-convert: match tree, parent and mergetag headers by key
#4111
Author: Adrian Ratiu
Date: Mon, 30 Nov 2026 13:43
60 lines
11851 bytes
convert_commit_object() only enters the "tree ", "parent " and
"mergetag " cases when something follows the space.

A line like "parent \n" falls through to the final "else", which
rejects any line it does not know.

The next commit makes that "else" copy unknown lines unchanged. Then
"parent \n" would be copied into the compat object instead of being
rejected. Worse, a "mergetag " line whose tag starts on the next line
would be copied together with the unconverted object ID in that tag.

Use "<=" instead of "<", so that these lines enter their own case and
are rejected there.

An empty "tree " or "parent " fails the length check before
parse_oid_hex_algop() is reached. An empty "mergetag " leaves a tag
that doesn't start with "object ", which convert_tag_object() rejects.

This doesn't change behaviour: these lines are rejected as before,
only now with an error saying why, e.g. "bad parent in commit".

Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
---
 object-file-convert.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/object-file-convert.c b/object-file-convert.c
index 63ee18630b..af14cf8300 100644
--- a/object-file-convert.c
+++ b/object-file-convert.c
@@ -167,7 +167,7 @@ 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) ||
@@ -179,7 +179,7 @@ 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) ||
@@ -192,7 +192,7 @@ 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;
 
-- 
2.56.1
[PATCH v3 4/4] object-file-convert: copy unknown commit headers unchanged
#4113
Author: Adrian Ratiu
Date: Mon, 30 Nov 2026 13:43
159 lines
16353 bytes
In a repo with extensions.compatObjectFormat, Git converts commits
to the compat format in two places which disagree about headers they
don't know:

1. When a commit is created with commit_tree_extended(), as
   git-commit(1) does, convert_commit_extra_headers() copies unknown
   headers unchanged.

2. When an existing commit object is converted (git-hash-object(1) -w)
   or when it's read by its compat ID, convert_commit_object() fails
   on them instead.

So git-hash-object(1) refuses such a commit, while "git commit --amend"
records a compat ID for it that can't be read back:
   "Failed to convert object from sha256 to sha1".

The rejection was added in 08a45903cb (object-file-convert: convert
commits that embed signed tags, 2023-10-01). Git can't know what an
unknown header holds. It might hold an object ID that needs
converting, so convert_commit_object() rejects all of them.

Some tools rely on such headers though. Jujutsu, for example, writes
a "change-id" header in every commit, so none of its commits can be
converted.

Make convert_commit_object() copy unknown headers and their
continuation lines unchanged, just like convert_commit_extra_headers(),
so both give the same compat object.

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 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:

 - Reject unknown headers in convert_commit_extra_headers() too.
   Both paths would then agree, but commits from tools that add
   their own headers could not be used in a compat repo.

 - Copy only headers known to hold no object IDs. Every tool would
   first need to get its headers added to that list.

 - Convert values that look like object IDs. Any other hex string
   could be taken for one, and Git shouldn't interpret headers it
   doesn't know.

 - Also reject lines that don't look like "<key> <value>". This would
   make the two paths disagree again, because
   convert_commit_extra_headers() copies such lines, so
   "git commit --amend" would record compat IDs that can't be read
   back.

Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
---
 object-file-convert.c         | 29 +++++++++++++++++++----------
 t/t1016-compatObjectFormat.sh | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 10 deletions(-)

diff --git a/object-file-convert.c b/object-file-convert.c
index af14cf8300..ae21eedc3d 100644
--- a/object-file-convert.c
+++ b/object-file-convert.c
@@ -223,17 +223,26 @@ static int convert_commit_object(struct repository *repo,
 			strbuf_release(&tag);
 			strbuf_release(&new_tag);
 		}
-		else if (((bufptr + 7) < tail) && !memcmp(bufptr, "author ", 7))
-			strbuf_add(out, bufptr, (eol - bufptr) + 1);
-		else if (((bufptr + 10) < tail) && !memcmp(bufptr, "committer ", 10))
-			strbuf_add(out, bufptr, (eol - bufptr) + 1);
-		else if (((bufptr + 9) < tail) && !memcmp(bufptr, "encoding ", 9))
-			strbuf_add(out, bufptr, (eol - bufptr) + 1);
-		else if (((bufptr + 6) < tail) && !memcmp(bufptr, "gpgsig", 6))
-			strbuf_add(out, bufptr, (eol - bufptr) + 1);
 		else {
-			/* Unknown line fail it might embed an oid */
-			return -1;
+			/*
+			 * Copy all other headers unchanged. author, committer,
+			 * encoding and gpgsig hold no object IDs. For unknown
+			 * headers we can't tell, so copy them too, like
+			 * convert_commit_extra_headers() does when the commit
+			 * is written. Both must give the same compat object.
+			 *
+			 * This means that a header holding object IDs is
+			 * copied without converting them. Any such header added
+			 * to Git needs its own case above, like parent or
+			 * mergetag, and the same conversion in
+			 * convert_commit_extra_headers().
+			 *
+			 * The cases above match a header by its key alone, as
+			 * read_commit_extra_header_lines() does, so that e.g. a
+			 * "mergetag " line with nothing after the space is
+			 * still handled as a mergetag instead of being copied.
+			 */
+			strbuf_add(out, bufptr, (eol - bufptr) + 1);
 		}
 		/* Consume any trailing continuation lines */
 		bufptr = eol + 1;
diff --git a/t/t1016-compatObjectFormat.sh b/t/t1016-compatObjectFormat.sh
index 9cafcee509..4f5bb814ef 100755
--- a/t/t1016-compatObjectFormat.sh
+++ b/t/t1016-compatObjectFormat.sh
@@ -188,6 +188,37 @@ do
 		eval signedtag4_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag4)
 	'
 
+	test_expect_success "create a $hash commit with an unknown header" '
+		git cat-file commit $(commit2_oid $hash) >../${hash}_commit2 &&
+		awk "{ print } /^committer / { print \"x-unknown one\"; print \" two\" }" \
+			<../${hash}_commit2 >../${hash}_unknownheader &&
+		oid=$(git hash-object -t commit -w ../${hash}_unknownheader) &&
+		eval unknownheader_${hash}_oid=$oid &&
+		git branch unknownheader $oid
+	'
+
+	test_expect_success "amend a $hash commit with an unknown header" '
+		git checkout unknownheader &&
+		git commit --amend -m "Amend a commit with an unknown header" &&
+		git cat-file commit HEAD >actual &&
+		test_grep "^x-unknown one$" actual &&
+		oid=$(git rev-parse HEAD) &&
+		eval unknownheader2_${hash}_oid=$oid
+	'
+
+	test_expect_success "reject a $hash commit with an empty mergetag line" '
+		git cat-file tag committag >../${hash}_committag &&
+		{
+			sed -e "/^committer /q" ../${hash}_commit2 &&
+			echo "mergetag " &&
+			sed "s/^/ /" ../${hash}_committag &&
+			echo &&
+			echo message
+		} >../${hash}_emptymergetag &&
+		test_must_fail git hash-object -t commit -w ../${hash}_emptymergetag 2>err &&
+		test_grep "Failed to convert object" err
+	'
+
 	test_expect_success 'rev-parse maps oid of object borrowed from alternate' '
 		for repo in alt borrow
 		do
@@ -298,6 +329,8 @@ compare_oids 'blob' more "$more_sha1_oid" "$more_sha256_oid"
 compare_oids 'blob' another "$another_sha1_oid" "$another_sha256_oid"
 compare_oids 'tree' tree2 "$tree2_sha1_oid" "$tree2_sha256_oid"
 compare_oids 'commit' commit2 "$commit2_sha1_oid" "$commit2_sha256_oid"
+compare_oids 'commit' unknownheader "$unknownheader_sha1_oid" "$unknownheader_sha256_oid"
+compare_oids 'commit' unknownheader2 "$unknownheader2_sha1_oid" "$unknownheader2_sha256_oid"
 compare_oids GPG2 'tag' signedtag2 "$signedtag2_sha1_oid" "$signedtag2_sha256_oid"
 compare_oids GPG2 'commit' signedcommit2 "$signedcommit2_sha1_oid" "$signedcommit2_sha256_oid"
 compare_oids GPG2 'commit' signedcommit3 "$signedcommit3_sha1_oid" "$signedcommit3_sha256_oid"
-- 
2.56.1
Re: [PATCH v3 3/4] object-file-convert: match tree, parent and mergetag headers by key
#4189
Author: Adrian Ratiu
Date: Tue, 01 Dec 2026 11:29
36 lines
11047 bytes
On Tue, 01 Dec 2026, Patrick Steinhardt <ps@pks.im> wrote:
> On Mon, Nov 30, 2026 at 03:43:24PM +0200, Adrian Ratiu wrote:
>> convert_commit_object() only enters the "tree ", "parent " and
>> "mergetag " cases when something follows the space.
>> 
>> A line like "parent \n" falls through to the final "else", which
>> rejects any line it does not know.
>> 
>> The next commit makes that "else" copy unknown lines unchanged. Then
>> "parent \n" would be copied into the compat object instead of being
>> rejected. Worse, a "mergetag " line whose tag starts on the next line
>> would be copied together with the unconverted object ID in that tag.
>> 
>> Use "<=" instead of "<", so that these lines enter their own case and
>> are rejected there.
>> 
>> An empty "tree " or "parent " fails the length check before
>> parse_oid_hex_algop() is reached. An empty "mergetag " leaves a tag
>> that doesn't start with "object ", which convert_tag_object() rejects.
>> 
>> This doesn't change behaviour: these lines are rejected as before,
>> only now with an error saying why, e.g. "bad parent in commit".
>
> This almost feels like we could've added some tests to verify the new
> behaviour. But on the other hand, I'm not sure it's worth it to verify
> that we have a slightly different error message now *shrug*
>
> On the other hand, the mergetag change sounds like a potential
> regression that could have been introduced by the next patch. So maybe
> we should at least add a test for that particular part?

Yes that is all correct and we do have a mergetag test in patch 4, I
just forgot to move the test here when I split the code from patch 4. :)

I'll move the test here and reword to clarify. Thanks!
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads