git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH RFC 5/8] clone: refactoring of building the fetch refspec

From
Paolo Bonzini <bonzini@gnu.org>
Date
Jul 20, 2009, 17:49 UTC
Message-ID
<1248112195-3761-6-git-send-email-bonzini@gnu.org>
In-Reply-To
<1248112195-3761-1-git-send-email-bonzini@gnu.org>

In builtin-clone.c, two variables (src_ref_prefix and branch_top.buf) were used to represent basically two parts of a refspec. Since a refspec is built anyway later, we can drop these variables and use refspec->dst when we need it.

Signed-off-by: Paolo Bonzini <bonzini@gnu.org>
---
 builtin-clone.c |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index 552ddf6..345101a 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -349,9 +349,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	int dest_exists;
 	const struct ref *refs, *head_points_at, *remote_head, *mapped_refs;
 	struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
-	struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
+	struct strbuf reflog_msg = STRBUF_INIT;
 	struct transport *transport = NULL;
-	char *src_ref_prefix = "refs/heads/";
 	int err = 0;
 
 	struct refspec *refspec;
@@ -452,20 +451,21 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
 	if (option_bare) {
 		if (option_mirror)
-			src_ref_prefix = "refs/";
-		strbuf_addstr(&branch_top, src_ref_prefix);
+			fetch_pattern = "+refs/*:refs/*";
+		else
+			fetch_pattern = "+refs/heads/*:refs/heads/*";
 
 		git_config_set("core.bare", "true");
 	} else {
-		strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
+		strbuf_addf(&value, "+refs/heads/*:refs/remotes/%s/*:*",
+			    option_origin);
+		fetch_pattern = value.buf;
 	}
 
-	strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
-
 	if (option_mirror || !option_bare) {
 		/* Configure the remote */
 		strbuf_addf(&key, "remote.%s.fetch", option_origin);
-		git_config_set_multivar(key.buf, value.buf, "^$", 0);
+		git_config_set_multivar(key.buf, fetch_pattern, "^$", 0);
 		strbuf_reset(&key);
 
 		if (option_mirror) {
@@ -479,7 +479,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		strbuf_reset(&key);
 	}
 
-	fetch_pattern = value.buf;
 	refspec = parse_fetch_refspec(1, &fetch_pattern);
 
 	strbuf_reset(&value);
@@ -549,7 +548,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 				   head_points_at->old_sha1,
 				   NULL, 0, DIE_ON_ERR);
 
-			strbuf_addstr(&head_ref, branch_top.buf);
+			strbuf_addstr(&head_ref, refspec->dst);
+			strbuf_setlen(&head_ref, head_ref.len - 1);
 			strbuf_addstr(&head_ref, "HEAD");
 
 			/* Remote branch link */
@@ -611,7 +611,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	}
 
 	strbuf_release(&reflog_msg);
-	strbuf_release(&branch_top);
 	strbuf_release(&key);
 	strbuf_release(&value);
 	junk_pid = 0;
-- 
1.6.2.5
Previous: Paolo BonziniNext: Paolo Bonzini
Message 10 of 16 in “introduce 'git remote add --push' and 'git clone --push'”
  1. 0/8 introduce 'git remote add --push' and 'git clone --push'Paolo Bonzini, Jul 20, 2009
  2. 1/8 reintroduce PUSH_DEFAULT_UNSPECIFIEDPaolo Bonzini, Jul 20, 2009
  3. 2/8 push: add push.default = mirrorPaolo Bonzini, Jul 20, 2009
  4. Junio C HamanoJul 20, 2009
  5. Paolo BonziniJul 20, 2009
  6. Junio C HamanoJul 20, 2009
  7. Paolo BonziniJul 20, 2009
  8. 3/8 git remote add: refactor configurationPaolo Bonzini, Jul 20, 2009
  9. 4/8 git remote add: add --push optionPaolo Bonzini, Jul 20, 2009
  10. 5/8 clone: refactoring of building the fetch refspecPaolo Bonzini, Jul 20, 2009
  11. 6/8 clone: use setup_remote_configPaolo Bonzini, Jul 20, 2009
  12. 7/8 config: add git_config_norepoPaolo Bonzini, Jul 20, 2009
  13. 8/8 clone: add --push optionPaolo Bonzini, Jul 20, 2009
  14. Junio C HamanoJul 20, 2009
  15. Paolo BonziniJul 21, 2009
  16. Junio C HamanoJul 21, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.