Skip to content

Commit a923e05

Browse files
rscharfegitster
authored andcommitted
send-pack: use internal argv_array of struct child_process
Avoid a magic number of NULL placeholder values and a magic index by constructing the command line for pack-objects using the embedded argv_array of the child_process. The resulting code is shorter and easier to extend. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c7191fa commit a923e05

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

send-pack.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,35 +58,25 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
5858
* the revision parameters to it via its stdin and
5959
* let its stdout go back to the other end.
6060
*/
61-
const char *argv[] = {
62-
"pack-objects",
63-
"--all-progress-implied",
64-
"--revs",
65-
"--stdout",
66-
NULL,
67-
NULL,
68-
NULL,
69-
NULL,
70-
NULL,
71-
NULL,
72-
};
7361
struct child_process po = CHILD_PROCESS_INIT;
7462
FILE *po_in;
7563
int i;
7664
int rc;
7765

78-
i = 4;
66+
argv_array_push(&po.args, "pack-objects");
67+
argv_array_push(&po.args, "--all-progress-implied");
68+
argv_array_push(&po.args, "--revs");
69+
argv_array_push(&po.args, "--stdout");
7970
if (args->use_thin_pack)
80-
argv[i++] = "--thin";
71+
argv_array_push(&po.args, "--thin");
8172
if (args->use_ofs_delta)
82-
argv[i++] = "--delta-base-offset";
73+
argv_array_push(&po.args, "--delta-base-offset");
8374
if (args->quiet || !args->progress)
84-
argv[i++] = "-q";
75+
argv_array_push(&po.args, "-q");
8576
if (args->progress)
86-
argv[i++] = "--progress";
77+
argv_array_push(&po.args, "--progress");
8778
if (is_repository_shallow())
88-
argv[i++] = "--shallow";
89-
po.argv = argv;
79+
argv_array_push(&po.args, "--shallow");
9080
po.in = -1;
9181
po.out = args->stateless_rpc ? -1 : fd;
9282
po.git_cmd = 1;

0 commit comments

Comments
 (0)