Skip to content

Commit

Permalink
describe: use argv-array
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Jul 9, 2013
1 parent b23e0b9 commit 45bc950
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions builtin/describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 45bc950

Please sign in to comment.