bundle: use argv-array

Instead of hand-crafted arrays to manage command line arguments we create internally, use argv-array helpers. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Nov 12, 2013 at 13:32 UTC 1e2371ea6656beaf94fd706eb414febac88c6398
1 file changed +16 -16
bundle.c
+16 -16
@@ -7,6 +7,7 @@
7 #include "list-objects.h"
8 #include "run-command.h"
9 #include "refs.h"
10 +#include "argv-array.h"
11
12 static const char bundle_signature[] = "# v2 git bundle\n";
13
@@ -234,13 +235,13 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
235 }
236
237 int create_bundle(struct bundle_header *header, const char *path,
237 - int argc, const char **argv)
238 + int argc, const char **argv)
239 {
240 static struct lock_file lock;
241 int bundle_fd = -1;
242 int bundle_to_stdout;
242 - const char **argv_boundary = xmalloc((argc + 4) * sizeof(const char *));
243 - const char **argv_pack = xmalloc(6 * sizeof(const char *));
243 + struct argv_array argv_boundary = ARGV_ARRAY_INIT;
244 + struct argv_array argv_pack = ARGV_ARRAY_INIT;
245 int i, ref_count = 0;
246 struct strbuf buf = STRBUF_INIT;
247 struct rev_info revs;
@@ -262,13 +263,14 @@ int create_bundle(struct bundle_header *header, const char *path,
263 init_revisions(&revs, NULL);
264
265 /* write prerequisites */
265 - memcpy(argv_boundary + 3, argv + 1, argc * sizeof(const char *));
266 - argv_boundary[0] = "rev-list";
267 - argv_boundary[1] = "--boundary";
268 - argv_boundary[2] = "--pretty=oneline";
269 - argv_boundary[argc + 2] = NULL;
266 + argv_array_pushl(&argv_boundary,
267 + "rev-list", "--boundary", "--pretty=oneline",
268 + NULL);
269 + for (i = 1; i < argc; i++)
270 + argv_array_push(&argv_boundary, argv[i]);
271 +
272 memset(&rls, 0, sizeof(rls));
271 - rls.argv = argv_boundary;
273 + rls.argv = argv_boundary.argv;
274 rls.out = -1;
275 rls.git_cmd = 1;
276 if (start_command(&rls))
@@ -383,14 +385,12 @@ int create_bundle(struct bundle_header *header, const char *path,
385 write_or_die(bundle_fd, "\n", 1);
386
387 /* write pack */
386 - argv_pack[0] = "pack-objects";
387 - argv_pack[1] = "--all-progress-implied";
388 - argv_pack[2] = "--stdout";
389 - argv_pack[3] = "--thin";
390 - argv_pack[4] = "--delta-base-offset";
391 - argv_pack[5] = NULL;
388 + argv_array_pushl(&argv_pack,
389 + "pack-objects", "--all-progress-implied",
390 + "--stdout", "--thin", "--delta-base-offset",
391 + NULL);
392 memset(&rls, 0, sizeof(rls));
393 - rls.argv = argv_pack;
393 + rls.argv = argv_pack.argv;
394 rls.in = -1;
395 rls.out = bundle_fd;
396 rls.git_cmd = 1;