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

@ -1738,15 +1738,12 @@ static int fetch_one(struct remote *remote, int argc, const char **argv,
for (i = 0; i < argc; i++) {
if (!strcmp(argv[i], "tag")) {
char *tag;
i++;
if (i >= argc)
die(_("You need to specify a tag name."));
tag = xstrfmt("refs/tags/%s:refs/tags/%s",
argv[i], argv[i]);
refspec_append(&rs, tag);
free(tag);
refspec_appendf(&rs, "refs/tags/%s:refs/tags/%s",
argv[i], argv[i]);
} else {
refspec_append(&rs, argv[i]);
}