X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=connect.c;h=7636bf976e78a6622281501af2dcc0135781f60a;hb=78360b576acb0ee47c90552cb3f976a3c6ba4d6a;hp=dd96f8e0435ded892001783b69fba6a6fb3be288;hpb=141201d124f3663a98e0f362c1af7f5f7b58dabb;p=git.git diff --git a/connect.c b/connect.c index dd96f8e04..7636bf976 100644 --- a/connect.c +++ b/connect.c @@ -41,12 +41,20 @@ int check_ref_type(const struct ref *ref, int flags) return check_ref(ref->name, strlen(ref->name), flags); } +static void add_extra_have(struct extra_have_objects *extra, unsigned char *sha1) +{ + ALLOC_GROW(extra->array, extra->nr + 1, extra->alloc); + hashcpy(&(extra->array[extra->nr][0]), sha1); + extra->nr++; +} + /* * Read all the refs from the other end */ struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, - unsigned int flags) + unsigned int flags, + struct extra_have_objects *extra_have) { *list = NULL; for (;;) { @@ -62,6 +70,9 @@ struct ref **get_remote_heads(int in, struct ref **list, if (buffer[len-1] == '\n') buffer[--len] = 0; + if (len > 4 && !prefixcmp(buffer, "ERR ")) + die("remote error: %s", buffer + 4); + if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ') die("protocol error: expected sha/ref, got '%s'", buffer); name = buffer + 41; @@ -72,13 +83,18 @@ struct ref **get_remote_heads(int in, struct ref **list, server_capabilities = xstrdup(name + name_len + 1); } + if (extra_have && + name_len == 5 && !memcmp(".have", name, 5)) { + add_extra_have(extra_have, old_sha1); + continue; + } + if (!check_ref(name, name_len, flags)) continue; if (nr_match && !path_match(name, nr_match, match)) continue; - ref = alloc_ref(name_len + 1); + ref = alloc_ref(buffer + 41); hashcpy(ref->old_sha1, old_sha1); - memcpy(ref->name, buffer + 41, name_len + 1); *list = ref; list = &ref->next; } @@ -299,7 +315,7 @@ static int git_tcp_connect_sock(char *host, int flags) /* Not numeric */ struct servent *se = getservbyname(port,"tcp"); if ( !se ) - die("Unknown port %s\n", port); + die("Unknown port %s", port); nport = se->s_port; } @@ -357,8 +373,6 @@ static void git_tcp_connect(int fd[2], char *host, int flags) static char *git_proxy_command; -static const char *rhost_name; -static int rhost_len; static int git_proxy_command_options(const char *var, const char *value, void *cb) @@ -367,6 +381,8 @@ static int git_proxy_command_options(const char *var, const char *value, const char *for_pos; int matchlen = -1; int hostlen; + const char *rhost_name = cb; + int rhost_len = strlen(rhost_name); if (git_proxy_command) return 0; @@ -410,11 +426,8 @@ static int git_proxy_command_options(const char *var, const char *value, static int git_use_proxy(const char *host) { - rhost_name = host; - rhost_len = strlen(host); git_proxy_command = getenv("GIT_PROXY_COMMAND"); - git_config(git_proxy_command_options, NULL); - rhost_name = NULL; + git_config(git_proxy_command_options, (void*)host); return (git_proxy_command && *git_proxy_command); } @@ -464,8 +477,8 @@ char *get_port(char *host) char *p = strchr(host, ':'); if (p) { - strtol(p+1, &end, 10); - if (*end == '\0') { + long port = strtol(p + 1, &end, 10); + if (end != p + 1 && *end == '\0' && 0 <= port && port < 65536) { *p = '\0'; return p+1; } @@ -491,7 +504,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig, const char *prog, int flags) { char *url = xstrdup(url_orig); - char *host, *path = url; + char *host, *path; char *end; int c; struct child_process *conn;