]> git.ipfire.org Git - thirdparty/git.git/blobdiff - transport.c
Miscellaneous const changes and utilities
[thirdparty/git.git] / transport.c
index 6fe6ec85031b849b569a2f3f11acca4c6c560f85..ab79f0cbb05977504584ce6a3e04815cb83588d1 100644 (file)
@@ -1,7 +1,9 @@
 #include "cache.h"
 #include "transport.h"
 #include "run-command.h"
+#ifndef NO_CURL
 #include "http.h"
+#endif
 #include "pkt-line.h"
 #include "fetch-pack.h"
 #include "walker.h"
@@ -105,7 +107,7 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
                return;
 
        for (;;) {
-               int cmp, len;
+               int cmp = cmp, len;
 
                if (!fgets(buffer, sizeof(buffer), f)) {
                        fclose(f);
@@ -139,7 +141,7 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
        }
 }
 
-static struct ref *get_refs_via_rsync(const struct transport *transport)
+static struct ref *get_refs_via_rsync(struct transport *transport)
 {
        struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT;
        struct ref dummy, *tail = &dummy;
@@ -279,7 +281,7 @@ static int rsync_transport_push(struct transport *transport,
        struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT;
        int result = 0, i;
        struct child_process rsync;
-       const char *args[8];
+       const char *args[10];
 
        /* first push the objects */
 
@@ -289,14 +291,19 @@ static int rsync_transport_push(struct transport *transport,
        memset(&rsync, 0, sizeof(rsync));
        rsync.argv = args;
        rsync.stdout_to_stderr = 1;
-       args[0] = "rsync";
-       args[1] = (transport->verbose > 0) ? "-av" : "-a";
-       args[2] = "--ignore-existing";
-       args[3] = "--exclude";
-       args[4] = "info";
-       args[5] = get_object_directory();;
-       args[6] = buf.buf;
-       args[7] = NULL;
+       i = 0;
+       args[i++] = "rsync";
+       args[i++] = "-a";
+       if (flags & TRANSPORT_PUSH_DRY_RUN)
+               args[i++] = "--dry-run";
+       if (transport->verbose > 0)
+               args[i++] = "-v";
+       args[i++] = "--ignore-existing";
+       args[i++] = "--exclude";
+       args[i++] = "info";
+       args[i++] = get_object_directory();
+       args[i++] = buf.buf;
+       args[i++] = NULL;
 
        if (run_command(&rsync))
                return error("Could not push objects to %s", transport->url);
@@ -314,7 +321,11 @@ static int rsync_transport_push(struct transport *transport,
        } else if (write_refs_to_temp_dir(&temp_dir, refspec_nr, refspec))
                return -1;
 
-       i = (flags & TRANSPORT_PUSH_FORCE) ? 2 : 3;
+       i = 2;
+       if (flags & TRANSPORT_PUSH_DRY_RUN)
+               args[i++] = "--dry-run";
+       if (!(flags & TRANSPORT_PUSH_FORCE))
+               args[i++] = "--ignore-existing";
        args[i++] = temp_dir.buf;
        args[i++] = transport->url;
        args[i++] = NULL;
@@ -368,6 +379,7 @@ static int disconnect_walker(struct transport *transport)
        return 0;
 }
 
+#ifndef NO_CURL
 static int curl_transport_push(struct transport *transport, int refspec_nr, const char **refspec, int flags) {
        const char **argv;
        int argc;
@@ -380,6 +392,8 @@ static int curl_transport_push(struct transport *transport, int refspec_nr, cons
                argv[argc++] = "--all";
        if (flags & TRANSPORT_PUSH_FORCE)
                argv[argc++] = "--force";
+       if (flags & TRANSPORT_PUSH_DRY_RUN)
+               argv[argc++] = "--dry-run";
        argv[argc++] = transport->url;
        while (refspec_nr--)
                argv[argc++] = *refspec++;
@@ -400,7 +414,6 @@ static int curl_transport_push(struct transport *transport, int refspec_nr, cons
        return !!err;
 }
 
-#ifndef NO_CURL
 static int missing__target(int code, int result)
 {
        return  /* file:// URL -- do we ever use one??? */
@@ -414,7 +427,7 @@ static int missing__target(int code, int result)
 
 #define missing_target(a) missing__target((a)->http_code, (a)->curl_result)
 
-static struct ref *get_refs_via_curl(const struct transport *transport)
+static struct ref *get_refs_via_curl(struct transport *transport)
 {
        struct buffer buffer;
        char *data, *start, *mid;
@@ -504,21 +517,6 @@ static int fetch_objs_via_curl(struct transport *transport,
        return fetch_objs_via_walker(transport, nr_objs, to_fetch);
 }
 
-#else
-
-static struct ref *get_refs_via_curl(const struct transport *transport)
-{
-       die("Cannot fetch from '%s' without curl ...", transport->url);
-       return NULL;
-}
-
-static int fetch_objs_via_curl(struct transport *transport,
-                                int nr_objs, struct ref **to_fetch)
-{
-       die("Cannot fetch from '%s' without curl ...", transport->url);
-       return -1;
-}
-
 #endif
 
 struct bundle_transport_data {
@@ -526,7 +524,7 @@ struct bundle_transport_data {
        struct bundle_header header;
 };
 
-static struct ref *get_refs_from_bundle(const struct transport *transport)
+static struct ref *get_refs_from_bundle(struct transport *transport)
 {
        struct bundle_transport_data *data = transport->data;
        struct ref *result = NULL;
@@ -598,23 +596,18 @@ static int set_git_option(struct transport *connection,
        return 1;
 }
 
-static struct ref *get_refs_via_connect(const struct transport *transport)
+static struct ref *get_refs_via_connect(struct transport *transport)
 {
        struct git_transport_data *data = transport->data;
        struct ref *refs;
        int fd[2];
-       pid_t pid;
        char *dest = xstrdup(transport->url);
-
-       pid = git_connect(fd, dest, data->uploadpack, 0);
-
-       if (pid < 0)
-               die("Failed to connect to \"%s\"", transport->url);
+       struct child_process *conn = git_connect(fd, dest, data->uploadpack, 0);
 
        get_remote_heads(fd[0], &refs, 0, NULL, 0);
        packet_flush(fd[1]);
 
-       finish_connect(pid);
+       finish_connect(conn);
 
        free(dest);
 
@@ -667,6 +660,8 @@ static int git_transport_push(struct transport *transport, int refspec_nr, const
                argv[argc++] = "--all";
        if (flags & TRANSPORT_PUSH_FORCE)
                argv[argc++] = "--force";
+       if (flags & TRANSPORT_PUSH_DRY_RUN)
+               argv[argc++] = "--dry-run";
        if (data->receivepack) {
                char *rp = xmalloc(strlen(data->receivepack) + 16);
                sprintf(rp, "--receive-pack=%s", data->receivepack);
@@ -733,9 +728,13 @@ struct transport *transport_get(struct remote *remote, const char *url)
        } else if (!prefixcmp(url, "http://")
                || !prefixcmp(url, "https://")
                || !prefixcmp(url, "ftp://")) {
+#ifdef NO_CURL
+               error("git was compiled without libcurl support.");
+#else
                ret->get_refs_list = get_refs_via_curl;
                ret->fetch = fetch_objs_via_curl;
                ret->push = curl_transport_push;
+#endif
                ret->disconnect = disconnect_walker;
 
        } else if (is_local(url) && is_file(url)) {
@@ -782,7 +781,7 @@ int transport_push(struct transport *transport,
        return transport->push(transport, refspec_nr, refspec, flags);
 }
 
-struct ref *transport_get_remote_refs(struct transport *transport)
+const struct ref *transport_get_remote_refs(struct transport *transport)
 {
        if (!transport->remote_refs)
                transport->remote_refs = transport->get_refs_list(transport);