{"thread":{"id":"20844","subject":"[PATCH 5/8] Allow programs to not depend on remotes having urls","startedAt":"2009-09-04T02:13:57Z","lastAt":"2009-09-04T12:45:49Z","messageCount":2,"participants":["Daniel Barkalow","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"122382","messageId":"alpine.LNX.2.00.0909032213290.28290@iabervon.org","threadId":"20844","inReplyTo":null,"subject":"[PATCH 5/8] Allow programs to not depend on remotes having urls","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-09-04T02:13:57Z","receivedAt":"2009-09-04T02:13:57Z","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     |    7 ++++-\n builtin-ls-remote.c |    4 +-\n builtin-push.c      |   67 ++++++++++++++++++++++++++++++++-------------------\n transport.c         |    3 ++\n 4 files changed, 52 insertions(+), 29 deletions(-)\n\ndiff --git a/builtin-fetch.c b/builtin-fetch.c\nindex 817dd6b..63a4ff0 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -309,7 +309,10 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,\n \tif (!fp)\n \t\treturn error(\"cannot open %s: %s\\n\", filename, strerror(errno));\n \n-\turl = transport_anonymize_url(raw_url);\n+\tif (raw_url)\n+\t\turl = transport_anonymize_url(raw_url);\n+\telse\n+\t\turl = xstrdup(\"foreign\");\n \tfor (rm = ref_map; rm; rm = rm->next) {\n \t\tstruct ref *ref = NULL;\n \n@@ -663,7 +666,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 67f6d96..8e9b917 100644\n--- a/builtin-push.c\n+++ b/builtin-push.c\n@@ -88,6 +88,34 @@ 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+\tint nonfastforward;\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+\t\t\t     &nonfastforward);\n+\terr |= transport_disconnect(transport);\n+\n+\tif (!err)\n+\t\treturn 0;\n+\n+\tif (nonfastforward) {\n+\t\tprintf(\"To prevent you from losing history, non-fast-forward updates were rejected.\\n\"\n+\t\t       \"Merge the remote changes before pushing again.\\n\"\n+\t\t       \"See 'non-fast forward' section of 'git push --help' for details.\\n\");\n+\t}\n+\n+\treturn 1;\n+}\n+\n static int do_push(const char *repo, int flags)\n {\n \tint i, errs;\n@@ -136,33 +164,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\tint nonfastforward;\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\t\t\t     &nonfastforward);\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\tif (nonfastforward) {\n-\t\t\tprintf(\"To prevent you from losing history, non-fast-forward updates were rejected.\\n\"\n-\t\t\t       \"Merge the remote changes before pushing again.\\n\"\n-\t\t\t       \"See 'non-fast forward' section of 'git push --help' for details.\\n\");\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\terrs++;\n \t}\n \treturn !!errs;\n }\ndiff --git a/transport.c b/transport.c\nindex 93430fa..684fd6c 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -813,6 +813,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.2.419.gc86f8\n"},{"id":"122431","messageId":"alpine.DEB.1.00.0909041445230.4605@intel-tinevez-2-302","threadId":"20844","inReplyTo":"alpine.LNX.2.00.0909032213290.28290@iabervon.org","subject":"Re: [PATCH 5/8] Allow programs to not depend on remotes having urls","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-09-04T12:45:49Z","receivedAt":"2009-09-04T12:45:49Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 3 Sep 2009, Daniel Barkalow wrote:\n\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\nFor the record: you did not convince me.  Not that you tried, to...\n\nCiao,\nDscho\n"}]}