From 291b968951519ffa545012c091a27ba9188cf51a Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Mon, 23 Jan 2017 21:00:46 +0100 Subject: [PATCH] WIP --skip --- builtin/revert.c | 7 +++++-- sequencer.c | 32 ++++++++++++++++++++++++++++---- sequencer.h | 2 +- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/builtin/revert.c b/builtin/revert.c index ffdd367f99..a1cc58f794 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -79,6 +79,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) struct option base_options[] = { OPT_CMDMODE(0, "quit", &cmd, N_("end revert or cherry-pick sequence"), 'q'), OPT_CMDMODE(0, "continue", &cmd, N_("resume revert or cherry-pick sequence"), 'c'), + OPT_CMDMODE(0, "skip", &cmd, N_("resume revert or cherry-pick sequence, skipping this commit"), 's'), OPT_CMDMODE(0, "abort", &cmd, N_("cancel revert or cherry-pick sequence"), 'a'), OPT_BOOL('n', "no-commit", &opts->no_commit, N_("don't automatically commit")), OPT_BOOL('e', "edit", &opts->edit, N_("edit the commit message")), @@ -123,6 +124,8 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) this_operation = "--quit"; else if (cmd == 'c') this_operation = "--continue"; + else if (cmd == 's') + this_operation = "--skip"; else { assert(cmd == 'a'); this_operation = "--abort"; @@ -172,8 +175,8 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) if (cmd == 'q') return sequencer_remove_state(opts); - if (cmd == 'c') - return sequencer_continue(opts); + if (cmd == 'c' || cmd == 's') + return sequencer_continue(opts, cmd); if (cmd == 'a') return sequencer_rollback(opts); return sequencer_pick_revisions(opts); diff --git a/sequencer.c b/sequencer.c index 72962fd2fa..72b443209c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1309,21 +1309,45 @@ static int continue_single_pick(void) return run_command_v_opt(argv, RUN_GIT_CMD); } -int sequencer_continue(struct replay_opts *opts) +/* + * Continue the sequencing, after either committing + * (cmd == 'c') or skipping (cmd == 's') the current + * commit. + */ +int sequencer_continue(struct replay_opts *opts, char cmd) { struct todo_list todo_list = TODO_LIST_INIT; - int res; + int single, res; if (read_and_refresh_cache(opts)) return -1; - if (!file_exists(get_todo_path(opts))) - return continue_single_pick(); + if (!file_exists(get_todo_path(opts))) { + if (cmd == 'c') { + return continue_single_pick(); + } else { + assert(cmd == 's'); + /* Skipping the only commit is equivalent to an abort */ + return sequencer_rollback(opts); + } + } if (read_populate_opts(opts)) return -1; if ((res = read_populate_todo(&todo_list, opts))) goto release_todo_list; + /* If we were asked to skip this commit, rollback + * and continue with the next */ + if (cmd == 's') { + if ((res = rollback_single_pick())) + goto release_todo_list; + cache_tree_free(&active_cache_tree); + if ((res = read_cache()) < 0) + goto release_todo_list; + printf("index unchanged: %d\n", is_index_unchanged()); + goto skip_this_commit; + } + /* check if there is something to commit */ res = is_index_unchanged(); if (res < 0) diff --git a/sequencer.h b/sequencer.h index c747cfcfc7..c10e89fdba 100644 --- a/sequencer.h +++ b/sequencer.h @@ -40,7 +40,7 @@ struct replay_opts { #define REPLAY_OPTS_INIT { -1 } int sequencer_pick_revisions(struct replay_opts *opts); -int sequencer_continue(struct replay_opts *opts); +int sequencer_continue(struct replay_opts *opts, char cmd); int sequencer_rollback(struct replay_opts *opts); int sequencer_remove_state(struct replay_opts *opts); -- 2.32.0.93.g670b81a890