# [PATCH] builtin/clone: get rid of 'value' strbuf

2 messages from 2017-06-14 to 2017-06-15. Participants: Christian Couder, Junio C Hamano.
Thread: https://gitlist.dev/t/46182

## Christian Couder, 2017-06-14 15:01

Subject: [PATCH] builtin/clone: get rid of 'value' strbuf
Message-ID: <20170614150148.29298-1-chriscool@tuxfamily.org>
URL: https://gitlist.dev/e/20170614150148.29298-1-chriscool%40tuxfamily.org

```
This makes the code simpler by removing a few lines, and getting
rid of one variable.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin/clone.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index a2ea019c59..370a233d22 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -870,7 +870,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	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 key = STRBUF_INIT;
 	struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
 	struct transport *transport = NULL;
 	const char *src_ref_prefix = "refs/heads/";
@@ -1035,7 +1035,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
 	}
 
-	strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
 	strbuf_addf(&key, "remote.%s.url", option_origin);
 	git_config_set(key.buf, repo);
 	strbuf_reset(&key);
@@ -1049,10 +1048,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	if (option_required_reference.nr || option_optional_reference.nr)
 		setup_reference();
 
-	fetch_pattern = value.buf;
+	fetch_pattern = xstrfmt("+%s*:%s*", src_ref_prefix, branch_top.buf);
 	refspec = parse_fetch_refspec(1, &fetch_pattern);
-
-	strbuf_reset(&value);
+	free((char *)fetch_pattern);
 
 	remote = remote_get(option_origin);
 	transport = transport_get(remote, remote->url[0]);
@@ -1191,7 +1189,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_mode = JUNK_LEAVE_ALL;
 
 	free(refspec);
-- 
2.13.1.453.g04e95ab038


```

## Junio C Hamano, 2017-06-15 22:10

Subject: Re: [PATCH] builtin/clone: get rid of 'value' strbuf
Message-ID: <xmqq1sqkzyux.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq1sqkzyux.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20170614150148.29298-1-chriscool@tuxfamily.org>

```
Christian Couder <christian.couder@gmail.com> writes:

> This makes the code simpler by removing a few lines, and getting
> rid of one variable.
>
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---

This patch may have meant well, but I think e5698f3a ("clone:
respect additional configured fetch refspecs during initial fetch",
2017-05-30) makes this change a moot point.

cf. https://public-inbox.org/git/20170530071244.32257-1-szeder.dev@gmail.com/

Thanks.




```
