Merge branch 'cc/subprocess-handshake-missing-capabilities' into next
[gitweb.git] / builtin / revert.c
index 37df613ac7eae3e37122adcaf3db931f0a325134..b9d927eb09c9ed87c84681df1396f4e6d9b13c97 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "parse-options.h"
 #include "diff.h"
@@ -89,7 +90,7 @@ static void verify_opt_compatible(const char *me, const char *base_opt, ...)
                die(_("%s: %s cannot be used with %s"), me, this_opt, base_opt);
 }
 
-static void parse_args(int argc, const char **argv, struct replay_opts *opts)
+static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
 {
        const char * const * usage_str = revert_or_cherry_pick_usage(opts);
        const char *me = action_name(opts);
@@ -134,25 +135,15 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
        if (opts->keep_redundant_commits)
                opts->allow_empty = 1;
 
-       /* Set the subcommand */
-       if (cmd == 'q')
-               opts->subcommand = REPLAY_REMOVE_STATE;
-       else if (cmd == 'c')
-               opts->subcommand = REPLAY_CONTINUE;
-       else if (cmd == 'a')
-               opts->subcommand = REPLAY_ROLLBACK;
-       else
-               opts->subcommand = REPLAY_NONE;
-
        /* Check for incompatible command line arguments */
-       if (opts->subcommand != REPLAY_NONE) {
+       if (cmd) {
                char *this_operation;
-               if (opts->subcommand == REPLAY_REMOVE_STATE)
+               if (cmd == 'q')
                        this_operation = "--quit";
-               else if (opts->subcommand == REPLAY_CONTINUE)
+               else if (cmd == 'c')
                        this_operation = "--continue";
                else {
-                       assert(opts->subcommand == REPLAY_ROLLBACK);
+                       assert(cmd == 'a');
                        this_operation = "--abort";
                }
 
@@ -164,6 +155,8 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
                                "--strategy-option", opts->xopts ? 1 : 0,
                                "-x", opts->record_origin,
                                "--ff", opts->allow_ff,
+                               "--rerere-autoupdate", opts->allow_rerere_auto == RERERE_AUTOUPDATE,
+                               "--no-rerere-autoupdate", opts->allow_rerere_auto == RERERE_NOAUTOUPDATE,
                                NULL);
        }
 
@@ -175,7 +168,7 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
                                "--edit", opts->edit,
                                NULL);
 
-       if (opts->subcommand != REPLAY_NONE) {
+       if (cmd) {
                opts->revs = NULL;
        } else {
                struct setup_revision_opt s_r_opt;
@@ -193,20 +186,30 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
 
        if (argc > 1)
                usage_with_options(usage_str, options);
+
+       /* These option values will be free()d */
+       opts->gpg_sign = xstrdup_or_null(opts->gpg_sign);
+       opts->strategy = xstrdup_or_null(opts->strategy);
+
+       if (cmd == 'q')
+               return sequencer_remove_state(opts);
+       if (cmd == 'c')
+               return sequencer_continue(opts);
+       if (cmd == 'a')
+               return sequencer_rollback(opts);
+       return sequencer_pick_revisions(opts);
 }
 
 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;
        git_config(git_default_config, NULL);
-       parse_args(argc, argv, &opts);
-       res = sequencer_pick_revisions(&opts);
+       res = run_sequencer(argc, argv, &opts);
        if (res < 0)
                die(_("revert failed"));
        return res;
@@ -214,14 +217,12 @@ 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);
-       res = sequencer_pick_revisions(&opts);
+       res = run_sequencer(argc, argv, &opts);
        if (res < 0)
                die(_("cherry-pick failed"));
        return res;