]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/rev-parse: allow shortening to more than 40 hex characters
authorPatrick Steinhardt <ps@pks.im>
Tue, 7 May 2024 04:53:15 +0000 (06:53 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 May 2024 05:50:49 +0000 (22:50 -0700)
commit07658e9ce5b156876eebf81f39e0672a5347eae5
treec43edb7b1542967eb68aca66fbe31b0836bfe5b2
parentbd455cec37551557e9122102606299c4bdc93505
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>
builtin/rev-parse.c
t/t1500-rev-parse.sh