Instead of calling get_remote_heads as a first command during the
protocol exchange, we need to have fine grained control over the
capability negotiation in version 2 of the protocol.

Introduce get_remote_capabilities, which will just listen to
capabilities of the remote and request_capabilities which will
tell the selection of capabilities to the remote.

Signed-off-by: Stefan Beller <sbel...@google.com>
---
 connect.c | 37 +++++++++++++++++++++++++++++++++++++
 remote.h  |  3 +++
 2 files changed, 40 insertions(+)

diff --git a/connect.c b/connect.c
index a2c777e..4ebe1dc 100644
--- a/connect.c
+++ b/connect.c
@@ -105,6 +105,43 @@ static void annotate_refs_with_symref_info(struct ref *ref)
        string_list_clear(&symref, 0);
 }
 
+void get_remote_capabilities(int in, char *src_buf, size_t src_len)
+{
+       string_list_clear(&server_capabilities, 1);
+       for (;;) {
+               int len;
+               char *line = packet_buffer;
+
+               len = packet_read(in, &src_buf, &src_len,
+                                 packet_buffer, sizeof(packet_buffer),
+                                 PACKET_READ_GENTLE_ON_EOF |
+                                 PACKET_READ_CHOMP_NEWLINE);
+               if (len < 0)
+                       die_initial_contact(0);
+
+               if (!len)
+                       break;
+
+               string_list_append(&server_capabilities, line);
+       }
+}
+
+int request_capabilities(int out, struct transport_options *options)
+{
+       if (options->multi_ack == 2)    packet_write(out, "multi_ack_detailed");
+       if (options->multi_ack == 1)    packet_write(out, "multi_ack");
+       if (options->no_done)           packet_write(out, "no-done");
+       if (options->use_sideband == 2) packet_write(out, "side-band-64k");
+       if (options->use_sideband == 1) packet_write(out, "side-band");
+       if (options->use_thin_pack)     packet_write(out, "thin-pack");
+       if (options->no_progress)       packet_write(out, "no-progress");
+       if (options->include_tag)       packet_write(out, "include-tag");
+       if (options->prefer_ofs_delta)  packet_write(out, "ofs-delta");
+       if (options->agent_supported)   packet_write(out, "agent=%s",
+                                                    
git_user_agent_sanitized());
+       packet_flush(out);
+}
+
 /*
  * Read all the refs from the other end
  */
diff --git a/remote.h b/remote.h
index 3767bed..61619c5 100644
--- a/remote.h
+++ b/remote.h
@@ -165,6 +165,9 @@ extern void get_remote_heads(int in, char *src_buf, size_t 
src_len,
                             struct sha1_array *extra_have,
                             struct sha1_array *shallow);
 
+void get_remote_capabilities(int in, char *src_buf, size_t src_len);
+int request_capabilities(int out, struct transport_options*);
+
 int resolve_remote_symref(struct ref *ref, struct ref *list);
 int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1);
 
-- 
2.4.1.345.gab207b6.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to