Skip to content

Commit

Permalink
Merge branch 'dd/upload-pack-stateless-eof'
Browse files Browse the repository at this point in the history
"git fetch --depth=<n>" over the stateless RPC / smart HTTP
transport handled EOF from the client poorly at the server end.

* dd/upload-pack-stateless-eof:
  upload-pack: allow stateless client EOF just prior to haves
  • Loading branch information
gitster committed Nov 18, 2020
2 parents e31aba4 + fb3d1a0 commit d1169be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
17 changes: 17 additions & 0 deletions t/t5530-upload-pack-error.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ test_expect_success 'upload-pack fails due to error in pack-objects enumeration'
grep "pack-objects died" output.err
'

test_expect_success 'upload-pack tolerates EOF just after stateless client wants' '
test_commit initial &&
head=$(git rev-parse HEAD) &&
{
packetize "want $head" &&
packetize "shallow $head" &&
packetize "deepen 1" &&
printf "0000"
} >request &&
printf "0000" >expect &&
git upload-pack --stateless-rpc . <request >actual &&
test_cmp expect actual
'

test_expect_success 'create empty repository' '
mkdir foo &&
Expand Down
13 changes: 12 additions & 1 deletion upload-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,18 @@ void upload_pack(struct upload_pack_options *options)
PACKET_READ_DIE_ON_ERR_PACKET);

receive_needs(&data, &reader);
if (data.want_obj.nr) {

/*
* An EOF at this exact point in negotiation should be
* acceptable from stateless clients as they will consume the
* shallow list before doing subsequent rpc with haves/etc.
*/
if (data.stateless_rpc)
reader.options |= PACKET_READ_GENTLE_ON_EOF;

if (data.want_obj.nr &&
packet_reader_peek(&reader) != PACKET_READ_EOF) {
reader.options &= ~PACKET_READ_GENTLE_ON_EOF;
get_common_commits(&data, &reader);
create_pack_file(&data, NULL);
}
Expand Down

0 comments on commit d1169be

Please sign in to comment.