Merge branch 'jc/fetch-progressive-stride'
authorJunio C Hamano <gitster@pobox.com>
Sun, 27 Mar 2011 03:13:15 +0000 (20:13 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 27 Mar 2011 03:13:15 +0000 (20:13 -0700)
* jc/fetch-progressive-stride:
fetch-pack: use smaller handshake window for initial request
fetch-pack: progressively use larger handshake windows
fetch-pack: factor out hardcoded handshake window size

Conflicts:
builtin/fetch-pack.c

1  2 
builtin/fetch-pack.c
diff --combined builtin/fetch-pack.c
index 0ef9a119405160ddacfb7a80a119ff749bb3a4f8,3c2c9406c499102138495638d98797886855c073..bf9990ce15bf582293535606467fb209457bcfe1
@@@ -1,4 -1,4 +1,4 @@@
 -#include "cache.h"
 +#include "builtin.h"
  #include "refs.h"
  #include "pkt-line.h"
  #include "commit.h"
@@@ -9,7 -9,6 +9,7 @@@
  #include "fetch-pack.h"
  #include "remote.h"
  #include "run-command.h"
 +#include "transport.h"
  
  static int transfer_unpack_limit = -1;
  static int fetch_unpack_limit = -1;
@@@ -219,21 -218,25 +219,35 @@@ static void send_request(int fd, struc
                safe_write(fd, buf->buf, buf->len);
  }
  
 +static void insert_one_alternate_ref(const struct ref *ref, void *unused)
 +{
 +      rev_list_insert_ref(NULL, ref->old_sha1, 0, NULL);
 +}
 +
 +static void insert_alternate_refs(void)
 +{
 +      foreach_alt_odb(refs_from_alternate_cb, insert_one_alternate_ref);
 +}
 +
+ #define INITIAL_FLUSH 16
+ #define LARGE_FLUSH 1024
+ static int next_flush(int count)
+ {
+       if (count < INITIAL_FLUSH * 2)
+               count += INITIAL_FLUSH;
+       else if (count < LARGE_FLUSH)
+               count <<= 1;
+       else
+               count += LARGE_FLUSH;
+       return count;
+ }
  static int find_common(int fd[2], unsigned char *result_sha1,
                       struct ref *refs)
  {
        int fetching;
-       int count = 0, flushes = 0, retval;
+       int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval;
        const unsigned char *sha1;
        unsigned in_vain = 0;
        int got_continue = 0;
        marked = 1;
  
        for_each_ref(rev_list_insert_ref, NULL);
 +      insert_alternate_refs();
  
        fetching = 0;
        for ( ; refs ; refs = refs->next) {
                if (args.verbose)
                        fprintf(stderr, "have %s\n", sha1_to_hex(sha1));
                in_vain++;
-               if (!(31 & ++count)) {
+               if (flush_at <= ++count) {
                        int ack;
  
                        packet_buf_flush(&req_buf);
                        send_request(fd[1], &req_buf);
                        strbuf_setlen(&req_buf, state_len);
                        flushes++;
+                       flush_at = next_flush(count);
  
                        /*
                         * We keep one window "ahead" of the other side, and
                         * will wait for an ACK only on the next one
                         */
-                       if (!args.stateless_rpc && count == 32)
+                       if (!args.stateless_rpc && count == INITIAL_FLUSH)
                                continue;
  
                        consume_shallow_list(fd[0]);
@@@ -830,8 -833,6 +845,8 @@@ int cmd_fetch_pack(int argc, const cha
        char **pack_lockfile_ptr = NULL;
        struct child_process *conn;
  
 +      packet_trace_identity("fetch-pack");
 +
        nr_heads = 0;
        heads = NULL;
        for (i = 1; i < argc; i++) {