run-command: introduce CHILD_PROCESS_INIT

Most struct child_process variables are cleared using memset first after declaration. Provide a macro, CHILD_PROCESS_INIT, that can be used to initialize them statically instead. That's shorter, doesn't require a function call and is slightly more readable (especially given that we already have STRBUF_INIT, ARGV_ARRAY_INIT etc.). Helped-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Aug 19, 2014 at 21:09 UTC d3180279322c7450a47decf8833de47f444ca93f
40 files changed +60 -107
Documentation/technical/api-run-command.txt
+2 -2
@@ -96,8 +96,8 @@ command to run in a sub-process.
96
97 The caller:
98
99 -1. allocates and clears (memset(&chld, 0, sizeof(chld));) a
100 - struct child_process variable;
99 +1. allocates and clears (memset(&chld, 0, sizeof(chld)); or
100 + using CHILD_PROCESS_INIT) a struct child_process variable;
101 2. initializes the members;
102 3. calls start_command();
103 4. processes the data;
archive-tar.c
+1 -2
@@ -395,7 +395,7 @@ static int write_tar_filter_archive(const struct archiver *ar,
395 struct archiver_args *args)
396 {
397 struct strbuf cmd = STRBUF_INIT;
398 - struct child_process filter;
398 + struct child_process filter = CHILD_PROCESS_INIT;
399 const char *argv[2];
400 int r;
401
@@ -406,7 +406,6 @@ static int write_tar_filter_archive(const struct archiver *ar,
406 if (args->compression_level >= 0)
407 strbuf_addf(&cmd, " -%d", args->compression_level);
408
409 - memset(&filter, 0, sizeof(filter));
409 argv[0] = cmd.buf;
410 argv[1] = NULL;
411 filter.argv = argv;
builtin/add.c
+1 -2
@@ -180,7 +180,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
180 char *file = git_pathdup("ADD_EDIT.patch");
181 const char *apply_argv[] = { "apply", "--recount", "--cached",
182 NULL, NULL };
183 - struct child_process child;
183 + struct child_process child = CHILD_PROCESS_INIT;
184 struct rev_info rev;
185 int out;
186 struct stat st;
@@ -214,7 +214,6 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
214 if (!st.st_size)
215 die(_("Empty patch. Aborted."));
216
217 - memset(&child, 0, sizeof(child));
217 child.git_cmd = 1;
218 child.argv = apply_argv;
219 if (run_command(&child))
builtin/commit.c
+1 -2
@@ -1508,7 +1508,7 @@ static int run_rewrite_hook(const unsigned char *oldsha1,
1508 {
1509 /* oldsha1 SP newsha1 LF NUL */
1510 static char buf[2*40 + 3];
1511 - struct child_process proc;
1511 + struct child_process proc = CHILD_PROCESS_INIT;
1512 const char *argv[3];
1513 int code;
1514 size_t n;
@@ -1520,7 +1520,6 @@ static int run_rewrite_hook(const unsigned char *oldsha1,
1520 argv[1] = "amend";
1521 argv[2] = NULL;
1522
1523 - memset(&proc, 0, sizeof(proc));
1523 proc.argv = argv;
1524 proc.in = -1;
1525 proc.stdout_to_stderr = 1;
builtin/help.c
+1 -2
@@ -79,12 +79,11 @@ static const char *get_man_viewer_info(const char *name)
79 static int check_emacsclient_version(void)
80 {
81 struct strbuf buffer = STRBUF_INIT;
82 - struct child_process ec_process;
82 + struct child_process ec_process = CHILD_PROCESS_INIT;
83 const char *argv_ec[] = { "emacsclient", "--version", NULL };
84 int version;
85
86 /* emacsclient prints its version number on stderr */
87 - memset(&ec_process, 0, sizeof(ec_process));
87 ec_process.argv = argv_ec;
88 ec_process.err = -1;
89 ec_process.stdout_to_stderr = 1;
builtin/merge.c
+1 -2
@@ -237,11 +237,10 @@ static void drop_save(void)
237 static int save_state(unsigned char *stash)
238 {
239 int len;
240 - struct child_process cp;
240 + struct child_process cp = CHILD_PROCESS_INIT;
241 struct strbuf buffer = STRBUF_INIT;
242 const char *argv[] = {"stash", "create", NULL};
243
244 - memset(&cp, 0, sizeof(cp));
244 cp.argv = argv;
245 cp.out = -1;
246 cp.git_cmd = 1;
builtin/notes.c
+1 -2
@@ -122,12 +122,11 @@ static void write_commented_object(int fd, const unsigned char *object)
122 {
123 const char *show_args[5] =
124 {"show", "--stat", "--no-notes", sha1_to_hex(object), NULL};
125 - struct child_process show;
125 + struct child_process show = CHILD_PROCESS_INIT;
126 struct strbuf buf = STRBUF_INIT;
127 struct strbuf cbuf = STRBUF_INIT;
128
129 /* Invoke "git show --stat --no-notes $object" */
130 - memset(&show, 0, sizeof(show));
130 show.argv = show_args;
131 show.no_stdin = 1;
132 show.out = -1;
builtin/receive-pack.c
+4 -8
@@ -255,7 +255,7 @@ static int copy_to_sideband(int in, int out, void *arg)
255 typedef int (*feed_fn)(void *, const char **, size_t *);
256 static int run_and_feed_hook(const char *hook_name, feed_fn feed, void *feed_state)
257 {
258 - struct child_process proc;
258 + struct child_process proc = CHILD_PROCESS_INIT;
259 struct async muxer;
260 const char *argv[2];
261 int code;
@@ -266,7 +266,6 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed, void *feed_sta
266
267 argv[1] = NULL;
268
269 - memset(&proc, 0, sizeof(proc));
269 proc.argv = argv;
270 proc.in = -1;
271 proc.stdout_to_stderr = 1;
@@ -350,7 +349,7 @@ static int run_receive_hook(struct command *commands, const char *hook_name,
349 static int run_update_hook(struct command *cmd)
350 {
351 const char *argv[5];
353 - struct child_process proc;
352 + struct child_process proc = CHILD_PROCESS_INIT;
353 int code;
354
355 argv[0] = find_hook("update");
@@ -362,7 +361,6 @@ static int run_update_hook(struct command *cmd)
361 argv[3] = sha1_to_hex(cmd->new_sha1);
362 argv[4] = NULL;
363
365 - memset(&proc, 0, sizeof(proc));
364 proc.no_stdin = 1;
365 proc.stdout_to_stderr = 1;
366 proc.err = use_sideband ? -1 : 0;
@@ -598,7 +596,7 @@ static void run_update_post_hook(struct command *commands)
596 struct command *cmd;
597 int argc;
598 const char **argv;
601 - struct child_process proc;
599 + struct child_process proc = CHILD_PROCESS_INIT;
600 char *hook;
601
602 hook = find_hook("post-update");
@@ -621,7 +619,6 @@ static void run_update_post_hook(struct command *commands)
619 }
620 argv[argc] = NULL;
621
624 - memset(&proc, 0, sizeof(proc));
622 proc.no_stdin = 1;
623 proc.stdout_to_stderr = 1;
624 proc.err = use_sideband ? -1 : 0;
@@ -911,7 +908,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
908 const char *hdr_err;
909 int status;
910 char hdr_arg[38];
914 - struct child_process child;
911 + struct child_process child = CHILD_PROCESS_INIT;
912 int fsck_objects = (receive_fsck_objects >= 0
913 ? receive_fsck_objects
914 : transfer_fsck_objects >= 0
@@ -933,7 +930,6 @@ static const char *unpack(int err_fd, struct shallow_info *si)
930 argv_array_pushl(&av, "--shallow-file", alt_shallow_file, NULL);
931 }
932
936 - memset(&child, 0, sizeof(child));
933 if (ntohl(hdr.hdr_entries) < unpack_limit) {
934 argv_array_pushl(&av, "unpack-objects", hdr_arg, NULL);
935 if (quiet)
builtin/remote-ext.c
+1 -2
@@ -179,9 +179,8 @@ static void send_git_request(int stdin_fd, const char *serv, const char *repo,
179 static int run_child(const char *arg, const char *service)
180 {
181 int r;
182 - struct child_process child;
182 + struct child_process child = CHILD_PROCESS_INIT;
183
184 - memset(&child, 0, sizeof(child));
184 child.in = -1;
185 child.out = -1;
186 child.err = 0;
builtin/repack.c
+1 -2
@@ -133,7 +133,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
133 {".idx"},
134 {".bitmap", 1},
135 };
136 - struct child_process cmd;
136 + struct child_process cmd = CHILD_PROCESS_INIT;
137 struct string_list_item *item;
138 struct argv_array cmd_args = ARGV_ARRAY_INIT;
139 struct string_list names = STRING_LIST_INIT_DUP;
@@ -250,7 +250,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
250
251 argv_array_push(&cmd_args, packtmp);
252
253 - memset(&cmd, 0, sizeof(cmd));
253 cmd.argv = cmd_args.argv;
254 cmd.git_cmd = 1;
255 cmd.out = -1;
builtin/replace.c
+2 -2
@@ -197,7 +197,7 @@ static int replace_object(const char *object_ref, const char *replace_ref, int f
197 static void export_object(const unsigned char *sha1, enum object_type type,
198 int raw, const char *filename)
199 {
200 - struct child_process cmd = { NULL };
200 + struct child_process cmd = CHILD_PROCESS_INIT;
201 int fd;
202
203 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
@@ -234,7 +234,7 @@ static void import_object(unsigned char *sha1, enum object_type type,
234
235 if (!raw && type == OBJ_TREE) {
236 const char *argv[] = { "mktree", NULL };
237 - struct child_process cmd = { argv };
237 + struct child_process cmd = CHILD_PROCESS_INIT;
238 struct strbuf result = STRBUF_INIT;
239
240 cmd.argv = argv;
builtin/verify-pack.c
+1 -2
@@ -8,7 +8,7 @@
8
9 static int verify_one_pack(const char *path, unsigned int flags)
10 {
11 - struct child_process index_pack;
11 + struct child_process index_pack = CHILD_PROCESS_INIT;
12 const char *argv[] = {"index-pack", NULL, NULL, NULL };
13 struct strbuf arg = STRBUF_INIT;
14 int verbose = flags & VERIFY_PACK_VERBOSE;
@@ -32,7 +32,6 @@ static int verify_one_pack(const char *path, unsigned int flags)
32 strbuf_addstr(&arg, ".pack");
33 argv[2] = arg.buf;
34
35 - memset(&index_pack, 0, sizeof(index_pack));
35 index_pack.argv = argv;
36 index_pack.git_cmd = 1;
37
bundle.c
+2 -4
@@ -240,7 +240,7 @@ int create_bundle(struct bundle_header *header, const char *path,
240 int i, ref_count = 0;
241 struct strbuf buf = STRBUF_INIT;
242 struct rev_info revs;
243 - struct child_process rls;
243 + struct child_process rls = CHILD_PROCESS_INIT;
244 FILE *rls_fout;
245
246 bundle_to_stdout = !strcmp(path, "-");
@@ -258,7 +258,6 @@ int create_bundle(struct bundle_header *header, const char *path,
258 init_revisions(&revs, NULL);
259
260 /* write prerequisites */
261 - memset(&rls, 0, sizeof(rls));
261 argv_array_pushl(&rls.args,
262 "rev-list", "--boundary", "--pretty=oneline",
263 NULL);
@@ -417,14 +416,13 @@ int unbundle(struct bundle_header *header, int bundle_fd, int flags)
416 {
417 const char *argv_index_pack[] = {"index-pack",
418 "--fix-thin", "--stdin", NULL, NULL};
420 - struct child_process ip;
419 + struct child_process ip = CHILD_PROCESS_INIT;
420
421 if (flags & BUNDLE_VERBOSE)
422 argv_index_pack[3] = "-v";
423
424 if (verify_bundle(header, 0))
425 return -1;
427 - memset(&ip, 0, sizeof(ip));
426 ip.argv = argv_index_pack;
427 ip.in = bundle_fd;
428 ip.no_stdout = 1;
column.c
+1 -1
@@ -367,7 +367,7 @@ int parseopt_column_callback(const struct option *opt,
367 }
368
369 static int fd_out = -1;
370 -static struct child_process column_process;
370 +static struct child_process column_process = CHILD_PROCESS_INIT;
371
372 int run_column_filter(int colopts, const struct column_options *opts)
373 {
connect.c
+1 -1
@@ -639,7 +639,7 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
639 return protocol;
640 }
641
642 -static struct child_process no_fork;
642 +static struct child_process no_fork = CHILD_PROCESS_INIT;
643
644 /*
645 * This returns a dummy child_process if the transport protocol does not
connected.c
+1 -2
@@ -25,7 +25,7 @@ static int check_everything_connected_real(sha1_iterate_fn fn,
25 struct transport *transport,
26 const char *shallow_file)
27 {
28 - struct child_process rev_list;
28 + struct child_process rev_list = CHILD_PROCESS_INIT;
29 const char *argv[9];
30 char commit[41];
31 unsigned char sha1[20];
@@ -60,7 +60,6 @@ static int check_everything_connected_real(sha1_iterate_fn fn,
60 argv[ac++] = "--quiet";
61 argv[ac] = NULL;
62
63 - memset(&rev_list, 0, sizeof(rev_list));
63 rev_list.argv = argv;
64 rev_list.git_cmd = 1;
65 rev_list.in = -1;
convert.c
+1 -2
@@ -321,7 +321,7 @@ static int filter_buffer(int in, int out, void *data)
321 /*
322 * Spawn cmd and feed the buffer contents through its stdin.
323 */
324 - struct child_process child_process;
324 + struct child_process child_process = CHILD_PROCESS_INIT;
325 struct filter_params *params = (struct filter_params *)data;
326 int write_err, status;
327 const char *argv[] = { NULL, NULL };
@@ -344,7 +344,6 @@ static int filter_buffer(int in, int out, void *data)
344
345 argv[0] = cmd.buf;
346
347 - memset(&child_process, 0, sizeof(child_process));
347 child_process.argv = argv;
348 child_process.use_shell = 1;
349 child_process.in = -1;
credential-cache.c
+1 -2
@@ -37,12 +37,11 @@ static int send_request(const char *socket, const struct strbuf *out)
37
38 static void spawn_daemon(const char *socket)
39 {
40 - struct child_process daemon;
40 + struct child_process daemon = CHILD_PROCESS_INIT;
41 const char *argv[] = { NULL, NULL, NULL };
42 char buf[128];
43 int r;
44
45 - memset(&daemon, 0, sizeof(daemon));
45 argv[0] = "git-credential-cache--daemon";
46 argv[1] = socket;
47 daemon.argv = argv;
credential.c
+1 -2
@@ -205,11 +205,10 @@ static int run_credential_helper(struct credential *c,
205 const char *cmd,
206 int want_output)
207 {
208 - struct child_process helper;
208 + struct child_process helper = CHILD_PROCESS_INIT;
209 const char *argv[] = { NULL, NULL };
210 FILE *fp;
211
212 - memset(&helper, 0, sizeof(helper));
212 argv[0] = cmd;
213 helper.argv = argv;
214 helper.use_shell = 1;
daemon.c
+3 -5
@@ -259,7 +259,7 @@ static const char *access_hook;
259
260 static int run_access_hook(struct daemon_service *service, const char *dir, const char *path)
261 {
262 - struct child_process child;
262 + struct child_process child = CHILD_PROCESS_INIT;
263 struct strbuf buf = STRBUF_INIT;
264 const char *argv[8];
265 const char **arg = argv;
@@ -277,7 +277,6 @@ static int run_access_hook(struct daemon_service *service, const char *dir, cons
277 *arg = NULL;
278 #undef STRARG
279
280 - memset(&child, 0, sizeof(child));
280 child.use_shell = 1;
281 child.argv = argv;
282 child.no_stdin = 1;
@@ -406,9 +405,8 @@ static void copy_to_log(int fd)
405
406 static int run_service_command(const char **argv)
407 {
409 - struct child_process cld;
408 + struct child_process cld = CHILD_PROCESS_INIT;
409
411 - memset(&cld, 0, sizeof(cld));
410 cld.argv = argv;
411 cld.git_cmd = 1;
412 cld.err = -1;
@@ -733,7 +731,7 @@ static void check_dead_children(void)
731 static char **cld_argv;
732 static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
733 {
736 - struct child_process cld = { NULL };
734 + struct child_process cld = CHILD_PROCESS_INIT;
735 char addrbuf[300] = "REMOTE_ADDR=", portbuf[300];
736 char *env[] = { addrbuf, portbuf, NULL };
737
diff.c
+1 -2
@@ -4931,7 +4931,7 @@ static char *run_textconv(const char *pgm, struct diff_filespec *spec,
4931 struct diff_tempfile *temp;
4932 const char *argv[3];
4933 const char **arg = argv;
4934 - struct child_process child;
4934 + struct child_process child = CHILD_PROCESS_INIT;
4935 struct strbuf buf = STRBUF_INIT;
4936 int err = 0;
4937
@@ -4940,7 +4940,6 @@ static char *run_textconv(const char *pgm, struct diff_filespec *spec,
4940 *arg++ = temp->name;
4941 *arg = NULL;
4942
4943 - memset(&child, 0, sizeof(child));
4943 child.use_shell = 1;
4944 child.argv = argv;
4945 child.out = -1;
editor.c
+1 -2
@@ -38,10 +38,9 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
38
39 if (strcmp(editor, ":")) {
40 const char *args[] = { editor, real_path(path), NULL };
41 - struct child_process p;
41 + struct child_process p = CHILD_PROCESS_INIT;
42 int ret, sig;
43
44 - memset(&p, 0, sizeof(p));
44 p.argv = args;
45 p.env = env;
46 p.use_shell = 1;
fetch-pack.c
+1 -2
@@ -666,7 +666,7 @@ static int get_pack(struct fetch_pack_args *args,
666 char hdr_arg[256];
667 const char **av, *cmd_name;
668 int do_keep = args->keep_pack;
669 - struct child_process cmd;
669 + struct child_process cmd = CHILD_PROCESS_INIT;
670 int ret;
671
672 memset(&demux, 0, sizeof(demux));
@@ -685,7 +685,6 @@ static int get_pack(struct fetch_pack_args *args,
685 else
686 demux.out = xd[0];
687
688 - memset(&cmd, 0, sizeof(cmd));
688 cmd.argv = argv;
689 av = argv;
690 *hdr_arg = 0;
gpg-interface.c
+2 -4
@@ -55,12 +55,11 @@ const char *get_signing_key(void)
55 */
56 int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key)
57 {
58 - struct child_process gpg;
58 + struct child_process gpg = CHILD_PROCESS_INIT;
59 const char *args[4];
60 ssize_t len;
61 size_t i, j, bottom;
62
63 - memset(&gpg, 0, sizeof(gpg));
63 gpg.argv = args;
64 gpg.in = -1;
65 gpg.out = -1;
@@ -116,7 +115,7 @@ int verify_signed_buffer(const char *payload, size_t payload_size,
115 const char *signature, size_t signature_size,
116 struct strbuf *gpg_output, struct strbuf *gpg_status)
117 {
119 - struct child_process gpg;
118 + struct child_process gpg = CHILD_PROCESS_INIT;
119 const char *args_gpg[] = {NULL, "--status-fd=1", "--verify", "FILE", "-", NULL};
120 char path[PATH_MAX];
121 int fd, ret;
@@ -133,7 +132,6 @@ int verify_signed_buffer(const char *payload, size_t payload_size,
132 path, strerror(errno));
133 close(fd);
134
136 - memset(&gpg, 0, sizeof(gpg));
135 gpg.argv = args_gpg;
136 gpg.in = -1;
137 gpg.out = -1;
http-backend.c
+1 -2
@@ -323,7 +323,7 @@ static void run_service(const char **argv)
323 const char *host = getenv("REMOTE_ADDR");
324 struct argv_array env = ARGV_ARRAY_INIT;
325 int gzipped_request = 0;
326 - struct child_process cld;
326 + struct child_process cld = CHILD_PROCESS_INIT;
327
328 if (encoding && !strcmp(encoding, "gzip"))
329 gzipped_request = 1;
@@ -341,7 +341,6 @@ static void run_service(const char **argv)
341 argv_array_pushf(&env, "GIT_COMMITTER_EMAIL=%s@http.%s",
342 user, host);
343
344 - memset(&cld, 0, sizeof(cld));
344 cld.argv = argv;
345 cld.env = env.argv;
346 if (gzipped_request)
http.c
+1 -2
@@ -1332,7 +1332,7 @@ int finish_http_pack_request(struct http_pack_request *preq)
1332 struct packed_git **lst;
1333 struct packed_git *p = preq->target;
1334 char *tmp_idx;
1335 - struct child_process ip;
1335 + struct child_process ip = CHILD_PROCESS_INIT;
1336 const char *ip_argv[8];
1337
1338 close_pack_index(p);
@@ -1355,7 +1355,6 @@ int finish_http_pack_request(struct http_pack_request *preq)
1355 ip_argv[3] = preq->tmpfile;
1356 ip_argv[4] = NULL;
1357
1358 - memset(&ip, 0, sizeof(ip));
1358 ip.argv = ip_argv;
1359 ip.git_cmd = 1;
1360 ip.no_stdin = 1;
imap-send.c
+1 -1
@@ -962,7 +962,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc)
962
963 if (srvc->tunnel) {
964 const char *argv[] = { srvc->tunnel, NULL };
965 - struct child_process tunnel = {NULL};
965 + struct child_process tunnel = CHILD_PROCESS_INIT;
966
967 imap_info("Starting tunnel '%s'... ", srvc->tunnel);
968
pager.c
+1 -1
@@ -18,7 +18,7 @@ struct pager_config {
18 */
19
20 static const char *pager_argv[] = { NULL, NULL };
21 -static struct child_process pager_process;
21 +static struct child_process pager_process = CHILD_PROCESS_INIT;
22
23 static void wait_for_pager(void)
24 {
prompt.c
+1 -2
@@ -6,7 +6,7 @@
6
7 static char *do_askpass(const char *cmd, const char *prompt)
8 {
9 - struct child_process pass;
9 + struct child_process pass = CHILD_PROCESS_INIT;
10 const char *args[3];
11 static struct strbuf buffer = STRBUF_INIT;
12 int err = 0;
@@ -15,7 +15,6 @@ static char *do_askpass(const char *cmd, const char *prompt)
15 args[1] = prompt;
16 args[2] = NULL;
17
18 - memset(&pass, 0, sizeof(pass));
18 pass.argv = args;
19 pass.out = -1;
20
remote-curl.c
+1 -2
@@ -623,10 +623,9 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
623 const char *svc = rpc->service_name;
624 struct strbuf buf = STRBUF_INIT;
625 struct strbuf *preamble = rpc->stdin_preamble;
626 - struct child_process client;
626 + struct child_process client = CHILD_PROCESS_INIT;
627 int err = 0;
628
629 - memset(&client, 0, sizeof(client));
629 client.in = -1;
630 client.out = -1;
631 client.git_cmd = 1;
remote-testsvn.c
+1 -2
@@ -175,7 +175,7 @@ static int cmd_import(const char *line)
175 char *note_msg;
176 unsigned char head_sha1[20];
177 unsigned int startrev;
178 - struct child_process svndump_proc;
178 + struct child_process svndump_proc = CHILD_PROCESS_INIT;
179 const char *command = "svnrdump";
180
181 if (read_ref(private_ref, head_sha1))
@@ -200,7 +200,6 @@ static int cmd_import(const char *line)
200 if(dumpin_fd < 0)
201 die_errno("Couldn't open svn dump file %s.", url);
202 } else {
203 - memset(&svndump_proc, 0, sizeof(struct child_process));
203 svndump_proc.out = -1;
204 argv_array_push(&svndump_proc.args, command);
205 argv_array_push(&svndump_proc.args, "dump");
run-command.c
+1 -2
@@ -763,14 +763,13 @@ char *find_hook(const char *name)
763
764 int run_hook_ve(const char *const *env, const char *name, va_list args)
765 {
766 - struct child_process hook;
766 + struct child_process hook = CHILD_PROCESS_INIT;
767 const char *p;
768
769 p = find_hook(name);
770 if (!p)
771 return 0;
772
773 - memset(&hook, 0, sizeof(hook));
773 argv_array_push(&hook.args, p);
774 while ((p = va_arg(args, const char *)))
775 argv_array_push(&hook.args, p);
run-command.h
+2
@@ -44,6 +44,8 @@ struct child_process {
44 unsigned clean_on_exit:1;
45 };
46
47 +#define CHILD_PROCESS_INIT { NULL, ARGV_ARRAY_INIT }
48 +
49 int start_command(struct child_process *);
50 int finish_command(struct child_process *);
51 int run_command(struct child_process *);
send-pack.c
+1 -2
@@ -47,7 +47,7 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru
47 NULL,
48 NULL,
49 };
50 - struct child_process po;
50 + struct child_process po = CHILD_PROCESS_INIT;
51 int i;
52
53 i = 4;
@@ -59,7 +59,6 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru
59 argv[i++] = "-q";
60 if (args->progress)
61 argv[i++] = "--progress";
62 - memset(&po, 0, sizeof(po));
62 po.argv = argv;
63 po.in = -1;
64 po.out = args->stateless_rpc ? -1 : fd;
submodule.c
+7 -14
@@ -433,13 +433,12 @@ static int submodule_needs_pushing(const char *path, const unsigned char sha1[20
433 return 0;
434
435 if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) {
436 - struct child_process cp;
436 + struct child_process cp = CHILD_PROCESS_INIT;
437 const char *argv[] = {"rev-list", NULL, "--not", "--remotes", "-n", "1" , NULL};
438 struct strbuf buf = STRBUF_INIT;
439 int needs_pushing = 0;
440
441 argv[1] = sha1_to_hex(sha1);
442 - memset(&cp, 0, sizeof(cp));
442 cp.argv = argv;
443 cp.env = local_repo_env;
444 cp.git_cmd = 1;
@@ -524,10 +523,9 @@ static int push_submodule(const char *path)
523 return 1;
524
525 if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) {
527 - struct child_process cp;
526 + struct child_process cp = CHILD_PROCESS_INIT;
527 const char *argv[] = {"push", NULL};
528
530 - memset(&cp, 0, sizeof(cp));
529 cp.argv = argv;
530 cp.env = local_repo_env;
531 cp.git_cmd = 1;
@@ -569,12 +567,11 @@ static int is_submodule_commit_present(const char *path, unsigned char sha1[20])
567 if (!add_submodule_odb(path) && lookup_commit_reference(sha1)) {
568 /* Even if the submodule is checked out and the commit is
569 * present, make sure it is reachable from a ref. */
572 - struct child_process cp;
570 + struct child_process cp = CHILD_PROCESS_INIT;
571 const char *argv[] = {"rev-list", "-n", "1", NULL, "--not", "--all", NULL};
572 struct strbuf buf = STRBUF_INIT;
573
574 argv[3] = sha1_to_hex(sha1);
577 - memset(&cp, 0, sizeof(cp));
575 cp.argv = argv;
576 cp.env = local_repo_env;
577 cp.git_cmd = 1;
@@ -695,7 +692,7 @@ int fetch_populated_submodules(const struct argv_array *options,
692 int quiet)
693 {
694 int i, result = 0;
698 - struct child_process cp;
695 + struct child_process cp = CHILD_PROCESS_INIT;
696 struct argv_array argv = ARGV_ARRAY_INIT;
697 struct string_list_item *name_for_path;
698 const char *work_tree = get_git_work_tree();
@@ -711,7 +708,6 @@ int fetch_populated_submodules(const struct argv_array *options,
708 argv_array_push(&argv, "--recurse-submodules-default");
709 /* default value, "--submodule-prefix" and its value are added later */
710
714 - memset(&cp, 0, sizeof(cp));
711 cp.env = local_repo_env;
712 cp.git_cmd = 1;
713 cp.no_stdin = 1;
@@ -794,7 +790,7 @@ out:
790 unsigned is_submodule_modified(const char *path, int ignore_untracked)
791 {
792 ssize_t len;
797 - struct child_process cp;
793 + struct child_process cp = CHILD_PROCESS_INIT;
794 const char *argv[] = {
795 "status",
796 "--porcelain",
@@ -821,7 +817,6 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
817 if (ignore_untracked)
818 argv[2] = "-uno";
819
824 - memset(&cp, 0, sizeof(cp));
820 cp.argv = argv;
821 cp.env = local_repo_env;
822 cp.git_cmd = 1;
@@ -862,7 +857,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
857
858 int submodule_uses_gitfile(const char *path)
859 {
865 - struct child_process cp;
860 + struct child_process cp = CHILD_PROCESS_INIT;
861 const char *argv[] = {
862 "submodule",
863 "foreach",
@@ -883,7 +878,6 @@ int submodule_uses_gitfile(const char *path)
878 strbuf_release(&buf);
879
880 /* Now test that all nested submodules use a gitfile too */
886 - memset(&cp, 0, sizeof(cp));
881 cp.argv = argv;
882 cp.env = local_repo_env;
883 cp.git_cmd = 1;
@@ -901,7 +895,7 @@ int ok_to_remove_submodule(const char *path)
895 {
896 struct stat st;
897 ssize_t len;
904 - struct child_process cp;
898 + struct child_process cp = CHILD_PROCESS_INIT;
899 const char *argv[] = {
900 "status",
901 "--porcelain",
@@ -918,7 +912,6 @@ int ok_to_remove_submodule(const char *path)
912 if (!submodule_uses_gitfile(path))
913 return 0;
914
921 - memset(&cp, 0, sizeof(cp));
915 cp.argv = argv;
916 cp.env = local_repo_env;
917 cp.git_cmd = 1;
test-run-command.c
+1 -3
@@ -15,9 +15,7 @@
15
16 int main(int argc, char **argv)
17 {
18 - struct child_process proc;
19 -
20 - memset(&proc, 0, sizeof(proc));
18 + struct child_process proc = CHILD_PROCESS_INIT;
19
20 if (argc < 3)
21 return 1;
test-subprocess.c
+1 -2
@@ -3,7 +3,7 @@
3
4 int main(int argc, char **argv)
5 {
6 - struct child_process cp;
6 + struct child_process cp = CHILD_PROCESS_INIT;
7 int nogit = 0;
8
9 setup_git_directory_gently(&nogit);
@@ -13,7 +13,6 @@ int main(int argc, char **argv)
13 setup_work_tree();
14 argv++;
15 }
16 - memset(&cp, 0, sizeof(cp));
16 cp.git_cmd = 1;
17 cp.argv = (const char **)argv + 1;
18 return run_command(&cp);
transport.c
+4 -8
@@ -201,7 +201,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
201 {
202 struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT;
203 struct ref dummy = {NULL}, *tail = &dummy;
204 - struct child_process rsync;
204 + struct child_process rsync = CHILD_PROCESS_INIT;
205 const char *args[5];
206 int temp_dir_len;
207
@@ -218,7 +218,6 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
218 strbuf_addstr(&buf, rsync_url(transport->url));
219 strbuf_addstr(&buf, "/refs");
220
221 - memset(&rsync, 0, sizeof(rsync));
221 rsync.argv = args;
222 rsync.stdout_to_stderr = 1;
223 args[0] = "rsync";
@@ -263,9 +262,8 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
262 static int fetch_objs_via_rsync(struct transport *transport,
263 int nr_objs, struct ref **to_fetch)
264 {
266 - struct child_process rsync;
265 + struct child_process rsync = CHILD_PROCESS_INIT;
266
268 - memset(&rsync, 0, sizeof(rsync));
267 rsync.stdout_to_stderr = 1;
268 argv_array_push(&rsync.args, "rsync");
269 argv_array_push(&rsync.args, (transport->verbose > 1) ? "-rv" : "-r");
@@ -327,7 +325,7 @@ static int rsync_transport_push(struct transport *transport,
325 {
326 struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT;
327 int result = 0, i;
330 - struct child_process rsync;
328 + struct child_process rsync = CHILD_PROCESS_INIT;
329 const char *args[10];
330
331 if (flags & TRANSPORT_PUSH_MIRROR)
@@ -338,7 +336,6 @@ static int rsync_transport_push(struct transport *transport,
336 strbuf_addstr(&buf, rsync_url(transport->url));
337 strbuf_addch(&buf, '/');
338
341 - memset(&rsync, 0, sizeof(rsync));
339 rsync.argv = args;
340 rsync.stdout_to_stderr = 1;
341 i = 0;
@@ -1056,7 +1053,7 @@ static int run_pre_push_hook(struct transport *transport,
1053 {
1054 int ret = 0, x;
1055 struct ref *r;
1059 - struct child_process proc;
1056 + struct child_process proc = CHILD_PROCESS_INIT;
1057 struct strbuf buf;
1058 const char *argv[4];
1059
@@ -1067,7 +1064,6 @@ static int run_pre_push_hook(struct transport *transport,
1064 argv[2] = transport->url;
1065 argv[3] = NULL;
1066
1070 - memset(&proc, 0, sizeof(proc));
1067 proc.argv = argv;
1068 proc.in = -1;
1069
upload-pack.c
+2 -3
@@ -80,7 +80,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
80
81 static void create_pack_file(void)
82 {
83 - struct child_process pack_objects;
83 + struct child_process pack_objects = CHILD_PROCESS_INIT;
84 char data[8193], progress[128];
85 char abort_msg[] = "aborting due to possible repository "
86 "corruption on the remote side.";
@@ -108,7 +108,6 @@ static void create_pack_file(void)
108 argv[arg++] = "--include-tag";
109 argv[arg++] = NULL;
110
111 - memset(&pack_objects, 0, sizeof(pack_objects));
111 pack_objects.in = -1;
112 pack_objects.out = -1;
113 pack_objects.err = -1;
@@ -448,7 +447,7 @@ static void check_non_tip(void)
447 static const char *argv[] = {
448 "rev-list", "--stdin", NULL,
449 };
451 - static struct child_process cmd;
450 + static struct child_process cmd = CHILD_PROCESS_INIT;
451 struct object *o;
452 char namebuf[42]; /* ^ + SHA-1 + LF */
453 int i;
wt-status.c
+1 -2
@@ -725,7 +725,7 @@ static void wt_status_print_changed(struct wt_status *s)
725
726 static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitted)
727 {
728 - struct child_process sm_summary;
728 + struct child_process sm_summary = CHILD_PROCESS_INIT;
729 struct argv_array env = ARGV_ARRAY_INIT;
730 struct argv_array argv = ARGV_ARRAY_INIT;
731 struct strbuf cmd_stdout = STRBUF_INIT;
@@ -744,7 +744,6 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
744 if (!uncommitted)
745 argv_array_push(&argv, s->amend ? "HEAD^" : "HEAD");
746
747 - memset(&sm_summary, 0, sizeof(sm_summary));
747 sm_summary.argv = argv.argv;
748 sm_summary.env = env.argv;
749 sm_summary.git_cmd = 1;