git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v3 06/10] clone: delay cloning until after remote HEAD checking
Date: Tue, 10 Jan 2012 16:57:03 +0700	[thread overview]
Message-ID: <1326189427-20800-7-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1326023188-15559-1-git-send-email-pclouds@gmail.com>

This gives us an opportunity to abort the command during remote HEAD
check without wasting much bandwidth.

Cloning with remote-helper remains before the check because the remote
helper updates mapped_refs, which is necessary for remote ref checks.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 I'm not familiar with remote-helper to see if there's any better way
 to do this..

 builtin/clone.c |   54 +++++++++++++++++++++++++++---------------------------
 transport.c     |    5 ++++-
 2 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index 73d07ed..05224d7 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -361,13 +361,8 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest,
 	closedir(dir);
 }
 
-static const struct ref *clone_local(const char *src_repo,
-				     const char *dest_repo)
+static void clone_local(const char *src_repo, const char *dest_repo)
 {
-	const struct ref *ret;
-	struct remote *remote;
-	struct transport *transport;
-
 	if (option_shared) {
 		struct strbuf alt = STRBUF_INIT;
 		strbuf_addf(&alt, "%s/objects", src_repo);
@@ -383,13 +378,8 @@ static const struct ref *clone_local(const char *src_repo,
 		strbuf_release(&dest);
 	}
 
-	remote = remote_get(src_repo);
-	transport = transport_get(remote, src_repo);
-	ret = transport_get_remote_refs(transport);
-	transport_disconnect(transport);
 	if (0 <= option_verbosity)
 		printf(_("done.\n"));
-	return ret;
 }
 
 static const char *junk_work_tree;
@@ -576,6 +566,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
 	struct transport *transport = NULL;
 	char *src_ref_prefix = "refs/heads/";
+	struct remote *remote;
 	int err = 0;
 
 	struct refspec *refspec;
@@ -727,13 +718,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
 	strbuf_reset(&value);
 
-	if (is_local) {
-		refs = clone_local(path, git_dir);
-		mapped_refs = wanted_peer_refs(refs, refspec);
-	} else {
-		struct remote *remote = remote_get(option_origin);
-		transport = transport_get(remote, remote->url[0]);
+	remote = remote_get(option_origin);
+	transport = transport_get(remote, remote->url[0]);
 
+	if (!is_local) {
 		if (!transport->get_refs_list || !transport->fetch)
 			die(_("Don't know how to clone %s"), transport->url);
 
@@ -748,14 +736,23 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		if (option_upload_pack)
 			transport_set_option(transport, TRANS_OPT_UPLOADPACK,
 					     option_upload_pack);
-
-		refs = transport_get_remote_refs(transport);
-		if (refs) {
-			mapped_refs = wanted_peer_refs(refs, refspec);
-			transport_fetch_refs(transport, mapped_refs);
-		}
 	}
 
+	refs = transport_get_remote_refs(transport);
+	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.
+	 *
+	 * 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)
+		transport_fetch_refs(transport, mapped_refs);
+
 	if (refs) {
 		remote_head = find_ref_by_name(refs, "HEAD");
 		remote_head_points_at =
@@ -790,15 +787,18 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 					      "refs/heads/master");
 	}
 
+	if (is_local)
+		clone_local(path, git_dir);
+	else if (refs && !remote->foreign_vcs)
+		transport_fetch_refs(transport, mapped_refs);
+
 	update_remote_refs(refs, mapped_refs, remote_head_points_at,
 			   branch_top.buf, reflog_msg.buf);
 
 	update_head(our_head_points_at, remote_head, reflog_msg.buf);
 
-	if (transport) {
-		transport_unlock_pack(transport);
-		transport_disconnect(transport);
-	}
+	transport_unlock_pack(transport);
+	transport_disconnect(transport);
 
 	err = checkout();
 
diff --git a/transport.c b/transport.c
index a99b7c9..aae9889 100644
--- a/transport.c
+++ b/transport.c
@@ -895,8 +895,10 @@ 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) {
@@ -938,6 +940,7 @@ 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 = helper;
 		transport_helper_init(ret, handler);
 	}
 
-- 
1.7.3.1.256.g2539c.dirty

  parent reply	other threads:[~2012-01-10  9:58 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-05 13:49 [PATCH] clone: allow detached checkout when --branch takes a tag Nguyễn Thái Ngọc Duy
2012-01-05 14:18 ` Jeff King
2012-01-06 11:09   ` Nguyen Thai Ngoc Duy
2012-01-06 14:42     ` Jeff King
2012-01-05 16:22 ` Junio C Hamano
2012-01-06  7:35   ` Nguyen Thai Ngoc Duy
2012-01-08 11:46 ` [PATCH v2 1/6] t5601: add && Nguyễn Thái Ngọc Duy
2012-01-08 11:46   ` [PATCH v2 2/6] clone: write detached HEAD in bare repositories Nguyễn Thái Ngọc Duy
2012-01-08 11:46   ` [PATCH v2 3/6] clone: factor out checkout code Nguyễn Thái Ngọc Duy
2012-01-10  0:32     ` Junio C Hamano
2012-01-10  2:01       ` Nguyen Thai Ngoc Duy
2012-01-10  4:59         ` Junio C Hamano
2012-01-10  5:57           ` Nguyen Thai Ngoc Duy
2012-01-08 11:46   ` [PATCH v2 4/6] clone: --branch=<branch> always means refs/heads/<branch> Nguyễn Thái Ngọc Duy
2012-01-10  0:33     ` Junio C Hamano
2012-01-08 11:46   ` [PATCH v2 5/6] clone: allow --branch to take a tag Nguyễn Thái Ngọc Duy
2012-01-08 11:46   ` [PATCH v2 6/6] clone: print advice on checking out detached HEAD Nguyễn Thái Ngọc Duy
2012-01-10  0:36     ` Junio C Hamano
2012-01-10  1:54       ` Nguyen Thai Ngoc Duy
2012-01-10  4:49         ` Junio C Hamano
2012-01-10  5:54           ` Nguyen Thai Ngoc Duy
2012-01-10  9:56   ` [PATCH v3 00/10] nd/clone-detached Nguyễn Thái Ngọc Duy
2012-01-13  7:21     ` [PATCH v4 " Nguyễn Thái Ngọc Duy
2012-01-13 19:52       ` Junio C Hamano
2012-01-14  4:48         ` Nguyen Thai Ngoc Duy
2012-01-14  6:53           ` Junio C Hamano
2012-01-14  7:40             ` Nguyen Thai Ngoc Duy
2012-01-15  2:34               ` Junio C Hamano
2012-01-16  9:46       ` [PATCH v5 00/10] nd/clone-detached rebase onto nd/clone-single-branch Nguyễn Thái Ngọc Duy
2012-01-16  9:46       ` [PATCH v5 01/10] t5601: add missing && cascade Nguyễn Thái Ngọc Duy
2012-01-16  9:46       ` [PATCH v5 02/10] clone: write detached HEAD in bare repositories Nguyễn Thái Ngọc Duy
2012-01-16  9:46       ` [PATCH v5 03/10] clone: factor out checkout code Nguyễn Thái Ngọc Duy
2012-01-16  9:46       ` [PATCH v5 04/10] clone: factor out HEAD update code Nguyễn Thái Ngọc Duy
2012-01-16  9:46       ` [PATCH v5 05/10] clone: factor out remote ref writing Nguyễn Thái Ngọc Duy
2012-01-16  9:46       ` [PATCH v5 06/10] clone: delay cloning until after remote HEAD checking Nguyễn Thái Ngọc Duy
2012-01-16  9:46       ` [PATCH v5 07/10] clone: --branch=<branch> always means refs/heads/<branch> Nguyễn Thái Ngọc Duy
2012-01-16  9:46       ` [PATCH v5 08/10] clone: refuse to clone if --branch points to bogus ref Nguyễn Thái Ngọc Duy
2012-01-16  9:46       ` [PATCH v5 09/10] clone: allow --branch to take a tag Nguyễn Thái Ngọc Duy
2012-01-16  9:46       ` [PATCH v5 10/10] clone: print advice on checking out detached HEAD Nguyễn Thái Ngọc Duy
2012-01-13  7:21     ` [PATCH v4 01/10] t5601: add missing && cascade Nguyễn Thái Ngọc Duy
2012-01-13  7:21     ` [PATCH v4 02/10] clone: write detached HEAD in bare repositories Nguyễn Thái Ngọc Duy
2012-01-13  7:21     ` [PATCH v4 03/10] clone: factor out checkout code Nguyễn Thái Ngọc Duy
2012-01-13  7:21     ` [PATCH v4 04/10] clone: factor out HEAD update code Nguyễn Thái Ngọc Duy
2012-01-13  7:21     ` [PATCH v4 05/10] clone: factor out remote ref writing Nguyễn Thái Ngọc Duy
2012-01-13  7:21     ` [PATCH v4 06/10] clone: delay cloning until after remote HEAD checking Nguyễn Thái Ngọc Duy
2012-01-13  7:21     ` [PATCH v4 07/10] clone: --branch=<branch> always means refs/heads/<branch> Nguyễn Thái Ngọc Duy
2012-01-13  7:22     ` [PATCH v4 08/10] clone: refuse to clone if --branch points to bogus ref Nguyễn Thái Ngọc Duy
2012-01-13  7:22     ` [PATCH v4 09/10] clone: allow --branch to take a tag Nguyễn Thái Ngọc Duy
2012-01-13  7:22     ` [PATCH v4 10/10] clone: print advice on checking out detached HEAD Nguyễn Thái Ngọc Duy
2012-01-10  9:56   ` [PATCH v3 01/10] t5601: add missing && cascade Nguyễn Thái Ngọc Duy
2012-01-10  9:56   ` [PATCH v3 02/10] clone: write detached HEAD in bare repositories Nguyễn Thái Ngọc Duy
2012-01-10  9:57   ` [PATCH v3 03/10] clone: factor out checkout code Nguyễn Thái Ngọc Duy
2012-01-10  9:57   ` [PATCH v3 04/10] clone: factor out HEAD update code Nguyễn Thái Ngọc Duy
2012-01-10  9:57   ` [PATCH v3 05/10] clone: factor out remote ref writing Nguyễn Thái Ngọc Duy
2012-01-10  9:57   ` Nguyễn Thái Ngọc Duy [this message]
2012-01-11 19:36     ` [PATCH v3 06/10] clone: delay cloning until after remote HEAD checking Junio C Hamano
2012-01-12  1:27       ` Nguyen Thai Ngoc Duy
2012-01-24  0:15     ` Junio C Hamano
2012-01-24  0:34       ` Junio C Hamano
2012-01-24  0:39         ` Junio C Hamano
2012-01-24  7:01           ` Nguyen Thai Ngoc Duy
2012-01-10  9:57   ` [PATCH v3 07/10] clone: --branch=<branch> always means refs/heads/<branch> Nguyễn Thái Ngọc Duy
2012-01-11 20:01     ` Junio C Hamano
2012-01-12  3:00       ` Nguyen Thai Ngoc Duy
2012-01-10  9:57   ` [PATCH v3 08/10] clone: refuse to clone if --branch points to bogus ref Nguyễn Thái Ngọc Duy
2012-01-10  9:57   ` [PATCH v3 09/10] clone: allow --branch to take a tag Nguyễn Thái Ngọc Duy
2012-01-11 23:57     ` Junio C Hamano
2012-01-10  9:57   ` [PATCH v3 10/10] clone: print advice on checking out detached HEAD Nguyễn Thái Ngọc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1326189427-20800-7-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).