{"thread":{"id":"29436","subject":"[PATCH] clone: fix up delay cloning conditions","startedAt":"2012-01-24T11:10:38Z","lastAt":"2012-01-24T11:10:38Z","messageCount":1,"participants":["Nguyễn Thái Ngọc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"183014","messageId":"1327403438-11514-1-git-send-email-pclouds@gmail.com","threadId":"29436","inReplyTo":null,"subject":"[PATCH] clone: fix up delay cloning conditions","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-01-24T11:10:38Z","receivedAt":"2012-01-24T11:10:38Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"6f48d39 (clone: delay cloning until after remote HEAD checking -\n2012-01-16) allows us to perform some checks on remote refs before the\nactual cloning happens. But not all transport types support\nthis. Remote helper with \"import\" capability will not return complete\nref information until fetch is performed and therefore the clone cannot\nbe delayed.\n\nforeign_vcs field in struct remote was used to detect this kind of transport\nand save the result. This is a mistake because foreign_vcs is designed\nto override url-based transport detection. As a result, if the same\n\"struct transport *\" object is used on many different urls and one of\nthem attached remote transport, the following urls will be mistakenly\nattached to the same transport. This fault is worked around by dad0b3d\n(push: do not let configured foreign-vcs permanently clobbered -\n2012-01-23)\n\nTo fix this, detect incomplete refs from transport_get_remote_refs()\nby SHA-1. Incomplete ones must have null SHA-1 (*). Then revert\nchanges related to foreign_cvs field in 6f48d39 and dad0b3d.\n\nA good thing from this change is that cloning smart http transport can\nalso be delayed. Earlier it falls into the same category \"remote\ntransport, no delay\".\n\n(*) Theoretically if one of the remote refs happens to have null SHA-1,\nit will trigger false alarm and the clone will not be delayed. But\nthat chance may be too small for us to pay attention to.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/clone.c |   20 ++++++++++++++------\n builtin/push.c  |    2 --\n transport.c     |    5 +----\n 3 files changed, 15 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 72eebca..379cafa 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -631,12 +631,13 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \tconst struct ref *remote_head_points_at;\n \tconst struct ref *our_head_points_at;\n \tstruct ref *mapped_refs;\n+\tconst struct ref *ref;\n \tstruct strbuf key = STRBUF_INIT, value = STRBUF_INIT;\n \tstruct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;\n \tstruct transport *transport = NULL;\n \tconst char *src_ref_prefix = \"refs/heads/\";\n \tstruct remote *remote;\n-\tint err = 0;\n+\tint err = 0, complete_refs_before_fetch = 1;\n \n \tstruct refspec *refspec;\n \tconst char *fetch_pattern;\n@@ -816,15 +817,22 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \tmapped_refs = refs ? wanted_peer_refs(refs, refspec) : NULL;\n \n \t/*\n-\t * mapped_refs may be updated if transport-helper is used so\n-\t * we need fetch it early because remote_head code below\n-\t * relies on it.\n+\t * transport_get_remote_refs() may return refs with null sha-1\n+\t * in mapped_refs (see struct transport->get_refs_list\n+\t * comment). In that case we need fetch it early because\n+\t * remote_head code below relies on it.\n \t *\n \t * for normal clones, transport_get_remote_refs() should\n \t * return reliable ref set, we can delay cloning until after\n \t * remote HEAD check.\n \t */\n-\tif (!is_local && remote->foreign_vcs && refs)\n+\tfor (ref = refs; ref; ref = ref->next)\n+\t\tif (is_null_sha1(ref->old_sha1)) {\n+\t\t\tcomplete_refs_before_fetch = 0;\n+\t\t\tbreak;\n+\t\t}\n+\n+\tif (!is_local && !complete_refs_before_fetch && refs)\n \t\ttransport_fetch_refs(transport, mapped_refs);\n \n \tif (refs) {\n@@ -856,7 +864,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \n \tif (is_local)\n \t\tclone_local(path, git_dir);\n-\telse if (refs && !remote->foreign_vcs)\n+\telse if (refs && complete_refs_before_fetch)\n \t\ttransport_fetch_refs(transport, mapped_refs);\n \n \tupdate_remote_refs(refs, mapped_refs, remote_head_points_at,\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 5fb98a0..35cce53 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -204,13 +204,11 @@ static int do_push(const char *repo, int flags)\n \t\turl_nr = remote->url_nr;\n \t}\n \tif (url_nr) {\n-\t\tconst char *configured_foreign_vcs = remote->foreign_vcs;\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\terrs++;\n-\t\t\tremote->foreign_vcs = configured_foreign_vcs;\n \t\t}\n \t} else {\n \t\tstruct transport *transport =\ndiff --git a/transport.c b/transport.c\nindex 4366639..a99b7c9 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -895,10 +895,8 @@ struct transport *transport_get(struct remote *remote, const char *url)\n \n \t\twhile (is_urlschemechar(p == url, *p))\n \t\t\tp++;\n-\t\tif (!prefixcmp(p, \"::\")) {\n+\t\tif (!prefixcmp(p, \"::\"))\n \t\t\thelper = xstrndup(url, p - url);\n-\t\t\tremote->foreign_vcs = helper;\n-\t\t}\n \t}\n \n \tif (helper) {\n@@ -940,7 +938,6 @@ struct transport *transport_get(struct remote *remote, const char *url)\n \t\tchar *handler = xmalloc(len + 1);\n \t\thandler[len] = 0;\n \t\tstrncpy(handler, url, len);\n-\t\tremote->foreign_vcs = handler;\n \t\ttransport_helper_init(ret, handler);\n \t}\n \n-- \n1.7.8.36.g69ee2\n"}]}