sequencer: allow skipping commits
cover sequencer: allow skipping commits
This series introduces a few options to the sequencer, to allow skipping unwanted/unnecessary commits.
The first patch is just cleanup. The second fixes a potential issue about sequencing options not being correctly remembered across interruptions.
The next two introduce cherry-pick options to skip empty (or only redundant) commits. The two options are introduced separately because of the complexity associated with the possible combinations that can be had.
The last commit allows --skip as a reset + --continue, to quickly skip the current commit during a failed cherry-pick or revert (for example because a better version of the commit was already merged).
Giuseppe Bilotta (5):
sequencer: sort options load/save by struct position
sequencer: save/load all options
cherry-pick: option to skip empty commits
cherry-pick: allow skipping only redundant commits
sequencer: allow to --skip current commit
Documentation/git-cherry-pick.txt | 10 +++ Documentation/sequencer.txt | 10 ++- builtin/revert.c | 24 +++++- sequencer.c | 163 ++++++++++++++++++++++++++++++-------- sequencer.h | 4 +- 5 files changed, 176 insertions(+), 35 deletions(-)
Signature · 1 line
2.11.0.616.gd72966cf44.dirty
PATCH 5/5 sequencer: allow to --skip current commit
If a sequencing gets interrupted (by a conflict or an empty commit or whatever), the user can now opt to just skip it passing the --skip command line option, which acts like a --continue, except that the current commit gets skipped.
--- Documentation/sequencer.txt | 10 +++++++++- builtin/revert.c | 7 +++++-- sequencer.c | 32 ++++++++++++++++++++++++++++---- sequencer.h | 2 +- 4 files changed, 43 insertions(+), 8 deletions(-)
Documentation/sequencer.txt +9 -1
@@ -1,7 +1,15 @@ --continue:: Continue the operation in progress using the information in '.git/sequencer'. Can be used to continue after resolving - conflicts in a failed cherry-pick or revert. + conflicts in a failed cherry-pick or revert. Use `--skip` + instead if the current commit should be ignored. + +--skip:: + Skips the current commit, and then continues the operation + in progress using the information in '.git/sequencer'.i + Can be used to continue to a cherry-pick or rever that was + interrupted by an empty commit, or by a commit that conflicts + and for which the resolution is to discard the commit. --quit:: Forget about the current operation in progress. Can be used
builtin/revert.c +5 -2
@@ -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" )),
@@ -127,6 +128,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" ;
@@ -188,8 +191,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);
sequencer.c +28 -4
@@ -1359,21 +1359,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; +discard_cache (); +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 )
sequencer.h +1 -1
@@ -41,7 +41,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);
Signature · 1 line
2.11.0.616.gd72966cf44.dirty
PATCH 3/5 cherry-pick: option to skip empty commits
In reply to Giuseppe BilottaThis allows cherry-picking a set of commits, some of which may be redundant, without stopping to ask for the user intervention.
--- Documentation/git-cherry-pick.txt | 4 ++++ builtin/revert.c | 1 + sequencer.c | 45 +++++++++++++++++++++++++++++++-------- sequencer.h | 1 + 4 files changed, 42 insertions(+), 9 deletions(-)
Documentation/git-cherry-pick.txt +4 -0
@@ -138,6 +138,10 @@ effect to your index in a row. examine the commit. This option overrides that behavior and creates an empty commit object. Implies `--allow-empty`. +--skip-empty:: + This option causes empty and redundant cherry-picked commits to + be skipped without requesting the user intervention. + --strategy=<strategy>:: Use the given merge strategy. Should only be used once. See the MERGE STRATEGIES section in linkgit:git-merge[1]
builtin/revert.c +1 -0
@@ -102,6 +102,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)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 ,"skip-empty" , &opts->skip_empty,N_ ("skip redundant, empty commits" )),OPT_END (), }; options =parse_options_concat (options, cp_extra);
sequencer.c +36 -9
107 lines not on this page · raw message
sequencer.h +1 -0
@@ -23,6 +23,7 @@ struct replay_opts {int allow_empty;int allow_empty_message;int keep_redundant_commits; +int skip_empty;int mainline;
Signature · 1 line
2.11.0.616.gd72966cf44.dirty
PATCH 1/5 sequencer: sort options load/save by struct position
In reply to Giuseppe BilottaNo functional change. The order in which options are serialized and reloaded is now the same in which they appear in the replay_opts structure. This makes it easier to spot when we forget to serialize/reload an option value.
--- sequencer.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
sequencer.c +12 -12
@@ -975,22 +975,22 @@ static int populate_opts_cb(const char *key, const char *value, void *data)if (!value) error_flag =0 ; -else if (!strcmp (key,"options.no-commit" )) - opts->no_commit =git_config_bool_or_int (key, value, &error_flag);else if (!strcmp (key,"options.edit" )) opts->edit =git_config_bool_or_int (key, value, &error_flag); -else if (!strcmp (key,"options.signoff" )) - opts->signoff =git_config_bool_or_int (key, value, &error_flag);else if (!strcmp (key,"options.record-origin" )) opts->record_origin =git_config_bool_or_int (key, value, &error_flag); +else if (!strcmp (key,"options.no-commit" )) + opts->no_commit =git_config_bool_or_int (key, value, &error_flag); +else if (!strcmp (key,"options.signoff" )) + opts->signoff =git_config_bool_or_int (key, value, &error_flag);else if (!strcmp (key,"options.allow-ff" )) opts->allow_ff =git_config_bool_or_int (key, value, &error_flag);else if (!strcmp (key,"options.mainline" )) opts->mainline =git_config_int (key, value); -else if (!strcmp (key,"options.strategy" )) -git_config_string_dup (&opts->strategy, key, value);else if (!strcmp (key,"options.gpg-sign" ))git_config_string_dup (&opts->gpg_sign, key, value); +else if (!strcmp (key,"options.strategy" )) +git_config_string_dup (&opts->strategy, key, value);else if (!strcmp (key,"options.strategy-option" )) {ALLOC_GROW (opts->xopts, opts->xopts_nr +1 , opts->xopts_alloc); opts->xopts[opts->xopts_nr++] =xstrdup (value);
@@ -1223,14 +1223,14 @@ static int save_opts(struct replay_opts *opts)const char *opts_file =git_path_opts_file ();int res =0 ; -if (opts->no_commit) - res |=git_config_set_in_file_gently (opts_file,"options.no-commit" ,"true" );if (opts->edit) res |=git_config_set_in_file_gently (opts_file,"options.edit" ,"true" ); -if (opts->signoff) - res |=git_config_set_in_file_gently (opts_file,"options.signoff" ,"true" );if (opts->record_origin) res |=git_config_set_in_file_gently (opts_file,"options.record-origin" ,"true" ); +if (opts->no_commit) + res |=git_config_set_in_file_gently (opts_file,"options.no-commit" ,"true" ); +if (opts->signoff) + res |=git_config_set_in_file_gently (opts_file,"options.signoff" ,"true" );if (opts->allow_ff) res |=git_config_set_in_file_gently (opts_file,"options.allow-ff" ,"true" );if (opts->mainline) {
@@ -1239,10 +1239,10 @@ static int save_opts(struct replay_opts *opts) res |=git_config_set_in_file_gently (opts_file,"options.mainline" , buf.buf);strbuf_release (&buf); } +if (opts->gpg_sign) + res |=git_config_set_in_file_gently (opts_file,"options.gpg-sign" , opts->gpg_sign);if (opts->strategy) res |=git_config_set_in_file_gently (opts_file,"options.strategy" , opts->strategy); -if (opts->gpg_sign) - res |=git_config_set_in_file_gently (opts_file,"options.gpg-sign" , opts->gpg_sign);if (opts->xopts) {int i;for (i =0 ; i < opts->xopts_nr; i++)
Signature · 1 line
2.11.0.616.gd72966cf44.dirty
PATCH 4/5 cherry-pick: allow skipping only redundant commits
In reply to Giuseppe BilottaThis allows the preservation of originally empty commits with the combination of flags --allow-empty --skip-redundant-commits.
--- Documentation/git-cherry-pick.txt | 8 ++++- builtin/revert.c | 18 +++++++++++- sequencer.c | 62 ++++++++++++++++++++++++++++++--------- sequencer.h | 1 + 4 files changed, 73 insertions(+), 16 deletions(-)
Documentation/git-cherry-pick.txt +7 -1
@@ -138,9 +138,15 @@ effect to your index in a row. examine the commit. This option overrides that behavior and creates an empty commit object. Implies `--allow-empty`. +--skip-redundant-commits:: + Redundant commits will be skipped altogether. This does not + influence commits that were originally empty (see + `--allow-empty` and `--skip-empty`). + --skip-empty:: This option causes empty and redundant cherry-picked commits to - be skipped without requesting the user intervention. + be skipped without requesting the user intervention. Implies + `--skip-redundant-commits`. --strategy=<strategy>:: Use the given merge strategy. Should only be used once.
builtin/revert.c +17 -1
@@ -102,7 +102,8 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)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 ,"skip-empty" , &opts->skip_empty,N_ ("skip redundant, empty commits" )), +OPT_BOOL (0 ,"skip-empty" , &opts->skip_empty,N_ ("skip both redundant and initially empty commits" )), +OPT_BOOL (0 ,"skip-redundant-commits" , &opts->skip_redundant_commits,N_ ("skip redundant commits" )),OPT_END (), }; options =parse_options_concat (options, cp_extra);
@@ -115,6 +116,9 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)/* implies allow_empty */ if (opts->keep_redundant_commits) opts->allow_empty =1 ; +/* implies skip_redundant_commits */ +if (opts->skip_empty) + opts->skip_redundant_commits =1 ;/* Check for incompatible command line arguments */ if (cmd) {
@@ -147,6 +151,18 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)"--edit" , opts->edit, NULL); +if (opts->keep_redundant_commits) +verify_opt_compatible (me,"--keep-redundant-commits" , +"--skip-empty" , opts->skip_empty, +"--skip-redundant-commits" , opts->skip_redundant_commits, +NULL ); + +if (opts->keep_redundant_commits) +verify_opt_compatible (me,"--skip-empty" , +"--allow-empty" , opts->allow_empty, +"--keep-redundant-commits" , opts->keep_redundant_commits, +NULL ); +if (cmd) { opts->revs =NULL ; }else {
sequencer.c +48 -14
100 lines not on this page · raw message
sequencer.h +1 -0
@@ -24,6 +24,7 @@ struct replay_opts {int allow_empty_message;int keep_redundant_commits;int skip_empty; +int skip_redundant_commits;;int mainline;
Signature · 1 line
2.11.0.616.gd72966cf44.dirty
PATCH 2/5 sequencer: save/load all options
In reply to Giuseppe BilottaAdd the missing replay_opts to save_opts and populate_opts, so that an interrupted cherry-pick will continue with the same setup it had before the interruption.
--- sequencer.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
sequencer.c +16 -0
@@ -985,6 +985,14 @@ static int populate_opts_cb(const char *key, const char *value, void *data) opts->signoff =git_config_bool_or_int (key, value, &error_flag); else if (!strcmp(key, "options.allow-ff")) opts->allow_ff =git_config_bool_or_int (key, value, &error_flag); + else if (!strcmp(key, "options.rerere-autoupdate")) + opts->allow_rerere_auto =git_config_bool_or_int (key, value, &error_flag); + else if (!strcmp(key, "options.allow-empty")) + opts->allow_empty =git_config_bool_or_int (key, value, &error_flag); + else if (!strcmp(key, "options.allow-empty-message")) + opts->allow_empty_message =git_config_bool_or_int (key, value, &error_flag); + else if (!strcmp(key, "options.keep-redundant-commits")) + opts->keep_redundant_commits =git_config_bool_or_int (key, value, &error_flag); else if (!strcmp(key, "options.mainline")) opts->mainline =git_config_int (key, value); else if (!strcmp(key, "options.gpg-sign"))
@@ -1233,6 +1241,14 @@ static int save_opts(struct replay_opts *opts) res |=git_config_set_in_file_gently (opts_file,"options.signoff" ,"true" );if (opts->allow_ff) res |=git_config_set_in_file_gently (opts_file,"options.allow-ff" ,"true" ); +if (opts->allow_rerere_auto) + res |=git_config_set_in_file_gently (opts_file,"options.rerere-autoupdate" ,"true" ); +if (opts->allow_empty) + res |=git_config_set_in_file_gently (opts_file,"options.allow-empty" ,"true" ); +if (opts->allow_empty_message) + res |=git_config_set_in_file_gently (opts_file,"options.allow-empty-message" ,"true" ); +if (opts->keep_redundant_commits) + res |=git_config_set_in_file_gently (opts_file,"options.keep-redundant-commits" ,"true" );if (opts->mainline) {struct strbuf buf =STRBUF_INIT ;strbuf_addf (&buf,"%d" , opts->mainline);
Signature · 1 line
2.11.0.616.gd72966cf44.dirty