]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'il/maint-colon-address'
authorJunio C Hamano <gitster@pobox.com>
Wed, 27 Jan 2010 22:56:42 +0000 (14:56 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 Jan 2010 22:56:42 +0000 (14:56 -0800)
* il/maint-colon-address:
  Allow use of []-wrapped addresses in git://
  Support addresses with ':' in git-daemon

connect.c
daemon.c

index 3a125621465a68a267d08f74d842238a078c51b2..20054e4d0fd4cf94288593726be179d07d19271c 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -502,12 +502,18 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
                c = ':';
        }
 
+       /*
+        * Don't do destructive transforms with git:// as that
+        * protocol code does '[]' dewrapping of its own.
+        */
        if (host[0] == '[') {
                end = strchr(host + 1, ']');
                if (end) {
-                       *end = 0;
+                       if (protocol != PROTO_GIT) {
+                               *end = 0;
+                               host++;
+                       }
                        end++;
-                       host++;
                } else
                        end = host;
        } else
index 360635eb1c14608b44568ce39d969eb8822e688d..6c2bd977131752e05d3ac545af0d977d6d7ca672 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -399,6 +399,33 @@ static char *xstrdup_tolower(const char *str)
        return dup;
 }
 
+static void parse_host_and_port(char *hostport, char **host,
+       char **port)
+{
+       if (*hostport == '[') {
+               char *end;
+
+               end = strchr(hostport, ']');
+               if (!end)
+                       die("Invalid reqeuest ('[' without ']')");
+               *end = '\0';
+               *host = hostport + 1;
+               if (!end[1])
+                       *port = NULL;
+               else if (end[1] == ':')
+                       *port = end + 2;
+               else
+                       die("Garbage after end of host part");
+       } else {
+               *host = hostport;
+               *port = strrchr(hostport, ':');
+               if (*port) {
+                       *port = '\0';
+                       ++*port;
+               }
+       }
+}
+
 /*
  * Read the host as supplied by the client connection.
  */
@@ -415,11 +442,10 @@ static void parse_host_arg(char *extra_args, int buflen)
                        vallen = strlen(val) + 1;
                        if (*val) {
                                /* Split <host>:<port> at colon. */
-                               char *host = val;
-                               char *port = strrchr(host, ':');
+                               char *host;
+                               char *port;
+                               parse_host_and_port(val, &host, &port);
                                if (port) {
-                                       *port = 0;
-                                       port++;
                                        free(tcp_port);
                                        tcp_port = xstrdup(port);
                                }