Skip to content

Commit 9049816

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dad0b3d commit 9049816

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

builtin/clone.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,13 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
631631
const struct ref *remote_head_points_at;
632632
const struct ref *our_head_points_at;
633633
struct ref *mapped_refs;
634+
const struct ref *ref;
634635
struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
635636
struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
636637
struct transport *transport = NULL;
637638
const char *src_ref_prefix = "refs/heads/";
638639
struct remote *remote;
639-
int err = 0;
640+
int err = 0, complete_refs_before_fetch = 1;
640641

641642
struct refspec *refspec;
642643
const char *fetch_pattern;
@@ -816,15 +817,22 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
816817
mapped_refs = refs ? wanted_peer_refs(refs, refspec) : NULL;
817818

818819
/*
819-
* mapped_refs may be updated if transport-helper is used so
820-
* we need fetch it early because remote_head code below
821-
* relies on it.
820+
* transport_get_remote_refs() may return refs with null sha-1
821+
* in mapped_refs (see struct transport->get_refs_list
822+
* comment). In that case we need fetch it early because
823+
* remote_head code below relies on it.
822824
*
823825
* for normal clones, transport_get_remote_refs() should
824826
* return reliable ref set, we can delay cloning until after
825827
* remote HEAD check.
826828
*/
827-
if (!is_local && remote->foreign_vcs && refs)
829+
for (ref = refs; ref; ref = ref->next)
830+
if (is_null_sha1(ref->old_sha1)) {
831+
complete_refs_before_fetch = 0;
832+
break;
833+
}
834+
835+
if (!is_local && !complete_refs_before_fetch && refs)
828836
transport_fetch_refs(transport, mapped_refs);
829837

830838
if (refs) {
@@ -856,7 +864,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
856864

857865
if (is_local)
858866
clone_local(path, git_dir);
859-
else if (refs && !remote->foreign_vcs)
867+
else if (refs && complete_refs_before_fetch)
860868
transport_fetch_refs(transport, mapped_refs);
861869

862870
update_remote_refs(refs, mapped_refs, remote_head_points_at,

builtin/push.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,11 @@ static int do_push(const char *repo, int flags)
204204
url_nr = remote->url_nr;
205205
}
206206
if (url_nr) {
207-
const char *configured_foreign_vcs = remote->foreign_vcs;
208207
for (i = 0; i < url_nr; i++) {
209208
struct transport *transport =
210209
transport_get(remote, url[i]);
211210
if (push_with_options(transport, flags))
212211
errs++;
213-
remote->foreign_vcs = configured_foreign_vcs;
214212
}
215213
} else {
216214
struct transport *transport =

transport.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -895,10 +895,8 @@ struct transport *transport_get(struct remote *remote, const char *url)
895895

896896
while (is_urlschemechar(p == url, *p))
897897
p++;
898-
if (!prefixcmp(p, "::")) {
898+
if (!prefixcmp(p, "::"))
899899
helper = xstrndup(url, p - url);
900-
remote->foreign_vcs = helper;
901-
}
902900
}
903901

904902
if (helper) {
@@ -940,7 +938,6 @@ struct transport *transport_get(struct remote *remote, const char *url)
940938
char *handler = xmalloc(len + 1);
941939
handler[len] = 0;
942940
strncpy(handler, url, len);
943-
remote->foreign_vcs = handler;
944941
transport_helper_init(ret, handler);
945942
}
946943

0 commit comments

Comments
 (0)