git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: David Turner <dturner@twopensource.com>
To: git@vger.kernel.org
Cc: David Turner <dturner@twopensource.com>
Subject: [PATCH/RFC 6/6] clone: send refspec for single-branch clones
Date: Fri, 15 Apr 2016 15:19:09 -0400	[thread overview]
Message-ID: <1460747949-3514-7-git-send-email-dturner@twopensource.com> (raw)
In-Reply-To: <1460747949-3514-1-git-send-email-dturner@twopensource.com>

For single-branch clones (when we know in advance what the remote
branch name will be), send a refspec so that the server doesn't
tell us about any other refs.

Signed-off-by: David Turner <dturner@twopensource.com>
---
 builtin/clone.c              | 16 +++++++++++++++-
 t/t5552-http-fetch-branch.sh |  5 +++++
 transport-helper.c           | 12 +++++++++++-
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index 91f668c..9a0291d 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -1010,7 +1010,21 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	if (transport->smart_options && !option_depth)
 		transport->smart_options->check_self_contained_and_connected = 1;
 
-	refs = transport_get_remote_refs(transport, NULL, 0);
+	if (option_single_branch && option_branch) {
+		struct refspec branch_refspec = {0};
+
+		if (starts_with(option_branch, "refs/")) {
+			branch_refspec.src = xstrdup(option_branch);
+		} else {
+			struct strbuf buf = STRBUF_INIT;
+			strbuf_addf(&buf, "refs/heads/%s", option_branch);
+			branch_refspec.src = strbuf_detach(&buf, NULL);
+		}
+		refs = transport_get_remote_refs(transport, &branch_refspec, 1);
+		free(branch_refspec.src);
+	} else {
+		refs = transport_get_remote_refs(transport, NULL, 0);
+	}
 
 	if (refs) {
 		mapped_refs = wanted_peer_refs(refs, refspec);
diff --git a/t/t5552-http-fetch-branch.sh b/t/t5552-http-fetch-branch.sh
index 0e905d9..8a8e218 100755
--- a/t/t5552-http-fetch-branch.sh
+++ b/t/t5552-http-fetch-branch.sh
@@ -38,5 +38,10 @@ test_expect_success 'fetch with refspec only fetches requested branch' '
 	)
 '
 
+test_expect_success 'single-branch clone only fetches requested branch' '
+	GIT_TRACE_PACKET="$TRASH_DIRECTORY/trace" git clone --single-branch -b master $HTTPD_URL/smart/repo.git sbc &&
+	! grep "refs/heads/another_branch" trace
+'
+
 stop_httpd
 test_done
diff --git a/transport-helper.c b/transport-helper.c
index 7d75d64..3775d63 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -28,6 +28,7 @@ struct helper_data {
 		signed_tags : 1,
 		check_connectivity : 1,
 		no_disconnect_req : 1,
+		refspec : 1,
 		no_private_update : 1;
 	char *export_marks;
 	char *import_marks;
@@ -114,8 +115,15 @@ static struct child_process *get_helper(struct transport *transport, const struc
 	int code;
 	int i;
 
-	if (data->helper)
+	if (data->helper) {
+		if (!data->refspec && req_refspec_nr) {
+			for (i = 0; i < req_refspec_nr; i++)
+				set_helper_option(transport, "refspec",
+						  req_refspecs[i].src);
+			data->refspec = 1;
+		}
 		return data->helper;
+	}
 
 	helper = xmalloc(sizeof(*helper));
 	child_process_init(helper);
@@ -220,6 +228,8 @@ static struct child_process *get_helper(struct transport *transport, const struc
 
 	for (i = 0; i < req_refspec_nr; i++)
 		set_helper_option(transport, "refspec", req_refspecs[i].src);
+	if (req_refspec_nr)
+		data->refspec = 1;
 	standard_options(transport);
 	return data->helper;
 }
-- 
2.4.2.767.g62658d5-twtrsrc

  parent reply	other threads:[~2016-04-15 19:19 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-15 19:19 [PATCH/RFC 0/6] fetch with refspec David Turner
2016-04-15 19:19 ` [PATCH/RFC 1/6] http-backend: use argv_array functions David Turner
2016-04-18 18:34   ` Junio C Hamano
2016-04-19 19:11     ` David Turner
2016-04-15 19:19 ` [PATCH/RFC 2/6] remote-curl.c: fix variable shadowing David Turner
2016-04-18 18:35   ` Junio C Hamano
2016-04-19 19:14     ` David Turner
2016-04-15 19:19 ` [PATCH/RFC 3/6] http-backend: handle refspec argument David Turner
2016-04-17  1:51   ` Eric Sunshine
2016-04-19 18:57     ` David Turner
2016-04-15 19:19 ` [PATCH/RFC 4/6] transport: add refspec list parameters to functions David Turner
2016-04-18 18:45   ` Junio C Hamano
2016-04-19  7:14     ` Jeff King
2016-04-19 18:04       ` Stefan Beller
2016-04-19 20:55       ` Junio C Hamano
2016-04-19 21:40       ` David Turner
2016-04-19 23:22         ` Jeff King
2016-04-19 23:43           ` David Turner
2016-04-20  1:17             ` Jeff King
2016-04-20 20:46               ` David Turner
2016-04-20 20:57                 ` Jeff King
2016-04-25 16:44                   ` David Turner
2016-04-25 22:10                     ` Stefan Beller
2016-04-27  3:59                       ` Stefan Beller
2016-04-27  4:11                         ` Jeff King
2016-04-27 15:07                           ` Junio C Hamano
2016-04-29 23:05                         ` David Turner
2016-04-29 23:12                           ` Stefan Beller
2016-04-19 19:31     ` David Turner
2016-04-15 19:19 ` [PATCH/RFC 5/6] fetch: pass refspec to http server David Turner
2016-04-17  2:33   ` Eric Sunshine
2016-04-19 21:25     ` David Turner
2016-04-15 19:19 ` David Turner [this message]
2016-04-17  2:36   ` [PATCH/RFC 6/6] clone: send refspec for single-branch clones Eric Sunshine
2016-04-19 21:24     ` David Turner
2016-04-15 19:30 ` [PATCH/RFC 0/6] fetch with refspec Stefan Beller

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=1460747949-3514-7-git-send-email-dturner@twopensource.com \
    --to=dturner@twopensource.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).