{"thread":{"id":"19535","subject":"[PATCH 4/7] Allow programs to not depend on remotes having urls","startedAt":"2009-05-27T18:15:42Z","lastAt":"2009-05-27T18:42:57Z","messageCount":2,"participants":["Daniel Barkalow","Bert Wesarg"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"114822","messageId":"alpine.LNX.2.00.0905271408380.2147@iabervon.org","threadId":"19535","inReplyTo":null,"subject":"[PATCH 4/7] Allow programs to not depend on remotes having urls","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-05-27T18:15:42Z","receivedAt":"2009-05-27T18:15:42Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"For fetch and ls-remote, which use the first url of a remote, have\ntransport_get() determine this by passing a remote and passing NULL\nfor the url. For push, which uses every url of a remote, use each url\nin turn if there are any, and use NULL if there are none.\n\nThis will allow the transport code to do something different if the\nlocation is not specified with a url.\n\nAlso, have the message for a fetch say \"foreign\" if there is no url.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n builtin-fetch.c     |   19 +++++++++++------\n builtin-ls-remote.c |    4 +-\n builtin-push.c      |   54 +++++++++++++++++++++++++++++++++-----------------\n transport.c         |    3 ++\n 4 files changed, 52 insertions(+), 28 deletions(-)\n\ndiff --git a/builtin-fetch.c b/builtin-fetch.c\nindex 77acabf..bb1534a 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -341,12 +341,17 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,\n \t\t\twhat = rm->name;\n \t\t}\n \n-\t\turl_len = strlen(url);\n-\t\tfor (i = url_len - 1; url[i] == '/' && 0 <= i; i--)\n-\t\t\t;\n-\t\turl_len = i + 1;\n-\t\tif (4 < i && !strncmp(\".git\", url + i - 3, 4))\n-\t\t\turl_len = i - 3;\n+\t\tif (url) {\n+\t\t\turl_len = strlen(url);\n+\t\t\tfor (i = url_len - 1; url[i] == '/' && 0 <= i; i--)\n+\t\t\t\t;\n+\t\t\turl_len = i + 1;\n+\t\t\tif (4 < i && !strncmp(\".git\", url + i - 3, 4))\n+\t\t\t\turl_len = i - 3;\n+\t\t} else {\n+\t\t\turl = \"foriegn\";\n+\t\t\turl_len = strlen(url);\n+\t\t}\n \n \t\tnote_len = 0;\n \t\tif (*what) {\n@@ -645,7 +650,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n \tif (!remote)\n \t\tdie(\"Where do you want to fetch from today?\");\n \n-\ttransport = transport_get(remote, remote->url[0]);\n+\ttransport = transport_get(remote, NULL);\n \tif (verbosity >= 2)\n \t\ttransport->verbose = 1;\n \tif (verbosity < 0)\ndiff --git a/builtin-ls-remote.c b/builtin-ls-remote.c\nindex 78a88f7..4c6fc58 100644\n--- a/builtin-ls-remote.c\n+++ b/builtin-ls-remote.c\n@@ -87,9 +87,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \tremote = nongit ? NULL : remote_get(dest);\n-\tif (remote && !remote->url_nr)\n+\tif (!nongit && !remote)\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 ? NULL : dest);\n \tif (uploadpack != NULL)\n \t\ttransport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);\n \ndiff --git a/builtin-push.c b/builtin-push.c\nindex 2eabcd3..49b5086 100644\n--- a/builtin-push.c\n+++ b/builtin-push.c\n@@ -113,6 +113,26 @@ static void setup_default_push_refspecs(void)\n \t}\n }\n \n+static int push_with_options(struct transport *transport, int flags)\n+{\n+\tint err;\n+\tif (receivepack)\n+\t\ttransport_set_option(transport,\n+\t\t\t\t     TRANS_OPT_RECEIVEPACK, receivepack);\n+\tif (thin)\n+\t\ttransport_set_option(transport, TRANS_OPT_THIN, \"yes\");\n+\n+\tif (flags & TRANSPORT_PUSH_VERBOSE)\n+\t\tfprintf(stderr, \"Pushing to %s\\n\", transport->url);\n+\terr = transport_push(transport, refspec_nr, refspec, flags);\n+\terr |= transport_disconnect(transport);\n+\n+\tif (!err)\n+\t\treturn 0;\n+\n+\treturn 1;\n+}\n+\n static int do_push(const char *repo, int flags)\n {\n \tint i, errs;\n@@ -152,26 +172,22 @@ static int do_push(const char *repo, int flags)\n \t\t\tsetup_default_push_refspecs();\n \t}\n \terrs = 0;\n-\tfor (i = 0; i < remote->url_nr; i++) {\n+\tif (remote->url_nr) {\n+\t\tfor (i = 0; i < remote->url_nr; i++) {\n+\t\t\tstruct transport *transport =\n+\t\t\t\ttransport_get(remote, remote->url[i]);\n+\t\t\tif (push_with_options(transport, flags)) {\n+\t\t\t\terror(\"failed to push some refs to '%s'\", remote->url[i]);\n+\t\t\t\terrs++;\n+\t\t\t}\n+\t\t}\n+\t} else {\n \t\tstruct transport *transport =\n-\t\t\ttransport_get(remote, remote->url[i]);\n-\t\tint err;\n-\t\tif (receivepack)\n-\t\t\ttransport_set_option(transport,\n-\t\t\t\t\t     TRANS_OPT_RECEIVEPACK, receivepack);\n-\t\tif (thin)\n-\t\t\ttransport_set_option(transport, TRANS_OPT_THIN, \"yes\");\n-\n-\t\tif (flags & TRANSPORT_PUSH_VERBOSE)\n-\t\t\tfprintf(stderr, \"Pushing to %s\\n\", remote->url[i]);\n-\t\terr = transport_push(transport, refspec_nr, refspec, flags);\n-\t\terr |= transport_disconnect(transport);\n-\n-\t\tif (!err)\n-\t\t\tcontinue;\n-\n-\t\terror(\"failed to push some refs to '%s'\", remote->url[i]);\n-\t\terrs++;\n+\t\t\ttransport_get(remote, NULL);\n+\t\tif (push_with_options(transport, flags)) {\n+\t\t\terror(\"failed to push some refs to foreign system\");\n+\t\t\terrs++;\n+\t\t}\n \t}\n \treturn !!errs;\n }\ndiff --git a/transport.c b/transport.c\nindex 28cd26e..b9f1f6e 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -937,6 +937,9 @@ struct transport *transport_get(struct remote *remote, const char *url)\n \tstruct transport *ret = xcalloc(1, sizeof(*ret));\n \n \tret->remote = remote;\n+\n+\tif (!url && remote)\n+\t\turl = remote->url[0];\n \tret->url = url;\n \n \tif (!prefixcmp(url, \"rsync:\")) {\n-- \n1.6.0.6\n"},{"id":"114826","messageId":"36ca99e90905271142q577f026bidffa1ae89714d2a5@mail.gmail.com","threadId":"19535","inReplyTo":"alpine.LNX.2.00.0905271408380.2147@iabervon.org","subject":"Re: [PATCH 4/7] Allow programs to not depend on remotes having urls","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2009-05-27T18:42:57Z","receivedAt":"2009-05-27T18:42:57Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"Daniel,\n\nI found a small typo.\n\nBert\n\nOn Wed, May 27, 2009 at 20:15, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> For fetch and ls-remote, which use the first url of a remote, have\n> transport_get() determine this by passing a remote and passing NULL\n> for the url. For push, which uses every url of a remote, use each url\n> in turn if there are any, and use NULL if there are none.\n>\n> This will allow the transport code to do something different if the\n> location is not specified with a url.\n>\n> Also, have the message for a fetch say \"foreign\" if there is no url.\n>\n> Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>\n> ---\n>  builtin-fetch.c     |   19 +++++++++++------\n>  builtin-ls-remote.c |    4 +-\n>  builtin-push.c      |   54 +++++++++++++++++++++++++++++++++-----------------\n>  transport.c         |    3 ++\n>  4 files changed, 52 insertions(+), 28 deletions(-)\n>\n> diff --git a/builtin-fetch.c b/builtin-fetch.c\n> index 77acabf..bb1534a 100644\n> --- a/builtin-fetch.c\n> +++ b/builtin-fetch.c\n> @@ -341,12 +341,17 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,\n>                        what = rm->name;\n>                }\n>\n> -               url_len = strlen(url);\n> -               for (i = url_len - 1; url[i] == '/' && 0 <= i; i--)\n> -                       ;\n> -               url_len = i + 1;\n> -               if (4 < i && !strncmp(\".git\", url + i - 3, 4))\n> -                       url_len = i - 3;\n> +               if (url) {\n> +                       url_len = strlen(url);\n> +                       for (i = url_len - 1; url[i] == '/' && 0 <= i; i--)\n> +                               ;\n> +                       url_len = i + 1;\n> +                       if (4 < i && !strncmp(\".git\", url + i - 3, 4))\n> +                               url_len = i - 3;\n> +               } else {\n> +                       url = \"foriegn\";\nTypo.\n"}]}