{"thread":{"id":"20395","subject":"[PATCH 06/13] Allow programs to not depend on remotes having urls","startedAt":"2009-08-05T05:02:07Z","lastAt":"2009-08-05T05:02:07Z","messageCount":1,"participants":["Daniel Barkalow"],"isPatch":true,"patchVersion":1,"patchTotal":13},"messages":[{"id":"119575","messageId":"alpine.LNX.2.00.0908050055440.2147@iabervon.org","threadId":"20395","inReplyTo":null,"subject":"[PATCH 06/13] Allow programs to not depend on remotes having urls","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-08-05T05:02:07Z","receivedAt":"2009-08-05T05:02:07Z","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 817dd6b..b51a019 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -346,12 +346,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 = \"foreign\";\n+\t\t\turl_len = strlen(url);\n+\t\t}\n \n \t\tnote_len = 0;\n \t\tif (*what) {\n@@ -663,7 +668,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 1d92e22..ae63521 100644\n--- a/builtin-push.c\n+++ b/builtin-push.c\n@@ -88,6 +88,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@@ -136,26 +156,22 @@ static int do_push(const char *repo, int flags)\n \t\turl = remote->url;\n \t\turl_nr = remote->url_nr;\n \t}\n-\tfor (i = 0; i < url_nr; i++) {\n+\tif (url_nr) {\n+\t\tfor (i = 0; i < url_nr; i++) {\n+\t\t\tstruct transport *transport =\n+\t\t\t\ttransport_get(remote, url[i]);\n+\t\t\tif (push_with_options(transport, flags)) {\n+\t\t\t\terror(\"failed to push some refs to '%s'\", 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, 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\", 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'\", 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 b99d934..983d183 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -808,6 +808,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 && remote->url)\n+\t\turl = remote->url[0];\n \tret->url = url;\n \n \tif (!prefixcmp(url, \"rsync:\")) {\n-- \n1.6.4.rc3.27.g95032.dirty\n"}]}