From: "Ophir Bleicher via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Ophir Bleicher <ophirble@gmail.com>, Ophir Bleicher <ophirble@gmail.com>
Subject: [PATCH] rev-parse: output requested object format in SHA-1 compatible repos
Date: Fri, 20 Nov 2026 15:08:33 +0000 [thread overview]
Message-ID: <pull.2494.git.git.1795187313105.gitgitgadget@gmail.com> (raw)
From: Ophir Bleicher <ophirble@gmail.com>
git rev-parse --output-object-format=sha1 <oid> outputs the wrong
hash when the repository uses SHA-256 but is SHA-1 compatible, and
the requested object was made before the repository was SHA-1
compatible.
For example:
git init --object-format=sha256
oid=$(echo unmapped | git hash-object -w --stdin)
git config extensions.compatObjectFormat sha1
git rev-parse --output-object-format=sha1 "$oid"
The last command outputs the SHA-256 value of the object, even
though --output-object-format=sha1 was passed.
Now an error is raised instead of outputting a wrong hash.
Signed-off-by: Ophir Bleicher <ophirble@gmail.com>
---
rev-parse: output requested object format in SHA-1 compatible repos
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2494%2FOphirBleicher%2Fsha1-compat-rev-parse-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2494/OphirBleicher/sha1-compat-rev-parse-v1
Pull-Request: https://github.com/git/git/pull/2494
builtin/rev-parse.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index fbc5ef8727..5d3ac2a865 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -1175,9 +1175,10 @@ 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))
+ die(_("cannot map object %s to %s"), oid_to_hex(&oid),
+ output_algo->name);
if (verify)
revs_count++;
else
base-commit: f7de81456940dd6f3274e461149bba12965de609
--
gitgitgadget
reply other threads:[~2026-11-20 15:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.2494.git.git.1795187313105.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=ophirble@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.