]> git.ipfire.org Git - thirdparty/git.git/commit - argv-array.c
argv-array: return the pushed string from argv_push*()
authorJunio C Hamano <gitster@pobox.com>
Mon, 21 May 2018 14:54:27 +0000 (16:54 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 22 May 2018 02:58:50 +0000 (11:58 +0900)
commit342c513a4ae100354097a9ca99a080eeb7e70c0b
tree86454cb22bbe18f45869ed4f6a3f50cdcb9ed904
parent3f1c1c360080114fcc9492211601f41d56112e3c
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>
argv-array.c
argv-array.h