{"thread":{"id":"21474","subject":"[PATCH] Require a struct remote in transport_get()","startedAt":"2009-11-04T02:38:51Z","lastAt":"2009-11-04T07:27:57Z","messageCount":3,"participants":["Daniel Barkalow","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"126703","messageId":"alpine.LNX.2.00.0911032133540.14365@iabervon.org","threadId":"21474","inReplyTo":null,"subject":"[PATCH] Require a struct remote in transport_get()","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-11-04T02:38:51Z","receivedAt":"2009-11-04T02:38:51Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"cmd_ls_remote() was calling transport_get() with a NULL remote and a\nnon-NULL url in the case where it was run outside a git\nrepository. This involved a bunch of ill-tested special\ncases. Instead, simply get the struct remote for the URL with\nremote_get(), which works fine outside a git repository, and can also\ntake global options into account.\n\nThis fixes a tiny and obscure bug where \"git ls-remote\" without a repo\ndidn't support global url.*.insteadOf, even though \"git clone\" and\n\"git ls-remote\" in any repo did.\n\nAlso, enforce that all callers provide a struct remote to transport_get().\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\nThis is sufficient to stop the segfault when tring \"git ls-remote \nhttp://...\" outside of a repo, but not to make it work, which requires \neither something simple but not ideal or something complex.\n\n builtin-ls-remote.c |    6 +++---\n transport.c         |    7 +++++--\n 2 files changed, 8 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin-ls-remote.c b/builtin-ls-remote.c\nindex 78a88f7..b5bad0c 100644\n--- a/builtin-ls-remote.c\n+++ b/builtin-ls-remote.c\n@@ -86,10 +86,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)\n \t\t\tpattern[j - i] = p;\n \t\t}\n \t}\n-\tremote = nongit ? NULL : remote_get(dest);\n-\tif (remote && !remote->url_nr)\n+\tremote = remote_get(dest);\n+\tif (!remote->url_nr)\n \t\tdie(\"remote %s has no configured URL\", dest);\n-\ttransport = transport_get(remote, remote ? remote->url[0] : dest);\n+\ttransport = transport_get(remote, remote->url[0]);\n \tif (uploadpack != NULL)\n \t\ttransport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);\n \ndiff --git a/transport.c b/transport.c\nindex 644a30a..298dc46 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -812,6 +812,9 @@ struct transport *transport_get(struct remote *remote, const char *url)\n {\n \tstruct transport *ret = xcalloc(1, sizeof(*ret));\n \n+\tif (!remote)\n+\t\tdie(\"No remote provided to transport_get()\");\n+\n \tret->remote = remote;\n \tret->url = url;\n \n@@ -849,10 +852,10 @@ struct transport *transport_get(struct remote *remote, const char *url)\n \t\tdata->thin = 1;\n \t\tdata->conn = NULL;\n \t\tdata->uploadpack = \"git-upload-pack\";\n-\t\tif (remote && remote->uploadpack)\n+\t\tif (remote->uploadpack)\n \t\t\tdata->uploadpack = remote->uploadpack;\n \t\tdata->receivepack = \"git-receive-pack\";\n-\t\tif (remote && remote->receivepack)\n+\t\tif (remote->receivepack)\n \t\t\tdata->receivepack = remote->receivepack;\n \t}\n \n-- \n1.6.5.2.142.g063c5.dirty\n"},{"id":"126716","messageId":"7vbpjin8v0.fsf@alter.siamese.dyndns.org","threadId":"21474","inReplyTo":"alpine.LNX.2.00.0911032133540.14365@iabervon.org","subject":"Re: [PATCH] Require a struct remote in transport_get()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-11-04T05:42:59Z","receivedAt":"2009-11-04T05:42:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniel Barkalow <barkalow@iabervon.org> writes:\n\n> cmd_ls_remote() was calling transport_get() with a NULL remote and a\n> non-NULL url in the case where it was run outside a git\n> repository. This involved a bunch of ill-tested special\n> cases. Instead, simply get the struct remote for the URL with\n> remote_get(), which works fine outside a git repository, and can also\n> take global options into account.\n>\n> This fixes a tiny and obscure bug where \"git ls-remote\" without a repo\n> didn't support global url.*.insteadOf, even though \"git clone\" and\n> \"git ls-remote\" in any repo did.\n>\n> Also, enforce that all callers provide a struct remote to transport_get().\n>\n> Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>\n> ---\n> This is sufficient to stop the segfault when tring \"git ls-remote \n> http://...\" outside of a repo, but not to make it work, which requires \n> either something simple but not ideal or something complex.\n\nThanks; I think this and your other patch are important fixes, and should\ngo directly on 'maint'.  Do you prefer to queue them on 'next' to cook for\na week instead?\n"},{"id":"126733","messageId":"alpine.LNX.2.00.0911040221100.14365@iabervon.org","threadId":"21474","inReplyTo":"7vbpjin8v0.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Require a struct remote in transport_get()","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-11-04T07:27:57Z","receivedAt":"2009-11-04T07:27:57Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Tue, 3 Nov 2009, Junio C Hamano wrote:\n\n> Daniel Barkalow <barkalow@iabervon.org> writes:\n> \n> > cmd_ls_remote() was calling transport_get() with a NULL remote and a\n> > non-NULL url in the case where it was run outside a git\n> > repository. This involved a bunch of ill-tested special\n> > cases. Instead, simply get the struct remote for the URL with\n> > remote_get(), which works fine outside a git repository, and can also\n> > take global options into account.\n> >\n> > This fixes a tiny and obscure bug where \"git ls-remote\" without a repo\n> > didn't support global url.*.insteadOf, even though \"git clone\" and\n> > \"git ls-remote\" in any repo did.\n> >\n> > Also, enforce that all callers provide a struct remote to transport_get().\n> >\n> > Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>\n> > ---\n> > This is sufficient to stop the segfault when tring \"git ls-remote \n> > http://...\" outside of a repo, but not to make it work, which requires \n> > either something simple but not ideal or something complex.\n> \n> Thanks; I think this and your other patch are important fixes, and should\n> go directly on 'maint'.  Do you prefer to queue them on 'next' to cook for\n> a week instead?\n\nI don't think a week on 'next' is likely to turn up any new information; \nthese are all uncommon code paths. It might be worth seeing if the \noriginal reporter is happy with how it's behaving now, though.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"}]}