From: Nguyễn Thái Ngọc Duy Date: Tue, 24 Jan 2012 11:10:38 +0000 (+0700) Subject: clone: fix up delay cloning conditions X-Git-Tag: v1.7.10-rc0~125^2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9049816140e75d3f7b15264e97e042f5ab0bf392;p=git.git clone: fix up delay cloning conditions 6f48d39 (clone: delay cloning until after remote HEAD checking - 2012-01-16) allows us to perform some checks on remote refs before the actual cloning happens. But not all transport types support this. Remote helper with "import" capability will not return complete ref information until fetch is performed and therefore the clone cannot be delayed. foreign_vcs field in struct remote was used to detect this kind of transport and save the result. This is a mistake because foreign_vcs is designed to override url-based transport detection. As a result, if the same "struct transport *" object is used on many different urls and one of them attached remote transport, the following urls will be mistakenly attached to the same transport. This fault is worked around by dad0b3d (push: do not let configured foreign-vcs permanently clobbered - 2012-01-23) To fix this, detect incomplete refs from transport_get_remote_refs() by SHA-1. Incomplete ones must have null SHA-1 (*). Then revert changes related to foreign_cvs field in 6f48d39 and dad0b3d. A good thing from this change is that cloning smart http transport can also be delayed. Earlier it falls into the same category "remote transport, no delay". (*) Theoretically if one of the remote refs happens to have null SHA-1, it will trigger false alarm and the clone will not be delayed. But that chance may be too small for us to pay attention to. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- diff --git a/builtin/clone.c b/builtin/clone.c index 72eebca53..379cafa63 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -631,12 +631,13 @@ int cmd_clone(int argc, const char **argv, const char *prefix) const struct ref *remote_head_points_at; const struct ref *our_head_points_at; struct ref *mapped_refs; + const struct ref *ref; struct strbuf key = STRBUF_INIT, value = STRBUF_INIT; struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT; struct transport *transport = NULL; const char *src_ref_prefix = "refs/heads/"; struct remote *remote; - int err = 0; + int err = 0, complete_refs_before_fetch = 1; struct refspec *refspec; const char *fetch_pattern; @@ -816,15 +817,22 @@ int cmd_clone(int argc, const char **argv, const char *prefix) mapped_refs = refs ? wanted_peer_refs(refs, refspec) : NULL; /* - * mapped_refs may be updated if transport-helper is used so - * we need fetch it early because remote_head code below - * relies on it. + * transport_get_remote_refs() may return refs with null sha-1 + * in mapped_refs (see struct transport->get_refs_list + * comment). In that case we need fetch it early because + * remote_head code below relies on it. * * for normal clones, transport_get_remote_refs() should * return reliable ref set, we can delay cloning until after * remote HEAD check. */ - if (!is_local && remote->foreign_vcs && refs) + for (ref = refs; ref; ref = ref->next) + if (is_null_sha1(ref->old_sha1)) { + complete_refs_before_fetch = 0; + break; + } + + if (!is_local && !complete_refs_before_fetch && refs) transport_fetch_refs(transport, mapped_refs); if (refs) { @@ -856,7 +864,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (is_local) clone_local(path, git_dir); - else if (refs && !remote->foreign_vcs) + else if (refs && complete_refs_before_fetch) transport_fetch_refs(transport, mapped_refs); update_remote_refs(refs, mapped_refs, remote_head_points_at, diff --git a/builtin/push.c b/builtin/push.c index 5fb98a009..35cce532f 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -204,13 +204,11 @@ static int do_push(const char *repo, int flags) url_nr = remote->url_nr; } if (url_nr) { - const char *configured_foreign_vcs = remote->foreign_vcs; for (i = 0; i < url_nr; i++) { struct transport *transport = transport_get(remote, url[i]); if (push_with_options(transport, flags)) errs++; - remote->foreign_vcs = configured_foreign_vcs; } } else { struct transport *transport = diff --git a/transport.c b/transport.c index 43666394d..a99b7c9c4 100644 --- a/transport.c +++ b/transport.c @@ -895,10 +895,8 @@ struct transport *transport_get(struct remote *remote, const char *url) while (is_urlschemechar(p == url, *p)) p++; - if (!prefixcmp(p, "::")) { + if (!prefixcmp(p, "::")) helper = xstrndup(url, p - url); - remote->foreign_vcs = helper; - } } if (helper) { @@ -940,7 +938,6 @@ struct transport *transport_get(struct remote *remote, const char *url) char *handler = xmalloc(len + 1); handler[len] = 0; strncpy(handler, url, len); - remote->foreign_vcs = handler; transport_helper_init(ret, handler); }