checkout_merged(): squelch false warning from some gcc
[gitweb.git] / builtin / fetch-pack.c
index 0ef9a119405160ddacfb7a80a119ff749bb3a4f8..85aff029b225c023f09fda635f16cc00a22ed7ca 100644 (file)
@@ -229,11 +229,26 @@ static void insert_alternate_refs(void)
        foreach_alt_odb(refs_from_alternate_cb, insert_one_alternate_ref);
 }
 
+#define INITIAL_FLUSH 16
+#define PIPESAFE_FLUSH 32
+#define LARGE_FLUSH 1024
+
+static int next_flush(int count)
+{
+       int flush_limit = args.stateless_rpc ? LARGE_FLUSH : PIPESAFE_FLUSH;
+
+       if (count < flush_limit)
+               count <<= 1;
+       else
+               count += flush_limit;
+       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;
@@ -347,19 +362,20 @@ static int find_common(int fd[2], unsigned char *result_sha1,
                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]);
@@ -720,7 +736,8 @@ static struct ref *do_fetch_pack(int fd[2],
                if (server_supports("no-done")) {
                        if (args.verbose)
                                fprintf(stderr, "Server supports no-done\n");
-                       no_done = 1;
+                       if (args.stateless_rpc)
+                               no_done = 1;
                }
        }
        else if (server_supports("multi_ack")) {