Skip to content
This repository was archived by the owner on Jul 2, 2019. It is now read-only.

Commit 1e2371e

Browse files
committed
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 <[email protected]>
1 parent 7061504 commit 1e2371e

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

bundle.c

+16-16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "list-objects.h"
88
#include "run-command.h"
99
#include "refs.h"
10+
#include "argv-array.h"
1011

1112
static const char bundle_signature[] = "# v2 git bundle\n";
1213

@@ -234,13 +235,13 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
234235
}
235236

236237
int create_bundle(struct bundle_header *header, const char *path,
237-
int argc, const char **argv)
238+
int argc, const char **argv)
238239
{
239240
static struct lock_file lock;
240241
int bundle_fd = -1;
241242
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;
244245
int i, ref_count = 0;
245246
struct strbuf buf = STRBUF_INIT;
246247
struct rev_info revs;
@@ -262,13 +263,14 @@ int create_bundle(struct bundle_header *header, const char *path,
262263
init_revisions(&revs, NULL);
263264

264265
/* 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+
270272
memset(&rls, 0, sizeof(rls));
271-
rls.argv = argv_boundary;
273+
rls.argv = argv_boundary.argv;
272274
rls.out = -1;
273275
rls.git_cmd = 1;
274276
if (start_command(&rls))
@@ -383,14 +385,12 @@ int create_bundle(struct bundle_header *header, const char *path,
383385
write_or_die(bundle_fd, "\n", 1);
384386

385387
/* 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);
392392
memset(&rls, 0, sizeof(rls));
393-
rls.argv = argv_pack;
393+
rls.argv = argv_pack.argv;
394394
rls.in = -1;
395395
rls.out = bundle_fd;
396396
rls.git_cmd = 1;

0 commit comments

Comments
 (0)