Re: [PATCH v3 01/25] sequencer: use static initializers for replay_opts
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 10, 2016, 22:14 UTC
- Message-ID
- <xmqqeg3ndf85.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <5c4c86f0ea7ee4a9bad15e48f72b8fe5baa72dfb.1476120229.git.johannes.schindelin@gmx.de>
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
Show 5 quoted lines
> This change is not completely faithful: instead of initializing all fields > to 0, we choose to initialize command and subcommand to -1 (instead of > defaulting to REPLAY_REVERT and REPLAY_NONE, respectively). Practically, > it makes no difference at all, but future-proofs the code to require > explicit assignments for both fields.
The assignments to opts.action immediately following, I would say this is quite faithful conversion that looks good.
Show 33 quoted lines
> int cmd_revert(int argc, const char **argv, const char *prefix)
> {
> - struct replay_opts opts;
> + struct replay_opts opts = REPLAY_OPTS_INIT;
> int res;
>
> - memset(&opts, 0, sizeof(opts));
> if (isatty(0))
> opts.edit = 1;
> opts.action = REPLAY_REVERT;
> @@ -195,10 +194,9 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
>
> int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
> {
> - struct replay_opts opts;
> + struct replay_opts opts = REPLAY_OPTS_INIT;
> int res;
>
> - memset(&opts, 0, sizeof(opts));
> opts.action = REPLAY_PICK;
> git_config(git_default_config, NULL);
> parse_args(argc, argv, &opts);
> diff --git a/sequencer.h b/sequencer.h
> index 5ed5cb1..db425ad 100644
> --- a/sequencer.h
> +++ b/sequencer.h
> @@ -47,6 +47,7 @@ struct replay_opts {
> /* Only used by REPLAY_NONE */
> struct rev_info *revs;
> };
> +#define REPLAY_OPTS_INIT { -1, -1 }
>
> int sequencer_pick_revisions(struct replay_opts *opts);