]> git.ipfire.org Git - thirdparty/git.git/commit - upload-pack.c
upload-pack: advertise capabilities when cloning empty repos
authorbrian m. carlson <bk2204@github.com>
Wed, 17 May 2023 19:24:43 +0000 (19:24 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 May 2023 20:22:46 +0000 (13:22 -0700)
commit933e3a4ee205353d8f093d5dfcd226fa432c4e58
tree247e2666a7fd325910d8bee3b830a54195c9ff64
parent2807bd2c10606e590886543afe4e4f208dddd489
upload-pack: advertise capabilities when cloning empty repos

When cloning an empty repository, protocol versions 0 and 1 currently
offer nothing but the header and flush packets for the /info/refs
endpoint. This means that no capabilities are provided, so the client
side doesn't know what capabilities are present.

However, this does pose a problem when working with SHA-256
repositories, since we use the capabilities to know the remote side's
object format (hash algorithm).  As of 8b214c2e9d ("clone: propagate
object-format when cloning from void", 2023-04-05), this has been fixed
for protocol v2, since there we always read the hash algorithm from the
remote.

Fortunately, the push version of the protocol already indicates a clue
for how to solve this.  When the /info/refs endpoint is accessed for a
push and the remote is empty, we include a dummy "capabilities^{}" ref
pointing to the all-zeros object ID.  The protocol documentation already
indicates this should _always_ be sent, even for fetches and clones, so
let's just do that, which means we'll properly announce the hash
algorithm as part of the capabilities.  This just works with the
existing code because we share the same ref code for fetches and clones,
and libgit2, JGit, and dulwich do as well.

There is one minor issue to fix, though.  If we called send_ref with
namespaces, we would return NULL with the capabilities entry, which
would cause a crash.  Instead, let's refactor out a function to print
just the ref itself without stripping the namespace and use it for our
special capabilities entry.

Add several sets of tests for HTTP as well as for local clones.  The
behavior can be slightly different for HTTP versus a local or SSH clone
because of the stateless-rpc functionality, so it's worth testing both.

Signed-off-by: brian m. carlson <bk2204@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5551-http-fetch-smart.sh
t/t5700-protocol-v1.sh
upload-pack.c