{"thread":{"id":"66839","subject":"[PATCH 0/3] compatObjectFormat: fix a BUG(), wrong id and unknown headers","startedAt":"2026-11-12T19:57:37Z","lastAt":"2026-11-19T14:18:22Z","messageCount":14,"participants":["Adrian Ratiu","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"558335","messageId":"20261112195740.2834341-1-adrian.ratiu@collabora.com","threadId":"66839","inReplyTo":null,"subject":"[PATCH 0/3] compatObjectFormat: fix a BUG(), wrong id and unknown headers","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-12T19:57:37Z","receivedAt":"2026-11-12T19:57:37Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"Hello all,\n\nI've been continuing my three-way Git, Gitoxide and Jujutsu sha1-sha256\ninterop testing and uncovered three more bugs, this time in Git's\ncompatObjectFormat.\n\nI'm reasonably confident in the first two patches.\n\nThe last patch needs careful review, because there are two conflicting\nbehaviors: Git copies unknown commit headers when it creates commits,\nbut rejects them when converting existing ones.\n\nI made both copy them, which removes a check added on purpose in\n08a45903cb (object-file-convert: convert commits that embed signed tags,\n2023-10-01) and I'm not 100% sure it's the right direction.\n\nMore details in the commit messages.\n\nMany thanks,\nAdrian\n\nAdrian Ratiu (3):\n  setup: reject compatObjectFormat == objectFormat\n  rev-parse: die when --output-object-format cannot map an object\n  object-file-convert: copy unknown commit headers unchanged\n\n builtin/rev-parse.c           |  8 +++++---\n object-file-convert.c         | 21 +++++++++++----------\n setup.c                       |  7 +++++++\n t/t1016-compatObjectFormat.sh | 18 ++++++++++++++++++\n t/t1302-repo-version.sh       | 14 ++++++++++++++\n t/t1500-rev-parse.sh          | 18 ++++++++++++++++++\n 6 files changed, 73 insertions(+), 13 deletions(-)\n\n-- \n2.56.1\n\n\n"},{"id":"558336","messageId":"20261112195740.2834341-2-adrian.ratiu@collabora.com","threadId":"66839","inReplyTo":"20261112195740.2834341-1-adrian.ratiu@collabora.com","subject":"[PATCH 1/3] setup: reject compatObjectFormat == objectFormat","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-12T19:57:38Z","receivedAt":"2026-11-12T19:57:38Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"When extensions.compatObjectFormat sets the same hash as the repo\nobject format, every command in a build with Rust aborts with:\n\n  BUG: repository.c:204: hash_algo and compat_hash_algo match\n\nThis includes \"git config\", so the bad value can't be removed with\nGit. It also happens with no extensions.objectFormat at all, when\ncompatObjectFormat is set to the default object format.\n\nCheck for this in verify_repository_format(), next to the other\nrepo format checks, and return an error instead.\n\nThe check runs before any of the Rust-only code. Builds without\nRust, which so far died because compatObjectFormat requires Rust,\nnow get the same error, so the test needs no RUST prereq.\n\nSigned-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n---\n setup.c                 |  7 +++++++\n t/t1302-repo-version.sh | 14 ++++++++++++++\n 2 files changed, 21 insertions(+)\n\ndiff --git a/setup.c b/setup.c\nindex 186815c780..52a9462edd 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -918,6 +918,13 @@ int verify_repository_format(const struct repository_format *format,\n \t\treturn -1;\n \t}\n \n+\tif (format->compat_hash_algo == format->hash_algo) {\n+\t\tstrbuf_addf(err, _(\"'%s' is '%s', the same as the object format\"),\n+\t\t\t    \"extensions.compatobjectformat\",\n+\t\t\t    hash_algos[format->hash_algo].name);\n+\t\treturn -1;\n+\t}\n+\n \treturn 0;\n }\n \ndiff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh\nindex 69723b88ff..858aea62a5 100755\n--- a/t/t1302-repo-version.sh\n+++ b/t/t1302-repo-version.sh\n@@ -98,6 +98,20 @@ abort 0 noop-v1\n allow 1 noop-v1\n EOF\n \n+for hash in sha1 sha256\n+do\n+\ttest_expect_success \"compatObjectFormat equal to objectFormat $hash\" \"\n+\t\ttest_when_finished 'rm -rf same' &&\n+\t\tgit init --object-format=$hash same &&\n+\t\tgit -C same config core.repositoryformatversion 1 &&\n+\t\tgit -C same config extensions.compatObjectFormat $hash &&\n+\t\ttest_must_fail git -C same rev-parse --git-dir 2>err &&\n+\t\ttest_grep \\\"'extensions.compatobjectformat' is '$hash', the same as the object format\\\" err &&\n+\t\tgit config --file=same/.git/config --unset extensions.compatObjectFormat &&\n+\t\tgit -C same rev-parse --git-dir\n+\t\"\n+done\n+\n test_expect_success 'precious-objects allowed' '\n \tgit config core.repositoryFormatVersion 1 &&\n \tgit config extensions.preciousObjects 1 &&\n-- \n2.56.1\n\n\n"},{"id":"558337","messageId":"20261112195740.2834341-3-adrian.ratiu@collabora.com","threadId":"66839","inReplyTo":"20261112195740.2834341-1-adrian.ratiu@collabora.com","subject":"[PATCH 2/3] rev-parse: die when --output-object-format cannot map an object","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-12T19:57:39Z","receivedAt":"2026-11-12T19:57:39Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"\"git rev-parse --output-object-format=<compat-format>\" should print\nan object compat id when extensions.compatObjectFormat is enabled.\n\nGit however doesn't record a compat id for every object, e.g. for\nobjects received by a fetch that goes through index-pack.\nFor such objects, rev-parse silently prints the wrong id: it prints\nthe storage id where the compat id is expected and exits with 0.\n\nThis happens because rev-parse ignores the repo_oid_to_algop() return\nvalue. When no mapping is found, that function fails and leaves the\nid unchanged, so the storage id is what gets printed.\n\nFix it to die with the same message as pack-objects. The other callers\nof repo_oid_to_algop() already check its result.\n\nThis only covers a single revision argument, the one case where\nrev-parse converts its output. Other forms, such as \"A..B\" or \"A^@\",\nprint storage ids whatever --output-object-format says. That is left\nfor a separate change.\n\nThe test copies a loose object into the repository by hand, so it\ndoesn't depend on whether fetch writes compat mappings.\n\nSigned-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n---\n builtin/rev-parse.c  |  8 +++++---\n t/t1500-rev-parse.sh | 18 ++++++++++++++++++\n 2 files changed, 23 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex d2154eac8d..ab2898ba52 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -1171,9 +1171,11 @@ int cmd_rev_parse(int argc,\n \t\t}\n \t\tif (!repo_get_oid_with_flags(the_repository, name, &oid,\n \t\t\t\t\t     flags)) {\n-\t\t\tif (output_algo)\n-\t\t\t\trepo_oid_to_algop(the_repository, &oid,\n-\t\t\t\t\t\t  output_algo, &oid);\n+\t\t\tif (output_algo &&\n+\t\t\t    repo_oid_to_algop(the_repository, &oid,\n+\t\t\t\t\t      output_algo, &oid))\n+\t\t\t\tdie(_(\"cannot map object %s to %s\"),\n+\t\t\t\t    oid_to_hex(&oid), output_algo->name);\n \t\t\tif (verify)\n \t\t\t\trevs_count++;\n \t\t\telse\ndiff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh\nindex 30bf8a4d0a..c15d9953a8 100755\n--- a/t/t1500-rev-parse.sh\n+++ b/t/t1500-rev-parse.sh\n@@ -241,6 +241,24 @@ test_expect_success RUST 'rev-parse --show-object-format in repo with compat mod\n \t)\n '\n \n+test_expect_success RUST 'rev-parse --output-object-format with unmapped object' '\n+\ttest_when_finished \"rm -rf plain compat\" &&\n+\tgit init --object-format=sha256 plain &&\n+\tgit init --object-format=sha256 compat &&\n+\tgit -C compat config extensions.compatobjectformat sha1 &&\n+\toid=$(echo unmapped | git -C plain hash-object -w --stdin) &&\n+\t# copy the object by hand, so that no compat mapping is written for it\n+\tpath=$(test_oid_to_path $oid) &&\n+\tmkdir compat/.git/objects/${path%/*} &&\n+\tcp plain/.git/objects/$path compat/.git/objects/$path &&\n+\techo $oid >expect &&\n+\tgit -C compat rev-parse --output-object-format=sha256 $oid >actual &&\n+\ttest_cmp expect actual &&\n+\ttest_must_fail git -C compat rev-parse --output-object-format=sha1 $oid >actual 2>err &&\n+\ttest_must_be_empty actual &&\n+\ttest_grep \"cannot map object $oid to sha1\" err\n+'\n+\n test_expect_success 'rev-parse --show-ref-storage-format' '\n \ttest_detect_ref_format >expect &&\n \tgit rev-parse --show-ref-storage-format >actual &&\n-- \n2.56.1\n\n\n"},{"id":"558338","messageId":"20261112195740.2834341-4-adrian.ratiu@collabora.com","threadId":"66839","inReplyTo":"20261112195740.2834341-1-adrian.ratiu@collabora.com","subject":"[PATCH 3/3] object-file-convert: copy unknown commit headers unchanged","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-12T19:57:40Z","receivedAt":"2026-11-12T19:57:40Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"In a repo with extensions.compatObjectFormat, Git converts commits\nto the compat format in two places which disagree about headers they\ndon't know:\n\n1. When a commit is created with commit_tree_extended(), as\n   \"git commit\" does, convert_commit_extra_headers() copies unknown\n   headers unchanged.\n\n2. When an existing commit object is converted (git hash-object -w)\n   or when it's read by its compat id, convert_commit_object() fails\n   on them instead.\n\nSo git hash-object refuses such a commit, while git commit --amend\nrecords a compat id for it that can't be read back:\n   \"Failed to convert object from sha256 to sha1\".\n\nThe rejection was added in 08a45903cb (object-file-convert: convert\ncommits that embed signed tags, 2023-10-01). Git can't know what an\nunknown header holds. It might hold an object id that needs\nconverting, so convert_commit_object() rejects all of them.\n\nSome tools rely on such headers though. Jujutsu, for example, writes\na \"change-id\" header in every commit, so none of its commits can be\nconverted.\n\nMake convert_commit_object() copy unknown headers and their\ncontinuation lines unchanged, just like convert_commit_extra_headers()\nso both give the same compat object.\n\nThe author, committer, encoding and gpgsig headers were already copied\nthe same, so their separate cases are no longer needed.\n\nA \"tree\", \"parent\" or \"mergetag\" line with nothing after the keyword\nused to be rejected as unknown and is now copied as well. Such a\ncommit is malformed in both formats anyway.\n\nAlternatives considered:\n\n - Reject unknown headers in convert_commit_extra_headers() too.\n   Both paths would then agree, but commits from tools that add\n   their own headers could not be used in a compat repo.\n\n - Copy only headers known to hold no object ids. Every tool would\n   first need to get its headers added to that list.\n\nThe test writes a commit with an unknown header with \"git hash-object\",\namends it with \"git commit\", and checks that both commits map to the\nsame objects in the SHA-1 and the SHA-256 repo.\n\nSigned-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n---\n object-file-convert.c         | 21 +++++++++++----------\n t/t1016-compatObjectFormat.sh | 18 ++++++++++++++++++\n 2 files changed, 29 insertions(+), 10 deletions(-)\n\ndiff --git a/object-file-convert.c b/object-file-convert.c\nindex 63ee18630b..1a0f98c9ff 100644\n--- a/object-file-convert.c\n+++ b/object-file-convert.c\n@@ -223,17 +223,18 @@ static int convert_commit_object(struct repository *repo,\n \t\t\tstrbuf_release(&tag);\n \t\t\tstrbuf_release(&new_tag);\n \t\t}\n-\t\telse if (((bufptr + 7) < tail) && !memcmp(bufptr, \"author \", 7))\n-\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n-\t\telse if (((bufptr + 10) < tail) && !memcmp(bufptr, \"committer \", 10))\n-\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n-\t\telse if (((bufptr + 9) < tail) && !memcmp(bufptr, \"encoding \", 9))\n-\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n-\t\telse if (((bufptr + 6) < tail) && !memcmp(bufptr, \"gpgsig\", 6))\n-\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n \t\telse {\n-\t\t\t/* Unknown line fail it might embed an oid */\n-\t\t\treturn -1;\n+\t\t\t/*\n+\t\t\t * Copy all other headers unchanged. author, committer, encoding and gpgsig\n+\t\t\t * hold no object ids. For unknown headers we can't tell, so copy them too,\n+\t\t\t * like convert_commit_extra_headers() does when the commit is written. Both\n+\t\t\t * must give the same compat object.\n+\t\t\t *\n+\t\t\t * This means that a header holding object ids is copied without converting\n+\t\t\t * them. Any such header added to Git needs its own case above, like parent\n+\t\t\t * or mergetag, and the same conversion in convert_commit_extra_headers().\n+\t\t\t */\n+\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n \t\t}\n \t\t/* Consume any trailing continuation lines */\n \t\tbufptr = eol + 1;\ndiff --git a/t/t1016-compatObjectFormat.sh b/t/t1016-compatObjectFormat.sh\nindex 9cafcee509..fde092a017 100755\n--- a/t/t1016-compatObjectFormat.sh\n+++ b/t/t1016-compatObjectFormat.sh\n@@ -187,6 +187,22 @@ do\n \t\teval signedtag3_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag3) &&\n \t\teval signedtag4_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag4)\n \t'\n+\ttest_expect_success \"create a $hash commit with an unknown header\" '\n+\t\tgit cat-file commit $(commit2_oid $hash) >../${hash}_commit2 &&\n+\t\tawk \"{ print } /^committer / { print \\\"x-unknown one\\\"; print \\\" two\\\" }\" \\\n+\t\t\t<../${hash}_commit2 >../${hash}_unknownheader &&\n+\t\toid=$(git hash-object -t commit -w ../${hash}_unknownheader) &&\n+\t\teval unknownheader_${hash}_oid=$oid &&\n+\t\tgit branch unknownheader $oid\n+\t'\n+\ttest_expect_success \"amend a $hash commit with an unknown header\" '\n+\t\tgit checkout unknownheader &&\n+\t\tgit commit --amend -m \"Amend a commit with an unknown header\" &&\n+\t\tgit cat-file commit HEAD >actual &&\n+\t\ttest_grep \"^x-unknown one$\" actual &&\n+\t\toid=$(git rev-parse HEAD) &&\n+\t\teval unknownheader2_${hash}_oid=$oid\n+\t'\n \n \ttest_expect_success 'rev-parse maps oid of object borrowed from alternate' '\n \t\tfor repo in alt borrow\n@@ -298,6 +314,8 @@ compare_oids 'blob' more \"$more_sha1_oid\" \"$more_sha256_oid\"\n compare_oids 'blob' another \"$another_sha1_oid\" \"$another_sha256_oid\"\n compare_oids 'tree' tree2 \"$tree2_sha1_oid\" \"$tree2_sha256_oid\"\n compare_oids 'commit' commit2 \"$commit2_sha1_oid\" \"$commit2_sha256_oid\"\n+compare_oids 'commit' unknownheader \"$unknownheader_sha1_oid\" \"$unknownheader_sha256_oid\"\n+compare_oids 'commit' unknownheader2 \"$unknownheader2_sha1_oid\" \"$unknownheader2_sha256_oid\"\n compare_oids GPG2 'tag' signedtag2 \"$signedtag2_sha1_oid\" \"$signedtag2_sha256_oid\"\n compare_oids GPG2 'commit' signedcommit2 \"$signedcommit2_sha1_oid\" \"$signedcommit2_sha256_oid\"\n compare_oids GPG2 'commit' signedcommit3 \"$signedcommit3_sha1_oid\" \"$signedcommit3_sha256_oid\"\n-- \n2.56.1\n\n\n"},{"id":"558517","messageId":"avqyiXdZIFoJbw34@pks.im","threadId":"66839","inReplyTo":"20261112195740.2834341-2-adrian.ratiu@collabora.com","subject":"Re: [PATCH 1/3] setup: reject compatObjectFormat == objectFormat","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-16T07:36:53Z","receivedAt":"2026-11-16T07:36:53Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Nov 12, 2026 at 09:57:38PM +0200, Adrian Ratiu wrote:\n> diff --git a/setup.c b/setup.c\n> index 186815c780..52a9462edd 100644\n> --- a/setup.c\n> +++ b/setup.c\n> @@ -918,6 +918,13 @@ int verify_repository_format(const struct repository_format *format,\n>  \t\treturn -1;\n>  \t}\n>  \n> +\tif (format->compat_hash_algo == format->hash_algo) {\n> +\t\tstrbuf_addf(err, _(\"'%s' is '%s', the same as the object format\"),\n> +\t\t\t    \"extensions.compatobjectformat\",\n\nWe should rather say \"extensions.compatObjectFormat\" here with proper\ncasing, as this is user-facing.\n\n> +\t\t\t    hash_algos[format->hash_algo].name);\n> +\t\treturn -1;\n> +\t}\n> +\n>  \treturn 0;\n>  }\n>  \n> diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh\n> index 69723b88ff..858aea62a5 100755\n> --- a/t/t1302-repo-version.sh\n> +++ b/t/t1302-repo-version.sh\n> @@ -98,6 +98,20 @@ abort 0 noop-v1\n>  allow 1 noop-v1\n>  EOF\n>  \n> +for hash in sha1 sha256\n> +do\n> +\ttest_expect_success \"compatObjectFormat equal to objectFormat $hash\" \"\n> +\t\ttest_when_finished 'rm -rf same' &&\n> +\t\tgit init --object-format=$hash same &&\n> +\t\tgit -C same config core.repositoryformatversion 1 &&\n> +\t\tgit -C same config extensions.compatObjectFormat $hash &&\n> +\t\ttest_must_fail git -C same rev-parse --git-dir 2>err &&\n> +\t\ttest_grep \\\"'extensions.compatobjectformat' is '$hash', the same as the object format\\\" err &&\n> +\t\tgit config --file=same/.git/config --unset extensions.compatObjectFormat &&\n\nNit: do we maybe want to use the modern alternate `git config unset`? If\nso, we should probably be consistent and also use `gi tconfig set`\nfurther up.\n\nPatrick\n\n"},{"id":"558518","messageId":"avqynlDKnJpJn6RZ@pks.im","threadId":"66839","inReplyTo":"20261112195740.2834341-3-adrian.ratiu@collabora.com","subject":"Re: [PATCH 2/3] rev-parse: die when --output-object-format cannot map an object","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-16T07:37:02Z","receivedAt":"2026-11-16T07:37:02Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Nov 12, 2026 at 09:57:39PM +0200, Adrian Ratiu wrote:\n> \"git rev-parse --output-object-format=<compat-format>\" should print\n> an object compat id when extensions.compatObjectFormat is enabled.\n> \n> Git however doesn't record a compat id for every object, e.g. for\n> objects received by a fetch that goes through index-pack.\n> For such objects, rev-parse silently prints the wrong id: it prints\n> the storage id where the compat id is expected and exits with 0.\n\nYeah, that's just plain wrong and extremely confusing.\n\n> This happens because rev-parse ignores the repo_oid_to_algop() return\n> value. When no mapping is found, that function fails and leaves the\n> id unchanged, so the storage id is what gets printed.\n> \n> Fix it to die with the same message as pack-objects. The other callers\n> of repo_oid_to_algop() already check its result.\n> \n> This only covers a single revision argument, the one case where\n> rev-parse converts its output. Other forms, such as \"A..B\" or \"A^@\",\n> print storage ids whatever --output-object-format says. That is left\n> for a separate change.\n\nThis paragraph is a bit hard to parse.\n\n  Note that this only covers the case where the user asks for a single\n  revision, as it is the only case where we pass the desired output hash\n  explicitly. All the other cases, like for example when the user passes\n  a range, do not use the desired output hash at all. Fixing that would\n  be a bigger change though, so this is left for a future patch series.\n\n> The test copies a loose object into the repository by hand, so it\n> doesn't depend on whether fetch writes compat mappings.\n\nDo we have to do that? I'm mostly asking in the context of the new\nobject storage format extension, which may change where and how exactly\nobjects are stored. So all tests that manually modify the object\ndatabase will break, and we'll want and need to fix those.\n\n> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\n> index d2154eac8d..ab2898ba52 100644\n> --- a/builtin/rev-parse.c\n> +++ b/builtin/rev-parse.c\n> @@ -1171,9 +1171,11 @@ int cmd_rev_parse(int argc,\n>  \t\t}\n>  \t\tif (!repo_get_oid_with_flags(the_repository, name, &oid,\n>  \t\t\t\t\t     flags)) {\n> -\t\t\tif (output_algo)\n> -\t\t\t\trepo_oid_to_algop(the_repository, &oid,\n> -\t\t\t\t\t\t  output_algo, &oid);\n> +\t\t\tif (output_algo &&\n> +\t\t\t    repo_oid_to_algop(the_repository, &oid,\n> +\t\t\t\t\t      output_algo, &oid))\n> +\t\t\t\tdie(_(\"cannot map object %s to %s\"),\n> +\t\t\t\t    oid_to_hex(&oid), output_algo->name);\n\nMakes sense. I would have checked for `< 0`, but that ultimately doesn't\nmatter much.\n\n> diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh\n> index 30bf8a4d0a..c15d9953a8 100755\n> --- a/t/t1500-rev-parse.sh\n> +++ b/t/t1500-rev-parse.sh\n> @@ -241,6 +241,24 @@ test_expect_success RUST 'rev-parse --show-object-format in repo with compat mod\n>  \t)\n>  '\n>  \n> +test_expect_success RUST 'rev-parse --output-object-format with unmapped object' '\n> +\ttest_when_finished \"rm -rf plain compat\" &&\n> +\tgit init --object-format=sha256 plain &&\n> +\tgit init --object-format=sha256 compat &&\n> +\tgit -C compat config extensions.compatobjectformat sha1 &&\n> +\toid=$(echo unmapped | git -C plain hash-object -w --stdin) &&\n> +\t# copy the object by hand, so that no compat mapping is written for it\n\nInstead of copying by hand, wouldn't it be possible to write the object\nwith the compat object format unset and then set it afterwards? That\nshould also ensure that we don't have the compat hash.\n\nPatrick\n\n"},{"id":"558519","messageId":"avqypRLPLZZFNqRs@pks.im","threadId":"66839","inReplyTo":"20261112195740.2834341-4-adrian.ratiu@collabora.com","subject":"Re: [PATCH 3/3] object-file-convert: copy unknown commit headers unchanged","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-16T07:37:09Z","receivedAt":"2026-11-16T07:37:09Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Nov 12, 2026 at 09:57:40PM +0200, Adrian Ratiu wrote:\n> In a repo with extensions.compatObjectFormat, Git converts commits\n> to the compat format in two places which disagree about headers they\n> don't know:\n> \n> 1. When a commit is created with commit_tree_extended(), as\n>    \"git commit\" does, convert_commit_extra_headers() copies unknown\n>    headers unchanged.\n> \n> 2. When an existing commit object is converted (git hash-object -w)\n>    or when it's read by its compat id, convert_commit_object() fails\n>    on them instead.\n> \n> So git hash-object refuses such a commit, while git commit --amend\n\ns/git hash-object/git-hash-object(1)/\n\n> records a compat id for it that can't be read back:\n\ns/compat id/compat ID/\n\n>    \"Failed to convert object from sha256 to sha1\".\n> \n> The rejection was added in 08a45903cb (object-file-convert: convert\n> commits that embed signed tags, 2023-10-01). Git can't know what an\n> unknown header holds. It might hold an object id that needs\n\ns/object id/object ID/\n\n> converting, so convert_commit_object() rejects all of them.\n> \n> Some tools rely on such headers though. Jujutsu, for example, writes\n> a \"change-id\" header in every commit, so none of its commits can be\n> converted.\n> \n> Make convert_commit_object() copy unknown headers and their\n> continuation lines unchanged, just like convert_commit_extra_headers()\n> so both give the same compat object.\n> \n> The author, committer, encoding and gpgsig headers were already copied\n> the same, so their separate cases are no longer needed.\n> \n> A \"tree\", \"parent\" or \"mergetag\" line with nothing after the keyword\n> used to be rejected as unknown and is now copied as well. Such a\n> commit is malformed in both formats anyway.\n\nHmm. I guess this here might raise some eyebrows. I guess it makes the\ncode simpler, but I wonder what the benefit is of converting an object\nthat is so obviously corrupt...\n\n... yeah, after reading the code we'd have to introduce a bunch of extra\nlogic to make this work as expected. As far as I can see though we _do_\nreject \"tree \" without trailing data, but we wouldn't reject \"tree\"\nwithout the trailing space.\n\nWe could fix that by introducing a generic format check:\n\n  - The line must have at least a single space separating key and value\n    of the header.\n\n  - The key must only contain characters of a specific set.\n\nOtherwise we might be too lenient and also accept data that doesn't even\nlook close to an object header.\n\nBut whether that's all worth it is a different question, as said. It's a\ncorrupt commit anyway, and we cannot address the root cause of that\ncorruption here anyway.\n\n> Alternatives considered:\n> \n>  - Reject unknown headers in convert_commit_extra_headers() too.\n>    Both paths would then agree, but commits from tools that add\n>    their own headers could not be used in a compat repo.\n\nYeah, that's certainly a direction we shouldn't go. There's way too many\ntools nowadays with widespread usage that write such unknown headers.\n\n>  - Copy only headers known to hold no object ids. Every tool would\n>    first need to get its headers added to that list.\n\nAgreed, that doesn't seem sensible, either. We don't want to be the\ngatekeeper of who is or who isn't allowed to have their own custom\nheader.\n\nA third alternative could have been to try and recognize commit IDs\nautomatically. E.g. if you see a 40-character hex string then we treat\nit as a commit ID. But I don't think that's sensible, either, as we\nshouldn't interpret what we don't know.\n\nA bit of a side note, but I have been wondering multiple times already\nwhether we should fix this gap by introducing a well-known object header\nprefix that tells us that the value of that header is indeed an object\nID, for example something like \"x-obj-foobar <oid>\". That would make our\ncommit graph extensible by third-party-tools without us having to\nunderstand what that tool even intends to do with that, and we would\nknow to treat such object IDs as reachable.\n\nBut that's of course a topic that is well outside the scope of this\npatch series.\n\n> diff --git a/object-file-convert.c b/object-file-convert.c\n> index 63ee18630b..1a0f98c9ff 100644\n> --- a/object-file-convert.c\n> +++ b/object-file-convert.c\n> @@ -223,17 +223,18 @@ static int convert_commit_object(struct repository *repo,\n>  \t\t\tstrbuf_release(&tag);\n>  \t\t\tstrbuf_release(&new_tag);\n>  \t\t}\n> -\t\telse if (((bufptr + 7) < tail) && !memcmp(bufptr, \"author \", 7))\n> -\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n> -\t\telse if (((bufptr + 10) < tail) && !memcmp(bufptr, \"committer \", 10))\n> -\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n> -\t\telse if (((bufptr + 9) < tail) && !memcmp(bufptr, \"encoding \", 9))\n> -\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n> -\t\telse if (((bufptr + 6) < tail) && !memcmp(bufptr, \"gpgsig\", 6))\n> -\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n>  \t\telse {\n> -\t\t\t/* Unknown line fail it might embed an oid */\n> -\t\t\treturn -1;\n> +\t\t\t/*\n> +\t\t\t * Copy all other headers unchanged. author, committer, encoding and gpgsig\n> +\t\t\t * hold no object ids. For unknown headers we can't tell, so copy them too,\n\ns/object ids/object IDs/\n\n> +\t\t\t * like convert_commit_extra_headers() does when the commit is written. Both\n> +\t\t\t * must give the same compat object.\n> +\t\t\t *\n> +\t\t\t * This means that a header holding object ids is copied without converting\n\nLikewise.\n\n> +\t\t\t * them. Any such header added to Git needs its own case above, like parent\n> +\t\t\t * or mergetag, and the same conversion in convert_commit_extra_headers().\n> +\t\t\t */\n> +\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n>  \t\t}\n>  \t\t/* Consume any trailing continuation lines */\n>  \t\tbufptr = eol + 1;\n> diff --git a/t/t1016-compatObjectFormat.sh b/t/t1016-compatObjectFormat.sh\n> index 9cafcee509..fde092a017 100755\n> --- a/t/t1016-compatObjectFormat.sh\n> +++ b/t/t1016-compatObjectFormat.sh\n> @@ -187,6 +187,22 @@ do\n>  \t\teval signedtag3_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag3) &&\n>  \t\teval signedtag4_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag4)\n>  \t'\n\nLet's have an empty line between tests.\n\n> +\ttest_expect_success \"create a $hash commit with an unknown header\" '\n> +\t\tgit cat-file commit $(commit2_oid $hash) >../${hash}_commit2 &&\n> +\t\tawk \"{ print } /^committer / { print \\\"x-unknown one\\\"; print \\\" two\\\" }\" \\\n> +\t\t\t<../${hash}_commit2 >../${hash}_unknownheader &&\n> +\t\toid=$(git hash-object -t commit -w ../${hash}_unknownheader) &&\n> +\t\teval unknownheader_${hash}_oid=$oid &&\n> +\t\tgit branch unknownheader $oid\n> +\t'\n> +\ttest_expect_success \"amend a $hash commit with an unknown header\" '\n> +\t\tgit checkout unknownheader &&\n> +\t\tgit commit --amend -m \"Amend a commit with an unknown header\" &&\n> +\t\tgit cat-file commit HEAD >actual &&\n> +\t\ttest_grep \"^x-unknown one$\" actual &&\n> +\t\toid=$(git rev-parse HEAD) &&\n> +\t\teval unknownheader2_${hash}_oid=$oid\n> +\t'\n>  \n>  \ttest_expect_success 'rev-parse maps oid of object borrowed from alternate' '\n>  \t\tfor repo in alt borrow\n\nThanks!\n\nPatrick\n\n"},{"id":"558607","messageId":"87ik1vkacy.fsf@collabora.com","threadId":"66839","inReplyTo":"avqyiXdZIFoJbw34@pks.im","subject":"Re: [PATCH 1/3] setup: reject compatObjectFormat == objectFormat","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-17T10:42:21Z","receivedAt":"2026-11-17T10:42:21Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"On Mon, 16 Nov 2026, Patrick Steinhardt <ps@pks.im> wrote:\n> On Thu, Nov 12, 2026 at 09:57:38PM +0200, Adrian Ratiu wrote:\n>> diff --git a/setup.c b/setup.c\n>> index 186815c780..52a9462edd 100644\n>> --- a/setup.c\n>> +++ b/setup.c\n>> @@ -918,6 +918,13 @@ int verify_repository_format(const struct repository_format *format,\n>>  \t\treturn -1;\n>>  \t}\n>>  \n>> +\tif (format->compat_hash_algo == format->hash_algo) {\n>> +\t\tstrbuf_addf(err, _(\"'%s' is '%s', the same as the object format\"),\n>> +\t\t\t    \"extensions.compatobjectformat\",\n>\n> We should rather say \"extensions.compatObjectFormat\" here with proper\n> casing, as this is user-facing.\n\nAck, will do in v2.\n\n>> +\t\t\t    hash_algos[format->hash_algo].name);\n>> +\t\treturn -1;\n>> +\t}\n>> +\n>>  \treturn 0;\n>>  }\n>>  \n>> diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh\n>> index 69723b88ff..858aea62a5 100755\n>> --- a/t/t1302-repo-version.sh\n>> +++ b/t/t1302-repo-version.sh\n>> @@ -98,6 +98,20 @@ abort 0 noop-v1\n>>  allow 1 noop-v1\n>>  EOF\n>>  \n>> +for hash in sha1 sha256\n>> +do\n>> +\ttest_expect_success \"compatObjectFormat equal to objectFormat $hash\" \"\n>> +\t\ttest_when_finished 'rm -rf same' &&\n>> +\t\tgit init --object-format=$hash same &&\n>> +\t\tgit -C same config core.repositoryformatversion 1 &&\n>> +\t\tgit -C same config extensions.compatObjectFormat $hash &&\n>> +\t\ttest_must_fail git -C same rev-parse --git-dir 2>err &&\n>> +\t\ttest_grep \\\"'extensions.compatobjectformat' is '$hash', the same as the object format\\\" err &&\n>> +\t\tgit config --file=same/.git/config --unset extensions.compatObjectFormat &&\n>\n> Nit: do we maybe want to use the modern alternate `git config unset`? If\n> so, we should probably be consistent and also use `gi tconfig set`\n> further up.\n\nAck, will do in v2.\n\n"},{"id":"558615","messageId":"87fqwzk6yv.fsf@collabora.com","threadId":"66839","inReplyTo":"avqynlDKnJpJn6RZ@pks.im","subject":"Re: [PATCH 2/3] rev-parse: die when --output-object-format cannot map an object","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-17T11:55:36Z","receivedAt":"2026-11-17T11:55:36Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"On Mon, 16 Nov 2026, Patrick Steinhardt <ps@pks.im> wrote:\n> On Thu, Nov 12, 2026 at 09:57:39PM +0200, Adrian Ratiu wrote:\n>> This happens because rev-parse ignores the repo_oid_to_algop() return\n>> value. When no mapping is found, that function fails and leaves the\n>> id unchanged, so the storage id is what gets printed.\n>> \n>> Fix it to die with the same message as pack-objects. The other callers\n>> of repo_oid_to_algop() already check its result.\n>> \n>> This only covers a single revision argument, the one case where\n>> rev-parse converts its output. Other forms, such as \"A..B\" or \"A^@\",\n>> print storage ids whatever --output-object-format says. That is left\n>> for a separate change.\n>\n> This paragraph is a bit hard to parse.\n>\n>   Note that this only covers the case where the user asks for a single\n>   revision, as it is the only case where we pass the desired output hash\n>   explicitly. All the other cases, like for example when the user passes\n>   a range, do not use the desired output hash at all. Fixing that would\n>   be a bigger change though, so this is left for a future patch series.\n\nAck, I'll reword it.\n\n>> The test copies a loose object into the repository by hand, so it\n>> doesn't depend on whether fetch writes compat mappings.\n>\n> Do we have to do that? I'm mostly asking in the context of the new\n> object storage format extension, which may change where and how exactly\n> objects are stored. So all tests that manually modify the object\n> database will break, and we'll want and need to fix those.\n\nWe can do it any other way, no problem.\n\nHow I reproduced this in the real world (non-test) is by creating a\ncommit with JJ, but I tried to avoid adding JJ as a test dependency. :)\n\nBesides, I'll fix this in newer JJ as well, to simply reject repos with\nextensions.compatObjectFormat, which is not supported either in Gitoxide\nor JJ.\n\n>> diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh\n>> index 30bf8a4d0a..c15d9953a8 100755\n>> --- a/t/t1500-rev-parse.sh\n>> +++ b/t/t1500-rev-parse.sh\n>> @@ -241,6 +241,24 @@ test_expect_success RUST 'rev-parse --show-object-format in repo with compat mod\n>>  \t)\n>>  '\n>>  \n>> +test_expect_success RUST 'rev-parse --output-object-format with unmapped object' '\n>> +\ttest_when_finished \"rm -rf plain compat\" &&\n>> +\tgit init --object-format=sha256 plain &&\n>> +\tgit init --object-format=sha256 compat &&\n>> +\tgit -C compat config extensions.compatobjectformat sha1 &&\n>> +\toid=$(echo unmapped | git -C plain hash-object -w --stdin) &&\n>> +\t# copy the object by hand, so that no compat mapping is written for it\n>\n> Instead of copying by hand, wouldn't it be possible to write the object\n> with the compat object format unset and then set it afterwards? That\n> should also ensure that we don't have the compat hash.\n\nYes, I just verified that it works. Will it this way in v2, thanks!\n\n"},{"id":"558623","messageId":"87cxs3jx5d.fsf@collabora.com","threadId":"66839","inReplyTo":"avqypRLPLZZFNqRs@pks.im","subject":"Re: [PATCH 3/3] object-file-convert: copy unknown commit headers unchanged","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-17T15:27:42Z","receivedAt":"2026-11-17T15:27:42Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"On Mon, 16 Nov 2026, Patrick Steinhardt <ps@pks.im> wrote:\n> On Thu, Nov 12, 2026 at 09:57:40PM +0200, Adrian Ratiu wrote:\n>> In a repo with extensions.compatObjectFormat, Git converts commits\n>> to the compat format in two places which disagree about headers they\n>> don't know:\n>> \n>> 1. When a commit is created with commit_tree_extended(), as\n>>    \"git commit\" does, convert_commit_extra_headers() copies unknown\n>>    headers unchanged.\n>> \n>> 2. When an existing commit object is converted (git hash-object -w)\n>>    or when it's read by its compat id, convert_commit_object() fails\n>>    on them instead.\n>> \n>> So git hash-object refuses such a commit, while git commit --amend\n>\n> s/git hash-object/git-hash-object(1)/\n>\n>> records a compat id for it that can't be read back:\n>\n> s/compat id/compat ID/\n>\n>>    \"Failed to convert object from sha256 to sha1\".\n>> \n>> The rejection was added in 08a45903cb (object-file-convert: convert\n>> commits that embed signed tags, 2023-10-01). Git can't know what an\n>> unknown header holds. It might hold an object id that needs\n>\n> s/object id/object ID/\n>\n\nAck on these and all the other ID / spacing fixes, will do them in v2.\n\n>> converting, so convert_commit_object() rejects all of them.\n>> \n>> Some tools rely on such headers though. Jujutsu, for example, writes\n>> a \"change-id\" header in every commit, so none of its commits can be\n>> converted.\n>> \n>> Make convert_commit_object() copy unknown headers and their\n>> continuation lines unchanged, just like convert_commit_extra_headers()\n>> so both give the same compat object.\n>> \n>> The author, committer, encoding and gpgsig headers were already copied\n>> the same, so their separate cases are no longer needed.\n>> \n>> A \"tree\", \"parent\" or \"mergetag\" line with nothing after the keyword\n>> used to be rejected as unknown and is now copied as well. Such a\n>> commit is malformed in both formats anyway.\n>\n> Hmm. I guess this here might raise some eyebrows. I guess it makes the\n> code simpler, but I wonder what the benefit is of converting an object\n> that is so obviously corrupt...\n>\n> ... yeah, after reading the code we'd have to introduce a bunch of extra\n> logic to make this work as expected. As far as I can see though we _do_\n> reject \"tree \" without trailing data, but we wouldn't reject \"tree\"\n> without the trailing space.\n\nI looked closer and v1 actually copies \"tree \" too, because of the\n(bufptr + 5) < eol check, \"tree \\n\" never reaches the tree branch. :)\n\nI also found I made mergetag worse: a \"mergetag \" line with an empty\nfirst line and the tag in continuation lines is also copied, so its\nembedded object ID ends up unconverted in the compat object.\n\nGit still treats that header as a mergetag (\"git show\" reports\n\"malformed mergetag\") and \"git commit --amend\" refuses to convert it, so\nv1 makes the two paths disagree again, just in the other direction.\n\nI can fix this in v2 by changing the three checks to <=, so the\nconverter classifies headers same as read_commit_extra_header_lines(),\nby the key before the first space.\n\nSo:\n\n\"tree \", \"parent \" and \"mergetag \" with an empty or bad value are\nrejected, as before this series.\n\n\"tree\", \"parent\" and \"mergetag\" without a space are not those headers as\nfar as Git is concerned, so they are copied like any unknown\nheader. That is also what --amend does with them.\n\nI'll also add a test for the empty mergetag case.\n\n>\n> We could fix that by introducing a generic format check:\n>\n>   - The line must have at least a single space separating key and value\n>     of the header.\n>\n>   - The key must only contain characters of a specific set.\n>\n> Otherwise we might be too lenient and also accept data that doesn't even\n> look close to an object header.\n>\n> But whether that's all worth it is a different question, as said. It's a\n> corrupt commit anyway, and we cannot address the root cause of that\n> corruption here anyway.\n\nWith the above I don't think we need it. A check only in the converter\nwould reject headers that read_commit_extra_header_lines() accepts and\n\"git commit --amend\" keeps (e.g. bare \"x-foo\" line), so amend would\nagain record compat IDs that can't be read back.\n\nIf we need such rules, I think fsck is the better place (today it\ndoesn't look at any header after \"committer\"). It's a separate topic\nthough.\n\n>> Alternatives considered:\n>> \n>>  - Reject unknown headers in convert_commit_extra_headers() too.\n>>    Both paths would then agree, but commits from tools that add\n>>    their own headers could not be used in a compat repo.\n>\n> Yeah, that's certainly a direction we shouldn't go. There's way too many\n> tools nowadays with widespread usage that write such unknown headers.\n>\n>>  - Copy only headers known to hold no object ids. Every tool would\n>>    first need to get its headers added to that list.\n>\n> Agreed, that doesn't seem sensible, either. We don't want to be the\n> gatekeeper of who is or who isn't allowed to have their own custom\n> header.\n>\n> A third alternative could have been to try and recognize commit IDs\n> automatically. E.g. if you see a 40-character hex string then we treat\n> it as a commit ID. But I don't think that's sensible, either, as we\n> shouldn't interpret what we don't know.\n\nAgreed, unknown unknowns are such a pain.\n\n>\n> A bit of a side note, but I have been wondering multiple times already\n> whether we should fix this gap by introducing a well-known object header\n> prefix that tells us that the value of that header is indeed an object\n> ID, for example something like \"x-obj-foobar <oid>\". That would make our\n> commit graph extensible by third-party-tools without us having to\n> understand what that tool even intends to do with that, and we would\n> know to treat such object IDs as reachable.\n>\n> But that's of course a topic that is well outside the scope of this\n> patch series.\n\nYes, I'm trying to keep this series small and just address the immediate\nbugs / breakages, to avoid it balooning into 10+ patch series again. :)\n\n"},{"id":"558847","messageId":"cover.1794932695.git.adrian.ratiu@collabora.com","threadId":"66839","inReplyTo":"20261112195740.2834341-1-adrian.ratiu@collabora.com","subject":"[PATCH v2 0/3] compatObjectFormat: fix a BUG(), wrong ID and unknown headers","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-19T14:18:19Z","receivedAt":"2026-11-19T14:18:19Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"Hello all,\n\nThis is v2 of the compatObjectFormat fixes found while testing sha1-sha256\ninterop between Git, Gitoxide and Jujutsu.\n\nBecause patch 3 drops a check that 08a45903cb (object-file-convert: convert\ncommits that embed signed tags, 2023-10-01) added on purpose, I'd still welcome\na look from Eric or Brian.\n\nChanges in v2:\n * Check repo_oid_to_algop() for \"< 0\" and reword the note on which\n   rev-parse forms are covered. The test now writes the object before\n   enabling compat instead of copying it into the object directory by\n   hand. (Patrick)\n * Match the \"tree \", \"parent \" and \"mergetag \" headers by their key,\n   like read_commit_extra_header_lines() does. (Patrick)\n * Minor casing, spacing, doc and commit msg fixes (Patrick)\n\nv1: https://lore.kernel.org/git/20261112195740.2834341-1-adrian.ratiu@collabora.com/\n\nMany thanks,\nAdrian\n\nAdrian Ratiu (3):\n  setup: reject compatObjectFormat == objectFormat\n  rev-parse: die when --output-object-format cannot map an object\n  object-file-convert: copy unknown commit headers unchanged\n\n builtin/rev-parse.c           |  8 +++++---\n object-file-convert.c         | 35 ++++++++++++++++++++++-------------\n setup.c                       |  7 +++++++\n t/t1016-compatObjectFormat.sh | 34 ++++++++++++++++++++++++++++++++++\n t/t1302-repo-version.sh       | 14 ++++++++++++++\n t/t1500-rev-parse.sh          | 14 ++++++++++++++\n 6 files changed, 96 insertions(+), 16 deletions(-)\n\nRange-diff against v1:\n1:  53c814a1e1 ! 1:  f74a0fd67a setup: reject compatObjectFormat == objectFormat\n    @@ setup.c: int verify_repository_format(const struct repository_format *format,\n      \n     +\tif (format->compat_hash_algo == format->hash_algo) {\n     +\t\tstrbuf_addf(err, _(\"'%s' is '%s', the same as the object format\"),\n    -+\t\t\t    \"extensions.compatobjectformat\",\n    ++\t\t\t    \"extensions.compatObjectFormat\",\n     +\t\t\t    hash_algos[format->hash_algo].name);\n     +\t\treturn -1;\n     +\t}\n    @@ t/t1302-repo-version.sh: abort 0 noop-v1\n     +\ttest_expect_success \"compatObjectFormat equal to objectFormat $hash\" \"\n     +\t\ttest_when_finished 'rm -rf same' &&\n     +\t\tgit init --object-format=$hash same &&\n    -+\t\tgit -C same config core.repositoryformatversion 1 &&\n    -+\t\tgit -C same config extensions.compatObjectFormat $hash &&\n    ++\t\tgit -C same config set core.repositoryformatversion 1 &&\n    ++\t\tgit -C same config set extensions.compatObjectFormat $hash &&\n     +\t\ttest_must_fail git -C same rev-parse --git-dir 2>err &&\n    -+\t\ttest_grep \\\"'extensions.compatobjectformat' is '$hash', the same as the object format\\\" err &&\n    -+\t\tgit config --file=same/.git/config --unset extensions.compatObjectFormat &&\n    ++\t\ttest_grep \\\"'extensions.compatObjectFormat' is '$hash', the same as the object format\\\" err &&\n    ++\t\tgit config unset --file=same/.git/config extensions.compatObjectFormat &&\n     +\t\tgit -C same rev-parse --git-dir\n     +\t\"\n     +done\n2:  066fc59207 ! 2:  5b91372748 rev-parse: die when --output-object-format cannot map an object\n    @@ Commit message\n         rev-parse: die when --output-object-format cannot map an object\n     \n         \"git rev-parse --output-object-format=<compat-format>\" should print\n    -    an object compat id when extensions.compatObjectFormat is enabled.\n    +    the compat ID of an object when extensions.compatObjectFormat is\n    +    enabled.\n     \n    -    Git however doesn't record a compat id for every object, e.g. for\n    +    Git however doesn't record a compat ID for every object, e.g. for\n         objects received by a fetch that goes through index-pack.\n    -    For such objects, rev-parse silently prints the wrong id: it prints\n    -    the storage id where the compat id is expected and exits with 0.\n    +    For such objects, rev-parse silently prints the wrong ID: it prints\n    +    the storage ID where the compat ID is expected and exits with 0.\n     \n         This happens because rev-parse ignores the repo_oid_to_algop() return\n         value. When no mapping is found, that function fails and leaves the\n    -    id unchanged, so the storage id is what gets printed.\n    +    ID unchanged, so the storage ID is what gets printed.\n     \n         Fix it to die with the same message as pack-objects. The other callers\n         of repo_oid_to_algop() already check its result.\n     \n    -    This only covers a single revision argument, the one case where\n    -    rev-parse converts its output. Other forms, such as \"A..B\" or \"A^@\",\n    -    print storage ids whatever --output-object-format says. That is left\n    -    for a separate change.\n    -\n    -    The test copies a loose object into the repository by hand, so it\n    -    doesn't depend on whether fetch writes compat mappings.\n    +    Note that this only covers the case where the user asks for a single\n    +    revision, as it is the only case where rev-parse passes the desired\n    +    output hash explicitly. All the other cases, like for example when the\n    +    user passes a range, do not use the desired output hash at all. Fixing\n    +    that would be a bigger change though, so it is left for a future patch\n    +    series.\n     \n         Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n     \n    @@ builtin/rev-parse.c: int cmd_rev_parse(int argc,\n     -\t\t\t\t\t\t  output_algo, &oid);\n     +\t\t\tif (output_algo &&\n     +\t\t\t    repo_oid_to_algop(the_repository, &oid,\n    -+\t\t\t\t\t      output_algo, &oid))\n    ++\t\t\t\t\t      output_algo, &oid) < 0)\n     +\t\t\t\tdie(_(\"cannot map object %s to %s\"),\n     +\t\t\t\t    oid_to_hex(&oid), output_algo->name);\n      \t\t\tif (verify)\n    @@ t/t1500-rev-parse.sh: test_expect_success RUST 'rev-parse --show-object-format i\n      '\n      \n     +test_expect_success RUST 'rev-parse --output-object-format with unmapped object' '\n    -+\ttest_when_finished \"rm -rf plain compat\" &&\n    -+\tgit init --object-format=sha256 plain &&\n    -+\tgit init --object-format=sha256 compat &&\n    -+\tgit -C compat config extensions.compatobjectformat sha1 &&\n    -+\toid=$(echo unmapped | git -C plain hash-object -w --stdin) &&\n    -+\t# copy the object by hand, so that no compat mapping is written for it\n    -+\tpath=$(test_oid_to_path $oid) &&\n    -+\tmkdir compat/.git/objects/${path%/*} &&\n    -+\tcp plain/.git/objects/$path compat/.git/objects/$path &&\n    ++\ttest_when_finished \"rm -rf unmapped\" &&\n    ++\tgit init --object-format=sha256 unmapped &&\n    ++\t# write the object before enabling compat, so it gets no compat mapping\n    ++\toid=$(echo unmapped | git -C unmapped hash-object -w --stdin) &&\n    ++\tgit -C unmapped config set extensions.compatObjectFormat sha1 &&\n     +\techo $oid >expect &&\n    -+\tgit -C compat rev-parse --output-object-format=sha256 $oid >actual &&\n    ++\tgit -C unmapped rev-parse --output-object-format=sha256 $oid >actual &&\n     +\ttest_cmp expect actual &&\n    -+\ttest_must_fail git -C compat rev-parse --output-object-format=sha1 $oid >actual 2>err &&\n    ++\ttest_must_fail git -C unmapped rev-parse --output-object-format=sha1 $oid >actual 2>err &&\n     +\ttest_must_be_empty actual &&\n     +\ttest_grep \"cannot map object $oid to sha1\" err\n     +'\n3:  a171e86b54 ! 3:  26080a7a38 object-file-convert: copy unknown commit headers unchanged\n    @@ Commit message\n         don't know:\n     \n         1. When a commit is created with commit_tree_extended(), as\n    -       \"git commit\" does, convert_commit_extra_headers() copies unknown\n    +       git-commit(1) does, convert_commit_extra_headers() copies unknown\n            headers unchanged.\n     \n    -    2. When an existing commit object is converted (git hash-object -w)\n    -       or when it's read by its compat id, convert_commit_object() fails\n    +    2. When an existing commit object is converted (git-hash-object(1) -w)\n    +       or when it's read by its compat ID, convert_commit_object() fails\n            on them instead.\n     \n    -    So git hash-object refuses such a commit, while git commit --amend\n    -    records a compat id for it that can't be read back:\n    +    So git-hash-object(1) refuses such a commit, while \"git commit --amend\"\n    +    records a compat ID for it that can't be read back:\n            \"Failed to convert object from sha256 to sha1\".\n     \n         The rejection was added in 08a45903cb (object-file-convert: convert\n         commits that embed signed tags, 2023-10-01). Git can't know what an\n    -    unknown header holds. It might hold an object id that needs\n    +    unknown header holds. It might hold an object ID that needs\n         converting, so convert_commit_object() rejects all of them.\n     \n         Some tools rely on such headers though. Jujutsu, for example, writes\n    @@ Commit message\n         converted.\n     \n         Make convert_commit_object() copy unknown headers and their\n    -    continuation lines unchanged, just like convert_commit_extra_headers()\n    +    continuation lines unchanged, just like convert_commit_extra_headers(),\n         so both give the same compat object.\n     \n         The author, committer, encoding and gpgsig headers were already copied\n         the same, so their separate cases are no longer needed.\n     \n    -    A \"tree\", \"parent\" or \"mergetag\" line with nothing after the keyword\n    -    used to be rejected as unknown and is now copied as well. Such a\n    -    commit is malformed in both formats anyway.\n    +    The \"tree \", \"parent \" and \"mergetag \" cases only matched a line with\n    +    something after the space. That didn't matter while all other lines\n    +    were rejected, but they would now be copied. For a \"mergetag \" line\n    +    whose tag starts on the next line, the object ID in the tag would be\n    +    copied unconverted, even though Git reads that header as a mergetag and\n    +    convert_commit_extra_headers() refuses to convert it.\n    +\n    +    Match these headers by their key alone instead, the way\n    +    read_commit_extra_header_lines() does. Such a line with an empty or bad\n    +    value is then rejected, as before. A \"tree\", \"parent\" or \"mergetag\"\n    +    line without a space is not one of these headers to Git, so it is\n    +    copied like any other unknown header, which is also what\n    +    convert_commit_extra_headers() does.\n     \n         Alternatives considered:\n     \n    @@ Commit message\n            Both paths would then agree, but commits from tools that add\n            their own headers could not be used in a compat repo.\n     \n    -     - Copy only headers known to hold no object ids. Every tool would\n    +     - Copy only headers known to hold no object IDs. Every tool would\n            first need to get its headers added to that list.\n     \n    -    The test writes a commit with an unknown header with \"git hash-object\",\n    -    amends it with \"git commit\", and checks that both commits map to the\n    -    same objects in the SHA-1 and the SHA-256 repo.\n    +     - Convert values that look like object IDs. Any other hex string\n    +       could be taken for one, and Git shouldn't interpret headers it\n    +       doesn't know.\n    +\n    +     - Also reject lines that don't look like \"<key> <value>\". This would\n    +       make the two paths disagree again, because\n    +       convert_commit_extra_headers() copies such lines, so\n    +       \"git commit --amend\" would record compat IDs that can't be read\n    +       back.\n     \n         Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n     \n      ## object-file-convert.c ##\n    +@@ object-file-convert.c: static int convert_commit_object(struct repository *repo,\n    + \t\tif (!eol)\n    + \t\t\treturn error(_(\"bad %s in commit\"), \"line\");\n    + \n    +-\t\tif (((bufptr + 5) < eol) && !memcmp(bufptr, \"tree \", 5))\n    ++\t\tif (((bufptr + 5) <= eol) && !memcmp(bufptr, \"tree \", 5))\n    + \t\t{\n    + \t\t\tif (((bufptr + tree_entry_len) != eol) ||\n    + \t\t\t    parse_oid_hex_algop(bufptr + 5, &oid, &p, from) ||\n    +@@ object-file-convert.c: static int convert_commit_object(struct repository *repo,\n    + \t\t\t\t\t     \"tree\", oid_to_hex(&oid));\n    + \t\t\tstrbuf_addf(out, \"tree %s\\n\", oid_to_hex(&mapped_oid));\n    + \t\t}\n    +-\t\telse if (((bufptr + 7) < eol) && !memcmp(bufptr, \"parent \", 7))\n    ++\t\telse if (((bufptr + 7) <= eol) && !memcmp(bufptr, \"parent \", 7))\n    + \t\t{\n    + \t\t\tif (((bufptr + parent_entry_len) != eol) ||\n    + \t\t\t    parse_oid_hex_algop(bufptr + 7, &oid, &p, from) ||\n    +@@ object-file-convert.c: static int convert_commit_object(struct repository *repo,\n    + \n    + \t\t\tstrbuf_addf(out, \"parent %s\\n\", oid_to_hex(&mapped_oid));\n    + \t\t}\n    +-\t\telse if (((bufptr + 9) < eol) && !memcmp(bufptr, \"mergetag \", 9))\n    ++\t\telse if (((bufptr + 9) <= eol) && !memcmp(bufptr, \"mergetag \", 9))\n    + \t\t{\n    + \t\t\tstruct strbuf tag = STRBUF_INIT, new_tag = STRBUF_INIT;\n    + \n     @@ object-file-convert.c: static int convert_commit_object(struct repository *repo,\n      \t\t\tstrbuf_release(&tag);\n      \t\t\tstrbuf_release(&new_tag);\n    @@ object-file-convert.c: static int convert_commit_object(struct repository *repo,\n     -\t\t\t/* Unknown line fail it might embed an oid */\n     -\t\t\treturn -1;\n     +\t\t\t/*\n    -+\t\t\t * Copy all other headers unchanged. author, committer, encoding and gpgsig\n    -+\t\t\t * hold no object ids. For unknown headers we can't tell, so copy them too,\n    -+\t\t\t * like convert_commit_extra_headers() does when the commit is written. Both\n    -+\t\t\t * must give the same compat object.\n    ++\t\t\t * Copy all other headers unchanged. author, committer,\n    ++\t\t\t * encoding and gpgsig hold no object IDs. For unknown\n    ++\t\t\t * headers we can't tell, so copy them too, like\n    ++\t\t\t * convert_commit_extra_headers() does when the commit\n    ++\t\t\t * is written. Both must give the same compat object.\n    ++\t\t\t *\n    ++\t\t\t * This means that a header holding object IDs is\n    ++\t\t\t * copied without converting them. Any such header added\n    ++\t\t\t * to Git needs its own case above, like parent or\n    ++\t\t\t * mergetag, and the same conversion in\n    ++\t\t\t * convert_commit_extra_headers().\n     +\t\t\t *\n    -+\t\t\t * This means that a header holding object ids is copied without converting\n    -+\t\t\t * them. Any such header added to Git needs its own case above, like parent\n    -+\t\t\t * or mergetag, and the same conversion in convert_commit_extra_headers().\n    ++\t\t\t * The cases above match a header by its key alone, as\n    ++\t\t\t * read_commit_extra_header_lines() does, so that e.g. a\n    ++\t\t\t * \"mergetag \" line with nothing after the space is\n    ++\t\t\t * still handled as a mergetag instead of being copied.\n     +\t\t\t */\n     +\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n      \t\t}\n    @@ object-file-convert.c: static int convert_commit_object(struct repository *repo,\n     \n      ## t/t1016-compatObjectFormat.sh ##\n     @@ t/t1016-compatObjectFormat.sh: do\n    - \t\teval signedtag3_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag3) &&\n      \t\teval signedtag4_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag4)\n      \t'\n    + \n     +\ttest_expect_success \"create a $hash commit with an unknown header\" '\n     +\t\tgit cat-file commit $(commit2_oid $hash) >../${hash}_commit2 &&\n     +\t\tawk \"{ print } /^committer / { print \\\"x-unknown one\\\"; print \\\" two\\\" }\" \\\n    @@ t/t1016-compatObjectFormat.sh: do\n     +\t\teval unknownheader_${hash}_oid=$oid &&\n     +\t\tgit branch unknownheader $oid\n     +\t'\n    ++\n     +\ttest_expect_success \"amend a $hash commit with an unknown header\" '\n     +\t\tgit checkout unknownheader &&\n     +\t\tgit commit --amend -m \"Amend a commit with an unknown header\" &&\n    @@ t/t1016-compatObjectFormat.sh: do\n     +\t\toid=$(git rev-parse HEAD) &&\n     +\t\teval unknownheader2_${hash}_oid=$oid\n     +\t'\n    - \n    ++\n    ++\ttest_expect_success \"reject a $hash commit with an empty mergetag line\" '\n    ++\t\tgit cat-file tag committag >../${hash}_committag &&\n    ++\t\t{\n    ++\t\t\tsed -n \"/^committer /q;p\" ../${hash}_commit2 &&\n    ++\t\t\tgrep \"^committer \" ../${hash}_commit2 &&\n    ++\t\t\techo \"mergetag \" &&\n    ++\t\t\tsed \"s/^/ /\" ../${hash}_committag &&\n    ++\t\t\techo &&\n    ++\t\t\techo message\n    ++\t\t} >../${hash}_emptymergetag &&\n    ++\t\ttest_must_fail git hash-object -t commit -w ../${hash}_emptymergetag 2>err &&\n    ++\t\ttest_grep \"Failed to convert object\" err\n    ++\t'\n    ++\n      \ttest_expect_success 'rev-parse maps oid of object borrowed from alternate' '\n      \t\tfor repo in alt borrow\n    + \t\tdo\n     @@ t/t1016-compatObjectFormat.sh: compare_oids 'blob' more \"$more_sha1_oid\" \"$more_sha256_oid\"\n      compare_oids 'blob' another \"$another_sha1_oid\" \"$another_sha256_oid\"\n      compare_oids 'tree' tree2 \"$tree2_sha1_oid\" \"$tree2_sha256_oid\"\n-- \n2.56.1\n\n\n"},{"id":"558848","messageId":"f74a0fd67af600f45bdb7560253c747aab073c65.1794932695.git.adrian.ratiu@collabora.com","threadId":"66839","inReplyTo":"cover.1794932695.git.adrian.ratiu@collabora.com","subject":"[PATCH v2 1/3] setup: reject compatObjectFormat == objectFormat","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-19T14:18:20Z","receivedAt":"2026-11-19T14:18:20Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"When extensions.compatObjectFormat sets the same hash as the repo\nobject format, every command in a build with Rust aborts with:\n\n  BUG: repository.c:204: hash_algo and compat_hash_algo match\n\nThis includes \"git config\", so the bad value can't be removed with\nGit. It also happens with no extensions.objectFormat at all, when\ncompatObjectFormat is set to the default object format.\n\nCheck for this in verify_repository_format(), next to the other\nrepo format checks, and return an error instead.\n\nThe check runs before any of the Rust-only code. Builds without\nRust, which so far died because compatObjectFormat requires Rust,\nnow get the same error, so the test needs no RUST prereq.\n\nSigned-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n---\n setup.c                 |  7 +++++++\n t/t1302-repo-version.sh | 14 ++++++++++++++\n 2 files changed, 21 insertions(+)\n\ndiff --git a/setup.c b/setup.c\nindex 186815c780..a97280cafe 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -918,6 +918,13 @@ int verify_repository_format(const struct repository_format *format,\n \t\treturn -1;\n \t}\n \n+\tif (format->compat_hash_algo == format->hash_algo) {\n+\t\tstrbuf_addf(err, _(\"'%s' is '%s', the same as the object format\"),\n+\t\t\t    \"extensions.compatObjectFormat\",\n+\t\t\t    hash_algos[format->hash_algo].name);\n+\t\treturn -1;\n+\t}\n+\n \treturn 0;\n }\n \ndiff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh\nindex 69723b88ff..718dafc95c 100755\n--- a/t/t1302-repo-version.sh\n+++ b/t/t1302-repo-version.sh\n@@ -98,6 +98,20 @@ abort 0 noop-v1\n allow 1 noop-v1\n EOF\n \n+for hash in sha1 sha256\n+do\n+\ttest_expect_success \"compatObjectFormat equal to objectFormat $hash\" \"\n+\t\ttest_when_finished 'rm -rf same' &&\n+\t\tgit init --object-format=$hash same &&\n+\t\tgit -C same config set core.repositoryformatversion 1 &&\n+\t\tgit -C same config set extensions.compatObjectFormat $hash &&\n+\t\ttest_must_fail git -C same rev-parse --git-dir 2>err &&\n+\t\ttest_grep \\\"'extensions.compatObjectFormat' is '$hash', the same as the object format\\\" err &&\n+\t\tgit config unset --file=same/.git/config extensions.compatObjectFormat &&\n+\t\tgit -C same rev-parse --git-dir\n+\t\"\n+done\n+\n test_expect_success 'precious-objects allowed' '\n \tgit config core.repositoryFormatVersion 1 &&\n \tgit config extensions.preciousObjects 1 &&\n-- \n2.56.1\n\n\n"},{"id":"558849","messageId":"5b9137274818319747b3eeafaf800ec6874df1d4.1794932695.git.adrian.ratiu@collabora.com","threadId":"66839","inReplyTo":"cover.1794932695.git.adrian.ratiu@collabora.com","subject":"[PATCH v2 2/3] rev-parse: die when --output-object-format cannot map an object","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-19T14:18:21Z","receivedAt":"2026-11-19T14:18:21Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"\"git rev-parse --output-object-format=<compat-format>\" should print\nthe compat ID of an object when extensions.compatObjectFormat is\nenabled.\n\nGit however doesn't record a compat ID for every object, e.g. for\nobjects received by a fetch that goes through index-pack.\nFor such objects, rev-parse silently prints the wrong ID: it prints\nthe storage ID where the compat ID is expected and exits with 0.\n\nThis happens because rev-parse ignores the repo_oid_to_algop() return\nvalue. When no mapping is found, that function fails and leaves the\nID unchanged, so the storage ID is what gets printed.\n\nFix it to die with the same message as pack-objects. The other callers\nof repo_oid_to_algop() already check its result.\n\nNote that this only covers the case where the user asks for a single\nrevision, as it is the only case where rev-parse passes the desired\noutput hash explicitly. All the other cases, like for example when the\nuser passes a range, do not use the desired output hash at all. Fixing\nthat would be a bigger change though, so it is left for a future patch\nseries.\n\nSigned-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n---\n builtin/rev-parse.c  |  8 +++++---\n t/t1500-rev-parse.sh | 14 ++++++++++++++\n 2 files changed, 19 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex d2154eac8d..f4b5a31aff 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -1171,9 +1171,11 @@ int cmd_rev_parse(int argc,\n \t\t}\n \t\tif (!repo_get_oid_with_flags(the_repository, name, &oid,\n \t\t\t\t\t     flags)) {\n-\t\t\tif (output_algo)\n-\t\t\t\trepo_oid_to_algop(the_repository, &oid,\n-\t\t\t\t\t\t  output_algo, &oid);\n+\t\t\tif (output_algo &&\n+\t\t\t    repo_oid_to_algop(the_repository, &oid,\n+\t\t\t\t\t      output_algo, &oid) < 0)\n+\t\t\t\tdie(_(\"cannot map object %s to %s\"),\n+\t\t\t\t    oid_to_hex(&oid), output_algo->name);\n \t\t\tif (verify)\n \t\t\t\trevs_count++;\n \t\t\telse\ndiff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh\nindex 30bf8a4d0a..a945f421da 100755\n--- a/t/t1500-rev-parse.sh\n+++ b/t/t1500-rev-parse.sh\n@@ -241,6 +241,20 @@ test_expect_success RUST 'rev-parse --show-object-format in repo with compat mod\n \t)\n '\n \n+test_expect_success RUST 'rev-parse --output-object-format with unmapped object' '\n+\ttest_when_finished \"rm -rf unmapped\" &&\n+\tgit init --object-format=sha256 unmapped &&\n+\t# write the object before enabling compat, so it gets no compat mapping\n+\toid=$(echo unmapped | git -C unmapped hash-object -w --stdin) &&\n+\tgit -C unmapped config set extensions.compatObjectFormat sha1 &&\n+\techo $oid >expect &&\n+\tgit -C unmapped rev-parse --output-object-format=sha256 $oid >actual &&\n+\ttest_cmp expect actual &&\n+\ttest_must_fail git -C unmapped rev-parse --output-object-format=sha1 $oid >actual 2>err &&\n+\ttest_must_be_empty actual &&\n+\ttest_grep \"cannot map object $oid to sha1\" err\n+'\n+\n test_expect_success 'rev-parse --show-ref-storage-format' '\n \ttest_detect_ref_format >expect &&\n \tgit rev-parse --show-ref-storage-format >actual &&\n-- \n2.56.1\n\n\n"},{"id":"558850","messageId":"26080a7a386bdd0ae14725d2e731d1be81774d49.1794932695.git.adrian.ratiu@collabora.com","threadId":"66839","inReplyTo":"cover.1794932695.git.adrian.ratiu@collabora.com","subject":"[PATCH v2 3/3] object-file-convert: copy unknown commit headers unchanged","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-19T14:18:22Z","receivedAt":"2026-11-19T14:18:22Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"In a repo with extensions.compatObjectFormat, Git converts commits\nto the compat format in two places which disagree about headers they\ndon't know:\n\n1. When a commit is created with commit_tree_extended(), as\n   git-commit(1) does, convert_commit_extra_headers() copies unknown\n   headers unchanged.\n\n2. When an existing commit object is converted (git-hash-object(1) -w)\n   or when it's read by its compat ID, convert_commit_object() fails\n   on them instead.\n\nSo git-hash-object(1) refuses such a commit, while \"git commit --amend\"\nrecords a compat ID for it that can't be read back:\n   \"Failed to convert object from sha256 to sha1\".\n\nThe rejection was added in 08a45903cb (object-file-convert: convert\ncommits that embed signed tags, 2023-10-01). Git can't know what an\nunknown header holds. It might hold an object ID that needs\nconverting, so convert_commit_object() rejects all of them.\n\nSome tools rely on such headers though. Jujutsu, for example, writes\na \"change-id\" header in every commit, so none of its commits can be\nconverted.\n\nMake convert_commit_object() copy unknown headers and their\ncontinuation lines unchanged, just like convert_commit_extra_headers(),\nso both give the same compat object.\n\nThe author, committer, encoding and gpgsig headers were already copied\nthe same, so their separate cases are no longer needed.\n\nThe \"tree \", \"parent \" and \"mergetag \" cases only matched a line with\nsomething after the space. That didn't matter while all other lines\nwere rejected, but they would now be copied. For a \"mergetag \" line\nwhose tag starts on the next line, the object ID in the tag would be\ncopied unconverted, even though Git reads that header as a mergetag and\nconvert_commit_extra_headers() refuses to convert it.\n\nMatch these headers by their key alone instead, the way\nread_commit_extra_header_lines() does. Such a line with an empty or bad\nvalue is then rejected, as before. A \"tree\", \"parent\" or \"mergetag\"\nline without a space is not one of these headers to Git, so it is\ncopied like any other unknown header, which is also what\nconvert_commit_extra_headers() does.\n\nAlternatives considered:\n\n - Reject unknown headers in convert_commit_extra_headers() too.\n   Both paths would then agree, but commits from tools that add\n   their own headers could not be used in a compat repo.\n\n - Copy only headers known to hold no object IDs. Every tool would\n   first need to get its headers added to that list.\n\n - Convert values that look like object IDs. Any other hex string\n   could be taken for one, and Git shouldn't interpret headers it\n   doesn't know.\n\n - Also reject lines that don't look like \"<key> <value>\". This would\n   make the two paths disagree again, because\n   convert_commit_extra_headers() copies such lines, so\n   \"git commit --amend\" would record compat IDs that can't be read\n   back.\n\nSigned-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n---\n object-file-convert.c         | 35 ++++++++++++++++++++++-------------\n t/t1016-compatObjectFormat.sh | 34 ++++++++++++++++++++++++++++++++++\n 2 files changed, 56 insertions(+), 13 deletions(-)\n\ndiff --git a/object-file-convert.c b/object-file-convert.c\nindex 63ee18630b..ae21eedc3d 100644\n--- a/object-file-convert.c\n+++ b/object-file-convert.c\n@@ -167,7 +167,7 @@ static int convert_commit_object(struct repository *repo,\n \t\tif (!eol)\n \t\t\treturn error(_(\"bad %s in commit\"), \"line\");\n \n-\t\tif (((bufptr + 5) < eol) && !memcmp(bufptr, \"tree \", 5))\n+\t\tif (((bufptr + 5) <= eol) && !memcmp(bufptr, \"tree \", 5))\n \t\t{\n \t\t\tif (((bufptr + tree_entry_len) != eol) ||\n \t\t\t    parse_oid_hex_algop(bufptr + 5, &oid, &p, from) ||\n@@ -179,7 +179,7 @@ static int convert_commit_object(struct repository *repo,\n \t\t\t\t\t     \"tree\", oid_to_hex(&oid));\n \t\t\tstrbuf_addf(out, \"tree %s\\n\", oid_to_hex(&mapped_oid));\n \t\t}\n-\t\telse if (((bufptr + 7) < eol) && !memcmp(bufptr, \"parent \", 7))\n+\t\telse if (((bufptr + 7) <= eol) && !memcmp(bufptr, \"parent \", 7))\n \t\t{\n \t\t\tif (((bufptr + parent_entry_len) != eol) ||\n \t\t\t    parse_oid_hex_algop(bufptr + 7, &oid, &p, from) ||\n@@ -192,7 +192,7 @@ static int convert_commit_object(struct repository *repo,\n \n \t\t\tstrbuf_addf(out, \"parent %s\\n\", oid_to_hex(&mapped_oid));\n \t\t}\n-\t\telse if (((bufptr + 9) < eol) && !memcmp(bufptr, \"mergetag \", 9))\n+\t\telse if (((bufptr + 9) <= eol) && !memcmp(bufptr, \"mergetag \", 9))\n \t\t{\n \t\t\tstruct strbuf tag = STRBUF_INIT, new_tag = STRBUF_INIT;\n \n@@ -223,17 +223,26 @@ static int convert_commit_object(struct repository *repo,\n \t\t\tstrbuf_release(&tag);\n \t\t\tstrbuf_release(&new_tag);\n \t\t}\n-\t\telse if (((bufptr + 7) < tail) && !memcmp(bufptr, \"author \", 7))\n-\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n-\t\telse if (((bufptr + 10) < tail) && !memcmp(bufptr, \"committer \", 10))\n-\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n-\t\telse if (((bufptr + 9) < tail) && !memcmp(bufptr, \"encoding \", 9))\n-\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n-\t\telse if (((bufptr + 6) < tail) && !memcmp(bufptr, \"gpgsig\", 6))\n-\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n \t\telse {\n-\t\t\t/* Unknown line fail it might embed an oid */\n-\t\t\treturn -1;\n+\t\t\t/*\n+\t\t\t * Copy all other headers unchanged. author, committer,\n+\t\t\t * encoding and gpgsig hold no object IDs. For unknown\n+\t\t\t * headers we can't tell, so copy them too, like\n+\t\t\t * convert_commit_extra_headers() does when the commit\n+\t\t\t * is written. Both must give the same compat object.\n+\t\t\t *\n+\t\t\t * This means that a header holding object IDs is\n+\t\t\t * copied without converting them. Any such header added\n+\t\t\t * to Git needs its own case above, like parent or\n+\t\t\t * mergetag, and the same conversion in\n+\t\t\t * convert_commit_extra_headers().\n+\t\t\t *\n+\t\t\t * The cases above match a header by its key alone, as\n+\t\t\t * read_commit_extra_header_lines() does, so that e.g. a\n+\t\t\t * \"mergetag \" line with nothing after the space is\n+\t\t\t * still handled as a mergetag instead of being copied.\n+\t\t\t */\n+\t\t\tstrbuf_add(out, bufptr, (eol - bufptr) + 1);\n \t\t}\n \t\t/* Consume any trailing continuation lines */\n \t\tbufptr = eol + 1;\ndiff --git a/t/t1016-compatObjectFormat.sh b/t/t1016-compatObjectFormat.sh\nindex 9cafcee509..fdb882c686 100755\n--- a/t/t1016-compatObjectFormat.sh\n+++ b/t/t1016-compatObjectFormat.sh\n@@ -188,6 +188,38 @@ do\n \t\teval signedtag4_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag4)\n \t'\n \n+\ttest_expect_success \"create a $hash commit with an unknown header\" '\n+\t\tgit cat-file commit $(commit2_oid $hash) >../${hash}_commit2 &&\n+\t\tawk \"{ print } /^committer / { print \\\"x-unknown one\\\"; print \\\" two\\\" }\" \\\n+\t\t\t<../${hash}_commit2 >../${hash}_unknownheader &&\n+\t\toid=$(git hash-object -t commit -w ../${hash}_unknownheader) &&\n+\t\teval unknownheader_${hash}_oid=$oid &&\n+\t\tgit branch unknownheader $oid\n+\t'\n+\n+\ttest_expect_success \"amend a $hash commit with an unknown header\" '\n+\t\tgit checkout unknownheader &&\n+\t\tgit commit --amend -m \"Amend a commit with an unknown header\" &&\n+\t\tgit cat-file commit HEAD >actual &&\n+\t\ttest_grep \"^x-unknown one$\" actual &&\n+\t\toid=$(git rev-parse HEAD) &&\n+\t\teval unknownheader2_${hash}_oid=$oid\n+\t'\n+\n+\ttest_expect_success \"reject a $hash commit with an empty mergetag line\" '\n+\t\tgit cat-file tag committag >../${hash}_committag &&\n+\t\t{\n+\t\t\tsed -n \"/^committer /q;p\" ../${hash}_commit2 &&\n+\t\t\tgrep \"^committer \" ../${hash}_commit2 &&\n+\t\t\techo \"mergetag \" &&\n+\t\t\tsed \"s/^/ /\" ../${hash}_committag &&\n+\t\t\techo &&\n+\t\t\techo message\n+\t\t} >../${hash}_emptymergetag &&\n+\t\ttest_must_fail git hash-object -t commit -w ../${hash}_emptymergetag 2>err &&\n+\t\ttest_grep \"Failed to convert object\" err\n+\t'\n+\n \ttest_expect_success 'rev-parse maps oid of object borrowed from alternate' '\n \t\tfor repo in alt borrow\n \t\tdo\n@@ -298,6 +330,8 @@ compare_oids 'blob' more \"$more_sha1_oid\" \"$more_sha256_oid\"\n compare_oids 'blob' another \"$another_sha1_oid\" \"$another_sha256_oid\"\n compare_oids 'tree' tree2 \"$tree2_sha1_oid\" \"$tree2_sha256_oid\"\n compare_oids 'commit' commit2 \"$commit2_sha1_oid\" \"$commit2_sha256_oid\"\n+compare_oids 'commit' unknownheader \"$unknownheader_sha1_oid\" \"$unknownheader_sha256_oid\"\n+compare_oids 'commit' unknownheader2 \"$unknownheader2_sha1_oid\" \"$unknownheader2_sha256_oid\"\n compare_oids GPG2 'tag' signedtag2 \"$signedtag2_sha1_oid\" \"$signedtag2_sha256_oid\"\n compare_oids GPG2 'commit' signedcommit2 \"$signedcommit2_sha1_oid\" \"$signedcommit2_sha256_oid\"\n compare_oids GPG2 'commit' signedcommit3 \"$signedcommit3_sha1_oid\" \"$signedcommit3_sha256_oid\"\n-- \n2.56.1\n\n\n"}]}