{"thread":{"id":"66898","subject":"[PATCH] rev-parse: output requested object format in SHA-1 compatible repos","startedAt":"2026-11-20T15:08:33Z","lastAt":"2026-11-20T15:08:33Z","messageCount":1,"participants":["Ophir Bleicher via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"558953","messageId":"pull.2494.git.git.1795187313105.gitgitgadget@gmail.com","threadId":"66898","inReplyTo":null,"subject":"[PATCH] rev-parse: output requested object format in SHA-1 compatible repos","fromName":"Ophir Bleicher via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-20T15:08:33Z","receivedAt":"2026-11-20T15:08:33Z","isPatch":true,"sender":{"key":"name:Ophir Bleicher","avatar":null},"body":"From: Ophir Bleicher <ophirble@gmail.com>\n\ngit rev-parse --output-object-format=sha1 <oid> outputs the wrong\nhash when the repository uses SHA-256 but is SHA-1 compatible, and\nthe requested object was made before the repository was SHA-1\ncompatible.\n\nFor example:\ngit init --object-format=sha256\noid=$(echo unmapped | git hash-object -w --stdin)\ngit config extensions.compatObjectFormat sha1\ngit rev-parse --output-object-format=sha1 \"$oid\"\n\nThe last command outputs the SHA-256 value of the object, even\nthough --output-object-format=sha1 was passed.\n\nNow an error is raised instead of outputting a wrong hash.\n\nSigned-off-by: Ophir Bleicher <ophirble@gmail.com>\n---\n    rev-parse: output requested object format in SHA-1 compatible repos\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2494%2FOphirBleicher%2Fsha1-compat-rev-parse-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2494/OphirBleicher/sha1-compat-rev-parse-v1\nPull-Request: https://github.com/git/git/pull/2494\n\n builtin/rev-parse.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex fbc5ef8727..5d3ac2a865 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -1175,9 +1175,10 @@ 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 && repo_oid_to_algop(the_repository, &oid,\n+\t\t\t\t\t\t\t     output_algo, &oid))\n+\t\t\t\tdie(_(\"cannot map object %s to %s\"), oid_to_hex(&oid),\n+\t\t\t\t      output_algo->name);\n \t\t\tif (verify)\n \t\t\t\trevs_count++;\n \t\t\telse\n\nbase-commit: f7de81456940dd6f3274e461149bba12965de609\n-- \ngitgitgadget\n\n"}]}