Skip to content

Commit c12f591

Browse files
committed
fetch-pack: factor out hardcoded handshake window size
The "git fetch" client presents the most recent 32 commits it has to the server and gives a chance to the server to say "ok, we heard enough", and continues reporting what it has in chunks of 32 commits, digging its history down to older commits. Move the hardcoded size of the handshake window outside the code, so that we can tweak it more easily. Signed-off-by: Junio C Hamano <[email protected]> Acked-by: Shawn Pearce <[email protected]>
1 parent 761ecf0 commit c12f591

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

builtin/fetch-pack.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,18 @@ static void send_request(int fd, struct strbuf *buf)
218218
safe_write(fd, buf->buf, buf->len);
219219
}
220220

221+
#define INITIAL_FLUSH 32
222+
223+
static int next_flush(int count)
224+
{
225+
return INITIAL_FLUSH + count;
226+
}
227+
221228
static int find_common(int fd[2], unsigned char *result_sha1,
222229
struct ref *refs)
223230
{
224231
int fetching;
225-
int count = 0, flushes = 0, retval;
232+
int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval;
226233
const unsigned char *sha1;
227234
unsigned in_vain = 0;
228235
int got_continue = 0;
@@ -335,19 +342,20 @@ static int find_common(int fd[2], unsigned char *result_sha1,
335342
if (args.verbose)
336343
fprintf(stderr, "have %s\n", sha1_to_hex(sha1));
337344
in_vain++;
338-
if (!(31 & ++count)) {
345+
if (flush_at <= ++count) {
339346
int ack;
340347

341348
packet_buf_flush(&req_buf);
342349
send_request(fd[1], &req_buf);
343350
strbuf_setlen(&req_buf, state_len);
344351
flushes++;
352+
flush_at = next_flush(count);
345353

346354
/*
347355
* We keep one window "ahead" of the other side, and
348356
* will wait for an ACK only on the next one
349357
*/
350-
if (!args.stateless_rpc && count == 32)
358+
if (!args.stateless_rpc && count == INITIAL_FLUSH)
351359
continue;
352360

353361
consume_shallow_list(fd[0]);

0 commit comments

Comments
 (0)