]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/hash-object: fix uninitialized hash function
authorPatrick Steinhardt <ps@pks.im>
Mon, 20 May 2024 23:14:33 +0000 (16:14 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 21 May 2024 16:05:13 +0000 (09:05 -0700)
commit8d058b8024ff57b2c6653a0667b01cfedb1bce44
tree3dc62bbb225c3a5a26777af7c162e767074b1276
parent4a1c95931f5f0dc541925703b7d9ad9409cd4067
builtin/hash-object: fix uninitialized hash function

The git-hash-object(1) command allows users to hash an object even
without a repository. Starting with c8aed5e8da (repository: stop setting
SHA1 as the default object hash, 2024-05-07), this will make us hit an
uninitialized hash function, which subsequently leads to a segfault.

Fix this by falling back to SHA-1 explicitly when running outside of
a Git repository. Users can use GIT_DEFAULT_HASH environment to
specify what hash algorithm they want, so arguably this code should
not be needed.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/hash-object.c
t/t1007-hash-object.sh
t/t1517-outside-repo.sh