diff options
author | René Scharfe <l.s.r@web.de> | 2014-08-19 21:09:35 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-08-20 09:53:37 -0700 |
commit | d3180279322c7450a47decf8833de47f444ca93f (patch) | |
tree | 6b15045aef08b51a0831ee75bb67fd0beddc0d0c /builtin | |
parent | Git 2.1 (diff) | |
download | tgif-d3180279322c7450a47decf8833de47f444ca93f.tar.xz |
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>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/add.c | 3 | ||||
-rw-r--r-- | builtin/commit.c | 3 | ||||
-rw-r--r-- | builtin/help.c | 3 | ||||
-rw-r--r-- | builtin/merge.c | 3 | ||||
-rw-r--r-- | builtin/notes.c | 3 | ||||
-rw-r--r-- | builtin/receive-pack.c | 12 | ||||
-rw-r--r-- | builtin/remote-ext.c | 3 | ||||
-rw-r--r-- | builtin/repack.c | 3 | ||||
-rw-r--r-- | builtin/replace.c | 4 | ||||
-rw-r--r-- | builtin/verify-pack.c | 3 |
10 files changed, 14 insertions, 26 deletions
diff --git a/builtin/add.c b/builtin/add.c index 4baf3a5635..352b85e8db 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -180,7 +180,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix) char *file = git_pathdup("ADD_EDIT.patch"); const char *apply_argv[] = { "apply", "--recount", "--cached", NULL, NULL }; - struct child_process child; + struct child_process child = CHILD_PROCESS_INIT; struct rev_info rev; int out; struct stat st; @@ -214,7 +214,6 @@ static int edit_patch(int argc, const char **argv, const char *prefix) if (!st.st_size) die(_("Empty patch. Aborted.")); - memset(&child, 0, sizeof(child)); child.git_cmd = 1; child.argv = apply_argv; if (run_command(&child)) diff --git a/builtin/commit.c b/builtin/commit.c index 5ed60364ce..b8b8663cc8 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1508,7 +1508,7 @@ static int run_rewrite_hook(const unsigned char *oldsha1, { /* oldsha1 SP newsha1 LF NUL */ static char buf[2*40 + 3]; - struct child_process proc; + struct child_process proc = CHILD_PROCESS_INIT; const char *argv[3]; int code; size_t n; @@ -1520,7 +1520,6 @@ static int run_rewrite_hook(const unsigned char *oldsha1, argv[1] = "amend"; argv[2] = NULL; - memset(&proc, 0, sizeof(proc)); proc.argv = argv; proc.in = -1; proc.stdout_to_stderr = 1; diff --git a/builtin/help.c b/builtin/help.c index 1fdefeb686..8343b4027d 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -79,12 +79,11 @@ static const char *get_man_viewer_info(const char *name) static int check_emacsclient_version(void) { struct strbuf buffer = STRBUF_INIT; - struct child_process ec_process; + struct child_process ec_process = CHILD_PROCESS_INIT; const char *argv_ec[] = { "emacsclient", "--version", NULL }; int version; /* emacsclient prints its version number on stderr */ - memset(&ec_process, 0, sizeof(ec_process)); ec_process.argv = argv_ec; ec_process.err = -1; ec_process.stdout_to_stderr = 1; diff --git a/builtin/merge.c b/builtin/merge.c index ce82eb297d..9da9e30d9b 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -237,11 +237,10 @@ static void drop_save(void) static int save_state(unsigned char *stash) { int len; - struct child_process cp; + struct child_process cp = CHILD_PROCESS_INIT; struct strbuf buffer = STRBUF_INIT; const char *argv[] = {"stash", "create", NULL}; - memset(&cp, 0, sizeof(cp)); cp.argv = argv; cp.out = -1; cp.git_cmd = 1; diff --git a/builtin/notes.c b/builtin/notes.c index 820c34135c..c25a412510 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -122,12 +122,11 @@ static void write_commented_object(int fd, const unsigned char *object) { const char *show_args[5] = {"show", "--stat", "--no-notes", sha1_to_hex(object), NULL}; - struct child_process show; + struct child_process show = CHILD_PROCESS_INIT; struct strbuf buf = STRBUF_INIT; struct strbuf cbuf = STRBUF_INIT; /* Invoke "git show --stat --no-notes $object" */ - memset(&show, 0, sizeof(show)); show.argv = show_args; show.no_stdin = 1; show.out = -1; diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index f93ac454b4..5ad9075b3c 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -255,7 +255,7 @@ static int copy_to_sideband(int in, int out, void *arg) typedef int (*feed_fn)(void *, const char **, size_t *); static int run_and_feed_hook(const char *hook_name, feed_fn feed, void *feed_state) { - struct child_process proc; + struct child_process proc = CHILD_PROCESS_INIT; struct async muxer; const char *argv[2]; int code; @@ -266,7 +266,6 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed, void *feed_sta argv[1] = NULL; - memset(&proc, 0, sizeof(proc)); proc.argv = argv; proc.in = -1; proc.stdout_to_stderr = 1; @@ -350,7 +349,7 @@ static int run_receive_hook(struct command *commands, const char *hook_name, static int run_update_hook(struct command *cmd) { const char *argv[5]; - struct child_process proc; + struct child_process proc = CHILD_PROCESS_INIT; int code; argv[0] = find_hook("update"); @@ -362,7 +361,6 @@ static int run_update_hook(struct command *cmd) argv[3] = sha1_to_hex(cmd->new_sha1); argv[4] = NULL; - memset(&proc, 0, sizeof(proc)); proc.no_stdin = 1; proc.stdout_to_stderr = 1; proc.err = use_sideband ? -1 : 0; @@ -598,7 +596,7 @@ static void run_update_post_hook(struct command *commands) struct command *cmd; int argc; const char **argv; - struct child_process proc; + struct child_process proc = CHILD_PROCESS_INIT; char *hook; hook = find_hook("post-update"); @@ -621,7 +619,6 @@ static void run_update_post_hook(struct command *commands) } argv[argc] = NULL; - memset(&proc, 0, sizeof(proc)); proc.no_stdin = 1; proc.stdout_to_stderr = 1; proc.err = use_sideband ? -1 : 0; @@ -911,7 +908,7 @@ static const char *unpack(int err_fd, struct shallow_info *si) const char *hdr_err; int status; char hdr_arg[38]; - struct child_process child; + struct child_process child = CHILD_PROCESS_INIT; int fsck_objects = (receive_fsck_objects >= 0 ? receive_fsck_objects : transfer_fsck_objects >= 0 @@ -933,7 +930,6 @@ static const char *unpack(int err_fd, struct shallow_info *si) argv_array_pushl(&av, "--shallow-file", alt_shallow_file, NULL); } - memset(&child, 0, sizeof(child)); if (ntohl(hdr.hdr_entries) < unpack_limit) { argv_array_pushl(&av, "unpack-objects", hdr_arg, NULL); if (quiet) diff --git a/builtin/remote-ext.c b/builtin/remote-ext.c index 692c834d9d..d699d28e98 100644 --- a/builtin/remote-ext.c +++ b/builtin/remote-ext.c @@ -179,9 +179,8 @@ static void send_git_request(int stdin_fd, const char *serv, const char *repo, static int run_child(const char *arg, const char *service) { int r; - struct child_process child; + struct child_process child = CHILD_PROCESS_INIT; - memset(&child, 0, sizeof(child)); child.in = -1; child.out = -1; child.err = 0; diff --git a/builtin/repack.c b/builtin/repack.c index a77e743b94..fc088dbe6a 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -133,7 +133,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) {".idx"}, {".bitmap", 1}, }; - struct child_process cmd; + struct child_process cmd = CHILD_PROCESS_INIT; struct string_list_item *item; struct argv_array cmd_args = ARGV_ARRAY_INIT; struct string_list names = STRING_LIST_INIT_DUP; @@ -250,7 +250,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix) argv_array_push(&cmd_args, packtmp); - memset(&cmd, 0, sizeof(cmd)); cmd.argv = cmd_args.argv; cmd.git_cmd = 1; cmd.out = -1; diff --git a/builtin/replace.c b/builtin/replace.c index 294b61b97e..d2aac64260 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -197,7 +197,7 @@ static int replace_object(const char *object_ref, const char *replace_ref, int f static void export_object(const unsigned char *sha1, enum object_type type, int raw, const char *filename) { - struct child_process cmd = { NULL }; + struct child_process cmd = CHILD_PROCESS_INIT; int fd; 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, if (!raw && type == OBJ_TREE) { const char *argv[] = { "mktree", NULL }; - struct child_process cmd = { argv }; + struct child_process cmd = CHILD_PROCESS_INIT; struct strbuf result = STRBUF_INIT; cmd.argv = argv; diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c index 972579f33c..7747537beb 100644 --- a/builtin/verify-pack.c +++ b/builtin/verify-pack.c @@ -8,7 +8,7 @@ static int verify_one_pack(const char *path, unsigned int flags) { - struct child_process index_pack; + struct child_process index_pack = CHILD_PROCESS_INIT; const char *argv[] = {"index-pack", NULL, NULL, NULL }; struct strbuf arg = STRBUF_INIT; int verbose = flags & VERIFY_PACK_VERBOSE; @@ -32,7 +32,6 @@ static int verify_one_pack(const char *path, unsigned int flags) strbuf_addstr(&arg, ".pack"); argv[2] = arg.buf; - memset(&index_pack, 0, sizeof(index_pack)); index_pack.argv = argv; index_pack.git_cmd = 1; |