]> git.ipfire.org Git - thirdparty/git.git/blobdiff - remote-curl.c
Merge git://git.bogomips.org/git-svn
[thirdparty/git.git] / remote-curl.c
index 1f41a90936e5865d94883f57887e7ce57b716f0f..775d6143037aa4573c0202715fe1b1a0f99e2799 100644 (file)
@@ -9,8 +9,7 @@
 #include "sideband.h"
 
 static struct remote *remote;
-static const char *url;
-static struct walker *walker;
+static const char *url; /* always ends with a trailing slash */
 
 struct options {
        int verbosity;
@@ -22,12 +21,6 @@ struct options {
 };
 static struct options options;
 
-static void init_walker(void)
-{
-       if (!walker)
-               walker = get_http_walker(url, remote);
-}
-
 static int set_option(const char *name, const char *value)
 {
        if (!strcmp(name, "verbosity")) {
@@ -108,7 +101,7 @@ static struct discovery* discover_refs(const char *service)
                return last;
        free_discovery(last);
 
-       strbuf_addf(&buffer, "%s/info/refs", url);
+       strbuf_addf(&buffer, "%sinfo/refs", url);
        if (!prefixcmp(url, "http://") || !prefixcmp(url, "https://")) {
                is_http = 1;
                if (!strchr(url, '?'))
@@ -119,7 +112,6 @@ static struct discovery* discover_refs(const char *service)
        }
        refs_url = strbuf_detach(&buffer, NULL);
 
-       init_walker();
        http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
 
        /* try again with "plain" url (no ? or & appended) */
@@ -128,7 +120,7 @@ static struct discovery* discover_refs(const char *service)
                strbuf_reset(&buffer);
 
                proto_git_candidate = 0;
-               strbuf_addf(&buffer, "%s/info/refs", url);
+               strbuf_addf(&buffer, "%sinfo/refs", url);
                refs_url = strbuf_detach(&buffer, NULL);
 
                http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
@@ -140,6 +132,8 @@ static struct discovery* discover_refs(const char *service)
        case HTTP_MISSING_TARGET:
                die("%s not found: did you run git update-server-info on the"
                    " server?", refs_url);
+       case HTTP_NOAUTH:
+               die("Authentication failed");
        default:
                http_error(refs_url, http_ret);
                die("HTTP request failed");
@@ -250,9 +244,8 @@ static struct ref *parse_info_refs(struct discovery *heads)
                i++;
        }
 
-       init_walker();
        ref = alloc_ref("HEAD");
-       if (!walker->fetch_ref(walker, ref) &&
+       if (!http_fetch_ref(url, ref) &&
            !resolve_remote_symref(ref, refs)) {
                ref->next = refs;
                refs = ref;
@@ -546,7 +539,6 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
        struct child_process client;
        int err = 0;
 
-       init_walker();
        memset(&client, 0, sizeof(client));
        client.in = -1;
        client.out = -1;
@@ -563,7 +555,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
        rpc->out = client.out;
        strbuf_init(&rpc->result, 0);
 
-       strbuf_addf(&buf, "%s/%s", url, svc);
+       strbuf_addf(&buf, "%s%s", url, svc);
        rpc->service_url = strbuf_detach(&buf, NULL);
 
        strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc);
@@ -580,11 +572,12 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
                rpc->len = n;
                err |= post_rpc(rpc);
        }
-       strbuf_read(&rpc->result, client.out, 0);
 
        close(client.in);
-       close(client.out);
        client.in = -1;
+       strbuf_read(&rpc->result, client.out, 0);
+
+       close(client.out);
        client.out = -1;
 
        err |= finish_command(&client);
@@ -598,6 +591,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
 
 static int fetch_dumb(int nr_heads, struct ref **to_fetch)
 {
+       struct walker *walker;
        char **targets = xmalloc(nr_heads * sizeof(char*));
        int ret, i;
 
@@ -606,13 +600,14 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch)
        for (i = 0; i < nr_heads; i++)
                targets[i] = xstrdup(sha1_to_hex(to_fetch[i]->old_sha1));
 
-       init_walker();
+       walker = get_http_walker(url);
        walker->get_all = 1;
        walker->get_tree = 1;
        walker->get_history = 1;
        walker->get_verbosely = options.verbosity >= 3;
        walker->get_recover = 0;
        ret = walker_fetch(walker, nr_heads, targets, NULL, NULL);
+       walker_free(walker);
 
        for (i = 0; i < nr_heads; i++)
                free(targets[i]);
@@ -850,11 +845,15 @@ int main(int argc, const char **argv)
        remote = remote_get(argv[1]);
 
        if (argc > 2) {
-               url = argv[2];
+               end_url_with_slash(&buf, argv[2]);
        } else {
-               url = remote->url[0];
+               end_url_with_slash(&buf, remote->url[0]);
        }
 
+       url = strbuf_detach(&buf, NULL);
+
+       http_init(remote);
+
        do {
                if (strbuf_getline(&buf, stdin, '\n') == EOF)
                        break;
@@ -900,5 +899,8 @@ int main(int argc, const char **argv)
                }
                strbuf_reset(&buf);
        } while (1);
+
+       http_cleanup();
+
        return 0;
 }