Re: [PATCH/RFC] upload-pack: fix slow fetches from a shallow repository
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 19, 2026, 13:27 UTC
- Message-ID
- <xmqqpkx57rcv.fsf@gitster.g>
- In-Reply-To
- <pull.2455.git.git.1792275106640.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 13 quoted lines
> diff --git a/upload-pack.c b/upload-pack.c > index 197bcfa279..844bf80575 100644 > --- a/upload-pack.c > +++ b/upload-pack.c > @@ -1718,9 +1718,8 @@ static void send_shallow_info(struct upload_pack_data *data) > > packet_writer_write(&data->writer, "shallow-info\n"); > > - if (!send_shallow_list(data) && > - is_repository_shallow(the_repository)) > - deepen(data, INFINITE_DEPTH); > + if (!send_shallow_list(data)) > + advertise_shallow_grafts(1);
The advertise_shallow_grafts() function is written for protocol v0 and uses packet_write_fmt() to write raw data directly to the named file descriptor (in this case, fd #1).
However, protocol v2 negotiation uses the packet_writer API. When sideband-all is in use, the response must be multiplexed over the sideband channel. Because the updated code fails to use the packet_writer API, 'shallow' lines are written without the '\001' band designator. The other side then interprets 's' (the first byte of 'shallow', which is 115 in decimal) as the sideband channel and dies with a protocol violation.
t/t5702-protocol-v2.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git c/t/t5702-protocol-v2.sh w/t/t5702-protocol-v2.sh index 7e69ba7f84..df3ec8c1c9 100755 --- c/t/t5702-protocol-v2.sh +++ w/t/t5702-protocol-v2.sh @@ -15,6 +15,18 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME start_git_daemon --export-all --enable=receive-pack daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent +test_expect_success 'fetch from shallow server over v2' ' + test_when_finished "rm -fr server shallow-server client" && + git init server && + test_commit -C server one && + test_commit -C server two && + git clone --depth=1 "file://$(pwd)/server" shallow-server && + test_commit -C shallow-server three && + + git -C shallow-server config uploadpack.allowsidebandall true && + git -c protocol.version=2 clone "file://$(pwd)/shallow-server" client +' + test_expect_success 'create repo to be served by git-daemon' ' git init "$daemon_parent" && test_commit -C "$daemon_parent" one