Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
describe: use argv-array
author
Junio C Hamano
<gitster@pobox.com>
Sun, 7 Jul 2013 21:42:23 +0000
(14:42 -0700)
committer
Junio C Hamano
<gitster@pobox.com>
Tue, 9 Jul 2013 15:15:28 +0000
(08:15 -0700)
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>
builtin/describe.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
b23e0b9
)
diff --git
a/builtin/describe.c
b/builtin/describe.c
index 4e675c3d0d7b1daeb7f12ef425514a11a92a5c3f..db41cd7974698aeb70b91d48a36b09ce2e558ef1 100644
(file)
--- a/
builtin/describe.c
+++ b/
builtin/describe.c
@@
-7,6
+7,7
@@
#include "parse-options.h"
#include "diff.h"
#include "hash.h"
#include "parse-options.h"
#include "diff.h"
#include "hash.h"
+#include "argv-array.h"
#define SEEN (1u<<0)
#define MAX_TAGS (FLAG_BITS - 1)
#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) {
die(_("--long is incompatible with --abbrev=0"));
if (contains) {
-
const char **args = xmalloc((7 + argc) * sizeof(char *))
;
- int i = 0;
- arg
s[i++] = "name-rev"
;
- arg
s[i++] = "--name-only";
-
args[i++] = "--no-undefined"
;
+
struct argv_array args
;
+
+ arg
v_array_init(&args)
;
+ arg
v_array_pushl(&args, "name-rev", "--name-only", "--no-undefined",
+
NULL)
;
if (always)
if (always)
- arg
s[i++] = "--always"
;
+ arg
v_array_push(&args, "--always")
;
if (!all) {
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);
}
init_hash(&names);