diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-07-08 01:42:23 +0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-07-09 19:15:28 +0400 |
commit | 45bc950b4330ab675724b5079aa1528acde9f404 (patch) | |
tree | 435099cc3ba68107c284667a5440c74e2c7bc2a4 | |
parent | b23e0b9353e38149e791bde0feb1220aa1c8bac1 (diff) |
describe: use argv-array
Instead of using a hand allocated args[] array, use argv-array API
to manage the dynamically created list of arguments when invoking
name-rev.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | builtin/describe.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/builtin/describe.c b/builtin/describe.c index 4e675c3d0d..db41cd7974 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -7,6 +7,7 @@ #include "parse-options.h" #include "diff.h" #include "hash.h" +#include "argv-array.h" #define SEEN (1u<<0) #define MAX_TAGS (FLAG_BITS - 1) @@ -442,24 +443,23 @@ int cmd_describe(int argc, const char **argv, const char *prefix) die(_("--long is incompatible with --abbrev=0")); if (contains) { - const char **args = xmalloc((7 + argc) * sizeof(char *)); - int i = 0; - args[i++] = "name-rev"; - args[i++] = "--name-only"; - args[i++] = "--no-undefined"; + struct argv_array args; + + argv_array_init(&args); + argv_array_pushl(&args, "name-rev", "--name-only", "--no-undefined", + NULL); if (always) - args[i++] = "--always"; + argv_array_push(&args, "--always"); if (!all) { - args[i++] = "--tags"; - if (pattern) { - char *s = xmalloc(strlen("--refs=refs/tags/") + strlen(pattern) + 1); - sprintf(s, "--refs=refs/tags/%s", pattern); - args[i++] = s; - } + argv_array_push(&args, "--tags"); + if (pattern) + argv_array_pushf(&args, "--refs=refs/tags/%s", pattern); + } + while (*argv) { + argv_array_push(&args, *argv); + argv++; } - memcpy(args + i, argv, argc * sizeof(char *)); - args[i + argc] = NULL; - return cmd_name_rev(i + argc, args, prefix); + return cmd_name_rev(args.argc, args.argv, prefix); } init_hash(&names); |