Merge branch 'bl/cherry-pick-empty'
Allow git-cherry-pick(1) to automatically drop redundant commits via a new `--empty` option, similar to the `--empty` options for git-rebase(1) and git-am(1). Includes a soft deprecation of `--keep-redundant-commits` as well as some related docs changes and sequencer code cleanup. * bl/cherry-pick-empty: cherry-pick: add `--empty` for more robust redundant commit handling cherry-pick: enforce `--keep-redundant-commits` incompatibility sequencer: do not require `allow_empty` for redundant commit options sequencer: handle unborn branch with `--allow-empty` rebase: update `--empty=ask` to `--empty=stop` docs: clean up `--empty` formatting in git-rebase(1) and git-am(1) docs: address inaccurate `--empty` default with `--exec`
This commit is contained in:
@ -58,7 +58,7 @@ enum empty_type {
|
||||
EMPTY_UNSPECIFIED = -1,
|
||||
EMPTY_DROP,
|
||||
EMPTY_KEEP,
|
||||
EMPTY_ASK
|
||||
EMPTY_STOP
|
||||
};
|
||||
|
||||
enum action {
|
||||
@ -945,10 +945,14 @@ static enum empty_type parse_empty_value(const char *value)
|
||||
return EMPTY_DROP;
|
||||
else if (!strcasecmp(value, "keep"))
|
||||
return EMPTY_KEEP;
|
||||
else if (!strcasecmp(value, "ask"))
|
||||
return EMPTY_ASK;
|
||||
else if (!strcasecmp(value, "stop"))
|
||||
return EMPTY_STOP;
|
||||
else if (!strcasecmp(value, "ask")) {
|
||||
warning(_("--empty=ask is deprecated; use '--empty=stop' instead."));
|
||||
return EMPTY_STOP;
|
||||
}
|
||||
|
||||
die(_("unrecognized empty type '%s'; valid values are \"drop\", \"keep\", and \"ask\"."), value);
|
||||
die(_("unrecognized empty type '%s'; valid values are \"drop\", \"keep\", and \"stop\"."), value);
|
||||
}
|
||||
|
||||
static int parse_opt_keep_empty(const struct option *opt, const char *arg,
|
||||
@ -1127,7 +1131,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
||||
"instead of ignoring them"),
|
||||
1, PARSE_OPT_HIDDEN),
|
||||
OPT_RERERE_AUTOUPDATE(&options.allow_rerere_autoupdate),
|
||||
OPT_CALLBACK_F(0, "empty", &options, "(drop|keep|ask)",
|
||||
OPT_CALLBACK_F(0, "empty", &options, "(drop|keep|stop)",
|
||||
N_("how to handle commits that become empty"),
|
||||
PARSE_OPT_NONEG, parse_opt_empty),
|
||||
OPT_CALLBACK_F('k', "keep-empty", &options, NULL,
|
||||
@ -1544,7 +1548,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
||||
|
||||
if (options.empty == EMPTY_UNSPECIFIED) {
|
||||
if (options.flags & REBASE_INTERACTIVE_EXPLICIT)
|
||||
options.empty = EMPTY_ASK;
|
||||
options.empty = EMPTY_STOP;
|
||||
else if (options.exec.nr > 0)
|
||||
options.empty = EMPTY_KEEP;
|
||||
else
|
||||
|
@ -43,6 +43,31 @@ static const char * const *revert_or_cherry_pick_usage(struct replay_opts *opts)
|
||||
return opts->action == REPLAY_REVERT ? revert_usage : cherry_pick_usage;
|
||||
}
|
||||
|
||||
enum empty_action {
|
||||
EMPTY_COMMIT_UNSPECIFIED = -1,
|
||||
STOP_ON_EMPTY_COMMIT, /* output errors and stop in the middle of a cherry-pick */
|
||||
DROP_EMPTY_COMMIT, /* skip with a notice message */
|
||||
KEEP_EMPTY_COMMIT, /* keep recording as empty commits */
|
||||
};
|
||||
|
||||
static int parse_opt_empty(const struct option *opt, const char *arg, int unset)
|
||||
{
|
||||
int *opt_value = opt->value;
|
||||
|
||||
BUG_ON_OPT_NEG(unset);
|
||||
|
||||
if (!strcmp(arg, "stop"))
|
||||
*opt_value = STOP_ON_EMPTY_COMMIT;
|
||||
else if (!strcmp(arg, "drop"))
|
||||
*opt_value = DROP_EMPTY_COMMIT;
|
||||
else if (!strcmp(arg, "keep"))
|
||||
*opt_value = KEEP_EMPTY_COMMIT;
|
||||
else
|
||||
return error(_("invalid value for '%s': '%s'"), "--empty", arg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int option_parse_m(const struct option *opt,
|
||||
const char *arg, int unset)
|
||||
{
|
||||
@ -85,6 +110,7 @@ static int run_sequencer(int argc, const char **argv, const char *prefix,
|
||||
const char * const * usage_str = revert_or_cherry_pick_usage(opts);
|
||||
const char *me = action_name(opts);
|
||||
const char *cleanup_arg = NULL;
|
||||
enum empty_action empty_opt = EMPTY_COMMIT_UNSPECIFIED;
|
||||
int cmd = 0;
|
||||
struct option base_options[] = {
|
||||
OPT_CMDMODE(0, "quit", &cmd, N_("end revert or cherry-pick sequence"), 'q'),
|
||||
@ -114,7 +140,10 @@ static int run_sequencer(int argc, const char **argv, const char *prefix,
|
||||
OPT_BOOL(0, "ff", &opts->allow_ff, N_("allow fast-forward")),
|
||||
OPT_BOOL(0, "allow-empty", &opts->allow_empty, N_("preserve initially empty commits")),
|
||||
OPT_BOOL(0, "allow-empty-message", &opts->allow_empty_message, N_("allow commits with empty messages")),
|
||||
OPT_BOOL(0, "keep-redundant-commits", &opts->keep_redundant_commits, N_("keep redundant, empty commits")),
|
||||
OPT_BOOL(0, "keep-redundant-commits", &opts->keep_redundant_commits, N_("deprecated: use --empty=keep instead")),
|
||||
OPT_CALLBACK_F(0, "empty", &empty_opt, "(stop|drop|keep)",
|
||||
N_("how to handle commits that become empty"),
|
||||
PARSE_OPT_NONEG, parse_opt_empty),
|
||||
OPT_END(),
|
||||
};
|
||||
options = parse_options_concat(options, cp_extra);
|
||||
@ -134,6 +163,11 @@ static int run_sequencer(int argc, const char **argv, const char *prefix,
|
||||
prepare_repo_settings(the_repository);
|
||||
the_repository->settings.command_requires_full_index = 0;
|
||||
|
||||
if (opts->action == REPLAY_PICK) {
|
||||
opts->drop_redundant_commits = (empty_opt == DROP_EMPTY_COMMIT);
|
||||
opts->keep_redundant_commits = opts->keep_redundant_commits || (empty_opt == KEEP_EMPTY_COMMIT);
|
||||
}
|
||||
|
||||
/* implies allow_empty */
|
||||
if (opts->keep_redundant_commits)
|
||||
opts->allow_empty = 1;
|
||||
@ -167,6 +201,8 @@ static int run_sequencer(int argc, const char **argv, const char *prefix,
|
||||
"--ff", opts->allow_ff,
|
||||
"--rerere-autoupdate", opts->allow_rerere_auto == RERERE_AUTOUPDATE,
|
||||
"--no-rerere-autoupdate", opts->allow_rerere_auto == RERERE_NOAUTOUPDATE,
|
||||
"--keep-redundant-commits", opts->keep_redundant_commits,
|
||||
"--empty", empty_opt != EMPTY_COMMIT_UNSPECIFIED,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user