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:

committed by
Junio C Hamano

parent
30035d9c66
commit
1af8b8c0a5
18
refspec.c
18
refspec.c
@ -153,7 +153,7 @@ void refspec_init(struct refspec *rs, int fetch)
|
||||
rs->fetch = fetch;
|
||||
}
|
||||
|
||||
void refspec_append(struct refspec *rs, const char *refspec)
|
||||
static void refspec_append_nodup(struct refspec *rs, char *refspec)
|
||||
{
|
||||
struct refspec_item item;
|
||||
|
||||
@ -163,7 +163,21 @@ void refspec_append(struct refspec *rs, const char *refspec)
|
||||
rs->items[rs->nr++] = item;
|
||||
|
||||
ALLOC_GROW(rs->raw, rs->raw_nr + 1, rs->raw_alloc);
|
||||
rs->raw[rs->raw_nr++] = xstrdup(refspec);
|
||||
rs->raw[rs->raw_nr++] = refspec;
|
||||
}
|
||||
|
||||
void refspec_append(struct refspec *rs, const char *refspec)
|
||||
{
|
||||
refspec_append_nodup(rs, xstrdup(refspec));
|
||||
}
|
||||
|
||||
void refspec_appendf(struct refspec *rs, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
refspec_append_nodup(rs, xstrvfmt(fmt, ap));
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void refspec_appendn(struct refspec *rs, const char **refspecs, int nr)
|
||||
|
Reference in New Issue
Block a user