Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-05-21 17:54:27 +0300
committerJunio C Hamano <gitster@pobox.com>2018-05-22 05:58:50 +0300
commit342c513a4ae100354097a9ca99a080eeb7e70c0b (patch)
tree86454cb22bbe18f45869ed4f6a3f50cdcb9ed904 /argv-array.c
parent3f1c1c360080114fcc9492211601f41d56112e3c (diff)
argv-array: return the pushed string from argv_push*()
Such an API change allows us to use an argv_array this way: struct argv_array to_free = ARGV_ARRAY_INIT; const char *msg; if (some condition) { msg = "constant string message"; ... other logic ... } else { msg = argv_array_pushf(&to_free, "format %s", var); } ... use "msg" ... ... do other things ... argv_array_clear(&to_free); Note that argv_array_pushl() and argv_array_pushv() are used to push one or more strings with a single call, so we do not return any one of these strings from these two functions in order to reduce the chance to misuse the API. Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Martin Ă…gren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'argv-array.c')
-rw-r--r--argv-array.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/argv-array.c b/argv-array.c
index 5d370fa336..449dfc105a 100644
--- a/argv-array.c
+++ b/argv-array.c
@@ -21,12 +21,13 @@ static void argv_array_push_nodup(struct argv_array *array, const char *value)
array->argv[array->argc] = NULL;
}
-void argv_array_push(struct argv_array *array, const char *value)
+const char *argv_array_push(struct argv_array *array, const char *value)
{
argv_array_push_nodup(array, xstrdup(value));
+ return array->argv[array->argc - 1];
}
-void argv_array_pushf(struct argv_array *array, const char *fmt, ...)
+const char *argv_array_pushf(struct argv_array *array, const char *fmt, ...)
{
va_list ap;
struct strbuf v = STRBUF_INIT;
@@ -36,6 +37,7 @@ void argv_array_pushf(struct argv_array *array, const char *fmt, ...)
va_end(ap);
argv_array_push_nodup(array, strbuf_detach(&v, NULL));
+ return array->argv[array->argc - 1];
}
void argv_array_pushl(struct argv_array *array, ...)