@matheusbsbs / matheus-bagliano / commits / c12f5917e4
Fork 0

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 <gitster@pobox.com> Acked-by: Shawn Pearce <spearce@spearce.org>

Junio C Hamano committed Mar 20, 2011 at 21:52 UTC c12f5917e4f528b056a8b9ca625397aee97ae1e4
1 file changed +11 -3
builtin/fetch-pack.c
+11 -3
@@ -218,11 +218,18 @@ static void send_request(int fd, struct strbuf *buf)
218 safe_write(fd, buf->buf, buf->len);
219 }
220
221 +#define INITIAL_FLUSH 32
222 +
223 +static int next_flush(int count)
224 +{
225 + return INITIAL_FLUSH + count;
226 +}
227 +
228 static int find_common(int fd[2], unsigned char *result_sha1,
229 struct ref *refs)
230 {
231 int fetching;
225 - int count = 0, flushes = 0, retval;
232 + int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval;
233 const unsigned char *sha1;
234 unsigned in_vain = 0;
235 int got_continue = 0;
@@ -335,19 +342,20 @@ static int find_common(int fd[2], unsigned char *result_sha1,
342 if (args.verbose)
343 fprintf(stderr, "have %s\n", sha1_to_hex(sha1));
344 in_vain++;
338 - if (!(31 & ++count)) {
345 + if (flush_at <= ++count) {
346 int ack;
347
348 packet_buf_flush(&req_buf);
349 send_request(fd[1], &req_buf);
350 strbuf_setlen(&req_buf, state_len);
351 flushes++;
352 + flush_at = next_flush(count);
353
354 /*
355 * We keep one window "ahead" of the other side, and
356 * will wait for an ACK only on the next one
357 */
350 - if (!args.stateless_rpc && count == 32)
358 + if (!args.stateless_rpc && count == INITIAL_FLUSH)
359 continue;
360
361 consume_shallow_list(fd[0]);