Code

Support receiving server capabilities
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>
Fri, 28 Oct 2005 02:48:54 +0000 (04:48 +0200)
committerJunio C Hamano <junkio@cox.net>
Sat, 29 Oct 2005 05:57:00 +0000 (22:57 -0700)
This patch implements the client side of backward compatible upload-pack
protocol extension, <20051027141619.0e8029f2.vsu@altlinux.ru> by Sergey.

The updated server can append "server_capabilities" which is supposed
to be a string containing space separated features of the server, after
one of elements in the initial list of SHA1-refname line, hidden with
an embedded NUL.

After get_remote_heads(), check if the server supports the feature like

if (server_supports("multi_ack"))
do_something();

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
cache.h
connect.c

diff --git a/cache.h b/cache.h
index 2e36cc5b8b28859a9e2322893789a27b9057a7be..677c6acc350155d606e2ba05a9bbf5eb28637a31 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -340,6 +340,7 @@ extern int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
                      int nr_refspec, char **refspec, int all);
 extern int get_ack(int fd, unsigned char *result_sha1);
 extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, int ignore_funny);
+extern int server_supports(const char *feature);
 
 extern struct packed_git *parse_pack_index(unsigned char *sha1);
 extern struct packed_git *parse_pack_index_file(const unsigned char *sha1,
index b171c5dbc8c9ecc32f6738d17c339858cbbf76f1..5cc49f975abf7d760f2064402cae2a38bc6a7976 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -8,6 +8,8 @@
 #include <arpa/inet.h>
 #include <netdb.h>
 
+static char *server_capabilities = "";
+
 /*
  * Read all the refs from the other end
  */
@@ -20,7 +22,7 @@ struct ref **get_remote_heads(int in, struct ref **list,
                unsigned char old_sha1[20];
                static char buffer[1000];
                char *name;
-               int len;
+               int len, name_len;
 
                len = packet_read_line(in, buffer, sizeof(buffer));
                if (!len)
@@ -36,6 +38,13 @@ struct ref **get_remote_heads(int in, struct ref **list,
                    check_ref_format(name + 5))
                        continue;
 
+               name_len = strlen(name);
+               if (len != name_len + 41) {
+                       if (server_capabilities)
+                               free(server_capabilities);
+                       server_capabilities = strdup(name + name_len + 1);
+               }
+
                if (nr_match && !path_match(name, nr_match, match))
                        continue;
                ref = xcalloc(1, sizeof(*ref) + len - 40);
@@ -47,6 +56,11 @@ struct ref **get_remote_heads(int in, struct ref **list,
        return list;
 }
 
+int server_supports(const char *feature)
+{
+       return strstr(feature, server_capabilities) != NULL;
+}
+
 int get_ack(int fd, unsigned char *result_sha1)
 {
        static char line[1000];