Code

Require a struct remote in transport_get()
authorDaniel Barkalow <barkalow@iabervon.org>
Wed, 4 Nov 2009 02:38:51 +0000 (21:38 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 4 Nov 2009 05:39:28 +0000 (21:39 -0800)
cmd_ls_remote() was calling transport_get() with a NULL remote and a
non-NULL url in the case where it was run outside a git
repository. This involved a bunch of ill-tested special
cases. Instead, simply get the struct remote for the URL with
remote_get(), which works fine outside a git repository, and can also
take global options into account.

This fixes a tiny and obscure bug where "git ls-remote" without a repo
didn't support global url.*.insteadOf, even though "git clone" and
"git ls-remote" in any repo did.

Also, enforce that all callers provide a struct remote to transport_get().

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-ls-remote.c
transport.c

index 78a88f74769645f0be86aa77d3dee3f5e99c916f..b5bad0c184fc1ebc49759f211781ecd4031fd027 100644 (file)
@@ -86,10 +86,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
                        pattern[j - i] = p;
                }
        }
-       remote = nongit ? NULL : remote_get(dest);
-       if (remote && !remote->url_nr)
+       remote = remote_get(dest);
+       if (!remote->url_nr)
                die("remote %s has no configured URL", dest);
-       transport = transport_get(remote, remote ? remote->url[0] : dest);
+       transport = transport_get(remote, remote->url[0]);
        if (uploadpack != NULL)
                transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
 
index 644a30a0b200b339d291f4cc3d35b2268d12facd..298dc46ec5ede0b972ec9be46556ffbec17df253 100644 (file)
@@ -812,6 +812,9 @@ struct transport *transport_get(struct remote *remote, const char *url)
 {
        struct transport *ret = xcalloc(1, sizeof(*ret));
 
+       if (!remote)
+               die("No remote provided to transport_get()");
+
        ret->remote = remote;
        ret->url = url;
 
@@ -849,10 +852,10 @@ struct transport *transport_get(struct remote *remote, const char *url)
                data->thin = 1;
                data->conn = NULL;
                data->uploadpack = "git-upload-pack";
-               if (remote && remote->uploadpack)
+               if (remote->uploadpack)
                        data->uploadpack = remote->uploadpack;
                data->receivepack = "git-receive-pack";
-               if (remote && remote->receivepack)
+               if (remote->receivepack)
                        data->receivepack = remote->receivepack;
        }