send-pack/receive-pack: allow errors to be reported back to pusher.
[gitweb.git] / connect.c
index a4d6d356fd3dd3a4169b94a56f71cf5ccc0cbd89..d6f4e4c3a7748a30528dce609ae3b6db09d4bd1d 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -34,10 +34,6 @@ struct ref **get_remote_heads(int in, struct ref **list,
                        die("protocol error: expected sha/ref, got '%s'", buffer);
                name = buffer + 41;
 
-               if (ignore_funny && 45 < len && !memcmp(name, "refs/", 5) &&
-                   check_ref_format(name + 5))
-                       continue;
-
                name_len = strlen(name);
                if (len != name_len + 41) {
                        if (server_capabilities)
@@ -45,6 +41,10 @@ struct ref **get_remote_heads(int in, struct ref **list,
                        server_capabilities = strdup(name + name_len + 1);
                }
 
+               if (ignore_funny && 45 < len && !memcmp(name, "refs/", 5) &&
+                   check_ref_format(name + 5))
+                       continue;
+
                if (nr_match && !path_match(name, nr_match, match))
                        continue;
                ref = xcalloc(1, sizeof(*ref) + len - 40);
@@ -427,7 +427,7 @@ static int git_tcp_connect(int fd[2], const char *prog, char *host, char *path)
                memset(&sa, 0, sizeof sa);
                sa.sin_family = he->h_addrtype;
                sa.sin_port = htons(nport);
-               memcpy(&sa.sin_addr, ap, he->h_length);
+               memcpy(&sa.sin_addr, *ap, he->h_length);
 
                if (connect(sockfd, (struct sockaddr *)&sa, sizeof sa) < 0) {
                        close(sockfd);
@@ -455,6 +455,10 @@ static int rhost_len;
 static int git_proxy_command_options(const char *var, const char *value)
 {
        if (!strcmp(var, "core.gitproxy")) {
+               const char *for_pos;
+               int matchlen = -1;
+               int hostlen;
+
                if (git_proxy_command)
                        return 0;
                /* [core]
@@ -463,10 +467,7 @@ static int git_proxy_command_options(const char *var, const char *value)
                 * gitproxy = netcatter-2 for sample.xz
                 * gitproxy = netcatter-default
                 */
-               const char *for_pos = strstr(value, " for ");
-               int matchlen = -1;
-               int hostlen;
-
+               for_pos = strstr(value, " for ");
                if (!for_pos)
                        /* matches everybody */
                        matchlen = strlen(value);
@@ -560,7 +561,8 @@ int git_connect(int fd[2], char *url, const char *prog)
 {
        char command[1024];
        char *host, *path = url;
-       char *colon = NULL;
+       char *end;
+       int c;
        int pipefd[2][2];
        pid_t pid;
        enum protocol protocol = PROTO_LOCAL;
@@ -570,15 +572,30 @@ int git_connect(int fd[2], char *url, const char *prog)
                *host = '\0';
                protocol = get_protocol(url);
                host += 3;
-               path = strchr(host, '/');
-       }
-       else {
+               c = '/';
+       } else {
                host = url;
-               if ((colon = strchr(host, ':'))) {
+               c = ':';
+       }
+
+       if (host[0] == '[') {
+               end = strchr(host + 1, ']');
+               if (end) {
+                       *end = 0;
+                       end++;
+                       host++;
+               } else
+                       end = host;
+       } else
+               end = host;
+
+       path = strchr(end, c);
+       if (c == ':') {
+               if (path) {
                        protocol = PROTO_SSH;
-                       *colon = '\0';
-                       path = colon + 1;
-               }
+                       *path++ = '\0';
+               } else
+                       path = host;
        }
 
        if (!path || !*path)