builtin/push.c: use strbuf instead of manual allocation
The command line arguments given to "git push" are massaged into a list of refspecs in set_refspecs() function. This was implemented using xmalloc, strcpy and friends, but it is much easier to read if done using strbuf. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
@ -41,29 +41,22 @@ static void set_refspecs(const char **refs, int nr)
|
|||||||
for (i = 0; i < nr; i++) {
|
for (i = 0; i < nr; i++) {
|
||||||
const char *ref = refs[i];
|
const char *ref = refs[i];
|
||||||
if (!strcmp("tag", ref)) {
|
if (!strcmp("tag", ref)) {
|
||||||
char *tag;
|
struct strbuf tagref = STRBUF_INIT;
|
||||||
int len;
|
|
||||||
if (nr <= ++i)
|
if (nr <= ++i)
|
||||||
die(_("tag shorthand without <tag>"));
|
die(_("tag shorthand without <tag>"));
|
||||||
len = strlen(refs[i]) + 11;
|
ref = refs[i];
|
||||||
if (deleterefs) {
|
if (deleterefs)
|
||||||
tag = xmalloc(len+1);
|
strbuf_addf(&tagref, ":refs/tags/%s", ref);
|
||||||
strcpy(tag, ":refs/tags/");
|
else
|
||||||
} else {
|
strbuf_addf(&tagref, "refs/tags/%s", ref);
|
||||||
tag = xmalloc(len);
|
ref = strbuf_detach(&tagref, NULL);
|
||||||
strcpy(tag, "refs/tags/");
|
} else if (deleterefs) {
|
||||||
}
|
struct strbuf delref = STRBUF_INIT;
|
||||||
strcat(tag, refs[i]);
|
if (strchr(ref, ':'))
|
||||||
ref = tag;
|
die(_("--delete only accepts plain target ref names"));
|
||||||
} else if (deleterefs && !strchr(ref, ':')) {
|
strbuf_addf(&delref, ":%s", ref);
|
||||||
char *delref;
|
ref = strbuf_detach(&delref, NULL);
|
||||||
int len = strlen(ref)+1;
|
}
|
||||||
delref = xmalloc(len+1);
|
|
||||||
strcpy(delref, ":");
|
|
||||||
strcat(delref, ref);
|
|
||||||
ref = delref;
|
|
||||||
} else if (deleterefs)
|
|
||||||
die(_("--delete only accepts plain target ref names"));
|
|
||||||
add_refspec(ref);
|
add_refspec(ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user