refspec: add and use refspec_appendf()

Add a function for building a refspec using printf-style formatting.  It
frees callers from managing their own buffer.  Use it throughout the
tree to shorten and simplify its callers.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe
2020-09-05 16:49:30 +02:00
committed by Junio C Hamano
parent 30035d9c66
commit 1af8b8c0a5
6 changed files with 35 additions and 49 deletions

View File

@ -953,7 +953,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
struct ref *mapped_refs;
const struct ref *ref;
struct strbuf key = STRBUF_INIT;
struct strbuf default_refspec = STRBUF_INIT;
struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
struct transport *transport = NULL;
const char *src_ref_prefix = "refs/heads/";
@ -1157,9 +1156,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
remote = remote_get(option_origin);
strbuf_addf(&default_refspec, "+%s*:%s*", src_ref_prefix,
branch_top.buf);
refspec_append(&remote->fetch, default_refspec.buf);
refspec_appendf(&remote->fetch, "+%s*:%s*", src_ref_prefix,
branch_top.buf);
transport = transport_get(remote, remote->url[0]);
transport_set_verbosity(transport, option_verbosity, option_progress);
@ -1332,7 +1330,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(&default_refspec);
junk_mode = JUNK_LEAVE_ALL;
strvec_clear(&ref_prefixes);