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

In c8aed5e8da (repository: stop setting SHA1 as the default object hash,
2024-05-07), we have adapted `initialize_repository()` to no longer set
up a default hash function. As this function is also used to set up
`the_repository`, the consequence is that `the_hash_algo` will now by
default be a `NULL` pointer unless the hash algorithm was configured
properly. This is done as a mechanism to detect cases where we may be
using the wrong hash function by accident.

This change now causes git-patch-id(1) to segfault when it's run outside
of a repository. As this command can read diffs from stdin, it does not
necessarily need a repository, but then relies on `the_hash_algo` to
compute the patch ID itself.

It is somewhat dubious that git-patch-id(1) relies on `the_hash_algo` in
the first place. Quoting its manpage:

    A "patch ID" is nothing but a sum of SHA-1 of the file diffs
    associated with a patch, with line numbers ignored. As such, it’s
    "reasonably stable", but at the same time also reasonably unique,
    i.e., two patches that have the same "patch ID" are almost
    guaranteed to be the same thing.

We explicitly document patch IDs to be using SHA-1. Furthermore, patch
IDs are supposed to be stable for most of the part. But even with the
same input, the patch IDs will now be different depending on the repo's
configured object hash.

Work around the issue by setting up SHA-1 when there was no startup
repository for now. This is arguably not the correct fix, but for now we
rather want to focus on getting the segfault fixed.

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