Skip to content

Commit 19ec592

Browse files
author
Colin Stolley
committed
push: Prepare pack before sending pack header.
For large pushes, preparing the pack can take a while. Currently we send the pack header first, followed by preparing the pack and then finally sending the pack. Unfortunately github.com will terminate a git-receive-pack command over http if it is idle for more than 10 seconds. This is easily exceeded for a large push, and so the push is rejected with a Broken Pipe error. This patch moves the pack preparation ahead of sending the pack header, so that the timeout is avoided. prepare_pack() can be called multiple times but will only do the work once, so the original PREPARE_PACK call inside git_packbuilder_foreach() remains.
1 parent 12b53eb commit 19ec592

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

src/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
13081308
#define ll_find_deltas(pb, l, ls, w, d) find_deltas(pb, l, &ls, w, d)
13091309
#endif
13101310

1311-
static int prepare_pack(git_packbuilder *pb)
1311+
int prepare_pack(git_packbuilder *pb)
13121312
{
13131313
git_pobject **delta_list;
13141314
size_t i, n = 0;

src/pack-objects.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,7 @@ struct git_packbuilder {
9797
};
9898

9999
int git_packbuilder__write_buf(git_str *buf, git_packbuilder *pb);
100+
int prepare_pack(git_packbuilder *pb);
101+
100102

101103
#endif

src/transports/smart_protocol.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,10 @@ int git_smart__push(git_transport *transport, git_push *push, const git_remote_c
10341034
}
10351035
}
10361036

1037+
/* prepare pack before sending pack header to avoid timeouts */
1038+
if (need_pack && ((error = prepare_pack(push->pb))) < 0)
1039+
goto done;
1040+
10371041
if ((error = git_smart__get_push_stream(t, &packbuilder_payload.stream)) < 0 ||
10381042
(error = gen_pktline(&pktline, push)) < 0 ||
10391043
(error = packbuilder_payload.stream->write(packbuilder_payload.stream, git_str_cstr(&pktline), git_str_len(&pktline))) < 0)

0 commit comments

Comments
 (0)