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

@ -287,19 +287,15 @@ static void read_branches_file(struct remote *remote)
frag = (char *)git_default_branch_name();
add_url_alias(remote, strbuf_detach(&buf, NULL));
strbuf_addf(&buf, "refs/heads/%s:refs/heads/%s",
frag, remote->name);
refspec_append(&remote->fetch, buf.buf);
refspec_appendf(&remote->fetch, "refs/heads/%s:refs/heads/%s",
frag, remote->name);
/*
* Cogito compatible push: push current HEAD to remote #branch
* (master if missing)
*/
strbuf_reset(&buf);
strbuf_addf(&buf, "HEAD:refs/heads/%s", frag);
refspec_append(&remote->push, buf.buf);
refspec_appendf(&remote->push, "HEAD:refs/heads/%s", frag);
remote->fetch_tags = 1; /* always auto-follow */
strbuf_release(&buf);
}
static int handle_config(const char *key, const char *value, void *cb)