]> git.ipfire.org Git - thirdparty/git.git/commit
remote-curl: fix parsing of detached SHA256 heads
authorPatrick Steinhardt <ps@pks.im>
Tue, 7 May 2024 04:53:10 +0000 (06:53 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 May 2024 05:50:49 +0000 (22:50 -0700)
commitbd455cec37551557e9122102606299c4bdc93505
tree1e4b69d77ca494c56a52f7a2db874b42065adbeb
parent813f17fd6bd9289185a50f1d1179393bd1339b9b
remote-curl: fix parsing of detached SHA256 heads

The dumb HTTP transport tries to read the remote HEAD reference by
downloading the "HEAD" file and then parsing it via `http_fetch_ref()`.
This function will either parse the file as an object ID in case it is
exactly `the_hash_algo->hexsz` long, or otherwise it will check whether
the reference starts with "ref :" and parse it as a symbolic ref.

This is broken when parsing detached HEADs of a remote SHA256 repository
because we never update `the_hash_algo` to the discovered remote object
hash. Consequently, `the_hash_algo` will always be the fallback SHA1
hash algorithm, which will cause us to fail parsing HEAD altogteher when
it contains a SHA256 object ID.

Fix this issue by setting up `the_hash_algo` via `repo_set_hash_algo()`.
While at it, let's make the expected SHA1 fallback explicit in our code,
which also addresses an upcoming issue where we are going to remove the
SHA1 fallback for `the_hash_algo`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote-curl.c
t/t5550-http-fetch-dumb.sh