aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/rev-parse.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-05-07 06:53:15 +0200
committerJunio C Hamano <gitster@pobox.com>2024-05-06 22:50:49 -0700
commit07658e9ce5b156876eebf81f39e0672a5347eae5 (patch)
treec43edb7b1542967eb68aca66fbe31b0836bfe5b2 /builtin/rev-parse.c
parentremote-curl: fix parsing of detached SHA256 heads (diff)
downloadgit-07658e9ce5b156876eebf81f39e0672a5347eae5.tar.gz
git-07658e9ce5b156876eebf81f39e0672a5347eae5.zip
builtin/rev-parse: allow shortening to more than 40 hex characters
The `--short=` option for git-rev-parse(1) allows the user to specify to how many characters object IDs should be shortened to. The option is broken though for SHA256 repositories because we set the maximum allowed hash size to `the_hash_algo->hexsz` before we have even set up the repo. Consequently, `the_hash_algo` will always be SHA1 and thus we truncate every hash after at most 40 characters. Fix this by accessing `the_hash_algo` only after we have set up the repo. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/rev-parse.c')
-rw-r--r--builtin/rev-parse.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index af79538632..7d10ee33c4 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -687,7 +687,6 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
const char *name = NULL;
struct object_context unused;
struct strbuf buf = STRBUF_INIT;
- const int hexsz = the_hash_algo->hexsz;
int seen_end_of_options = 0;
enum format_type format = FORMAT_DEFAULT;
@@ -863,8 +862,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
abbrev = strtoul(arg, NULL, 10);
if (abbrev < MINIMUM_ABBREV)
abbrev = MINIMUM_ABBREV;
- else if (hexsz <= abbrev)
- abbrev = hexsz;
+ else if ((int)the_hash_algo->hexsz <= abbrev)
+ abbrev = the_hash_algo->hexsz;
continue;
}
if (!strcmp(arg, "--sq")) {