diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-05-21 01:14:32 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-05-21 18:05:13 +0200 |
commit | 4a1c95931f5f0dc541925703b7d9ad9409cd4067 (patch) | |
tree | 5f31a7bd6fa6b68401503a7fcd37d1811e08416a /t/t1517-outside-repo.sh | |
parent | t1517: test commands that are designed to be run outside repository (diff) | |
download | git-4a1c95931f5f0dc541925703b7d9ad9409cd4067.tar.xz git-4a1c95931f5f0dc541925703b7d9ad9409cd4067.zip |
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>
Diffstat (limited to 't/t1517-outside-repo.sh')
-rwxr-xr-x | t/t1517-outside-repo.sh | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/t/t1517-outside-repo.sh b/t/t1517-outside-repo.sh index 389974d9fb..278ef57b3a 100755 --- a/t/t1517-outside-repo.sh +++ b/t/t1517-outside-repo.sh @@ -21,7 +21,7 @@ test_expect_success 'set up a non-repo directory and test file' ' git diff >sample.patch ' -test_expect_failure 'compute a patch-id outside repository (uses SHA-1)' ' +test_expect_success 'compute a patch-id outside repository (uses SHA-1)' ' nongit env GIT_DEFAULT_HASH=sha1 \ git patch-id <sample.patch >patch-id.expect && nongit \ |