From c913c5964c3a7b5158a76c02721acbd0df6e2b40 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 11 Dec 2018 08:11:32 -0800 Subject: rebase: make builtin and legacy script error messages the same The conversion of the script version of rebase took messages that were prefixed with "error:" and passed them along to die(), which adds a "fatal:" prefix, thus resulting in messages of the form: fatal: error: cannot combine... which seems redundant. Remove the "error:" prefix from the builtin version of rebase, and change the prefix from "error:" to "fatal:" in the legacy script to match. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano diff --git a/builtin/rebase.c b/builtin/rebase.c index b5c99ec..85f980b 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1223,12 +1223,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) break; if (is_interactive(&options) && i >= 0) - die(_("error: cannot combine interactive options " + die(_("cannot combine interactive options " "(--interactive, --exec, --rebase-merges, " "--preserve-merges, --keep-empty, --root + " "--onto) with am options (%s)"), buf.buf); if (options.type == REBASE_MERGE && i >= 0) - die(_("error: cannot combine merge options (--merge, " + die(_("cannot combine merge options (--merge, " "--strategy, --strategy-option) with am options " "(%s)"), buf.buf); } @@ -1248,15 +1248,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) * git-rebase.txt caveats with "unless you know what you are doing" */ if (options.rebase_merges) - die(_("error: cannot combine '--preserve-merges' with " + die(_("cannot combine '--preserve-merges' with " "'--rebase-merges'")); if (options.rebase_merges) { if (strategy_options.nr) - die(_("error: cannot combine '--rebase-merges' with " + die(_("cannot combine '--rebase-merges' with " "'--strategy-option'")); if (options.strategy) - die(_("error: cannot combine '--rebase-merges' with " + die(_("cannot combine '--rebase-merges' with " "'--strategy'")); } diff --git a/git-legacy-rebase.sh b/git-legacy-rebase.sh index b4c7dbf..11548e9 100755 --- a/git-legacy-rebase.sh +++ b/git-legacy-rebase.sh @@ -508,13 +508,13 @@ if test -n "$git_am_opt"; then then if test -n "$incompatible_opts" then - die "$(gettext "error: cannot combine interactive options (--interactive, --exec, --rebase-merges, --preserve-merges, --keep-empty, --root + --onto) with am options ($incompatible_opts)")" + die "$(gettext "fatal: cannot combine interactive options (--interactive, --exec, --rebase-merges, --preserve-merges, --keep-empty, --root + --onto) with am options ($incompatible_opts)")" fi fi if test -n "$do_merge"; then if test -n "$incompatible_opts" then - die "$(gettext "error: cannot combine merge options (--merge, --strategy, --strategy-option) with am options ($incompatible_opts)")" + die "$(gettext "fatal: cannot combine merge options (--merge, --strategy, --strategy-option) with am options ($incompatible_opts)")" fi fi fi @@ -522,7 +522,7 @@ fi if test -n "$signoff" then test -n "$preserve_merges" && - die "$(gettext "error: cannot combine '--signoff' with '--preserve-merges'")" + die "$(gettext "fatal: cannot combine '--signoff' with '--preserve-merges'")" git_am_opt="$git_am_opt $signoff" force_rebase=t fi @@ -533,15 +533,15 @@ then # Note: incompatibility with --interactive is just a strong warning; # git-rebase.txt caveats with "unless you know what you are doing" test -n "$rebase_merges" && - die "$(gettext "error: cannot combine '--preserve-merges' with '--rebase-merges'")" + die "$(gettext "fatal: cannot combine '--preserve-merges' with '--rebase-merges'")" fi if test -n "$rebase_merges" then test -n "$strategy_opts" && - die "$(gettext "error: cannot combine '--rebase-merges' with '--strategy-option'")" + die "$(gettext "fatal: cannot combine '--rebase-merges' with '--strategy-option'")" test -n "$strategy" && - die "$(gettext "error: cannot combine '--rebase-merges' with '--strategy'")" + die "$(gettext "fatal: cannot combine '--rebase-merges' with '--strategy'")" fi if test -z "$rebase_root" -- cgit v0.10.2-6-g49f6 From 72ee67319f703201631b33697291720afd4e1d66 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 11 Dec 2018 08:11:33 -0800 Subject: rebase: fix incompatible options error message In commit f57696802c30 ("rebase: really just passthru the `git am` options", 2018-11-14), the handling of `git am` options was simplified dramatically (and an option parsing bug was fixed), but it introduced a small regression in the error message shown when options only understood by separate backends were used: $ git rebase --keep --ignore-whitespace fatal: cannot combine interactive options (--interactive, --exec, --rebase-merges, --preserve-merges, --keep-empty, --root + --onto) with am options (.git/rebase-apply/applying) $ git rebase --merge --ignore-whitespace fatal: cannot combine merge options (--merge, --strategy, --strategy-option) with am options (.git/rebase-apply/applying) Note that in both cases, the list of "am options" is ".git/rebase-apply/applying", which makes no sense. Since the lists of backend-specific options is documented pretty thoroughly in the rebase man page (in the "Incompatible Options" section, with multiple links throughout the document), and since I expect this list to change over time, just simplify the error message. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano diff --git a/builtin/rebase.c b/builtin/rebase.c index 85f980b..78e9822 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1223,14 +1223,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) break; if (is_interactive(&options) && i >= 0) - die(_("cannot combine interactive options " - "(--interactive, --exec, --rebase-merges, " - "--preserve-merges, --keep-empty, --root + " - "--onto) with am options (%s)"), buf.buf); + die(_("cannot combine am options " + "with interactive options")); if (options.type == REBASE_MERGE && i >= 0) - die(_("cannot combine merge options (--merge, " - "--strategy, --strategy-option) with am options " - "(%s)"), buf.buf); + die(_("cannot combine am options with merge options ")); } if (options.signoff) { diff --git a/git-legacy-rebase.sh b/git-legacy-rebase.sh index 11548e9..fccb33b 100755 --- a/git-legacy-rebase.sh +++ b/git-legacy-rebase.sh @@ -508,13 +508,13 @@ if test -n "$git_am_opt"; then then if test -n "$incompatible_opts" then - die "$(gettext "fatal: cannot combine interactive options (--interactive, --exec, --rebase-merges, --preserve-merges, --keep-empty, --root + --onto) with am options ($incompatible_opts)")" + die "$(gettext "fatal: cannot combine am options with interactive options")" fi fi if test -n "$do_merge"; then if test -n "$incompatible_opts" then - die "$(gettext "fatal: cannot combine merge options (--merge, --strategy, --strategy-option) with am options ($incompatible_opts)")" + die "$(gettext "fatal: cannot combine am options with merge options")" fi fi fi -- cgit v0.10.2-6-g49f6 From 5400677903bdb852e0ca89e41e009afb8a1b6239 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 11 Dec 2018 08:11:34 -0800 Subject: t5407: add a test demonstrating how interactive handles --skip differently The post-rewrite hook is documented as being invoked by commands that rewrite commits such as commit --amend and rebase, and that it will be called for each rewritten commit. Apparently, the three backends handled --skip'ed commits differently: am: treat the skipped commit as though it weren't rewritten merge: same as 'am' backend interactive: treat skipped commits as having been rewritten to empty (view them as an empty fixup to their parent) For now, just add a testcase documenting the different behavior (use --keep to force usage of the interactive machinery even though we have no empty commits). A subsequent commit will remove the inconsistency in --skip handling. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh index 9b2a274..6426ec8 100755 --- a/t/t5407-post-rewrite-hook.sh +++ b/t/t5407-post-rewrite-hook.sh @@ -125,6 +125,37 @@ test_expect_success 'git rebase -m --skip' ' verify_hook_input ' +test_expect_success 'git rebase with implicit use of interactive backend' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --keep --onto A B && + echo C > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<-EOF && + $(git rev-parse C) $(git rev-parse HEAD^) + $(git rev-parse D) $(git rev-parse HEAD) + EOF + verify_hook_input +' + +test_expect_success 'git rebase --skip with implicit use of interactive backend' ' + git reset --hard D && + clear_hook_input && + test_must_fail git rebase --keep --onto A B && + test_must_fail git rebase --skip && + echo D > foo && + git add foo && + git rebase --continue && + echo rebase >expected.args && + cat >expected.data <<-EOF && + $(git rev-parse C) $(git rev-parse HEAD^) + $(git rev-parse D) $(git rev-parse HEAD) + EOF + verify_hook_input +' + . "$TEST_DIRECTORY"/lib-rebase.sh set_fake_editor -- cgit v0.10.2-6-g49f6 From 45339f74ef87123ab79831310bf8047cebe5177b Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 11 Dec 2018 08:11:35 -0800 Subject: am, rebase--merge: do not overlook --skip'ed commits with post-rewrite The post-rewrite hook is supposed to be invoked for each rewritten commit. The fact that a commit was selected and processed by the rebase operation (even though when we hit an error a user said it had no more useful changes), suggests we should write an entry for it. In particular, let's treat it as an empty commit trivially squashed into its parent. This brings the rebase--am and rebase--merge backends in sync with the behavior of the interactive rebase backend. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano diff --git a/builtin/am.c b/builtin/am.c index 8f27f33..af9d034 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -2000,6 +2000,15 @@ static void am_skip(struct am_state *state) if (clean_index(&head, &head)) die(_("failed to clean index")); + if (state->rebasing) { + FILE *fp = xfopen(am_path(state, "rewritten"), "a"); + + assert(!is_null_oid(&state->orig_commit)); + fprintf(fp, "%s ", oid_to_hex(&state->orig_commit)); + fprintf(fp, "%s\n", oid_to_hex(&head)); + fclose(fp); + } + am_next(state); am_load(state); am_run(state, 0); diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh index aa2f2f0..91250cb 100644 --- a/git-rebase--merge.sh +++ b/git-rebase--merge.sh @@ -121,6 +121,8 @@ continue) skip) read_state git rerere clear + cmt="$(cat "$state_dir/cmt.$msgnum")" + echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten" msgnum=$(($msgnum + 1)) while test "$msgnum" -le "$end" do diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh index 6426ec8..a4a5903 100755 --- a/t/t5407-post-rewrite-hook.sh +++ b/t/t5407-post-rewrite-hook.sh @@ -78,6 +78,7 @@ test_expect_success 'git rebase --skip' ' git rebase --continue && echo rebase >expected.args && cat >expected.data <<-EOF && + $(git rev-parse C) $(git rev-parse HEAD^) $(git rev-parse D) $(git rev-parse HEAD) EOF verify_hook_input @@ -91,6 +92,7 @@ test_expect_success 'git rebase --skip the last one' ' echo rebase >expected.args && cat >expected.data <<-EOF && $(git rev-parse E) $(git rev-parse HEAD) + $(git rev-parse F) $(git rev-parse HEAD) EOF verify_hook_input ' @@ -120,6 +122,7 @@ test_expect_success 'git rebase -m --skip' ' git rebase --continue && echo rebase >expected.args && cat >expected.data <<-EOF && + $(git rev-parse C) $(git rev-parse HEAD^) $(git rev-parse D) $(git rev-parse HEAD) EOF verify_hook_input -- cgit v0.10.2-6-g49f6 From 899b49c446fa645419676899c9409e2975a5dd26 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 11 Dec 2018 08:11:36 -0800 Subject: git-rebase, sequencer: extend --quiet option for the interactive machinery While 'quiet' and 'interactive' may sound like antonyms, the interactive machinery actually has logic that implements several interactive_rebase=implied cases (--exec, --keep-empty, --rebase-merges) which won't pop up an editor. The rewrite of interactive rebase in C added a quiet option, though it only turns stats off. Since we want to make the interactive machinery also take over for git-rebase--merge, it should fully implement the --quiet option. git-rebase--interactive was already somewhat quieter than git-rebase--merge and git-rebase--am, possibly because cherry-pick has just traditionally been quieter. As such, we only drop a few informational messages -- "Rebasing (n/m)" and "Successfully rebased..." Also, for simplicity, remove the differences in how quiet and verbose options were recorded. Having one be signalled by the presence of a "verbose" file in the state_dir, while the other was signalled by the contents of a "quiet" file was just weirdly inconsistent. (This inconsistency pre-dated the rewrite into C.) Make them consistent by having them both key off the presence of the file. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano diff --git a/builtin/rebase.c b/builtin/rebase.c index 78e9822..ec2e5fb 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -185,10 +185,7 @@ static int read_basic_state(struct rebase_options *opts) if (get_oid(buf.buf, &opts->orig_head)) return error(_("invalid orig-head: '%s'"), buf.buf); - strbuf_reset(&buf); - if (read_one(state_dir_path("quiet", opts), &buf)) - return -1; - if (buf.len) + if (file_exists(state_dir_path("quiet", opts))) opts->flags &= ~REBASE_NO_QUIET; else opts->flags |= REBASE_NO_QUIET; diff --git a/git-legacy-rebase.sh b/git-legacy-rebase.sh index fccb33b..f4088b7 100755 --- a/git-legacy-rebase.sh +++ b/git-legacy-rebase.sh @@ -113,7 +113,7 @@ read_basic_state () { else orig_head=$(cat "$state_dir"/head) fi && - GIT_QUIET=$(cat "$state_dir"/quiet) && + test -f "$state_dir"/quiet && GIT_QUIET=t test -f "$state_dir"/verbose && verbose=t test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)" test -f "$state_dir"/strategy_opts && diff --git a/git-rebase--common.sh b/git-rebase--common.sh index 7e39d22..dc18c68 100644 --- a/git-rebase--common.sh +++ b/git-rebase--common.sh @@ -10,7 +10,7 @@ write_basic_state () { echo "$head_name" > "$state_dir"/head-name && echo "$onto" > "$state_dir"/onto && echo "$orig_head" > "$state_dir"/orig-head && - echo "$GIT_QUIET" > "$state_dir"/quiet && + test t = "$GIT_QUIET" && : > "$state_dir"/quiet test t = "$verbose" && : > "$state_dir"/verbose test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy test -n "$strategy_opts" && echo "$strategy_opts" > \ diff --git a/sequencer.c b/sequencer.c index e1a4dd1..bc25615 100644 --- a/sequencer.c +++ b/sequencer.c @@ -150,6 +150,7 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete") static GIT_PATH_FUNC(rebase_path_gpg_sign_opt, "rebase-merge/gpg_sign_opt") static GIT_PATH_FUNC(rebase_path_orig_head, "rebase-merge/orig-head") static GIT_PATH_FUNC(rebase_path_verbose, "rebase-merge/verbose") +static GIT_PATH_FUNC(rebase_path_quiet, "rebase-merge/quiet") static GIT_PATH_FUNC(rebase_path_signoff, "rebase-merge/signoff") static GIT_PATH_FUNC(rebase_path_head_name, "rebase-merge/head-name") static GIT_PATH_FUNC(rebase_path_onto, "rebase-merge/onto") @@ -157,7 +158,6 @@ static GIT_PATH_FUNC(rebase_path_autostash, "rebase-merge/autostash") static GIT_PATH_FUNC(rebase_path_strategy, "rebase-merge/strategy") static GIT_PATH_FUNC(rebase_path_strategy_opts, "rebase-merge/strategy_opts") static GIT_PATH_FUNC(rebase_path_allow_rerere_autoupdate, "rebase-merge/allow_rerere_autoupdate") -static GIT_PATH_FUNC(rebase_path_quiet, "rebase-merge/quiet") static int git_sequencer_config(const char *k, const char *v, void *cb) { @@ -2357,6 +2357,9 @@ static int read_populate_opts(struct replay_opts *opts) if (file_exists(rebase_path_verbose())) opts->verbose = 1; + if (file_exists(rebase_path_quiet())) + opts->quiet = 1; + if (file_exists(rebase_path_signoff())) { opts->allow_ff = 0; opts->signoff = 1; @@ -2424,9 +2427,6 @@ int write_basic_state(struct replay_opts *opts, const char *head_name, if (quiet) write_file(rebase_path_quiet(), "%s\n", quiet); - else - write_file(rebase_path_quiet(), "\n"); - if (opts->verbose) write_file(rebase_path_verbose(), "%s", ""); if (opts->strategy) @@ -3503,10 +3503,11 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) fprintf(f, "%d\n", todo_list->done_nr); fclose(f); } - fprintf(stderr, "Rebasing (%d/%d)%s", - todo_list->done_nr, - todo_list->total_nr, - opts->verbose ? "\n" : "\r"); + if (!opts->quiet) + fprintf(stderr, "Rebasing (%d/%d)%s", + todo_list->done_nr, + todo_list->total_nr, + opts->verbose ? "\n" : "\r"); } unlink(rebase_path_message()); unlink(rebase_path_author_script()); @@ -3738,8 +3739,10 @@ cleanup_head_ref: } apply_autostash(opts); - fprintf(stderr, "Successfully rebased and updated %s.\n", - head_ref.buf); + if (!opts->quiet) + fprintf(stderr, + "Successfully rebased and updated %s.\n", + head_ref.buf); strbuf_release(&buf); strbuf_release(&head_ref); diff --git a/sequencer.h b/sequencer.h index 5071a73..729222b 100644 --- a/sequencer.h +++ b/sequencer.h @@ -39,6 +39,7 @@ struct replay_opts { int allow_empty_message; int keep_redundant_commits; int verbose; + int quiet; int mainline; -- cgit v0.10.2-6-g49f6 From 7b76ac664cbe68c64bf79bd37e8b5d5fe690ba29 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 11 Dec 2018 08:11:37 -0800 Subject: git-legacy-rebase: simplify unnecessary triply-nested if The git-legacy-rebase.sh script previously had code of the form: if git_am_opt: if interactive: if incompatible_opts: show_error_about_interactive_and_am_incompatibilities if rebase-merge: if incompatible_opts show_error_about_merge_and_am_incompatibilities which was a triply nested if. However, the first conditional (git_am_opt) and third (incompatible_opts) were somewhat redundant: the latter condition was a strict subset of the former. Simplify this by moving the innermost conditional to the outside, allowing us to remove the test on git_am_opt entirely and giving us the following form: if incompatible_opts: if interactive: show_error_about_interactive_and_am_incompatibilities if rebase-merge: show_error_about_merge_and_am_incompatibilities Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano diff --git a/git-legacy-rebase.sh b/git-legacy-rebase.sh index f4088b7..6baf101 100755 --- a/git-legacy-rebase.sh +++ b/git-legacy-rebase.sh @@ -501,21 +501,17 @@ then git_format_patch_opt="$git_format_patch_opt --progress" fi -if test -n "$git_am_opt"; then - incompatible_opts=$(echo " $git_am_opt " | \ - sed -e 's/ -q / /g' -e 's/^ \(.*\) $/\1/') +incompatible_opts=$(echo " $git_am_opt " | \ + sed -e 's/ -q / /g' -e 's/^ \(.*\) $/\1/') +if test -n "$incompatible_opts" +then if test -n "$interactive_rebase" then - if test -n "$incompatible_opts" - then - die "$(gettext "fatal: cannot combine am options with interactive options")" - fi + die "$(gettext "fatal: cannot combine am options with interactive options")" fi - if test -n "$do_merge"; then - if test -n "$incompatible_opts" - then - die "$(gettext "fatal: cannot combine am options with merge options")" - fi + if test -n "$do_merge" + then + die "$(gettext "fatal: cannot combine am options with merge options")" fi fi -- cgit v0.10.2-6-g49f6 From c91c944a068e12eca5d4b6040ad05c7068437111 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 11 Dec 2018 08:11:38 -0800 Subject: rebase: define linearization ordering and enforce it Ever since commit 3f213981e44a ("add tests for rebasing merged history", 2013-06-06), t3425 has had tests which included the rebasing of merged history and whose order of applied commits was checked. Unfortunately, the tests expected different behavior depending on which backend was in use. Implementing these checks was the following four lines (including the TODO message) which were repeated verbatim three times in t3425: #TODO: make order consistent across all flavors of rebase test_run_rebase success 'e n o' '' test_run_rebase success 'e n o' -m test_run_rebase success 'n o e' -i As part of the effort to reduce differences between the rebase backends so that users get more uniform behavior, let's define the correct behavior and modify the different backends so they all get the right answer. It turns out that the difference in behavior here is entirely due to topological sorting; since some backends require topological sorting (particularly when --rebase-merges is specified), require it for all modes. Modify the am and merge backends to implement this. Performance Considerations: I was unable to measure any appreciable performance difference with this change. Trying to control the run-to-run variation was difficult; I eventually found a headless beefy box that I could ssh into, which seemed to help. Using git.git, I ran the following testcase: $ git reset --hard v2.20.0-rc1~2 $ time git rebase --quiet v2.20.0-rc0~16 I first ran once to warm any disk caches, then ran five subsequent runs and recorded the times of those five. I observed the following results for the average time: Before this change: "real" timing: 1.340s (standard deviation: 0.040s) "user" timing: 1.050s (standard deviation: 0.041s) "sys" timing: 0.270s (standard deviation: 0.011s) After this change: "real" timing: 1.327s (standard deviation: 0.065s) "user" timing: 1.031s (standard deviation: 0.061s) "sys" timing: 0.280s (standard deviation: 0.014s) Measurements aside, I would expect the timing for walking revisions to be dwarfed by the work involved in creating and applying patches, so this isn't too surprising. Further, while somewhat counter-intuitive, it is possible that turning on topological sorting is actually a performance improvement: by way of comparison, turning on --topo-order made fast-export faster (see https://public-inbox.org/git/20090211135640.GA19600@coredump.intra.peff.net/). Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano diff --git a/git-rebase--am.sh b/git-rebase--am.sh index 99b8c17..6416716 100644 --- a/git-rebase--am.sh +++ b/git-rebase--am.sh @@ -36,7 +36,7 @@ rm -f "$GIT_DIR/rebased-patches" git format-patch -k --stdout --full-index --cherry-pick --right-only \ --src-prefix=a/ --dst-prefix=b/ --no-renames --no-cover-letter \ - --pretty=mboxrd \ + --pretty=mboxrd --topo-order \ $git_format_patch_opt \ "$revisions" ${restrict_revision+^$restrict_revision} \ >"$GIT_DIR/rebased-patches" diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh index 91250cb..ced38bb 100644 --- a/git-rebase--merge.sh +++ b/git-rebase--merge.sh @@ -143,7 +143,7 @@ write_basic_state rm -f "$(git rev-parse --git-path REBASE_HEAD)" msgnum=0 -for cmt in $(git rev-list --reverse --no-merges "$revisions") +for cmt in $(git rev-list --topo-order --reverse --no-merges "$revisions") do msgnum=$(($msgnum + 1)) echo "$cmt" > "$state_dir/cmt.$msgnum" diff --git a/t/t3425-rebase-topology-merges.sh b/t/t3425-rebase-topology-merges.sh index 5f892e3..fd8efe8 100755 --- a/t/t3425-rebase-topology-merges.sh +++ b/t/t3425-rebase-topology-merges.sh @@ -70,9 +70,8 @@ test_run_rebase () { test_linear_range "\'"$expected"\'" d.. " } -#TODO: make order consistent across all flavors of rebase -test_run_rebase success 'e n o' '' -test_run_rebase success 'e n o' -m +test_run_rebase success 'n o e' '' +test_run_rebase success 'n o e' -m test_run_rebase success 'n o e' -i test_run_rebase () { @@ -87,9 +86,8 @@ test_run_rebase () { test_linear_range "\'"$expected"\'" c.. " } -#TODO: make order consistent across all flavors of rebase -test_run_rebase success 'd e n o' '' -test_run_rebase success 'd e n o' -m +test_run_rebase success 'd n o e' '' +test_run_rebase success 'd n o e' -m test_run_rebase success 'd n o e' -i test_run_rebase () { @@ -104,9 +102,8 @@ test_run_rebase () { test_linear_range "\'"$expected"\'" c.. " } -#TODO: make order consistent across all flavors of rebase -test_run_rebase success 'd e n o' '' -test_run_rebase success 'd e n o' -m +test_run_rebase success 'd n o e' '' +test_run_rebase success 'd n o e' -m test_run_rebase success 'd n o e' -i if ! test_have_prereq REBASE_P; then -- cgit v0.10.2-6-g49f6 From 68aa495b590d417e88562ab1e5da7d84d0531f21 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 11 Dec 2018 08:11:39 -0800 Subject: rebase: implement --merge via the interactive machinery As part of an ongoing effort to make rebase have more uniform behavior, modify the merge backend to behave like the interactive one, by re-implementing it on top of the latter. Interactive rebases are implemented in terms of cherry-pick rather than the merge-recursive builtin, but cherry-pick also calls into the recursive merge machinery by default and can accept special merge strategies and/or special strategy options. As such, there really is not any need for having both git-rebase--merge and git-rebase--interactive anymore. Delete git-rebase--merge.sh and instead implement it in builtin/rebase.c. This results in a few deliberate but small user-visible changes: * The progress output is modified (see t3406 and t3420 for examples) * A few known test failures are now fixed (see t3421) * bash-prompt during a rebase --merge is now REBASE-i instead of REBASE-m. Reason: The prompt is a reflection of the backend in use; this allows users to report an issue to the git mailing list with the appropriate backend information, and allows advanced users to know where to search for relevant control files. (see t9903) testcase modification notes: t3406: --interactive and --merge had slightly different progress output while running; adjust a test to match the new expectation t3420: these test precise output while running, but rebase--am, rebase--merge, and rebase--interactive all were built on very different commands (am, merge-recursive, cherry-pick), so the tests expected different output for each type. Now we expect --merge and --interactive to have the same output. t3421: --interactive fixes some bugs in --merge! Wahoo! t9903: --merge uses the interactive backend so the prompt expected is now REBASE-i. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano diff --git a/.gitignore b/.gitignore index 0d77ea5..910b1d2 100644 --- a/.gitignore +++ b/.gitignore @@ -124,7 +124,6 @@ /git-rebase--am /git-rebase--common /git-rebase--interactive -/git-rebase--merge /git-rebase--preserve-merges /git-receive-pack /git-reflog diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index dff17b3..8bfa36a 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -504,15 +504,7 @@ See also INCOMPATIBLE OPTIONS below. INCOMPATIBLE OPTIONS -------------------- -git-rebase has many flags that are incompatible with each other, -predominantly due to the fact that it has three different underlying -implementations: - - * one based on linkgit:git-am[1] (the default) - * one based on git-merge-recursive (merge backend) - * one based on linkgit:git-cherry-pick[1] (interactive backend) - -Flags only understood by the am backend: +The following options: * --committer-date-is-author-date * --ignore-date @@ -520,15 +512,12 @@ Flags only understood by the am backend: * --ignore-whitespace * -C -Flags understood by both merge and interactive backends: +are incompatible with the following options: * --merge * --strategy * --strategy-option * --allow-empty-message - -Flags only understood by the interactive backend: - * --[no-]autosquash * --rebase-merges * --preserve-merges @@ -539,7 +528,7 @@ Flags only understood by the interactive backend: * --edit-todo * --root when used in combination with --onto -Other incompatible flag pairs: +In addition, the following pairs of options are incompatible: * --preserve-merges and --interactive * --preserve-merges and --signoff diff --git a/Makefile b/Makefile index 1a44c81..82e1eb1 100644 --- a/Makefile +++ b/Makefile @@ -628,7 +628,6 @@ SCRIPT_LIB += git-parse-remote SCRIPT_LIB += git-rebase--am SCRIPT_LIB += git-rebase--common SCRIPT_LIB += git-rebase--preserve-merges -SCRIPT_LIB += git-rebase--merge SCRIPT_LIB += git-sh-setup SCRIPT_LIB += git-sh-i18n diff --git a/builtin/rebase.c b/builtin/rebase.c index ec2e5fb..d95843a 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -122,7 +122,7 @@ static void imply_interactive(struct rebase_options *opts, const char *option) case REBASE_PRESERVE_MERGES: break; case REBASE_MERGE: - /* we silently *upgrade* --merge to --interactive if needed */ + /* we now implement --merge via --interactive */ default: opts->type = REBASE_INTERACTIVE; /* implied */ break; @@ -481,10 +481,6 @@ static int run_specific_rebase(struct rebase_options *opts) backend = "git-rebase--am"; backend_func = "git_rebase__am"; break; - case REBASE_MERGE: - backend = "git-rebase--merge"; - backend_func = "git_rebase__merge"; - break; case REBASE_PRESERVE_MERGES: backend = "git-rebase--preserve-merges"; backend_func = "git_rebase__preserve_merges"; @@ -1191,6 +1187,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } } + if (options.type == REBASE_MERGE) + imply_interactive(&options, "--merge"); + if (options.root && !options.onto_name) imply_interactive(&options, "--root without --onto"); @@ -1220,10 +1219,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) break; if (is_interactive(&options) && i >= 0) - die(_("cannot combine am options " - "with interactive options")); - if (options.type == REBASE_MERGE && i >= 0) - die(_("cannot combine am options with merge options ")); + die(_("cannot combine am options with either " + "interactive or merge options")); } if (options.signoff) { diff --git a/git-legacy-rebase.sh b/git-legacy-rebase.sh index 6baf101..0c9c19b 100755 --- a/git-legacy-rebase.sh +++ b/git-legacy-rebase.sh @@ -218,6 +218,7 @@ then state_dir="$apply_dir" elif test -d "$merge_dir" then + type=interactive if test -d "$merge_dir"/rewritten then type=preserve-merges @@ -225,10 +226,7 @@ then preserve_merges=t elif test -f "$merge_dir"/interactive then - type=interactive interactive_rebase=explicit - else - type=merge fi state_dir="$merge_dir" fi @@ -477,6 +475,7 @@ then test -z "$interactive_rebase" && interactive_rebase=implied fi +actually_interactive= if test -n "$interactive_rebase" then if test -z "$preserve_merges" @@ -485,11 +484,12 @@ then else type=preserve-merges fi - + actually_interactive=t state_dir="$merge_dir" elif test -n "$do_merge" then - type=merge + interactive_rebase=implied + type=interactive state_dir="$merge_dir" else type=am @@ -505,13 +505,9 @@ incompatible_opts=$(echo " $git_am_opt " | \ sed -e 's/ -q / /g' -e 's/^ \(.*\) $/\1/') if test -n "$incompatible_opts" then - if test -n "$interactive_rebase" - then - die "$(gettext "fatal: cannot combine am options with interactive options")" - fi - if test -n "$do_merge" + if test -n "$actually_interactive" || test "$do_merge" then - die "$(gettext "fatal: cannot combine am options with merge options")" + die "$(gettext "fatal: cannot combine am options with either interactive or merge options")" fi fi @@ -676,7 +672,7 @@ require_clean_work_tree "rebase" "$(gettext "Please commit or stash them.")" # but this should be done only when upstream and onto are the same # and if this is not an interactive rebase. mb=$(git merge-base "$onto" "$orig_head") -if test -z "$interactive_rebase" && test "$upstream" = "$onto" && +if test -z "$actually_interactive" && test "$upstream" = "$onto" && test "$mb" = "$onto" && test -z "$restrict_revision" && # linear history? ! (git rev-list --parents "$onto".."$orig_head" | sane_grep " .* ") > /dev/null @@ -726,6 +722,19 @@ then GIT_PAGER='' git diff --stat --summary "$mb_tree" "$onto" fi +if test -z "$actually_interactive" && test "$mb" = "$orig_head" +then + say "$(eval_gettext "Fast-forwarded \$branch_name to \$onto_name.")" + GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" \ + git checkout -q "$onto^0" || die "could not detach HEAD" + # If the $onto is a proper descendant of the tip of the branch, then + # we just fast-forwarded. + git update-ref ORIG_HEAD $orig_head + move_to_original_branch + finish_rebase + exit 0 +fi + test -n "$interactive_rebase" && run_specific_rebase # Detach HEAD and reset the tree @@ -735,16 +744,6 @@ GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" \ git checkout -q "$onto^0" || die "could not detach HEAD" git update-ref ORIG_HEAD $orig_head -# If the $onto is a proper descendant of the tip of the branch, then -# we just fast-forwarded. -if test "$mb" = "$orig_head" -then - say "$(eval_gettext "Fast-forwarded \$branch_name to \$onto_name.")" - move_to_original_branch - finish_rebase - exit 0 -fi - if test -n "$rebase_root" then revisions="$onto..$orig_head" diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh deleted file mode 100644 index ced38bb..0000000 --- a/git-rebase--merge.sh +++ /dev/null @@ -1,166 +0,0 @@ -# This shell script fragment is sourced by git-rebase to implement -# its merge-based non-interactive mode that copes well with renamed -# files. -# -# Copyright (c) 2010 Junio C Hamano. -# - -prec=4 - -read_state () { - onto_name=$(cat "$state_dir"/onto_name) && - end=$(cat "$state_dir"/end) && - msgnum=$(cat "$state_dir"/msgnum) -} - -continue_merge () { - test -d "$state_dir" || die "$state_dir directory does not exist" - - unmerged=$(git ls-files -u) - if test -n "$unmerged" - then - echo "You still have unmerged paths in your index" - echo "did you forget to use git add?" - die "$resolvemsg" - fi - - cmt=$(cat "$state_dir/current") - if ! git diff-index --quiet --ignore-submodules HEAD -- - then - if ! git commit ${gpg_sign_opt:+"$gpg_sign_opt"} $signoff $allow_empty_message \ - --no-verify -C "$cmt" - then - echo "Commit failed, please do not call \"git commit\"" - echo "directly, but instead do one of the following: " - die "$resolvemsg" - fi - if test -z "$GIT_QUIET" - then - printf "Committed: %0${prec}d " $msgnum - fi - echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten" - else - if test -z "$GIT_QUIET" - then - printf "Already applied: %0${prec}d " $msgnum - fi - fi - test -z "$GIT_QUIET" && - GIT_PAGER='' git log --format=%s -1 "$cmt" - - # onto the next patch: - msgnum=$(($msgnum + 1)) - echo "$msgnum" >"$state_dir/msgnum" -} - -call_merge () { - msgnum="$1" - echo "$msgnum" >"$state_dir/msgnum" - cmt="$(cat "$state_dir/cmt.$msgnum")" - echo "$cmt" > "$state_dir/current" - git update-ref REBASE_HEAD "$cmt" - hd=$(git rev-parse --verify HEAD) - cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD) - eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"' - eval GITHEAD_$hd='$onto_name' - export GITHEAD_$cmt GITHEAD_$hd - if test -n "$GIT_QUIET" - then - GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY - fi - test -z "$strategy" && strategy=recursive - # If cmt doesn't have a parent, don't include it as a base - base=$(git rev-parse --verify --quiet $cmt^) - eval 'git merge-$strategy' $strategy_opts $base ' -- "$hd" "$cmt"' - rv=$? - case "$rv" in - 0) - unset GITHEAD_$cmt GITHEAD_$hd - return - ;; - 1) - git rerere $allow_rerere_autoupdate - die "$resolvemsg" - ;; - 2) - echo "Strategy: $strategy failed, try another" 1>&2 - die "$resolvemsg" - ;; - *) - die "Unknown exit code ($rv) from command:" \ - "git merge-$strategy $cmt^ -- HEAD $cmt" - ;; - esac -} - -finish_rb_merge () { - move_to_original_branch - if test -s "$state_dir"/rewritten - then - git notes copy --for-rewrite=rebase <"$state_dir"/rewritten - hook="$(git rev-parse --git-path hooks/post-rewrite)" - test -x "$hook" && "$hook" rebase <"$state_dir"/rewritten - fi - say All done. -} - -git_rebase__merge () { - -case "$action" in -continue) - read_state - continue_merge - while test "$msgnum" -le "$end" - do - call_merge "$msgnum" - continue_merge - done - finish_rb_merge - return - ;; -skip) - read_state - git rerere clear - cmt="$(cat "$state_dir/cmt.$msgnum")" - echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten" - msgnum=$(($msgnum + 1)) - while test "$msgnum" -le "$end" - do - call_merge "$msgnum" - continue_merge - done - finish_rb_merge - return - ;; -show-current-patch) - exec git show REBASE_HEAD -- - ;; -esac - -mkdir -p "$state_dir" -echo "$onto_name" > "$state_dir/onto_name" -write_basic_state -rm -f "$(git rev-parse --git-path REBASE_HEAD)" - -msgnum=0 -for cmt in $(git rev-list --topo-order --reverse --no-merges "$revisions") -do - msgnum=$(($msgnum + 1)) - echo "$cmt" > "$state_dir/cmt.$msgnum" -done - -echo 1 >"$state_dir/msgnum" -echo $msgnum >"$state_dir/end" - -end=$msgnum -msgnum=1 - -while test "$msgnum" -le "$end" -do - call_merge "$msgnum" - continue_merge -done - -finish_rb_merge - -} diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh index f64b130..b393e1e 100755 --- a/t/t3406-rebase-message.sh +++ b/t/t3406-rebase-message.sh @@ -17,14 +17,9 @@ test_expect_success 'setup' ' git tag start ' -cat >expect <<\EOF -Already applied: 0001 A -Already applied: 0002 B -Committed: 0003 Z -EOF - test_expect_success 'rebase -m' ' git rebase -m master >report && + >expect && sed -n -e "/^Already applied: /p" \ -e "/^Committed: /p" report >actual && test_cmp expect actual diff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh index 4c7494c..2d1094e 100755 --- a/t/t3420-rebase-autostash.sh +++ b/t/t3420-rebase-autostash.sh @@ -53,41 +53,6 @@ create_expected_success_interactive () { EOF } -create_expected_success_merge () { - cat >expected <<-EOF - $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual) - HEAD is now at $(git rev-parse --short feature-branch) third commit - First, rewinding head to replay your work on top of it... - Merging unrelated-onto-branch with HEAD~1 - Merging: - $(git rev-parse --short unrelated-onto-branch) unrelated commit - $(git rev-parse --short feature-branch^) second commit - found 1 common ancestor: - $(git rev-parse --short feature-branch~2) initial commit - [detached HEAD $(git rev-parse --short rebased-feature-branch~1)] second commit - Author: A U Thor - Date: Thu Apr 7 15:14:13 2005 -0700 - 2 files changed, 2 insertions(+) - create mode 100644 file1 - create mode 100644 file2 - Committed: 0001 second commit - Merging unrelated-onto-branch with HEAD~0 - Merging: - $(git rev-parse --short rebased-feature-branch~1) second commit - $(git rev-parse --short feature-branch) third commit - found 1 common ancestor: - $(git rev-parse --short feature-branch~1) second commit - [detached HEAD $(git rev-parse --short rebased-feature-branch)] third commit - Author: A U Thor - Date: Thu Apr 7 15:15:13 2005 -0700 - 1 file changed, 1 insertion(+) - create mode 100644 file3 - Committed: 0002 third commit - All done. - Applied autostash. - EOF -} - create_expected_failure_am () { cat >expected <<-EOF $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual) @@ -112,43 +77,6 @@ create_expected_failure_interactive () { EOF } -create_expected_failure_merge () { - cat >expected <<-EOF - $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual) - HEAD is now at $(git rev-parse --short feature-branch) third commit - First, rewinding head to replay your work on top of it... - Merging unrelated-onto-branch with HEAD~1 - Merging: - $(git rev-parse --short unrelated-onto-branch) unrelated commit - $(git rev-parse --short feature-branch^) second commit - found 1 common ancestor: - $(git rev-parse --short feature-branch~2) initial commit - [detached HEAD $(git rev-parse --short rebased-feature-branch~1)] second commit - Author: A U Thor - Date: Thu Apr 7 15:14:13 2005 -0700 - 2 files changed, 2 insertions(+) - create mode 100644 file1 - create mode 100644 file2 - Committed: 0001 second commit - Merging unrelated-onto-branch with HEAD~0 - Merging: - $(git rev-parse --short rebased-feature-branch~1) second commit - $(git rev-parse --short feature-branch) third commit - found 1 common ancestor: - $(git rev-parse --short feature-branch~1) second commit - [detached HEAD $(git rev-parse --short rebased-feature-branch)] third commit - Author: A U Thor - Date: Thu Apr 7 15:15:13 2005 -0700 - 1 file changed, 1 insertion(+) - create mode 100644 file3 - Committed: 0002 third commit - All done. - Applying autostash resulted in conflicts. - Your changes are safe in the stash. - You can run "git stash pop" or "git stash drop" at any time. - EOF -} - testrebase () { type=$1 dotest=$2 @@ -177,6 +105,9 @@ testrebase () { test_expect_success "rebase$type --autostash: check output" ' test_when_finished git branch -D rebased-feature-branch && suffix=${type#\ --} && suffix=${suffix:-am} && + if test ${suffix} = "merge"; then + suffix=interactive + fi && create_expected_success_$suffix && test_i18ncmp expected actual ' @@ -274,6 +205,9 @@ testrebase () { test_expect_success "rebase$type: check output with conflicting stash" ' test_when_finished git branch -D rebased-feature-branch && suffix=${type#\ --} && suffix=${suffix:-am} && + if test ${suffix} = "merge"; then + suffix=interactive + fi && create_expected_failure_$suffix && test_i18ncmp expected actual ' diff --git a/t/t3421-rebase-topology-linear.sh b/t/t3421-rebase-topology-linear.sh index 23ad4cf..7274dca 100755 --- a/t/t3421-rebase-topology-linear.sh +++ b/t/t3421-rebase-topology-linear.sh @@ -111,7 +111,7 @@ test_run_rebase () { " } test_run_rebase success '' -test_run_rebase failure -m +test_run_rebase success -m test_run_rebase success -i test_have_prereq !REBASE_P || test_run_rebase success -p @@ -126,7 +126,7 @@ test_run_rebase () { " } test_run_rebase success '' -test_run_rebase failure -m +test_run_rebase success -m test_run_rebase success -i test_have_prereq !REBASE_P || test_run_rebase success -p @@ -141,7 +141,7 @@ test_run_rebase () { " } test_run_rebase success '' -test_run_rebase failure -m +test_run_rebase success -m test_run_rebase success -i test_have_prereq !REBASE_P || test_run_rebase success -p @@ -284,7 +284,7 @@ test_run_rebase () { " } test_run_rebase success '' -test_run_rebase failure -m +test_run_rebase success -m test_run_rebase success -i test_have_prereq !REBASE_P || test_run_rebase success -p @@ -315,7 +315,7 @@ test_run_rebase () { " } test_run_rebase success '' -test_run_rebase failure -m +test_run_rebase success -m test_run_rebase success -i test_have_prereq !REBASE_P || test_run_rebase failure -p diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh index 81a5179..5cadedb 100755 --- a/t/t9903-bash-prompt.sh +++ b/t/t9903-bash-prompt.sh @@ -180,7 +180,7 @@ test_expect_success 'prompt - interactive rebase' ' ' test_expect_success 'prompt - rebase merge' ' - printf " (b2|REBASE-m 1/3)" >expected && + printf " (b2|REBASE-i 1/3)" >expected && git checkout b2 && test_when_finished "git checkout master" && test_must_fail git rebase --merge b1 b2 && -- cgit v0.10.2-6-g49f6