{"thread":{"id":"48102","subject":"[RFC PATCH 0/3] rebase-interactive","startedAt":"2018-03-20T20:45:19Z","lastAt":"2018-03-21T22:44:01Z","messageCount":14,"participants":["Wink Saville","Eric Sunshine","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"342359","messageId":"20180320204507.12623-1-wink@saville.com","threadId":"48102","inReplyTo":null,"subject":"[RFC PATCH 0/3] rebase-interactive","fromName":"Wink Saville","fromEmail":"wink@saville.com","sentAt":"2018-03-20T20:45:04Z","receivedAt":"2018-03-20T20:45:19Z","isPatch":true,"sender":{"key":"wink@saville.com","avatar":"https://avatars.githubusercontent.com/u/1024284?v=4"},"body":"I've not worked on the git sources before and while looking into\nfixing test_expect_failure 'exchange two commits with -p' in\nt3404-rebase-interactive.sh, I found it difficult to understand\nthe git testing infracture and git-rebase--interactive.sh.\n\nSo as part of learning my way around I thought I'd refactor\ngit-rebase--interactive to make it easier for me to understand.\nAt this point I do have some understanding and will be working\non fixing the bug. In the mean time I'm requesting comments on\nthis refactoring patch sequence.\n\nPatch 0001 creates a library of functions which can be\nused by git-rebase--interactive and\ngit-rebase--interactive--preserve-merges. The functions are\nthose that exist in git-rebase--interactive.sh plus new\nfunctions created from the body of git_rebase_interactive\nthat will be used git_rebase_interactive in the third patch\nand git_rebase_interactive_preserve_merges in the second\npatch. None of the functions are invoked so there is no\nlogic changes and the system builds and passes all tests\non travis-ci.org.\n\nPatch 0002 creates git-rebase--interactive--preserve-merges.sh\nwith the function git_rebase_interactive_preserve_merges. The contents\nof the function are refactored from git_rebase_interactive and\nuses existing and new functions in the library. A small modification\nof git-rebase is also done to invoke the new function when the -p\nswitch is used with git-rebase. When this is applied on top of\n0001 the system builds and passes all tests on travis-ci.org.\n\nThe final patch, 0003, removes all unused code from\ngit_rebase_interactive and uses the functions from the library\nwhere appropriate. And, of course, when applied on top of 0002\nthe system builds and passes all tests on travis-ci.org.\n\nWink Saville (3):\n  rebase-interactive: create git-rebase--interactive--lib.sh\n  rebase-interactive: create git-rebase--interactive--preserve-merges\n  rebase-interactive: refactor git-rebase--interactive to use library\n\n .gitignore                                  |    2 +\n Makefile                                    |    2 +\n git-rebase--interactive--lib.sh             |  944 +++++++++++++++++++++++++\n git-rebase--interactive--preserve-merges.sh |  134 ++++\n git-rebase--interactive.sh                  | 1019 +--------------------------\n git-rebase.sh                               |    7 +-\n 6 files changed, 1107 insertions(+), 1001 deletions(-)\n create mode 100644 git-rebase--interactive--lib.sh\n create mode 100644 git-rebase--interactive--preserve-merges.sh\n\n-- \n2.16.2\n\n"},{"id":"342360","messageId":"20180320204507.12623-2-wink@saville.com","threadId":"48102","inReplyTo":"20180320204507.12623-1-wink@saville.com","subject":"[RFC PATCH 1/3] rebase-interactive: create git-rebase--interactive--lib.sh","fromName":"Wink Saville","fromEmail":"wink@saville.com","sentAt":"2018-03-20T20:45:05Z","receivedAt":"2018-03-20T20:45:25Z","isPatch":true,"sender":{"key":"wink@saville.com","avatar":"https://avatars.githubusercontent.com/u/1024284?v=4"},"body":"Create a library that can be used for interactive rebasing by\nseparate scripts. In particular, the current git-rebase--interactive.sh\nwill be reduced to a single function which uses the library and a new\nfile, git-rebase--interactive--preserve-merges.sh will also be a single\nfunction that uses the library.\n\nSigned-off-by: Wink Saville <wink@saville.com>\n---\n .gitignore                      |   1 +\n Makefile                        |   1 +\n git-rebase--interactive--lib.sh | 944 ++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 946 insertions(+)\n create mode 100644 git-rebase--interactive--lib.sh\n\ndiff --git a/.gitignore b/.gitignore\nindex 833ef3b0b..4ea246780 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -116,6 +116,7 @@\n /git-rebase--am\n /git-rebase--helper\n /git-rebase--interactive\n+/git-rebase--interactive--lib\n /git-rebase--merge\n /git-receive-pack\n /git-reflog\ndiff --git a/Makefile b/Makefile\nindex de4b8f0c0..f13540da6 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -567,6 +567,7 @@ SCRIPT_LIB += git-mergetool--lib\n SCRIPT_LIB += git-parse-remote\n SCRIPT_LIB += git-rebase--am\n SCRIPT_LIB += git-rebase--interactive\n+SCRIPT_LIB += git-rebase--interactive--lib\n SCRIPT_LIB += git-rebase--merge\n SCRIPT_LIB += git-sh-setup\n SCRIPT_LIB += git-sh-i18n\ndiff --git a/git-rebase--interactive--lib.sh b/git-rebase--interactive--lib.sh\nnew file mode 100644\nindex 000000000..0cb902f98\n--- /dev/null\n+++ b/git-rebase--interactive--lib.sh\n@@ -0,0 +1,944 @@\n+#!/bin/sh\n+# This shell script fragment is sourced by git-rebase--interactive\n+# and git-rebase--interactive--preserve-merges in suppor of the\n+# interactive mode.  \"git rebase --interactive\" makes it easy\n+# to fix up commits in the middle of a series and rearrange commits.\n+#\n+# Copyright (c) 2006 Johannes E. Schindelin\n+#\n+# The original idea comes from Eric W. Biederman, in\n+# https://public-inbox.org/git/m1odwkyuf5.fsf_-_@ebiederm.dsl.xmission.com/\n+#\n+\n+# The file containing rebase commands, comments, and empty lines.\n+# This file is created by \"git rebase -i\" then edited by the user.  As\n+# the lines are processed, they are removed from the front of this\n+# file and written to the tail of $done.\n+todo=\"$state_dir\"/git-rebase-todo\n+\n+# The rebase command lines that have already been processed.  A line\n+# is moved here when it is first handled, before any associated user\n+# actions.\n+done=\"$state_dir\"/done\n+\n+# The commit message that is planned to be used for any changes that\n+# need to be committed following a user interaction.\n+msg=\"$state_dir\"/message\n+\n+# The file into which is accumulated the suggested commit message for\n+# squash/fixup commands.  When the first of a series of squash/fixups\n+# is seen, the file is created and the commit message from the\n+# previous commit and from the first squash/fixup commit are written\n+# to it.  The commit message for each subsequent squash/fixup commit\n+# is appended to the file as it is processed.\n+#\n+# The first line of the file is of the form\n+#     # This is a combination of $count commits.\n+# where $count is the number of commits whose messages have been\n+# written to the file so far (including the initial \"pick\" commit).\n+# Each time that a commit message is processed, this line is read and\n+# updated.  It is deleted just before the combined commit is made.\n+squash_msg=\"$state_dir\"/message-squash\n+\n+# If the current series of squash/fixups has not yet included a squash\n+# command, then this file exists and holds the commit message of the\n+# original \"pick\" commit.  (If the series ends without a \"squash\"\n+# command, then this can be used as the commit message of the combined\n+# commit without opening the editor.)\n+fixup_msg=\"$state_dir\"/message-fixup\n+\n+# $rewritten is the name of a directory containing files for each\n+# commit that is reachable by at least one merge base of $head and\n+# $upstream. They are not necessarily rewritten, but their children\n+# might be.  This ensures that commits on merged, but otherwise\n+# unrelated side branches are left alone. (Think \"X\" in the man page's\n+# example.)\n+rewritten=\"$state_dir\"/rewritten\n+\n+dropped=\"$state_dir\"/dropped\n+\n+end=\"$state_dir\"/end\n+msgnum=\"$state_dir\"/msgnum\n+\n+# A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and\n+# GIT_AUTHOR_DATE that will be used for the commit that is currently\n+# being rebased.\n+author_script=\"$state_dir\"/author-script\n+\n+# When an \"edit\" rebase command is being processed, the SHA1 of the\n+# commit to be edited is recorded in this file.  When \"git rebase\n+# --continue\" is executed, if there are any staged changes then they\n+# will be amended to the HEAD commit, but only provided the HEAD\n+# commit is still the commit to be edited.  When any other rebase\n+# command is processed, this file is deleted.\n+amend=\"$state_dir\"/amend\n+\n+# For the post-rewrite hook, we make a list of rewritten commits and\n+# their new sha1s.  The rewritten-pending list keeps the sha1s of\n+# commits that have been processed, but not committed yet,\n+# e.g. because they are waiting for a 'squash' command.\n+rewritten_list=\"$state_dir\"/rewritten-list\n+rewritten_pending=\"$state_dir\"/rewritten-pending\n+\n+# Work around Git for Windows' Bash whose \"read\" does not strip CRLF\n+# and leaves CR at the end instead.\n+cr=$(printf \"\\015\")\n+\n+strategy_args=${strategy:+--strategy=$strategy}\n+test -n \"$strategy_opts\" &&\n+eval '\n+\tfor strategy_opt in '\"$strategy_opts\"'\n+\tdo\n+\t\tstrategy_args=\"$strategy_args -X$(git rev-parse --sq-quote \"${strategy_opt#--}\")\"\n+\tdone\n+'\n+\n+GIT_CHERRY_PICK_HELP=\"$resolvemsg\"\n+export GIT_CHERRY_PICK_HELP\n+\n+comment_char=$(git config --get core.commentchar 2>/dev/null)\n+case \"$comment_char\" in\n+'' | auto)\n+\tcomment_char=\"#\"\n+\t;;\n+?)\n+\t;;\n+*)\n+\tcomment_char=$(echo \"$comment_char\" | cut -c1)\n+\t;;\n+esac\n+\n+warn () {\n+\tprintf '%s\\n' \"$*\" >&2\n+}\n+\n+# Output the commit message for the specified commit.\n+commit_message () {\n+\tgit cat-file commit \"$1\" | sed \"1,/^$/d\"\n+}\n+\n+orig_reflog_action=\"$GIT_REFLOG_ACTION\"\n+\n+comment_for_reflog () {\n+\tcase \"$orig_reflog_action\" in\n+\t''|rebase*)\n+\t\tGIT_REFLOG_ACTION=\"rebase -i ($1)\"\n+\t\texport GIT_REFLOG_ACTION\n+\t\t;;\n+\tesac\n+}\n+\n+setup_reflog_action () {\n+\tcomment_for_reflog start\n+\n+\tif test ! -z \"$switch_to\"\n+\tthen\n+\t\tGIT_REFLOG_ACTION=\"$GIT_REFLOG_ACTION: checkout $switch_to\"\n+\t\toutput git checkout \"$switch_to\" -- ||\n+\t\t\tdie \"$(eval_gettext \"Could not checkout \\$switch_to\")\"\n+\n+\t\tcomment_for_reflog start\n+\tfi\n+}\n+\n+last_count=\n+mark_action_done () {\n+\tsed -e 1q < \"$todo\" >> \"$done\"\n+\tsed -e 1d < \"$todo\" >> \"$todo\".new\n+\tmv -f \"$todo\".new \"$todo\"\n+\tnew_count=$(( $(git stripspace --strip-comments <\"$done\" | wc -l) ))\n+\techo $new_count >\"$msgnum\"\n+\ttotal=$(($new_count + $(git stripspace --strip-comments <\"$todo\" | wc -l)))\n+\techo $total >\"$end\"\n+\tif test \"$last_count\" != \"$new_count\"\n+\tthen\n+\t\tlast_count=$new_count\n+\t\teval_gettext \"Rebasing (\\$new_count/\\$total)\"; printf \"\\r\"\n+\t\ttest -z \"$verbose\" || echo\n+\tfi\n+}\n+\n+# Put the last action marked done at the beginning of the todo list\n+# again. If there has not been an action marked done yet, leave the list of\n+# items on the todo list unchanged.\n+reschedule_last_action () {\n+\ttail -n 1 \"$done\" | cat - \"$todo\" >\"$todo\".new\n+\tsed -e \\$d <\"$done\" >\"$done\".new\n+\tmv -f \"$todo\".new \"$todo\"\n+\tmv -f \"$done\".new \"$done\"\n+}\n+\n+append_todo_help () {\n+\tgettext \"\n+Commands:\n+p, pick = use commit\n+r, reword = use commit, but edit the commit message\n+e, edit = use commit, but stop for amending\n+s, squash = use commit, but meld into previous commit\n+f, fixup = like \\\"squash\\\", but discard this commit's log message\n+x, exec = run command (the rest of the line) using shell\n+d, drop = remove commit\n+\n+These lines can be re-ordered; they are executed from top to bottom.\n+\" | git stripspace --comment-lines >>\"$todo\"\n+\n+\tif test $(get_missing_commit_check_level) = error\n+\tthen\n+\t\tgettext \"\n+Do not remove any line. Use 'drop' explicitly to remove a commit.\n+\" | git stripspace --comment-lines >>\"$todo\"\n+\telse\n+\t\tgettext \"\n+If you remove a line here THAT COMMIT WILL BE LOST.\n+\" | git stripspace --comment-lines >>\"$todo\"\n+\tfi\n+}\n+\n+make_patch () {\n+\tsha1_and_parents=\"$(git rev-list --parents -1 \"$1\")\"\n+\tcase \"$sha1_and_parents\" in\n+\t?*' '?*' '?*)\n+\t\tgit diff --cc $sha1_and_parents\n+\t\t;;\n+\t?*' '?*)\n+\t\tgit diff-tree -p \"$1^!\"\n+\t\t;;\n+\t*)\n+\t\techo \"Root commit\"\n+\t\t;;\n+\tesac > \"$state_dir\"/patch\n+\ttest -f \"$msg\" ||\n+\t\tcommit_message \"$1\" > \"$msg\"\n+\ttest -f \"$author_script\" ||\n+\t\tget_author_ident_from_commit \"$1\" > \"$author_script\"\n+}\n+\n+die_with_patch () {\n+\techo \"$1\" > \"$state_dir\"/stopped-sha\n+\tgit update-ref REBASE_HEAD \"$1\"\n+\tmake_patch \"$1\"\n+\tdie \"$2\"\n+}\n+\n+exit_with_patch () {\n+\techo \"$1\" > \"$state_dir\"/stopped-sha\n+\tgit update-ref REBASE_HEAD \"$1\"\n+\tmake_patch $1\n+\tgit rev-parse --verify HEAD > \"$amend\"\n+\tgpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote \"$gpg_sign_opt\")}\n+\twarn \"$(eval_gettext \"\\\n+You can amend the commit now, with\n+\n+\tgit commit --amend \\$gpg_sign_opt_quoted\n+\n+Once you are satisfied with your changes, run\n+\n+\tgit rebase --continue\")\"\n+\twarn\n+\texit $2\n+}\n+\n+die_abort () {\n+\tapply_autostash\n+\trm -rf \"$state_dir\"\n+\tdie \"$1\"\n+}\n+\n+has_action () {\n+\ttest -n \"$(git stripspace --strip-comments <\"$1\")\"\n+}\n+\n+is_empty_commit() {\n+\ttree=$(git rev-parse -q --verify \"$1\"^{tree} 2>/dev/null) || {\n+\t\tsha1=$1\n+\t\tdie \"$(eval_gettext \"\\$sha1: not a commit that can be picked\")\"\n+\t}\n+\tptree=$(git rev-parse -q --verify \"$1\"^^{tree} 2>/dev/null) ||\n+\t\tptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904\n+\ttest \"$tree\" = \"$ptree\"\n+}\n+\n+is_merge_commit()\n+{\n+\tgit rev-parse --verify --quiet \"$1\"^2 >/dev/null 2>&1\n+}\n+\n+# Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and\n+# GIT_AUTHOR_DATE exported from the current environment.\n+do_with_author () {\n+\t(\n+\t\texport GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE\n+\t\t\"$@\"\n+\t)\n+}\n+\n+git_sequence_editor () {\n+\tif test -z \"$GIT_SEQUENCE_EDITOR\"\n+\tthen\n+\t\tGIT_SEQUENCE_EDITOR=\"$(git config sequence.editor)\"\n+\t\tif [ -z \"$GIT_SEQUENCE_EDITOR\" ]\n+\t\tthen\n+\t\t\tGIT_SEQUENCE_EDITOR=\"$(git var GIT_EDITOR)\" || return $?\n+\t\tfi\n+\tfi\n+\n+\teval \"$GIT_SEQUENCE_EDITOR\" '\"$@\"'\n+}\n+\n+pick_one () {\n+\tff=--ff\n+\n+\tcase \"$1\" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac\n+\tcase \"$force_rebase\" in '') ;; ?*) ff= ;; esac\n+\toutput git rev-parse --verify $sha1 ||\n+\t\tdie \"$(eval_gettext \"Invalid commit name: \\$sha1\")\"\n+\n+\tif is_empty_commit \"$sha1\"\n+\tthen\n+\t\tempty_args=\"--allow-empty\"\n+\tfi\n+\n+\ttest -d \"$rewritten\" &&\n+\t\tpick_one_preserving_merges \"$@\" && return\n+\toutput eval git cherry-pick $allow_rerere_autoupdate $allow_empty_message \\\n+\t\t\t${gpg_sign_opt:+$(git rev-parse --sq-quote \"$gpg_sign_opt\")} \\\n+\t\t\t\"$strategy_args\" $empty_args $ff \"$@\"\n+\n+\t# If cherry-pick dies it leaves the to-be-picked commit unrecorded.\n+\t# Reschedule previous task so this commit is not lost.\n+\tret=$?\n+\tcase \"$ret\" in [01]) ;; *) reschedule_last_action ;; esac\n+\treturn $ret\n+}\n+\n+pick_one_preserving_merges () {\n+\tfast_forward=t\n+\tcase \"$1\" in\n+\t-n)\n+\t\tfast_forward=f\n+\t\tsha1=$2\n+\t\t;;\n+\t*)\n+\t\tsha1=$1\n+\t\t;;\n+\tesac\n+\tsha1=$(git rev-parse $sha1)\n+\n+\tif test -f \"$state_dir\"/current-commit && test \"$fast_forward\" = t\n+\tthen\n+\t\twhile read current_commit\n+\t\tdo\n+\t\t\tgit rev-parse HEAD > \"$rewritten\"/$current_commit\n+\t\tdone <\"$state_dir\"/current-commit\n+\t\trm \"$state_dir\"/current-commit ||\n+\t\t    die \"$(gettext \\\n+\t\t\t\"Cannot write current commit's replacement sha1\")\"\n+\tfi\n+\n+\techo $sha1 >> \"$state_dir\"/current-commit\n+\n+\t# rewrite parents; if none were rewritten, we can fast-forward.\n+\tnew_parents=\n+\tpend=\" $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)\"\n+\tif test \"$pend\" = \" \"\n+\tthen\n+\t\tpend=\" root\"\n+\tfi\n+\twhile [ \"$pend\" != \"\" ]\n+\tdo\n+\t\tp=$(expr \"$pend\" : ' \\([^ ]*\\)')\n+\t\tpend=\"${pend# $p}\"\n+\n+\t\tif test -f \"$rewritten\"/$p\n+\t\tthen\n+\t\t\tnew_p=$(cat \"$rewritten\"/$p)\n+\t\t\t# If the todo reordered commits, and our parent is\n+\t\t\t# marked for rewriting, but hasn't been gotten to yet,\n+\t\t\t# assume the user meant to drop it on top of the\n+\t\t\t# current HEAD\n+\t\t\tif test -z \"$new_p\"\n+\t\t\tthen\n+\t\t\t\tnew_p=$(git rev-parse HEAD)\n+\t\t\tfi\n+\n+\t\t\ttest $p != $new_p && fast_forward=f\n+\t\t\tcase \"$new_parents\" in\n+\t\t\t*$new_p*)\n+\t\t\t\t;; # do nothing; that parent is already there\n+\t\t\t*)\n+\t\t\t\tnew_parents=\"$new_parents $new_p\"\n+\t\t\t\t;;\n+\t\t\tesac\n+\t\telse\n+\t\t\tif test -f \"$dropped\"/$p\n+\t\t\tthen\n+\t\t\t\tfast_forward=f\n+\t\t\t\treplacement=\"$(cat \"$dropped\"/$p)\"\n+\t\t\t\ttest -z \"$replacement\" && replacement=root\n+\t\t\t\tpend=\" $replacement$pend\"\n+\t\t\telse\n+\t\t\t\tnew_parents=\"$new_parents $p\"\n+\t\t\tfi\n+\t\tfi\n+\tdone\n+\tcase $fast_forward in\n+\tt)\n+\t\toutput warn \"$(eval_gettext \"Fast-forward to \\$sha1\")\"\n+\t\toutput git reset --hard $sha1 ||\n+\t\t\tdie \"$(eval_gettext \"Cannot fast-forward to \\$sha1\")\"\n+\t\t;;\n+\tf)\n+\t\tfirst_parent=$(expr \"$new_parents\" : ' \\([^ ]*\\)')\n+\n+\t\tif [ \"$1\" != \"-n\" ]\n+\t\tthen\n+\t\t\t# detach HEAD to current parent\n+\t\t\toutput git checkout $first_parent 2> /dev/null ||\n+\t\t\t   die \"$(eval_gettext \"Cannot move HEAD to \\$first_parent\")\"\n+\t\tfi\n+\n+\t\tcase \"$new_parents\" in\n+\t\t' '*' '*)\n+\t\t\ttest \"a$1\" = a-n && die \"$(eval_gettext \"Refusing to squash a merge: \\$sha1\")\"\n+\n+\t\t\t# redo merge\n+\t\t\tauthor_script_content=$(get_author_ident_from_commit $sha1)\n+\t\t\teval \"$author_script_content\"\n+\t\t\tmsg_content=\"$(commit_message $sha1)\"\n+\t\t\t# No point in merging the first parent, that's HEAD\n+\t\t\tnew_parents=${new_parents# $first_parent}\n+\t\t\tmerge_args=\"--no-log --no-ff\"\n+\t\t\tif ! do_with_author output eval \\\n+\t\t\t\tgit merge ${gpg_sign_opt:+$(git rev-parse \\\n+\t\t\t\t\t--sq-quote \"$gpg_sign_opt\")} \\\n+\t\t\t\t$allow_rerere_autoupdate \"$merge_args\" \\\n+\t\t\t\t\"$strategy_args\" \\\n+\t\t\t\t-m \"$(git rev-parse --sq-quote \"$msg_content\")\" \\\n+\t\t\t\t\"$new_parents\"\n+\t\t\tthen\n+\t\t\t\tprintf \"%s\\n\" \"$msg_content\" > \"$GIT_DIR\"/MERGE_MSG\n+\t\t\t\tdie_with_patch $sha1 \"$(eval_gettext \"Error redoing merge \\$sha1\")\"\n+\t\t\tfi\n+\t\t\techo \"$sha1 $(git rev-parse HEAD^0)\" >> \"$rewritten_list\"\n+\t\t\t;;\n+\t\t*)\n+\t\t\toutput eval git cherry-pick $allow_rerere_autoupdate \\\n+\t\t\t\t$allow_empty_message \\\n+\t\t\t\t${gpg_sign_opt:+$(git rev-parse --sq-quote \"$gpg_sign_opt\")} \\\n+\t\t\t\t\"$strategy_args\" \"$@\" ||\n+\t\t\t\tdie_with_patch $sha1 \"$(eval_gettext \"Could not pick \\$sha1\")\"\n+\t\t\t;;\n+\t\tesac\n+\t\t;;\n+\tesac\n+}\n+\n+this_nth_commit_message () {\n+\tn=$1\n+\teval_gettext \"This is the commit message #\\${n}:\"\n+}\n+\n+skip_nth_commit_message () {\n+\tn=$1\n+\teval_gettext \"The commit message #\\${n} will be skipped:\"\n+}\n+\n+update_squash_messages () {\n+\tif test -f \"$squash_msg\"; then\n+\t\tmv \"$squash_msg\" \"$squash_msg\".bak || exit\n+\t\tcount=$(($(sed -n \\\n+\t\t\t-e \"1s/^$comment_char[^0-9]*\\([0-9][0-9]*\\).*/\\1/p\" \\\n+\t\t\t-e \"q\" < \"$squash_msg\".bak)+1))\n+\t\t{\n+\t\t\tprintf '%s\\n' \"$comment_char $(eval_ngettext \\\n+\t\t\t\t\"This is a combination of \\$count commit.\" \\\n+\t\t\t\t\"This is a combination of \\$count commits.\" \\\n+\t\t\t\t$count)\"\n+\t\t\tsed -e 1d -e '2,/^./{\n+\t\t\t\t/^$/d\n+\t\t\t}' <\"$squash_msg\".bak\n+\t\t} >\"$squash_msg\"\n+\telse\n+\t\tcommit_message HEAD >\"$fixup_msg\" ||\n+\t\tdie \"$(eval_gettext \"Cannot write \\$fixup_msg\")\"\n+\t\tcount=2\n+\t\t{\n+\t\t\tprintf '%s\\n' \"$comment_char $(gettext \"This is a combination of 2 commits.\")\"\n+\t\t\tprintf '%s\\n' \"$comment_char $(gettext \"This is the 1st commit message:\")\"\n+\t\t\techo\n+\t\t\tcat \"$fixup_msg\"\n+\t\t} >\"$squash_msg\"\n+\tfi\n+\tcase $1 in\n+\tsquash)\n+\t\trm -f \"$fixup_msg\"\n+\t\techo\n+\t\tprintf '%s\\n' \"$comment_char $(this_nth_commit_message $count)\"\n+\t\techo\n+\t\tcommit_message $2\n+\t\t;;\n+\tfixup)\n+\t\techo\n+\t\tprintf '%s\\n' \"$comment_char $(skip_nth_commit_message $count)\"\n+\t\techo\n+\t\t# Change the space after the comment character to TAB:\n+\t\tcommit_message $2 | git stripspace --comment-lines | sed -e 's/ /\t/'\n+\t\t;;\n+\tesac >>\"$squash_msg\"\n+}\n+\n+peek_next_command () {\n+\tgit stripspace --strip-comments <\"$todo\" | sed -n -e 's/ .*//p' -e q\n+}\n+\n+# A squash/fixup has failed.  Prepare the long version of the squash\n+# commit message, then die_with_patch.  This code path requires the\n+# user to edit the combined commit message for all commits that have\n+# been squashed/fixedup so far.  So also erase the old squash\n+# messages, effectively causing the combined commit to be used as the\n+# new basis for any further squash/fixups.  Args: sha1 rest\n+die_failed_squash() {\n+\tsha1=$1\n+\trest=$2\n+\tmv \"$squash_msg\" \"$msg\" || exit\n+\trm -f \"$fixup_msg\"\n+\tcp \"$msg\" \"$GIT_DIR\"/MERGE_MSG || exit\n+\twarn\n+\twarn \"$(eval_gettext \"Could not apply \\$sha1... \\$rest\")\"\n+\tdie_with_patch $sha1 \"\"\n+}\n+\n+flush_rewritten_pending() {\n+\ttest -s \"$rewritten_pending\" || return\n+\tnewsha1=\"$(git rev-parse HEAD^0)\"\n+\tsed \"s/$/ $newsha1/\" < \"$rewritten_pending\" >> \"$rewritten_list\"\n+\trm -f \"$rewritten_pending\"\n+}\n+\n+record_in_rewritten() {\n+\toldsha1=\"$(git rev-parse $1)\"\n+\techo \"$oldsha1\" >> \"$rewritten_pending\"\n+\n+\tcase \"$(peek_next_command)\" in\n+\tsquash|s|fixup|f)\n+\t\t;;\n+\t*)\n+\t\tflush_rewritten_pending\n+\t\t;;\n+\tesac\n+}\n+\n+do_pick () {\n+\tsha1=$1\n+\trest=$2\n+\tif test \"$(git rev-parse HEAD)\" = \"$squash_onto\"\n+\tthen\n+\t\t# Set the correct commit message and author info on the\n+\t\t# sentinel root before cherry-picking the original changes\n+\t\t# without committing (-n).  Finally, update the sentinel again\n+\t\t# to include these changes.  If the cherry-pick results in a\n+\t\t# conflict, this means our behaviour is similar to a standard\n+\t\t# failed cherry-pick during rebase, with a dirty index to\n+\t\t# resolve before manually running git commit --amend then git\n+\t\t# rebase --continue.\n+\t\tgit commit --allow-empty --allow-empty-message --amend \\\n+\t\t\t   --no-post-rewrite -n -q -C $sha1 &&\n+\t\t\tpick_one -n $sha1 &&\n+\t\t\tgit commit --allow-empty --allow-empty-message \\\n+\t\t\t\t   --amend --no-post-rewrite -n -q -C $sha1 \\\n+\t\t\t\t   ${gpg_sign_opt:+\"$gpg_sign_opt\"} ||\n+\t\t\t\t   die_with_patch $sha1 \"$(eval_gettext \"Could not apply \\$sha1... \\$rest\")\"\n+\telse\n+\t\tpick_one $sha1 ||\n+\t\t\tdie_with_patch $sha1 \"$(eval_gettext \"Could not apply \\$sha1... \\$rest\")\"\n+\tfi\n+}\n+\n+do_next () {\n+\trm -f \"$msg\" \"$author_script\" \"$amend\" \"$state_dir\"/stopped-sha || exit\n+\tread -r command sha1 rest < \"$todo\"\n+\tcase \"$command\" in\n+\t\"$comment_char\"*|''|noop|drop|d)\n+\t\tmark_action_done\n+\t\t;;\n+\t\"$cr\")\n+\t\t# Work around CR left by \"read\" (e.g. with Git for Windows' Bash).\n+\t\tmark_action_done\n+\t\t;;\n+\tpick|p)\n+\t\tcomment_for_reflog pick\n+\n+\t\tmark_action_done $sha1 \"$rest\"\n+\t\tdo_pick $sha1 \"$rest\"\n+\t\trecord_in_rewritten $sha1\n+\t\t;;\n+\treword|r)\n+\t\tcomment_for_reflog reword\n+\n+\t\tmark_action_done\n+\t\tdo_pick $sha1 \"$rest\"\n+\t\tgit commit --amend --no-post-rewrite ${gpg_sign_opt:+\"$gpg_sign_opt\"} \\\n+\t\t\t$allow_empty_message || {\n+\t\t\twarn \"$(eval_gettext \"\\\n+Could not amend commit after successfully picking \\$sha1... \\$rest\n+This is most likely due to an empty commit message, or the pre-commit hook\n+failed. If the pre-commit hook failed, you may need to resolve the issue before\n+you are able to reword the commit.\")\"\n+\t\t\texit_with_patch $sha1 1\n+\t\t}\n+\t\trecord_in_rewritten $sha1\n+\t\t;;\n+\tedit|e)\n+\t\tcomment_for_reflog edit\n+\n+\t\tmark_action_done\n+\t\tdo_pick $sha1 \"$rest\"\n+\t\tsha1_abbrev=$(git rev-parse --short $sha1)\n+\t\twarn \"$(eval_gettext \"Stopped at \\$sha1_abbrev... \\$rest\")\"\n+\t\texit_with_patch $sha1 0\n+\t\t;;\n+\tsquash|s|fixup|f)\n+\t\tcase \"$command\" in\n+\t\tsquash|s)\n+\t\t\tsquash_style=squash\n+\t\t\t;;\n+\t\tfixup|f)\n+\t\t\tsquash_style=fixup\n+\t\t\t;;\n+\t\tesac\n+\t\tcomment_for_reflog $squash_style\n+\n+\t\ttest -f \"$done\" && has_action \"$done\" ||\n+\t\t\tdie \"$(eval_gettext \"Cannot '\\$squash_style' without a previous commit\")\"\n+\n+\t\tmark_action_done\n+\t\tupdate_squash_messages $squash_style $sha1\n+\t\tauthor_script_content=$(get_author_ident_from_commit HEAD)\n+\t\techo \"$author_script_content\" > \"$author_script\"\n+\t\teval \"$author_script_content\"\n+\t\tif ! pick_one -n $sha1\n+\t\tthen\n+\t\t\tgit rev-parse --verify HEAD >\"$amend\"\n+\t\t\tdie_failed_squash $sha1 \"$rest\"\n+\t\tfi\n+\t\tcase \"$(peek_next_command)\" in\n+\t\tsquash|s|fixup|f)\n+\t\t\t# This is an intermediate commit; its message will only be\n+\t\t\t# used in case of trouble.  So use the long version:\n+\t\t\tdo_with_author output git commit --amend --no-verify -F \"$squash_msg\" \\\n+\t\t\t\t${gpg_sign_opt:+\"$gpg_sign_opt\"} $allow_empty_message ||\n+\t\t\t\tdie_failed_squash $sha1 \"$rest\"\n+\t\t\t;;\n+\t\t*)\n+\t\t\t# This is the final command of this squash/fixup group\n+\t\t\tif test -f \"$fixup_msg\"\n+\t\t\tthen\n+\t\t\t\tdo_with_author git commit --amend --no-verify -F \"$fixup_msg\" \\\n+\t\t\t\t\t${gpg_sign_opt:+\"$gpg_sign_opt\"} $allow_empty_message ||\n+\t\t\t\t\tdie_failed_squash $sha1 \"$rest\"\n+\t\t\telse\n+\t\t\t\tcp \"$squash_msg\" \"$GIT_DIR\"/SQUASH_MSG || exit\n+\t\t\t\trm -f \"$GIT_DIR\"/MERGE_MSG\n+\t\t\t\tdo_with_author git commit --amend --no-verify -F \"$GIT_DIR\"/SQUASH_MSG -e \\\n+\t\t\t\t\t${gpg_sign_opt:+\"$gpg_sign_opt\"} $allow_empty_message ||\n+\t\t\t\t\tdie_failed_squash $sha1 \"$rest\"\n+\t\t\tfi\n+\t\t\trm -f \"$squash_msg\" \"$fixup_msg\"\n+\t\t\t;;\n+\t\tesac\n+\t\trecord_in_rewritten $sha1\n+\t\t;;\n+\tx|\"exec\")\n+\t\tread -r command rest < \"$todo\"\n+\t\tmark_action_done\n+\t\teval_gettextln \"Executing: \\$rest\"\n+\t\t\"${SHELL:-/bin/sh}\" -c \"$rest\" # Actual execution\n+\t\tstatus=$?\n+\t\t# Run in subshell because require_clean_work_tree can die.\n+\t\tdirty=f\n+\t\t(require_clean_work_tree \"rebase\" 2>/dev/null) || dirty=t\n+\t\tif test \"$status\" -ne 0\n+\t\tthen\n+\t\t\twarn \"$(eval_gettext \"Execution failed: \\$rest\")\"\n+\t\t\ttest \"$dirty\" = f ||\n+\t\t\t\twarn \"$(gettext \"and made changes to the index and/or the working tree\")\"\n+\n+\t\t\twarn \"$(gettext \"\\\n+You can fix the problem, and then run\n+\n+\tgit rebase --continue\")\"\n+\t\t\twarn\n+\t\t\tif test $status -eq 127\t\t# command not found\n+\t\t\tthen\n+\t\t\t\tstatus=1\n+\t\t\tfi\n+\t\t\texit \"$status\"\n+\t\telif test \"$dirty\" = t\n+\t\tthen\n+\t\t\t# TRANSLATORS: after these lines is a command to be issued by the user\n+\t\t\twarn \"$(eval_gettext \"\\\n+Execution succeeded: \\$rest\n+but left changes to the index and/or the working tree\n+Commit or stash your changes, and then run\n+\n+\tgit rebase --continue\")\"\n+\t\t\twarn\n+\t\t\texit 1\n+\t\tfi\n+\t\t;;\n+\t*)\n+\t\twarn \"$(eval_gettext \"Unknown command: \\$command \\$sha1 \\$rest\")\"\n+\t\tfixtodo=\"$(gettext \"Please fix this using 'git rebase --edit-todo'.\")\"\n+\t\tif git rev-parse --verify -q \"$sha1\" >/dev/null\n+\t\tthen\n+\t\t\tdie_with_patch $sha1 \"$fixtodo\"\n+\t\telse\n+\t\t\tdie \"$fixtodo\"\n+\t\tfi\n+\t\t;;\n+\tesac\n+\ttest -s \"$todo\" && return\n+\n+\tcomment_for_reflog finish &&\n+\tnewhead=$(git rev-parse HEAD) &&\n+\tcase $head_name in\n+\trefs/*)\n+\t\tmessage=\"$GIT_REFLOG_ACTION: $head_name onto $onto\" &&\n+\t\tgit update-ref -m \"$message\" $head_name $newhead $orig_head &&\n+\t\tgit symbolic-ref \\\n+\t\t  -m \"$GIT_REFLOG_ACTION: returning to $head_name\" \\\n+\t\t  HEAD $head_name\n+\t\t;;\n+\tesac && {\n+\t\ttest ! -f \"$state_dir\"/verbose ||\n+\t\t\tgit diff-tree --stat $orig_head..HEAD\n+\t} &&\n+\t{\n+\t\ttest -s \"$rewritten_list\" &&\n+\t\tgit notes copy --for-rewrite=rebase < \"$rewritten_list\" ||\n+\t\ttrue # we don't care if this copying failed\n+\t} &&\n+\thook=\"$(git rev-parse --git-path hooks/post-rewrite)\"\n+\tif test -x \"$hook\" && test -s \"$rewritten_list\"; then\n+\t\t\"$hook\" rebase < \"$rewritten_list\"\n+\t\ttrue # we don't care if this hook failed\n+\tfi &&\n+\t\twarn \"$(eval_gettext \"Successfully rebased and updated \\$head_name.\")\"\n+\n+\treturn 1 # not failure; just to break the do_rest loop\n+}\n+\n+# can only return 0, when the infinite loop breaks\n+do_rest () {\n+\twhile :\n+\tdo\n+\t\tdo_next || break\n+\tdone\n+}\n+\n+expand_todo_ids() {\n+\tgit rebase--helper --expand-ids\n+}\n+\n+collapse_todo_ids() {\n+\tgit rebase--helper --shorten-ids\n+}\n+\n+# Switch to the branch in $into and notify it in the reflog\n+checkout_onto () {\n+\tGIT_REFLOG_ACTION=\"$GIT_REFLOG_ACTION: checkout $onto_name\"\n+\toutput git checkout $onto || die_abort \"$(gettext \"could not detach HEAD\")\"\n+\tgit update-ref ORIG_HEAD $orig_head\n+}\n+\n+get_missing_commit_check_level () {\n+\tcheck_level=$(git config --get rebase.missingCommitsCheck)\n+\tcheck_level=${check_level:-ignore}\n+\t# Don't be case sensitive\n+\tprintf '%s' \"$check_level\" | tr 'A-Z' 'a-z'\n+}\n+\n+init_basic_state () {\n+\torig_head=$(git rev-parse --verify HEAD) || die \"$(gettext \"No HEAD?\")\"\n+\tmkdir -p \"$state_dir\" || die \"$(eval_gettext \"Could not create temporary \\$state_dir\")\"\n+\trm -f \"$(git rev-parse --git-path REBASE_HEAD)\"\n+\n+\t: > \"$state_dir\"/interactive || die \"$(gettext \"Could not mark as interactive\")\"\n+\twrite_basic_state\n+}\n+\n+# Initiate an action which is first parameter.\n+# Returns 0 if the action was able to complete\n+# or 1 if further processing is required.\n+initiate_action () {\n+\tcase $1 in\n+\tcontinue)\n+\t\tif test ! -d \"$rewritten\"\n+\t\tthen\n+\t\t\texec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \\\n+\t\t\t\t--continue\n+\t\tfi\n+\t\t# do we have anything to commit?\n+\t\tif git diff-index --cached --quiet HEAD --\n+\t\tthen\n+\t\t\t# Nothing to commit -- skip this commit\n+\t\t\ttest ! -f \"$GIT_DIR\"/CHERRY_PICK_HEAD ||\n+\t\t\trm \"$GIT_DIR\"/CHERRY_PICK_HEAD ||\n+\t\t\tdie \"$(gettext \"Could not remove CHERRY_PICK_HEAD\")\"\n+\t\telse\n+\t\t\tif ! test -f \"$author_script\"\n+\t\t\tthen\n+\t\t\t\tgpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote \"$gpg_sign_opt\")}\n+\t\t\t\tdie \"$(eval_gettext \"\\\n+You have staged changes in your working tree.\n+If these changes are meant to be\n+squashed into the previous commit, run:\n+\n+  git commit --amend \\$gpg_sign_opt_quoted\n+\n+If they are meant to go into a new commit, run:\n+\n+  git commit \\$gpg_sign_opt_quoted\n+\n+In both cases, once you're done, continue with:\n+\n+  git rebase --continue\n+\")\"\n+\t\t\tfi\n+\t\t\t. \"$author_script\" ||\n+\t\t\t\tdie \"$(gettext \"Error trying to find the author identity to amend commit\")\"\n+\t\t\tif test -f \"$amend\"\n+\t\t\tthen\n+\t\t\t\tcurrent_head=$(git rev-parse --verify HEAD)\n+\t\t\t\ttest \"$current_head\" = $(cat \"$amend\") ||\n+\t\t\t\tdie \"$(gettext \"\\\n+You have uncommitted changes in your working tree.\n+Please commit them first and then run:\n+    'git rebase --continue' again.\")\"\n+\t\t\t\tdo_with_author git commit --amend --no-verify \\\n+\t\t\t\t    -F \"$msg\" \\\n+\t\t\t\t    -e ${gpg_sign_opt:+\"$gpg_sign_opt\"} \\\n+\t\t\t\t    $allow_empty_message ||\n+\t\t\t\tdie \"$(gettext \"Could not commit staged changes.\")\"\n+\t\t\telse\n+\t\t\t\tdo_with_author git commit --no-verify \\\n+\t\t\t\t    -F \"$msg\" \\\n+\t\t\t\t    -e ${gpg_sign_opt:+\"$gpg_sign_opt\"} \\\n+\t\t\t\t    $allow_empty_message ||\n+\t\t\t\tdie \"$(gettext \"Could not commit staged changes.\")\"\n+\t\t\tfi\n+\t\tfi\n+\n+\t\tif test -r \"$state_dir\"/stopped-sha\n+\t\tthen\n+\t\t\trecord_in_rewritten \"$(cat \"$state_dir\"/stopped-sha)\"\n+\t\tfi\n+\n+\t\trequire_clean_work_tree \"rebase\"\n+\t\tdo_rest\n+\t\treturn 0 # done\n+\t\t;;\n+\tskip)\n+\t\tgit rerere clear\n+\n+\t\tif test ! -d \"$rewritten\"\n+\t\tthen\n+\t\t\texec git rebase--helper ${force_rebase:+--no-ff} \\\n+\t\t\t\t$allow_empty_message --continue\n+\t\tfi\n+\t\tdo_rest\n+\t\treturn 0 # done\n+\t\t;;\n+\tedit-todo)\n+\t\tgit stripspace --strip-comments <\"$todo\" >\"$todo\".new\n+\t\tmv -f \"$todo\".new \"$todo\"\n+\t\tcollapse_todo_ids\n+\t\tappend_todo_help\n+\t\tgettext \"\n+You are editing the todo file of an ongoing interactive rebase.\n+To continue rebase after editing, run:\n+    git rebase --continue\n+\n+\t\" | git stripspace --comment-lines >>\"$todo\"\n+\n+\t\tgit_sequence_editor \"$todo\" ||\n+\t\t\tdie \"$(gettext \"Could not execute editor\")\"\n+\t\texpand_todo_ids\n+\n+\t\texit\n+\t\t;;\n+\tshow-current-patch)\n+\t\texec git show REBASE_HEAD --\n+\t\t;;\n+\t*)\n+\t\treturn 1 # continue\n+\t\t;;\n+\tesac\n+}\n+\n+# Complete the action\n+complete_action() {\n+\n+\ttest -s \"$todo\" || echo noop >> \"$todo\"\n+\ttest -z \"$autosquash\" || git rebase--helper --rearrange-squash || exit\n+\ttest -n \"$cmd\" && git rebase--helper --add-exec-commands \"$cmd\"\n+\n+\ttodocount=$(git stripspace --strip-comments <\"$todo\" | wc -l)\n+\ttodocount=${todocount##* }\n+\n+\tcat >>\"$todo\" <<EOF\n+\n+$comment_char $(eval_ngettext \\\n+\t\"Rebase \\$shortrevisions onto \\$shortonto (\\$todocount command)\" \\\n+\t\"Rebase \\$shortrevisions onto \\$shortonto (\\$todocount commands)\" \\\n+\t\"$todocount\")\n+EOF\n+\n+\tappend_todo_help\n+\tgettext \"\n+However, if you remove everything, the rebase will be aborted.\n+\n+\" | git stripspace --comment-lines >>\"$todo\"\n+\n+\tif test -z \"$keep_empty\"\n+\tthen\n+\t\tprintf '%s\\n' \"$comment_char \\\n+\t\t    $(gettext \"Note that empty commits are commented out\")\" \\\n+\t\t    >>\"$todo\"\n+\tfi\n+\n+\thas_action \"$todo\" ||\n+\t\treturn 2\n+\n+\tcp \"$todo\" \"$todo\".backup\n+\tcollapse_todo_ids\n+\t#dbg_pause \"invoke git_sequence_editor\"\n+\tgit_sequence_editor \"$todo\" ||\n+\t\tdie_abort \"$(gettext \"Could not execute editor\")\"\n+\n+\thas_action \"$todo\" ||\n+\t\treturn 2\n+\n+\tgit rebase--helper --check-todo-list || {\n+\t\tret=$?\n+\t\tcheckout_onto\n+\t\texit $ret\n+\t}\n+\n+\texpand_todo_ids\n+\n+\ttest -d \"$rewritten\" || test -n \"$force_rebase\" ||\n+\tonto=\"$(git rebase--helper --skip-unnecessary-picks)\" ||\n+\tdie \"Could not skip unnecessary pick commands\"\n+\n+\tcheckout_onto\n+\n+\tif test -z \"$rebase_root\" && test ! -d \"$rewritten\"\n+\tthen\n+\t\trequire_clean_work_tree \"rebase\"\n+\t\texec git rebase--helper ${force_rebase:+--no-ff} \\\n+\t\t\t$allow_empty_message --continue\n+\telse\n+\t\tdo_rest\n+\tfi\n+}\n-- \n2.16.2\n\n"},{"id":"342361","messageId":"20180320204507.12623-3-wink@saville.com","threadId":"48102","inReplyTo":"20180320204507.12623-1-wink@saville.com","subject":"[RFC PATCH 2/3] rebase-interactive: create git-rebase--interactive--preserve-merges","fromName":"Wink Saville","fromEmail":"wink@saville.com","sentAt":"2018-03-20T20:45:06Z","receivedAt":"2018-03-20T20:45:35Z","isPatch":true,"sender":{"key":"wink@saville.com","avatar":"https://avatars.githubusercontent.com/u/1024284?v=4"},"body":"Extract the code that is executed when $preserve_merges is t from\ngit-rebase--interactive to git-rebase--interactive--preserve-merges.sh.\nThe extracted code uses functions from git-rebase--interactve--lib.\n\nSigned-off-by: Wink Saville <wink@saville.com>\n---\n .gitignore                                  |   1 +\n Makefile                                    |   1 +\n git-rebase--interactive--preserve-merges.sh | 134 ++++++++++++++++++++++++++++\n git-rebase.sh                               |   7 +-\n 4 files changed, 142 insertions(+), 1 deletion(-)\n create mode 100644 git-rebase--interactive--preserve-merges.sh\n\ndiff --git a/.gitignore b/.gitignore\nindex 4ea246780..c57a6b563 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -116,6 +116,7 @@\n /git-rebase--am\n /git-rebase--helper\n /git-rebase--interactive\n+/git-rebase--interactive--preserve-merges\n /git-rebase--interactive--lib\n /git-rebase--merge\n /git-receive-pack\ndiff --git a/Makefile b/Makefile\nindex f13540da6..543e0a659 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -567,6 +567,7 @@ SCRIPT_LIB += git-mergetool--lib\n SCRIPT_LIB += git-parse-remote\n SCRIPT_LIB += git-rebase--am\n SCRIPT_LIB += git-rebase--interactive\n+SCRIPT_LIB += git-rebase--interactive--preserve-merges\n SCRIPT_LIB += git-rebase--interactive--lib\n SCRIPT_LIB += git-rebase--merge\n SCRIPT_LIB += git-sh-setup\ndiff --git a/git-rebase--interactive--preserve-merges.sh b/git-rebase--interactive--preserve-merges.sh\nnew file mode 100644\nindex 000000000..e00b5c990\n--- /dev/null\n+++ b/git-rebase--interactive--preserve-merges.sh\n@@ -0,0 +1,134 @@\n+#!/bin/sh\n+# This shell script fragment is sourced by git-rebase to implement\n+# its interactive mode with --preserve-merges flag.\n+# \"git rebase --interactive\" makes it easy to fix up commits in the\n+# middle of a series and rearrange commits and adding --preserve-merges\n+# requests it to preserve merges while rebase.\n+#\n+# Copyright (c) 2006 Johannes E. Schindelin\n+#\n+# The original idea comes from Eric W. Biederman, in\n+# https://public-inbox.org/git/m1odwkyuf5.fsf_-_@ebiederm.dsl.xmission.com/\n+\n+. git-rebase--interactive--lib\n+\n+# The whole contents of this file is run by dot-sourcing it from\n+# inside a shell function.  It used to be that \"return\"s we see\n+# below were not inside any function, and expected to return\n+# to the function that dot-sourced us.\n+#\n+# However, older (9.x) versions of FreeBSD /bin/sh misbehave on such a\n+# construct and continue to run the statements that follow such a \"return\".\n+# As a work-around, we introduce an extra layer of a function\n+# here, and immediately call it after defining it.\n+git_rebase__interactive__preserve_merges () {\n+\tinitiate_action \"$action\"\n+\tret=$?\n+\tif test $ret == 0; then\n+\t\treturn 0\n+\tfi\n+\n+\tsetup_reflog_action\n+\tinit_basic_state\n+\n+\tif test -z \"$rebase_root\"\n+\tthen\n+\t\tmkdir \"$rewritten\" &&\n+\t\tfor c in $(git merge-base --all $orig_head $upstream)\n+\t\tdo\n+\t\t\techo $onto > \"$rewritten\"/$c ||\n+\t\t\t    die \"$(gettext \"Could not init rewritten commits\")\"\n+\t\tdone\n+\telse\n+\t\tmkdir \"$rewritten\" &&\n+\t\techo $onto > \"$rewritten\"/root ||\n+\t\t\tdie \"$(gettext \"Could not init rewritten commits\")\"\n+\tfi\n+\n+\t# No cherry-pick because our first pass is to determine\n+\t# parents to rewrite and skipping dropped commits would\n+\t# prematurely end our probe\n+\tmerges_option=\n+\n+\tshorthead=$(git rev-parse --short $orig_head)\n+\tshortonto=$(git rev-parse --short $onto)\n+\tif test -z \"$rebase_root\"\n+\t\t# this is now equivalent to ! -z \"$upstream\"\n+\tthen\n+\t\tshortupstream=$(git rev-parse --short $upstream)\n+\t\trevisions=$upstream...$orig_head\n+\t\tshortrevisions=$shortupstream..$shorthead\n+\telse\n+\t\trevisions=$onto...$orig_head\n+\t\tshortrevisions=$shorthead\n+\tfi\n+\n+\t# The 'rev-list .. | sed'\n+\t#   requires %m to parse; where as the the instruction\n+\t#   requires %H to parse\n+\tformat=$(git config --get rebase.instructionFormat)\n+\tgit rev-list $merges_option --format=\"%m%H ${format:-%s}\" \\\n+\t\t--reverse --left-right --topo-order \\\n+\t\t$revisions ${restrict_revision+^$restrict_revision} | \\\n+\t\tsed -n \"s/^>//p\" |\n+\twhile read -r sha1 rest\n+\tdo\n+\t\tif test -z \"$keep_empty\" \\\n+\t\t\t&& is_empty_commit $sha1 \\\n+\t\t\t&& ! is_merge_commit $sha1\n+\t\tthen\n+\t\t\tcomment_out=\"$comment_char \"\n+\t\telse\n+\t\t\tcomment_out=\n+\t\tfi\n+\n+\t\tif test -z \"$rebase_root\"\n+\t\tthen\n+\t\t\tpreserve=t\n+\t\t\tfor p in $(git rev-list --parents -1 $sha1 | \\\n+\t\t\t\tcut -d' ' -s -f2-)\n+\t\t\tdo\n+\t\t\t\tif test -f \"$rewritten\"/$p\n+\t\t\t\tthen\n+\t\t\t\t\tpreserve=f\n+\t\t\t\tfi\n+\t\t\tdone\n+\t\telse\n+\t\t\tpreserve=f\n+\t\tfi\n+\t\tif test f = \"$preserve\"\n+\t\tthen\n+\t\t\ttouch \"$rewritten\"/$sha1\n+\t\t\tprintf '%s\\n' \"${comment_out}pick $sha1 $rest\" >>\"$todo\"\n+\t\tfi\n+\tdone\n+\n+\tmkdir \"$dropped\"\n+\t# Save all non-cherry-picked changes\n+\tgit rev-list $revisions --left-right --cherry-pick | \\\n+\t\tsed -n \"s/^>//p\" > \"$state_dir\"/not-cherry-picks\n+\t# Now all commits and note which ones are missing in\n+\t# not-cherry-picks and hence being dropped\n+\tgit rev-list $revisions |\n+\twhile read rev\n+\tdo\n+\t\tif test -f \"$rewritten\"/$rev &&\n+\t\t   ! sane_grep \"$rev\" \"$state_dir\"/not-cherry-picks >/dev/null\n+\t\tthen\n+\t\t\t# Use -f2 because if rev-list is telling us this commit\n+\t\t\t# is not worthwhile, we don't want to track its\n+\t\t\t# multiple heads, just the history of its first-parent\n+\t\t\t# for others that will be rebasing on top of it.\n+\t\t\tgit rev-list --parents -1 $rev | \\\n+\t\t\t\tcut -d' ' -s -f2 > \"$dropped\"/$rev\n+\t\t\tsha1=$(git rev-list -1 $rev)\n+\t\t\tsane_grep -v \"^[a-z][a-z]* $sha1\" <\"$todo\" > \"${todo}2\"\n+\t\t\tmv \"${todo}2\" \"$todo\"\n+\t\t\trm \"$rewritten\"/$rev\n+\t\tfi\n+\tdone\n+\n+\tcomplete_action\n+}\n+# ... and then we call the whole thing.\n+git_rebase__interactive__preserve_merges\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex a1f6e5de6..3c2fc35f7 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -196,7 +196,12 @@ run_specific_rebase () {\n \t\texport GIT_EDITOR\n \t\tautosquash=\n \tfi\n-\t. git-rebase--$type\n+\tif test \"$type\" = interactive\n+\tthen\n+\t\t. git-rebase--${type}${preserve_merges:+--preserve-merges}\n+\telse\n+\t\t. git-rebase--${type}\n+\tfi\n \tret=$?\n \tif test $ret -eq 0\n \tthen\n-- \n2.16.2\n\n"},{"id":"342362","messageId":"20180320204507.12623-4-wink@saville.com","threadId":"48102","inReplyTo":"20180320204507.12623-1-wink@saville.com","subject":"[RFC PATCH 3/3] rebase-interactive: refactor git-rebase--interactive to use library","fromName":"Wink Saville","fromEmail":"wink@saville.com","sentAt":"2018-03-20T20:45:07Z","receivedAt":"2018-03-20T20:45:38Z","isPatch":true,"sender":{"key":"wink@saville.com","avatar":"https://avatars.githubusercontent.com/u/1024284?v=4"},"body":"Refactor git-rebase--interactive to use git-rebase--interactive--lib\nthis simplifies and reduces the size of the code by about 1000 LoC.\n\nSigned-off-by: Wink Saville <wink@saville.com>\n---\n git-rebase--interactive.sh | 1019 +-------------------------------------------\n 1 file changed, 19 insertions(+), 1000 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex 331c8dfea..3d2b89e1c 100644\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -1,3 +1,4 @@\n+#!/bin/sh\n # This shell script fragment is sourced by git-rebase to implement\n # its interactive mode.  \"git rebase --interactive\" makes it easy\n # to fix up commits in the middle of a series and rearrange commits.\n@@ -6,742 +7,8 @@\n #\n # The original idea comes from Eric W. Biederman, in\n # https://public-inbox.org/git/m1odwkyuf5.fsf_-_@ebiederm.dsl.xmission.com/\n-#\n-# The file containing rebase commands, comments, and empty lines.\n-# This file is created by \"git rebase -i\" then edited by the user.  As\n-# the lines are processed, they are removed from the front of this\n-# file and written to the tail of $done.\n-todo=\"$state_dir\"/git-rebase-todo\n-\n-# The rebase command lines that have already been processed.  A line\n-# is moved here when it is first handled, before any associated user\n-# actions.\n-done=\"$state_dir\"/done\n-\n-# The commit message that is planned to be used for any changes that\n-# need to be committed following a user interaction.\n-msg=\"$state_dir\"/message\n-\n-# The file into which is accumulated the suggested commit message for\n-# squash/fixup commands.  When the first of a series of squash/fixups\n-# is seen, the file is created and the commit message from the\n-# previous commit and from the first squash/fixup commit are written\n-# to it.  The commit message for each subsequent squash/fixup commit\n-# is appended to the file as it is processed.\n-#\n-# The first line of the file is of the form\n-#     # This is a combination of $count commits.\n-# where $count is the number of commits whose messages have been\n-# written to the file so far (including the initial \"pick\" commit).\n-# Each time that a commit message is processed, this line is read and\n-# updated.  It is deleted just before the combined commit is made.\n-squash_msg=\"$state_dir\"/message-squash\n-\n-# If the current series of squash/fixups has not yet included a squash\n-# command, then this file exists and holds the commit message of the\n-# original \"pick\" commit.  (If the series ends without a \"squash\"\n-# command, then this can be used as the commit message of the combined\n-# commit without opening the editor.)\n-fixup_msg=\"$state_dir\"/message-fixup\n-\n-# $rewritten is the name of a directory containing files for each\n-# commit that is reachable by at least one merge base of $head and\n-# $upstream. They are not necessarily rewritten, but their children\n-# might be.  This ensures that commits on merged, but otherwise\n-# unrelated side branches are left alone. (Think \"X\" in the man page's\n-# example.)\n-rewritten=\"$state_dir\"/rewritten\n-\n-dropped=\"$state_dir\"/dropped\n-\n-end=\"$state_dir\"/end\n-msgnum=\"$state_dir\"/msgnum\n-\n-# A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and\n-# GIT_AUTHOR_DATE that will be used for the commit that is currently\n-# being rebased.\n-author_script=\"$state_dir\"/author-script\n-\n-# When an \"edit\" rebase command is being processed, the SHA1 of the\n-# commit to be edited is recorded in this file.  When \"git rebase\n-# --continue\" is executed, if there are any staged changes then they\n-# will be amended to the HEAD commit, but only provided the HEAD\n-# commit is still the commit to be edited.  When any other rebase\n-# command is processed, this file is deleted.\n-amend=\"$state_dir\"/amend\n-\n-# For the post-rewrite hook, we make a list of rewritten commits and\n-# their new sha1s.  The rewritten-pending list keeps the sha1s of\n-# commits that have been processed, but not committed yet,\n-# e.g. because they are waiting for a 'squash' command.\n-rewritten_list=\"$state_dir\"/rewritten-list\n-rewritten_pending=\"$state_dir\"/rewritten-pending\n-\n-# Work around Git for Windows' Bash whose \"read\" does not strip CRLF\n-# and leaves CR at the end instead.\n-cr=$(printf \"\\015\")\n-\n-strategy_args=${strategy:+--strategy=$strategy}\n-test -n \"$strategy_opts\" &&\n-eval '\n-\tfor strategy_opt in '\"$strategy_opts\"'\n-\tdo\n-\t\tstrategy_args=\"$strategy_args -X$(git rev-parse --sq-quote \"${strategy_opt#--}\")\"\n-\tdone\n-'\n-\n-GIT_CHERRY_PICK_HELP=\"$resolvemsg\"\n-export GIT_CHERRY_PICK_HELP\n-\n-comment_char=$(git config --get core.commentchar 2>/dev/null)\n-case \"$comment_char\" in\n-'' | auto)\n-\tcomment_char=\"#\"\n-\t;;\n-?)\n-\t;;\n-*)\n-\tcomment_char=$(echo \"$comment_char\" | cut -c1)\n-\t;;\n-esac\n-\n-warn () {\n-\tprintf '%s\\n' \"$*\" >&2\n-}\n-\n-# Output the commit message for the specified commit.\n-commit_message () {\n-\tgit cat-file commit \"$1\" | sed \"1,/^$/d\"\n-}\n-\n-orig_reflog_action=\"$GIT_REFLOG_ACTION\"\n-\n-comment_for_reflog () {\n-\tcase \"$orig_reflog_action\" in\n-\t''|rebase*)\n-\t\tGIT_REFLOG_ACTION=\"rebase -i ($1)\"\n-\t\texport GIT_REFLOG_ACTION\n-\t\t;;\n-\tesac\n-}\n-\n-last_count=\n-mark_action_done () {\n-\tsed -e 1q < \"$todo\" >> \"$done\"\n-\tsed -e 1d < \"$todo\" >> \"$todo\".new\n-\tmv -f \"$todo\".new \"$todo\"\n-\tnew_count=$(( $(git stripspace --strip-comments <\"$done\" | wc -l) ))\n-\techo $new_count >\"$msgnum\"\n-\ttotal=$(($new_count + $(git stripspace --strip-comments <\"$todo\" | wc -l)))\n-\techo $total >\"$end\"\n-\tif test \"$last_count\" != \"$new_count\"\n-\tthen\n-\t\tlast_count=$new_count\n-\t\teval_gettext \"Rebasing (\\$new_count/\\$total)\"; printf \"\\r\"\n-\t\ttest -z \"$verbose\" || echo\n-\tfi\n-}\n-\n-# Put the last action marked done at the beginning of the todo list\n-# again. If there has not been an action marked done yet, leave the list of\n-# items on the todo list unchanged.\n-reschedule_last_action () {\n-\ttail -n 1 \"$done\" | cat - \"$todo\" >\"$todo\".new\n-\tsed -e \\$d <\"$done\" >\"$done\".new\n-\tmv -f \"$todo\".new \"$todo\"\n-\tmv -f \"$done\".new \"$done\"\n-}\n-\n-append_todo_help () {\n-\tgettext \"\n-Commands:\n-p, pick = use commit\n-r, reword = use commit, but edit the commit message\n-e, edit = use commit, but stop for amending\n-s, squash = use commit, but meld into previous commit\n-f, fixup = like \\\"squash\\\", but discard this commit's log message\n-x, exec = run command (the rest of the line) using shell\n-d, drop = remove commit\n-\n-These lines can be re-ordered; they are executed from top to bottom.\n-\" | git stripspace --comment-lines >>\"$todo\"\n-\n-\tif test $(get_missing_commit_check_level) = error\n-\tthen\n-\t\tgettext \"\n-Do not remove any line. Use 'drop' explicitly to remove a commit.\n-\" | git stripspace --comment-lines >>\"$todo\"\n-\telse\n-\t\tgettext \"\n-If you remove a line here THAT COMMIT WILL BE LOST.\n-\" | git stripspace --comment-lines >>\"$todo\"\n-\tfi\n-}\n-\n-make_patch () {\n-\tsha1_and_parents=\"$(git rev-list --parents -1 \"$1\")\"\n-\tcase \"$sha1_and_parents\" in\n-\t?*' '?*' '?*)\n-\t\tgit diff --cc $sha1_and_parents\n-\t\t;;\n-\t?*' '?*)\n-\t\tgit diff-tree -p \"$1^!\"\n-\t\t;;\n-\t*)\n-\t\techo \"Root commit\"\n-\t\t;;\n-\tesac > \"$state_dir\"/patch\n-\ttest -f \"$msg\" ||\n-\t\tcommit_message \"$1\" > \"$msg\"\n-\ttest -f \"$author_script\" ||\n-\t\tget_author_ident_from_commit \"$1\" > \"$author_script\"\n-}\n-\n-die_with_patch () {\n-\techo \"$1\" > \"$state_dir\"/stopped-sha\n-\tgit update-ref REBASE_HEAD \"$1\"\n-\tmake_patch \"$1\"\n-\tdie \"$2\"\n-}\n-\n-exit_with_patch () {\n-\techo \"$1\" > \"$state_dir\"/stopped-sha\n-\tgit update-ref REBASE_HEAD \"$1\"\n-\tmake_patch $1\n-\tgit rev-parse --verify HEAD > \"$amend\"\n-\tgpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote \"$gpg_sign_opt\")}\n-\twarn \"$(eval_gettext \"\\\n-You can amend the commit now, with\n-\n-\tgit commit --amend \\$gpg_sign_opt_quoted\n-\n-Once you are satisfied with your changes, run\n \n-\tgit rebase --continue\")\"\n-\twarn\n-\texit $2\n-}\n-\n-die_abort () {\n-\tapply_autostash\n-\trm -rf \"$state_dir\"\n-\tdie \"$1\"\n-}\n-\n-has_action () {\n-\ttest -n \"$(git stripspace --strip-comments <\"$1\")\"\n-}\n-\n-is_empty_commit() {\n-\ttree=$(git rev-parse -q --verify \"$1\"^{tree} 2>/dev/null) || {\n-\t\tsha1=$1\n-\t\tdie \"$(eval_gettext \"\\$sha1: not a commit that can be picked\")\"\n-\t}\n-\tptree=$(git rev-parse -q --verify \"$1\"^^{tree} 2>/dev/null) ||\n-\t\tptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904\n-\ttest \"$tree\" = \"$ptree\"\n-}\n-\n-is_merge_commit()\n-{\n-\tgit rev-parse --verify --quiet \"$1\"^2 >/dev/null 2>&1\n-}\n-\n-# Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and\n-# GIT_AUTHOR_DATE exported from the current environment.\n-do_with_author () {\n-\t(\n-\t\texport GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE\n-\t\t\"$@\"\n-\t)\n-}\n-\n-git_sequence_editor () {\n-\tif test -z \"$GIT_SEQUENCE_EDITOR\"\n-\tthen\n-\t\tGIT_SEQUENCE_EDITOR=\"$(git config sequence.editor)\"\n-\t\tif [ -z \"$GIT_SEQUENCE_EDITOR\" ]\n-\t\tthen\n-\t\t\tGIT_SEQUENCE_EDITOR=\"$(git var GIT_EDITOR)\" || return $?\n-\t\tfi\n-\tfi\n-\n-\teval \"$GIT_SEQUENCE_EDITOR\" '\"$@\"'\n-}\n-\n-pick_one () {\n-\tff=--ff\n-\n-\tcase \"$1\" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac\n-\tcase \"$force_rebase\" in '') ;; ?*) ff= ;; esac\n-\toutput git rev-parse --verify $sha1 || die \"$(eval_gettext \"Invalid commit name: \\$sha1\")\"\n-\n-\tif is_empty_commit \"$sha1\"\n-\tthen\n-\t\tempty_args=\"--allow-empty\"\n-\tfi\n-\n-\ttest -d \"$rewritten\" &&\n-\t\tpick_one_preserving_merges \"$@\" && return\n-\toutput eval git cherry-pick $allow_rerere_autoupdate $allow_empty_message \\\n-\t\t\t${gpg_sign_opt:+$(git rev-parse --sq-quote \"$gpg_sign_opt\")} \\\n-\t\t\t\"$strategy_args\" $empty_args $ff \"$@\"\n-\n-\t# If cherry-pick dies it leaves the to-be-picked commit unrecorded. Reschedule\n-\t# previous task so this commit is not lost.\n-\tret=$?\n-\tcase \"$ret\" in [01]) ;; *) reschedule_last_action ;; esac\n-\treturn $ret\n-}\n-\n-pick_one_preserving_merges () {\n-\tfast_forward=t\n-\tcase \"$1\" in\n-\t-n)\n-\t\tfast_forward=f\n-\t\tsha1=$2\n-\t\t;;\n-\t*)\n-\t\tsha1=$1\n-\t\t;;\n-\tesac\n-\tsha1=$(git rev-parse $sha1)\n-\n-\tif test -f \"$state_dir\"/current-commit\n-\tthen\n-\t\tif test \"$fast_forward\" = t\n-\t\tthen\n-\t\t\twhile read current_commit\n-\t\t\tdo\n-\t\t\t\tgit rev-parse HEAD > \"$rewritten\"/$current_commit\n-\t\t\tdone <\"$state_dir\"/current-commit\n-\t\t\trm \"$state_dir\"/current-commit ||\n-\t\t\t\tdie \"$(gettext \"Cannot write current commit's replacement sha1\")\"\n-\t\tfi\n-\tfi\n-\n-\techo $sha1 >> \"$state_dir\"/current-commit\n-\n-\t# rewrite parents; if none were rewritten, we can fast-forward.\n-\tnew_parents=\n-\tpend=\" $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)\"\n-\tif test \"$pend\" = \" \"\n-\tthen\n-\t\tpend=\" root\"\n-\tfi\n-\twhile [ \"$pend\" != \"\" ]\n-\tdo\n-\t\tp=$(expr \"$pend\" : ' \\([^ ]*\\)')\n-\t\tpend=\"${pend# $p}\"\n-\n-\t\tif test -f \"$rewritten\"/$p\n-\t\tthen\n-\t\t\tnew_p=$(cat \"$rewritten\"/$p)\n-\n-\t\t\t# If the todo reordered commits, and our parent is marked for\n-\t\t\t# rewriting, but hasn't been gotten to yet, assume the user meant to\n-\t\t\t# drop it on top of the current HEAD\n-\t\t\tif test -z \"$new_p\"\n-\t\t\tthen\n-\t\t\t\tnew_p=$(git rev-parse HEAD)\n-\t\t\tfi\n-\n-\t\t\ttest $p != $new_p && fast_forward=f\n-\t\t\tcase \"$new_parents\" in\n-\t\t\t*$new_p*)\n-\t\t\t\t;; # do nothing; that parent is already there\n-\t\t\t*)\n-\t\t\t\tnew_parents=\"$new_parents $new_p\"\n-\t\t\t\t;;\n-\t\t\tesac\n-\t\telse\n-\t\t\tif test -f \"$dropped\"/$p\n-\t\t\tthen\n-\t\t\t\tfast_forward=f\n-\t\t\t\treplacement=\"$(cat \"$dropped\"/$p)\"\n-\t\t\t\ttest -z \"$replacement\" && replacement=root\n-\t\t\t\tpend=\" $replacement$pend\"\n-\t\t\telse\n-\t\t\t\tnew_parents=\"$new_parents $p\"\n-\t\t\tfi\n-\t\tfi\n-\tdone\n-\tcase $fast_forward in\n-\tt)\n-\t\toutput warn \"$(eval_gettext \"Fast-forward to \\$sha1\")\"\n-\t\toutput git reset --hard $sha1 ||\n-\t\t\tdie \"$(eval_gettext \"Cannot fast-forward to \\$sha1\")\"\n-\t\t;;\n-\tf)\n-\t\tfirst_parent=$(expr \"$new_parents\" : ' \\([^ ]*\\)')\n-\n-\t\tif [ \"$1\" != \"-n\" ]\n-\t\tthen\n-\t\t\t# detach HEAD to current parent\n-\t\t\toutput git checkout $first_parent 2> /dev/null ||\n-\t\t\t\tdie \"$(eval_gettext \"Cannot move HEAD to \\$first_parent\")\"\n-\t\tfi\n-\n-\t\tcase \"$new_parents\" in\n-\t\t' '*' '*)\n-\t\t\ttest \"a$1\" = a-n && die \"$(eval_gettext \"Refusing to squash a merge: \\$sha1\")\"\n-\n-\t\t\t# redo merge\n-\t\t\tauthor_script_content=$(get_author_ident_from_commit $sha1)\n-\t\t\teval \"$author_script_content\"\n-\t\t\tmsg_content=\"$(commit_message $sha1)\"\n-\t\t\t# No point in merging the first parent, that's HEAD\n-\t\t\tnew_parents=${new_parents# $first_parent}\n-\t\t\tmerge_args=\"--no-log --no-ff\"\n-\t\t\tif ! do_with_author output eval \\\n-\t\t\t\tgit merge ${gpg_sign_opt:+$(git rev-parse \\\n-\t\t\t\t\t--sq-quote \"$gpg_sign_opt\")} \\\n-\t\t\t\t$allow_rerere_autoupdate \"$merge_args\" \\\n-\t\t\t\t\"$strategy_args\" \\\n-\t\t\t\t-m \"$(git rev-parse --sq-quote \"$msg_content\")\" \\\n-\t\t\t\t\"$new_parents\"\n-\t\t\tthen\n-\t\t\t\tprintf \"%s\\n\" \"$msg_content\" > \"$GIT_DIR\"/MERGE_MSG\n-\t\t\t\tdie_with_patch $sha1 \"$(eval_gettext \"Error redoing merge \\$sha1\")\"\n-\t\t\tfi\n-\t\t\techo \"$sha1 $(git rev-parse HEAD^0)\" >> \"$rewritten_list\"\n-\t\t\t;;\n-\t\t*)\n-\t\t\toutput eval git cherry-pick $allow_rerere_autoupdate \\\n-\t\t\t\t$allow_empty_message \\\n-\t\t\t\t${gpg_sign_opt:+$(git rev-parse --sq-quote \"$gpg_sign_opt\")} \\\n-\t\t\t\t\"$strategy_args\" \"$@\" ||\n-\t\t\t\tdie_with_patch $sha1 \"$(eval_gettext \"Could not pick \\$sha1\")\"\n-\t\t\t;;\n-\t\tesac\n-\t\t;;\n-\tesac\n-}\n-\n-this_nth_commit_message () {\n-\tn=$1\n-\teval_gettext \"This is the commit message #\\${n}:\"\n-}\n-\n-skip_nth_commit_message () {\n-\tn=$1\n-\teval_gettext \"The commit message #\\${n} will be skipped:\"\n-}\n-\n-update_squash_messages () {\n-\tif test -f \"$squash_msg\"; then\n-\t\tmv \"$squash_msg\" \"$squash_msg\".bak || exit\n-\t\tcount=$(($(sed -n \\\n-\t\t\t-e \"1s/^$comment_char[^0-9]*\\([0-9][0-9]*\\).*/\\1/p\" \\\n-\t\t\t-e \"q\" < \"$squash_msg\".bak)+1))\n-\t\t{\n-\t\t\tprintf '%s\\n' \"$comment_char $(eval_ngettext \\\n-\t\t\t\t\"This is a combination of \\$count commit.\" \\\n-\t\t\t\t\"This is a combination of \\$count commits.\" \\\n-\t\t\t\t$count)\"\n-\t\t\tsed -e 1d -e '2,/^./{\n-\t\t\t\t/^$/d\n-\t\t\t}' <\"$squash_msg\".bak\n-\t\t} >\"$squash_msg\"\n-\telse\n-\t\tcommit_message HEAD >\"$fixup_msg\" ||\n-\t\tdie \"$(eval_gettext \"Cannot write \\$fixup_msg\")\"\n-\t\tcount=2\n-\t\t{\n-\t\t\tprintf '%s\\n' \"$comment_char $(gettext \"This is a combination of 2 commits.\")\"\n-\t\t\tprintf '%s\\n' \"$comment_char $(gettext \"This is the 1st commit message:\")\"\n-\t\t\techo\n-\t\t\tcat \"$fixup_msg\"\n-\t\t} >\"$squash_msg\"\n-\tfi\n-\tcase $1 in\n-\tsquash)\n-\t\trm -f \"$fixup_msg\"\n-\t\techo\n-\t\tprintf '%s\\n' \"$comment_char $(this_nth_commit_message $count)\"\n-\t\techo\n-\t\tcommit_message $2\n-\t\t;;\n-\tfixup)\n-\t\techo\n-\t\tprintf '%s\\n' \"$comment_char $(skip_nth_commit_message $count)\"\n-\t\techo\n-\t\t# Change the space after the comment character to TAB:\n-\t\tcommit_message $2 | git stripspace --comment-lines | sed -e 's/ /\t/'\n-\t\t;;\n-\tesac >>\"$squash_msg\"\n-}\n-\n-peek_next_command () {\n-\tgit stripspace --strip-comments <\"$todo\" | sed -n -e 's/ .*//p' -e q\n-}\n-\n-# A squash/fixup has failed.  Prepare the long version of the squash\n-# commit message, then die_with_patch.  This code path requires the\n-# user to edit the combined commit message for all commits that have\n-# been squashed/fixedup so far.  So also erase the old squash\n-# messages, effectively causing the combined commit to be used as the\n-# new basis for any further squash/fixups.  Args: sha1 rest\n-die_failed_squash() {\n-\tsha1=$1\n-\trest=$2\n-\tmv \"$squash_msg\" \"$msg\" || exit\n-\trm -f \"$fixup_msg\"\n-\tcp \"$msg\" \"$GIT_DIR\"/MERGE_MSG || exit\n-\twarn\n-\twarn \"$(eval_gettext \"Could not apply \\$sha1... \\$rest\")\"\n-\tdie_with_patch $sha1 \"\"\n-}\n-\n-flush_rewritten_pending() {\n-\ttest -s \"$rewritten_pending\" || return\n-\tnewsha1=\"$(git rev-parse HEAD^0)\"\n-\tsed \"s/$/ $newsha1/\" < \"$rewritten_pending\" >> \"$rewritten_list\"\n-\trm -f \"$rewritten_pending\"\n-}\n-\n-record_in_rewritten() {\n-\toldsha1=\"$(git rev-parse $1)\"\n-\techo \"$oldsha1\" >> \"$rewritten_pending\"\n-\n-\tcase \"$(peek_next_command)\" in\n-\tsquash|s|fixup|f)\n-\t\t;;\n-\t*)\n-\t\tflush_rewritten_pending\n-\t\t;;\n-\tesac\n-}\n-\n-do_pick () {\n-\tsha1=$1\n-\trest=$2\n-\tif test \"$(git rev-parse HEAD)\" = \"$squash_onto\"\n-\tthen\n-\t\t# Set the correct commit message and author info on the\n-\t\t# sentinel root before cherry-picking the original changes\n-\t\t# without committing (-n).  Finally, update the sentinel again\n-\t\t# to include these changes.  If the cherry-pick results in a\n-\t\t# conflict, this means our behaviour is similar to a standard\n-\t\t# failed cherry-pick during rebase, with a dirty index to\n-\t\t# resolve before manually running git commit --amend then git\n-\t\t# rebase --continue.\n-\t\tgit commit --allow-empty --allow-empty-message --amend \\\n-\t\t\t   --no-post-rewrite -n -q -C $sha1 &&\n-\t\t\tpick_one -n $sha1 &&\n-\t\t\tgit commit --allow-empty --allow-empty-message \\\n-\t\t\t\t   --amend --no-post-rewrite -n -q -C $sha1 \\\n-\t\t\t\t   ${gpg_sign_opt:+\"$gpg_sign_opt\"} ||\n-\t\t\t\t   die_with_patch $sha1 \"$(eval_gettext \"Could not apply \\$sha1... \\$rest\")\"\n-\telse\n-\t\tpick_one $sha1 ||\n-\t\t\tdie_with_patch $sha1 \"$(eval_gettext \"Could not apply \\$sha1... \\$rest\")\"\n-\tfi\n-}\n-\n-do_next () {\n-\trm -f \"$msg\" \"$author_script\" \"$amend\" \"$state_dir\"/stopped-sha || exit\n-\tread -r command sha1 rest < \"$todo\"\n-\tcase \"$command\" in\n-\t\"$comment_char\"*|''|noop|drop|d)\n-\t\tmark_action_done\n-\t\t;;\n-\t\"$cr\")\n-\t\t# Work around CR left by \"read\" (e.g. with Git for Windows' Bash).\n-\t\tmark_action_done\n-\t\t;;\n-\tpick|p)\n-\t\tcomment_for_reflog pick\n-\n-\t\tmark_action_done\n-\t\tdo_pick $sha1 \"$rest\"\n-\t\trecord_in_rewritten $sha1\n-\t\t;;\n-\treword|r)\n-\t\tcomment_for_reflog reword\n-\n-\t\tmark_action_done\n-\t\tdo_pick $sha1 \"$rest\"\n-\t\tgit commit --amend --no-post-rewrite ${gpg_sign_opt:+\"$gpg_sign_opt\"} \\\n-\t\t\t$allow_empty_message || {\n-\t\t\twarn \"$(eval_gettext \"\\\n-Could not amend commit after successfully picking \\$sha1... \\$rest\n-This is most likely due to an empty commit message, or the pre-commit hook\n-failed. If the pre-commit hook failed, you may need to resolve the issue before\n-you are able to reword the commit.\")\"\n-\t\t\texit_with_patch $sha1 1\n-\t\t}\n-\t\trecord_in_rewritten $sha1\n-\t\t;;\n-\tedit|e)\n-\t\tcomment_for_reflog edit\n-\n-\t\tmark_action_done\n-\t\tdo_pick $sha1 \"$rest\"\n-\t\tsha1_abbrev=$(git rev-parse --short $sha1)\n-\t\twarn \"$(eval_gettext \"Stopped at \\$sha1_abbrev... \\$rest\")\"\n-\t\texit_with_patch $sha1 0\n-\t\t;;\n-\tsquash|s|fixup|f)\n-\t\tcase \"$command\" in\n-\t\tsquash|s)\n-\t\t\tsquash_style=squash\n-\t\t\t;;\n-\t\tfixup|f)\n-\t\t\tsquash_style=fixup\n-\t\t\t;;\n-\t\tesac\n-\t\tcomment_for_reflog $squash_style\n-\n-\t\ttest -f \"$done\" && has_action \"$done\" ||\n-\t\t\tdie \"$(eval_gettext \"Cannot '\\$squash_style' without a previous commit\")\"\n-\n-\t\tmark_action_done\n-\t\tupdate_squash_messages $squash_style $sha1\n-\t\tauthor_script_content=$(get_author_ident_from_commit HEAD)\n-\t\techo \"$author_script_content\" > \"$author_script\"\n-\t\teval \"$author_script_content\"\n-\t\tif ! pick_one -n $sha1\n-\t\tthen\n-\t\t\tgit rev-parse --verify HEAD >\"$amend\"\n-\t\t\tdie_failed_squash $sha1 \"$rest\"\n-\t\tfi\n-\t\tcase \"$(peek_next_command)\" in\n-\t\tsquash|s|fixup|f)\n-\t\t\t# This is an intermediate commit; its message will only be\n-\t\t\t# used in case of trouble.  So use the long version:\n-\t\t\tdo_with_author output git commit --amend --no-verify -F \"$squash_msg\" \\\n-\t\t\t\t${gpg_sign_opt:+\"$gpg_sign_opt\"} $allow_empty_message ||\n-\t\t\t\tdie_failed_squash $sha1 \"$rest\"\n-\t\t\t;;\n-\t\t*)\n-\t\t\t# This is the final command of this squash/fixup group\n-\t\t\tif test -f \"$fixup_msg\"\n-\t\t\tthen\n-\t\t\t\tdo_with_author git commit --amend --no-verify -F \"$fixup_msg\" \\\n-\t\t\t\t\t${gpg_sign_opt:+\"$gpg_sign_opt\"} $allow_empty_message ||\n-\t\t\t\t\tdie_failed_squash $sha1 \"$rest\"\n-\t\t\telse\n-\t\t\t\tcp \"$squash_msg\" \"$GIT_DIR\"/SQUASH_MSG || exit\n-\t\t\t\trm -f \"$GIT_DIR\"/MERGE_MSG\n-\t\t\t\tdo_with_author git commit --amend --no-verify -F \"$GIT_DIR\"/SQUASH_MSG -e \\\n-\t\t\t\t\t${gpg_sign_opt:+\"$gpg_sign_opt\"} $allow_empty_message ||\n-\t\t\t\t\tdie_failed_squash $sha1 \"$rest\"\n-\t\t\tfi\n-\t\t\trm -f \"$squash_msg\" \"$fixup_msg\"\n-\t\t\t;;\n-\t\tesac\n-\t\trecord_in_rewritten $sha1\n-\t\t;;\n-\tx|\"exec\")\n-\t\tread -r command rest < \"$todo\"\n-\t\tmark_action_done\n-\t\teval_gettextln \"Executing: \\$rest\"\n-\t\t\"${SHELL:-@SHELL_PATH@}\" -c \"$rest\" # Actual execution\n-\t\tstatus=$?\n-\t\t# Run in subshell because require_clean_work_tree can die.\n-\t\tdirty=f\n-\t\t(require_clean_work_tree \"rebase\" 2>/dev/null) || dirty=t\n-\t\tif test \"$status\" -ne 0\n-\t\tthen\n-\t\t\twarn \"$(eval_gettext \"Execution failed: \\$rest\")\"\n-\t\t\ttest \"$dirty\" = f ||\n-\t\t\t\twarn \"$(gettext \"and made changes to the index and/or the working tree\")\"\n-\n-\t\t\twarn \"$(gettext \"\\\n-You can fix the problem, and then run\n-\n-\tgit rebase --continue\")\"\n-\t\t\twarn\n-\t\t\tif test $status -eq 127\t\t# command not found\n-\t\t\tthen\n-\t\t\t\tstatus=1\n-\t\t\tfi\n-\t\t\texit \"$status\"\n-\t\telif test \"$dirty\" = t\n-\t\tthen\n-\t\t\t# TRANSLATORS: after these lines is a command to be issued by the user\n-\t\t\twarn \"$(eval_gettext \"\\\n-Execution succeeded: \\$rest\n-but left changes to the index and/or the working tree\n-Commit or stash your changes, and then run\n-\n-\tgit rebase --continue\")\"\n-\t\t\twarn\n-\t\t\texit 1\n-\t\tfi\n-\t\t;;\n-\t*)\n-\t\twarn \"$(eval_gettext \"Unknown command: \\$command \\$sha1 \\$rest\")\"\n-\t\tfixtodo=\"$(gettext \"Please fix this using 'git rebase --edit-todo'.\")\"\n-\t\tif git rev-parse --verify -q \"$sha1\" >/dev/null\n-\t\tthen\n-\t\t\tdie_with_patch $sha1 \"$fixtodo\"\n-\t\telse\n-\t\t\tdie \"$fixtodo\"\n-\t\tfi\n-\t\t;;\n-\tesac\n-\ttest -s \"$todo\" && return\n-\n-\tcomment_for_reflog finish &&\n-\tnewhead=$(git rev-parse HEAD) &&\n-\tcase $head_name in\n-\trefs/*)\n-\t\tmessage=\"$GIT_REFLOG_ACTION: $head_name onto $onto\" &&\n-\t\tgit update-ref -m \"$message\" $head_name $newhead $orig_head &&\n-\t\tgit symbolic-ref \\\n-\t\t  -m \"$GIT_REFLOG_ACTION: returning to $head_name\" \\\n-\t\t  HEAD $head_name\n-\t\t;;\n-\tesac && {\n-\t\ttest ! -f \"$state_dir\"/verbose ||\n-\t\t\tgit diff-tree --stat $orig_head..HEAD\n-\t} &&\n-\t{\n-\t\ttest -s \"$rewritten_list\" &&\n-\t\tgit notes copy --for-rewrite=rebase < \"$rewritten_list\" ||\n-\t\ttrue # we don't care if this copying failed\n-\t} &&\n-\thook=\"$(git rev-parse --git-path hooks/post-rewrite)\"\n-\tif test -x \"$hook\" && test -s \"$rewritten_list\"; then\n-\t\t\"$hook\" rebase < \"$rewritten_list\"\n-\t\ttrue # we don't care if this hook failed\n-\tfi &&\n-\t\twarn \"$(eval_gettext \"Successfully rebased and updated \\$head_name.\")\"\n-\n-\treturn 1 # not failure; just to break the do_rest loop\n-}\n-\n-# can only return 0, when the infinite loop breaks\n-do_rest () {\n-\twhile :\n-\tdo\n-\t\tdo_next || break\n-\tdone\n-}\n-\n-expand_todo_ids() {\n-\tgit rebase--helper --expand-ids\n-}\n-\n-collapse_todo_ids() {\n-\tgit rebase--helper --shorten-ids\n-}\n-\n-# Switch to the branch in $into and notify it in the reflog\n-checkout_onto () {\n-\tGIT_REFLOG_ACTION=\"$GIT_REFLOG_ACTION: checkout $onto_name\"\n-\toutput git checkout $onto || die_abort \"$(gettext \"could not detach HEAD\")\"\n-\tgit update-ref ORIG_HEAD $orig_head\n-}\n-\n-get_missing_commit_check_level () {\n-\tcheck_level=$(git config --get rebase.missingCommitsCheck)\n-\tcheck_level=${check_level:-ignore}\n-\t# Don't be case sensitive\n-\tprintf '%s' \"$check_level\" | tr 'A-Z' 'a-z'\n-}\n+. git-rebase--interactive--lib\n \n # The whole contents of this file is run by dot-sourcing it from\n # inside a shell function.  It used to be that \"return\"s we see\n@@ -754,283 +21,35 @@ get_missing_commit_check_level () {\n # here, and immediately call it after defining it.\n git_rebase__interactive () {\n \n-case \"$action\" in\n-continue)\n-\tif test ! -d \"$rewritten\"\n-\tthen\n-\t\texec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \\\n-\t\t\t--continue\n-\tfi\n-\t# do we have anything to commit?\n-\tif git diff-index --cached --quiet HEAD --\n-\tthen\n-\t\t# Nothing to commit -- skip this commit\n-\n-\t\ttest ! -f \"$GIT_DIR\"/CHERRY_PICK_HEAD ||\n-\t\trm \"$GIT_DIR\"/CHERRY_PICK_HEAD ||\n-\t\tdie \"$(gettext \"Could not remove CHERRY_PICK_HEAD\")\"\n-\telse\n-\t\tif ! test -f \"$author_script\"\n-\t\tthen\n-\t\t\tgpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote \"$gpg_sign_opt\")}\n-\t\t\tdie \"$(eval_gettext \"\\\n-You have staged changes in your working tree.\n-If these changes are meant to be\n-squashed into the previous commit, run:\n-\n-  git commit --amend \\$gpg_sign_opt_quoted\n-\n-If they are meant to go into a new commit, run:\n-\n-  git commit \\$gpg_sign_opt_quoted\n-\n-In both cases, once you're done, continue with:\n-\n-  git rebase --continue\n-\")\"\n-\t\tfi\n-\t\t. \"$author_script\" ||\n-\t\t\tdie \"$(gettext \"Error trying to find the author identity to amend commit\")\"\n-\t\tif test -f \"$amend\"\n-\t\tthen\n-\t\t\tcurrent_head=$(git rev-parse --verify HEAD)\n-\t\t\ttest \"$current_head\" = $(cat \"$amend\") ||\n-\t\t\tdie \"$(gettext \"\\\n-You have uncommitted changes in your working tree. Please commit them\n-first and then run 'git rebase --continue' again.\")\"\n-\t\t\tdo_with_author git commit --amend --no-verify -F \"$msg\" -e \\\n-\t\t\t\t${gpg_sign_opt:+\"$gpg_sign_opt\"} $allow_empty_message ||\n-\t\t\t\tdie \"$(gettext \"Could not commit staged changes.\")\"\n-\t\telse\n-\t\t\tdo_with_author git commit --no-verify -F \"$msg\" -e \\\n-\t\t\t\t${gpg_sign_opt:+\"$gpg_sign_opt\"} $allow_empty_message ||\n-\t\t\t\tdie \"$(gettext \"Could not commit staged changes.\")\"\n-\t\tfi\n-\tfi\n-\n-\tif test -r \"$state_dir\"/stopped-sha\n-\tthen\n-\t\trecord_in_rewritten \"$(cat \"$state_dir\"/stopped-sha)\"\n-\tfi\n-\n-\trequire_clean_work_tree \"rebase\"\n-\tdo_rest\n-\treturn 0\n-\t;;\n-skip)\n-\tgit rerere clear\n-\n-\tif test ! -d \"$rewritten\"\n-\tthen\n-\t\texec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \\\n-\t\t\t--continue\n+\tinitiate_action \"$action\"\n+\tret=$?\n+\tif test $ret = 0; then\n+\t\treturn 0\n \tfi\n-\tdo_rest\n-\treturn 0\n-\t;;\n-edit-todo)\n-\tgit stripspace --strip-comments <\"$todo\" >\"$todo\".new\n-\tmv -f \"$todo\".new \"$todo\"\n-\tcollapse_todo_ids\n-\tappend_todo_help\n-\tgettext \"\n-You are editing the todo file of an ongoing interactive rebase.\n-To continue rebase after editing, run:\n-    git rebase --continue\n-\n-\" | git stripspace --comment-lines >>\"$todo\"\n-\n-\tgit_sequence_editor \"$todo\" ||\n-\t\tdie \"$(gettext \"Could not execute editor\")\"\n-\texpand_todo_ids\n-\n-\texit\n-\t;;\n-show-current-patch)\n-\texec git show REBASE_HEAD --\n-\t;;\n-esac\n-\n-comment_for_reflog start\n-\n-if test ! -z \"$switch_to\"\n-then\n-\tGIT_REFLOG_ACTION=\"$GIT_REFLOG_ACTION: checkout $switch_to\"\n-\toutput git checkout \"$switch_to\" -- ||\n-\t\tdie \"$(eval_gettext \"Could not checkout \\$switch_to\")\"\n \n-\tcomment_for_reflog start\n-fi\n+\tsetup_reflog_action\n+\tinit_basic_state\n \n-orig_head=$(git rev-parse --verify HEAD) || die \"$(gettext \"No HEAD?\")\"\n-mkdir -p \"$state_dir\" || die \"$(eval_gettext \"Could not create temporary \\$state_dir\")\"\n-rm -f \"$(git rev-parse --git-path REBASE_HEAD)\"\n+\tmerges_option=\"--no-merges --cherry-pick\"\n \n-: > \"$state_dir\"/interactive || die \"$(gettext \"Could not mark as interactive\")\"\n-write_basic_state\n-if test t = \"$preserve_merges\"\n-then\n+\tshorthead=$(git rev-parse --short $orig_head)\n+\tshortonto=$(git rev-parse --short $onto)\n \tif test -z \"$rebase_root\"\n+\t\t# this is now equivalent to ! -z \"$upstream\"\n \tthen\n-\t\tmkdir \"$rewritten\" &&\n-\t\tfor c in $(git merge-base --all $orig_head $upstream)\n-\t\tdo\n-\t\t\techo $onto > \"$rewritten\"/$c ||\n-\t\t\t\tdie \"$(gettext \"Could not init rewritten commits\")\"\n-\t\tdone\n+\t\tshortupstream=$(git rev-parse --short $upstream)\n+\t\trevisions=$upstream...$orig_head\n+\t\tshortrevisions=$shortupstream..$shorthead\n \telse\n-\t\tmkdir \"$rewritten\" &&\n-\t\techo $onto > \"$rewritten\"/root ||\n-\t\t\tdie \"$(gettext \"Could not init rewritten commits\")\"\n+\t\trevisions=$onto...$orig_head\n+\t\tshortrevisions=$shorthead\n \tfi\n-\t# No cherry-pick because our first pass is to determine\n-\t# parents to rewrite and skipping dropped commits would\n-\t# prematurely end our probe\n-\tmerges_option=\n-else\n-\tmerges_option=\"--no-merges --cherry-pick\"\n-fi\n \n-shorthead=$(git rev-parse --short $orig_head)\n-shortonto=$(git rev-parse --short $onto)\n-if test -z \"$rebase_root\"\n-\t# this is now equivalent to ! -z \"$upstream\"\n-then\n-\tshortupstream=$(git rev-parse --short $upstream)\n-\trevisions=$upstream...$orig_head\n-\tshortrevisions=$shortupstream..$shorthead\n-else\n-\trevisions=$onto...$orig_head\n-\tshortrevisions=$shorthead\n-fi\n-if test t != \"$preserve_merges\"\n-then\n \tgit rebase--helper --make-script ${keep_empty:+--keep-empty} \\\n \t\t$revisions ${restrict_revision+^$restrict_revision} >\"$todo\" ||\n-\tdie \"$(gettext \"Could not generate todo list\")\"\n-else\n-\tformat=$(git config --get rebase.instructionFormat)\n-\t# the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse\n-\tgit rev-list $merges_option --format=\"%m%H ${format:-%s}\" \\\n-\t\t--reverse --left-right --topo-order \\\n-\t\t$revisions ${restrict_revision+^$restrict_revision} | \\\n-\t\tsed -n \"s/^>//p\" |\n-\twhile read -r sha1 rest\n-\tdo\n-\n-\t\tif test -z \"$keep_empty\" && is_empty_commit $sha1 && ! is_merge_commit $sha1\n-\t\tthen\n-\t\t\tcomment_out=\"$comment_char \"\n-\t\telse\n-\t\t\tcomment_out=\n-\t\tfi\n-\n-\t\tif test -z \"$rebase_root\"\n-\t\tthen\n-\t\t\tpreserve=t\n-\t\t\tfor p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)\n-\t\t\tdo\n-\t\t\t\tif test -f \"$rewritten\"/$p\n-\t\t\t\tthen\n-\t\t\t\t\tpreserve=f\n-\t\t\t\tfi\n-\t\t\tdone\n-\t\telse\n-\t\t\tpreserve=f\n-\t\tfi\n-\t\tif test f = \"$preserve\"\n-\t\tthen\n-\t\t\ttouch \"$rewritten\"/$sha1\n-\t\t\tprintf '%s\\n' \"${comment_out}pick $sha1 $rest\" >>\"$todo\"\n-\t\tfi\n-\tdone\n-fi\n-\n-# Watch for commits that been dropped by --cherry-pick\n-if test t = \"$preserve_merges\"\n-then\n-\tmkdir \"$dropped\"\n-\t# Save all non-cherry-picked changes\n-\tgit rev-list $revisions --left-right --cherry-pick | \\\n-\t\tsed -n \"s/^>//p\" > \"$state_dir\"/not-cherry-picks\n-\t# Now all commits and note which ones are missing in\n-\t# not-cherry-picks and hence being dropped\n-\tgit rev-list $revisions |\n-\twhile read rev\n-\tdo\n-\t\tif test -f \"$rewritten\"/$rev &&\n-\t\t   ! sane_grep \"$rev\" \"$state_dir\"/not-cherry-picks >/dev/null\n-\t\tthen\n-\t\t\t# Use -f2 because if rev-list is telling us this commit is\n-\t\t\t# not worthwhile, we don't want to track its multiple heads,\n-\t\t\t# just the history of its first-parent for others that will\n-\t\t\t# be rebasing on top of it\n-\t\t\tgit rev-list --parents -1 $rev | cut -d' ' -s -f2 > \"$dropped\"/$rev\n-\t\t\tsha1=$(git rev-list -1 $rev)\n-\t\t\tsane_grep -v \"^[a-z][a-z]* $sha1\" <\"$todo\" > \"${todo}2\" ; mv \"${todo}2\" \"$todo\"\n-\t\t\trm \"$rewritten\"/$rev\n-\t\tfi\n-\tdone\n-fi\n-\n-test -s \"$todo\" || echo noop >> \"$todo\"\n-test -z \"$autosquash\" || git rebase--helper --rearrange-squash || exit\n-test -n \"$cmd\" && git rebase--helper --add-exec-commands \"$cmd\"\n-\n-todocount=$(git stripspace --strip-comments <\"$todo\" | wc -l)\n-todocount=${todocount##* }\n-\n-cat >>\"$todo\" <<EOF\n-\n-$comment_char $(eval_ngettext \\\n-\t\"Rebase \\$shortrevisions onto \\$shortonto (\\$todocount command)\" \\\n-\t\"Rebase \\$shortrevisions onto \\$shortonto (\\$todocount commands)\" \\\n-\t\"$todocount\")\n-EOF\n-append_todo_help\n-gettext \"\n-However, if you remove everything, the rebase will be aborted.\n-\n-\" | git stripspace --comment-lines >>\"$todo\"\n-\n-if test -z \"$keep_empty\"\n-then\n-\tprintf '%s\\n' \"$comment_char $(gettext \"Note that empty commits are commented out\")\" >>\"$todo\"\n-fi\n-\n-\n-has_action \"$todo\" ||\n-\treturn 2\n-\n-cp \"$todo\" \"$todo\".backup\n-collapse_todo_ids\n-git_sequence_editor \"$todo\" ||\n-\tdie_abort \"$(gettext \"Could not execute editor\")\"\n-\n-has_action \"$todo\" ||\n-\treturn 2\n-\n-git rebase--helper --check-todo-list || {\n-\tret=$?\n-\tcheckout_onto\n-\texit $ret\n-}\n-\n-expand_todo_ids\n-\n-test -d \"$rewritten\" || test -n \"$force_rebase\" ||\n-onto=\"$(git rebase--helper --skip-unnecessary-picks)\" ||\n-die \"Could not skip unnecessary pick commands\"\n-\n-checkout_onto\n-if test -z \"$rebase_root\" && test ! -d \"$rewritten\"\n-then\n-\trequire_clean_work_tree \"rebase\"\n-\texec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \\\n-\t\t--continue\n-fi\n-do_rest\n+\t    die \"$(gettext \"Could not generate todo list\")\"\n \n+\tcomplete_action\n }\n # ... and then we call the whole thing.\n git_rebase__interactive\n-- \n2.16.2\n\n"},{"id":"342363","messageId":"CAPig+cRw4MSfcKJcgT-srCE7sDYi3qA0TrNApXBDBsgodVb3Pg@mail.gmail.com","threadId":"48102","inReplyTo":"20180320204507.12623-1-wink@saville.com","subject":"Re: [RFC PATCH 0/3] rebase-interactive","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-03-20T21:11:05Z","receivedAt":"2018-03-20T21:11:12Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Mar 20, 2018 at 4:45 PM, Wink Saville <wink@saville.com> wrote:\n> Patch 0001 creates a library of functions which can be\n> used by git-rebase--interactive and\n> git-rebase--interactive--preserve-merges. The functions are\n> those that exist in git-rebase--interactive.sh plus new\n> functions created from the body of git_rebase_interactive\n> that will be used git_rebase_interactive in the third patch\n> and git_rebase_interactive_preserve_merges in the second\n> patch. None of the functions are invoked so there is no\n> logic changes and the system builds and passes all tests\n> on travis-ci.org.\n>\n> Patch 0002 creates git-rebase--interactive--preserve-merges.sh\n> with the function git_rebase_interactive_preserve_merges. The contents\n> of the function are refactored from git_rebase_interactive and\n> uses existing and new functions in the library. A small modification\n> of git-rebase is also done to invoke the new function when the -p\n> switch is used with git-rebase. When this is applied on top of\n> 0001 the system builds and passes all tests on travis-ci.org.\n>\n> The final patch, 0003, removes all unused code from\n> git_rebase_interactive and uses the functions from the library\n> where appropriate. And, of course, when applied on top of 0002\n> the system builds and passes all tests on travis-ci.org.\n\nA problem with this approach is that it loses \"blame\" information. A\ngit-blame of git-rebase--interactive--lib.sh shows all code in that\nfile as having arisen spontaneously from thin air; it is unable to\ntrace its real history. It would be much better to actually _move_\ncode to the new file (and update callers if necessary), which would\npreserve provenance.\n\nIdeally, patches which move code around should do so verbatim (or at\nleast as close to verbatim as possible) to ease review burden.\nSometimes changes to code are needed to make it relocatable before\nmovement, in which case those changes should be made as separate\npreparatory patches, again to ease review.\n\nAs it is, without detailed spelunking, it is not immediately clear to\na reviewer which functions in git-rebase--interactive--lib.sh are\nnewly written, and which are merely moved (or moved and edited) from\ngit-rebase--interactive.sh. This shortcoming suggests that the patch\nseries could be re-worked to do the refactoring in a more piecemeal\nfashion which more clearly holds the hands of those trying to\nunderstand the changes. (For instance, one or more preparatory patches\nmay be needed to make the code relocatable, followed by verbatim code\nrelocation, possibly iterating these steps if some changes depend upon\nearlier changes, etc.)\n\nThanks.\n"},{"id":"342364","messageId":"CAKk8ispSvaAr3iRhC4X+gufeKm20AQzw9_mvuysT7SiDsZQYJw@mail.gmail.com","threadId":"48102","inReplyTo":"CAPig+cRw4MSfcKJcgT-srCE7sDYi3qA0TrNApXBDBsgodVb3Pg@mail.gmail.com","subject":"Re: [RFC PATCH 0/3] rebase-interactive","fromName":"Wink Saville","fromEmail":"wink@saville.com","sentAt":"2018-03-20T21:23:41Z","receivedAt":"2018-03-20T21:24:09Z","isPatch":true,"sender":{"key":"wink@saville.com","avatar":"https://avatars.githubusercontent.com/u/1024284?v=4"},"body":"On Tue, Mar 20, 2018 at 2:11 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> On Tue, Mar 20, 2018 at 4:45 PM, Wink Saville <wink@saville.com> wrote:\n>> Patch 0001 creates a library of functions which can be\n>> used by git-rebase--interactive and\n>> git-rebase--interactive--preserve-merges. The functions are\n>> those that exist in git-rebase--interactive.sh plus new\n>> functions created from the body of git_rebase_interactive\n>> that will be used git_rebase_interactive in the third patch\n>> and git_rebase_interactive_preserve_merges in the second\n>> patch. None of the functions are invoked so there is no\n>> logic changes and the system builds and passes all tests\n>> on travis-ci.org.\n>>\n>> Patch 0002 creates git-rebase--interactive--preserve-merges.sh\n>> with the function git_rebase_interactive_preserve_merges. The contents\n>> of the function are refactored from git_rebase_interactive and\n>> uses existing and new functions in the library. A small modification\n>> of git-rebase is also done to invoke the new function when the -p\n>> switch is used with git-rebase. When this is applied on top of\n>> 0001 the system builds and passes all tests on travis-ci.org.\n>>\n>> The final patch, 0003, removes all unused code from\n>> git_rebase_interactive and uses the functions from the library\n>> where appropriate. And, of course, when applied on top of 0002\n>> the system builds and passes all tests on travis-ci.org.\n>\n> A problem with this approach is that it loses \"blame\" information. A\n> git-blame of git-rebase--interactive--lib.sh shows all code in that\n> file as having arisen spontaneously from thin air; it is unable to\n> trace its real history. It would be much better to actually _move_\n> code to the new file (and update callers if necessary), which would\n> preserve provenance.\n>\n> Ideally, patches which move code around should do so verbatim (or at\n> least as close to verbatim as possible) to ease review burden.\n> Sometimes changes to code are needed to make it relocatable before\n> movement, in which case those changes should be made as separate\n> preparatory patches, again to ease review.\n>\n> As it is, without detailed spelunking, it is not immediately clear to\n> a reviewer which functions in git-rebase--interactive--lib.sh are\n> newly written, and which are merely moved (or moved and edited) from\n> git-rebase--interactive.sh. This shortcoming suggests that the patch\n> series could be re-worked to do the refactoring in a more piecemeal\n> fashion which more clearly holds the hands of those trying to\n> understand the changes. (For instance, one or more preparatory patches\n> may be needed to make the code relocatable, followed by verbatim code\n> relocation, possibly iterating these steps if some changes depend upon\n> earlier changes, etc.)\n>\n> Thanks.\n\nMust all intermediate commits continue build and pass tests?\n"},{"id":"342365","messageId":"CAPig+cSvvg=hXjXLKM2yYqqy=q+z_T_TVkuUJe0W=R_494CMkA@mail.gmail.com","threadId":"48102","inReplyTo":"CAKk8ispSvaAr3iRhC4X+gufeKm20AQzw9_mvuysT7SiDsZQYJw@mail.gmail.com","subject":"Re: [RFC PATCH 0/3] rebase-interactive","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-03-20T21:47:14Z","receivedAt":"2018-03-20T21:47:20Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Mar 20, 2018 at 5:23 PM, Wink Saville <wink@saville.com> wrote:\n> On Tue, Mar 20, 2018 at 2:11 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n>> A problem with this approach is that it loses \"blame\" information. A\n>> git-blame of git-rebase--interactive--lib.sh shows all code in that\n>> file as having arisen spontaneously from thin air; it is unable to\n>> trace its real history. It would be much better to actually _move_\n>> code to the new file (and update callers if necessary), which would\n>> preserve provenance.\n>>\n>> Ideally, patches which move code around should do so verbatim (or at\n>> least as close to verbatim as possible) to ease review burden.\n>> Sometimes changes to code are needed to make it relocatable before\n>> movement, in which case those changes should be made as separate\n>> preparatory patches, again to ease review.\n>>\n>> As it is, without detailed spelunking, it is not immediately clear to\n>> a reviewer which functions in git-rebase--interactive--lib.sh are\n>> newly written, and which are merely moved (or moved and edited) from\n>> git-rebase--interactive.sh. This shortcoming suggests that the patch\n>> series could be re-worked to do the refactoring in a more piecemeal\n>> fashion which more clearly holds the hands of those trying to\n>> understand the changes. (For instance, one or more preparatory patches\n>> may be needed to make the code relocatable, followed by verbatim code\n>> relocation, possibly iterating these steps if some changes depend upon\n>> earlier changes, etc.)\n>\n> Must all intermediate commits continue build and pass tests?\n\nYes, not just because it is good hygiene, but also because it\npreserves git-bisect'ability.\n"},{"id":"342376","messageId":"CAKk8ispayA9ceLLRTQJd8_h_S7VaQqSoTBKGz+GjB3EbB7WO+g@mail.gmail.com","threadId":"48102","inReplyTo":"CAPig+cSvvg=hXjXLKM2yYqqy=q+z_T_TVkuUJe0W=R_494CMkA@mail.gmail.com","subject":"Re: [RFC PATCH 0/3] rebase-interactive","fromName":"Wink Saville","fromEmail":"wink@saville.com","sentAt":"2018-03-21T03:31:13Z","receivedAt":"2018-03-21T03:31:40Z","isPatch":true,"sender":{"key":"wink@saville.com","avatar":"https://avatars.githubusercontent.com/u/1024284?v=4"},"body":"On Tue, Mar 20, 2018 at 2:47 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> On Tue, Mar 20, 2018 at 5:23 PM, Wink Saville <wink@saville.com> wrote:\n>> On Tue, Mar 20, 2018 at 2:11 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n>>> A problem with this approach is that it loses \"blame\" information. A\n>>> git-blame of git-rebase--interactive--lib.sh shows all code in that\n>>> file as having arisen spontaneously from thin air; it is unable to\n>>> trace its real history. It would be much better to actually _move_\n>>> code to the new file (and update callers if necessary), which would\n>>> preserve provenance.\n>>>\n>>> Ideally, patches which move code around should do so verbatim (or at\n>>> least as close to verbatim as possible) to ease review burden.\n>>> Sometimes changes to code are needed to make it relocatable before\n>>> movement, in which case those changes should be made as separate\n>>> preparatory patches, again to ease review.\n>>>\n>>> As it is, without detailed spelunking, it is not immediately clear to\n>>> a reviewer which functions in git-rebase--interactive--lib.sh are\n>>> newly written, and which are merely moved (or moved and edited) from\n>>> git-rebase--interactive.sh. This shortcoming suggests that the patch\n>>> series could be re-worked to do the refactoring in a more piecemeal\n>>> fashion which more clearly holds the hands of those trying to\n>>> understand the changes. (For instance, one or more preparatory patches\n>>> may be needed to make the code relocatable, followed by verbatim code\n>>> relocation, possibly iterating these steps if some changes depend upon\n>>> earlier changes, etc.)\n>>\n>> Must all intermediate commits continue build and pass tests?\n>\n> Yes, not just because it is good hygiene, but also because it\n> preserves git-bisect'ability.\n\nThat's what I figured.\n\nAnyway, I've played around and my current thoughts are to not create\nany new files and\nkeep git_rebase__interactive and the new\ngit_rebase__interactive__preserve_merges\nfunctions in git-rebase--interactive.sh.\n\nDoing that will preserve the blame for the existing functions. But if\nI do indentation\nreformating as I extract functions that will be shared between\ngit_rebase__interactive\nand git_rebase__interactive__preserve_merges then we still lose the blame\ninformation unless the \"-w\" parameter is passed to blame. I could choose to\nnot do the indentation, but that doesn't seem like a good idea.\n\nAn alternative is that we don't accept the refactoring. What I'd\nprobably do is use\nthe refactored code to figure out a fix for the bug and then back port\nthe fix to the\nexisting code.\n\nMy opinion is that to not accept \"improved\" code because we lose blame\ninformation\nis not a good trade off. Of course what I might think is \"improved\"\nothers may rightfully\nsay the refactoring is gratuitous. If that is the case than not doing\nthe refactoring is the\nright solution. I don't see a right or wong here, just a typical\nengineering trade off.\n\nThoughts or other ideas?\n"},{"id":"342396","messageId":"CAPig+cSm3kHF_hTRKutCCNsY82sE3xZfXJkQsKi+zedq9rdnPw@mail.gmail.com","threadId":"48102","inReplyTo":"CAKk8ispayA9ceLLRTQJd8_h_S7VaQqSoTBKGz+GjB3EbB7WO+g@mail.gmail.com","subject":"Re: [RFC PATCH 0/3] rebase-interactive","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-03-21T08:54:43Z","receivedAt":"2018-03-21T08:54:52Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"{cc:+junio}\n\nOn Tue, Mar 20, 2018 at 11:31 PM, Wink Saville <wink@saville.com> wrote:\n> Anyway, I've played around and my current thoughts are to not create\n> any new files and keep git_rebase__interactive and the new\n> git_rebase__interactive__preserve_merges functions in\n> git-rebase--interactive.sh. Doing that will preserve the blame for\n> the existing functions.\n\n\"blame -C\" detects code movement across files, so you needn't feel\nconstrained in that sense. (In fact, \"blame -C -C\" should detect the\ncopied -- not moved -- code in your patch 1/2, so my objection is not\nentirely valid, although \"-C -C\" is potentially much slower.)\n\nNevertheless, leaving all the code in git-rebase--interactive.sh\nsounds sensible if there is not a compelling reason to split it out,\nespecially since each refactoring (especially a big one) has the\npotential to collide with in-flight or planned topics.\n\n> But if I do indentation reformating as I extract functions that will\n> be shared between git_rebase__interactive and\n> git_rebase__interactive__preserve_merges then we still lose the\n> blame information unless the \"-w\" parameter is passed to blame. I\n> could choose to not do the indentation, but that doesn't seem like a\n> good idea.\n\nDon't worry about indentation changes during refactoring and code\nmovement; it's frequently necessary, and \"blame\" still works (with\n\"-w\", as you point out).\n\n> Thoughts or other ideas?\n\nA few...\n\nAlthough you may have the entire refactoring in your head -- you know\nwhat you moved where and why and what changes were needed to make the\nmove possible -- reviewers don't have that luxury. A nearly 1000-line\npatch, such as 1/3, which copies code (possibly verbatim or possibly\nwith edits -- reviewers don't know which) and which contains\nnewly-written code is a significant burden on reviewers. Crafting a\npatch series such that it holds the hands of reviewers by laying out\neach change in easily digested chunks helps significantly, both with\nattracting more and better reviews, and with potential buy-in that the\nchanges are worthwhile.\n\nHowever, I'm just one (potential) reviewer, and I don't want you\nwasting your time embarking on large-scale changes based upon my\ncomments before hearing from Dscho (Johannes) and Junio if such\nrefactoring is even welcome.\n"},{"id":"342429","messageId":"cover.1521653702.git.wink@saville.com","threadId":"48102","inReplyTo":"CAPig+cSm3kHF_hTRKutCCNsY82sE3xZfXJkQsKi+zedq9rdnPw@mail.gmail.com","subject":"[RFC PATCH v2 0/1] rebase-interactive: Add git_rebase__interactive__preserve_merges","fromName":"Wink Saville","fromEmail":"wink@saville.com","sentAt":"2018-03-21T17:44:37Z","receivedAt":"2018-03-21T17:44:55Z","isPatch":true,"sender":{"key":"wink@saville.com","avatar":"https://avatars.githubusercontent.com/u/1024284?v=4"},"body":"Version 2 keeps all changes in git-rebase--interactive.sh this should\nmake it easier to use blame. But there is quite a bit of refactoring\nand reformatting so using \"git blame -w\" or \"git blame -w -C -C\" is\nneeded to improve the results of blame.\n\nI can break this into several patches to have the history show the code\nmovement more directly if that is desired.\n\nWink Saville (1):\n  rebase-interactive: Add git_rebase__interactive__preserve_merges\n\n git-rebase--interactive.sh | 469 +++++++++++++++++++++++++--------------------\n git-rebase.sh              |  16 +-\n 2 files changed, 273 insertions(+), 212 deletions(-)\n\n-- \n2.16.2\n\n"},{"id":"342430","messageId":"c169a69be3c61fd1e90eaf79febccef2afdfbd3b.1521653702.git.wink@saville.com","threadId":"48102","inReplyTo":"cover.1521653702.git.wink@saville.com","subject":"[RFC PATCH v2 1/1] rebase-interactive: Add git_rebase__interactive__preserve_merges","fromName":"Wink Saville","fromEmail":"wink@saville.com","sentAt":"2018-03-21T17:44:38Z","receivedAt":"2018-03-21T17:44:58Z","isPatch":true,"sender":{"key":"wink@saville.com","avatar":"https://avatars.githubusercontent.com/u/1024284?v=4"},"body":"Refactor git_rebase__interactive__preserve_merges out of\ngit_rebase__interactive resulting in fewer conditionals making\nboth routines are simpler.\n\nChanged run_specific_rebase in git-rebase to dispatch to the appropriate\nfunction after sourcing git-rebase--interactive.\n---\n git-rebase--interactive.sh | 469 +++++++++++++++++++++++++--------------------\n git-rebase.sh              |  16 +-\n 2 files changed, 273 insertions(+), 212 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex 331c8dfea..65ff75654 100644\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -1,5 +1,7 @@\n-# This shell script fragment is sourced by git-rebase to implement\n-# its interactive mode.  \"git rebase --interactive\" makes it easy\n+#!/bin/sh\n+# This shell script fragment is sourced by git-rebase--interactive\n+# and git-rebase--interactive--preserve-merges in support of the\n+# interactive mode.  \"git rebase --interactive\" makes it easy\n # to fix up commits in the middle of a series and rearrange commits.\n #\n # Copyright (c) 2006 Johannes E. Schindelin\n@@ -7,6 +9,7 @@\n # The original idea comes from Eric W. Biederman, in\n # https://public-inbox.org/git/m1odwkyuf5.fsf_-_@ebiederm.dsl.xmission.com/\n #\n+\n # The file containing rebase commands, comments, and empty lines.\n # This file is created by \"git rebase -i\" then edited by the user.  As\n # the lines are processed, they are removed from the front of this\n@@ -125,6 +128,19 @@ comment_for_reflog () {\n \tesac\n }\n \n+setup_reflog_action () {\n+\tcomment_for_reflog start\n+\n+\tif test ! -z \"$switch_to\"\n+\tthen\n+\t\tGIT_REFLOG_ACTION=\"$GIT_REFLOG_ACTION: checkout $switch_to\"\n+\t\toutput git checkout \"$switch_to\" -- ||\n+\t\t\tdie \"$(eval_gettext \"Could not checkout \\$switch_to\")\"\n+\n+\t\tcomment_for_reflog start\n+\tfi\n+}\n+\n last_count=\n mark_action_done () {\n \tsed -e 1q < \"$todo\" >> \"$done\"\n@@ -274,7 +290,8 @@ pick_one () {\n \n \tcase \"$1\" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac\n \tcase \"$force_rebase\" in '') ;; ?*) ff= ;; esac\n-\toutput git rev-parse --verify $sha1 || die \"$(eval_gettext \"Invalid commit name: \\$sha1\")\"\n+\toutput git rev-parse --verify $sha1 ||\n+\t\tdie \"$(eval_gettext \"Invalid commit name: \\$sha1\")\"\n \n \tif is_empty_commit \"$sha1\"\n \tthen\n@@ -287,8 +304,8 @@ pick_one () {\n \t\t\t${gpg_sign_opt:+$(git rev-parse --sq-quote \"$gpg_sign_opt\")} \\\n \t\t\t\"$strategy_args\" $empty_args $ff \"$@\"\n \n-\t# If cherry-pick dies it leaves the to-be-picked commit unrecorded. Reschedule\n-\t# previous task so this commit is not lost.\n+\t# If cherry-pick dies it leaves the to-be-picked commit unrecorded.\n+\t# Reschedule previous task so this commit is not lost.\n \tret=$?\n \tcase \"$ret\" in [01]) ;; *) reschedule_last_action ;; esac\n \treturn $ret\n@@ -307,17 +324,15 @@ pick_one_preserving_merges () {\n \tesac\n \tsha1=$(git rev-parse $sha1)\n \n-\tif test -f \"$state_dir\"/current-commit\n+\tif test -f \"$state_dir\"/current-commit && test \"$fast_forward\" = t\n \tthen\n-\t\tif test \"$fast_forward\" = t\n-\t\tthen\n-\t\t\twhile read current_commit\n-\t\t\tdo\n-\t\t\t\tgit rev-parse HEAD > \"$rewritten\"/$current_commit\n-\t\t\tdone <\"$state_dir\"/current-commit\n-\t\t\trm \"$state_dir\"/current-commit ||\n-\t\t\t\tdie \"$(gettext \"Cannot write current commit's replacement sha1\")\"\n-\t\tfi\n+\t\twhile read current_commit\n+\t\tdo\n+\t\t\tgit rev-parse HEAD > \"$rewritten\"/$current_commit\n+\t\tdone <\"$state_dir\"/current-commit\n+\t\trm \"$state_dir\"/current-commit ||\n+\t\t    die \"$(gettext \\\n+\t\t\t\"Cannot write current commit's replacement sha1\")\"\n \tfi\n \n \techo $sha1 >> \"$state_dir\"/current-commit\n@@ -337,10 +352,10 @@ pick_one_preserving_merges () {\n \t\tif test -f \"$rewritten\"/$p\n \t\tthen\n \t\t\tnew_p=$(cat \"$rewritten\"/$p)\n-\n-\t\t\t# If the todo reordered commits, and our parent is marked for\n-\t\t\t# rewriting, but hasn't been gotten to yet, assume the user meant to\n-\t\t\t# drop it on top of the current HEAD\n+\t\t\t# If the todo reordered commits, and our parent is\n+\t\t\t# marked for rewriting, but hasn't been gotten to yet,\n+\t\t\t# assume the user meant to drop it on top of the\n+\t\t\t# current HEAD\n \t\t\tif test -z \"$new_p\"\n \t\t\tthen\n \t\t\t\tnew_p=$(git rev-parse HEAD)\n@@ -379,7 +394,7 @@ pick_one_preserving_merges () {\n \t\tthen\n \t\t\t# detach HEAD to current parent\n \t\t\toutput git checkout $first_parent 2> /dev/null ||\n-\t\t\t\tdie \"$(eval_gettext \"Cannot move HEAD to \\$first_parent\")\"\n+\t\t\t   die \"$(eval_gettext \"Cannot move HEAD to \\$first_parent\")\"\n \t\tfi\n \n \t\tcase \"$new_parents\" in\n@@ -553,7 +568,7 @@ do_next () {\n \tpick|p)\n \t\tcomment_for_reflog pick\n \n-\t\tmark_action_done\n+\t\tmark_action_done $sha1 \"$rest\"\n \t\tdo_pick $sha1 \"$rest\"\n \t\trecord_in_rewritten $sha1\n \t\t;;\n@@ -637,7 +652,7 @@ you are able to reword the commit.\")\"\n \t\tread -r command rest < \"$todo\"\n \t\tmark_action_done\n \t\teval_gettextln \"Executing: \\$rest\"\n-\t\t\"${SHELL:-@SHELL_PATH@}\" -c \"$rest\" # Actual execution\n+\t\t\"${SHELL:-/bin/sh}\" -c \"$rest\" # Actual execution\n \t\tstatus=$?\n \t\t# Run in subshell because require_clean_work_tree can die.\n \t\tdirty=f\n@@ -743,37 +758,38 @@ get_missing_commit_check_level () {\n \tprintf '%s' \"$check_level\" | tr 'A-Z' 'a-z'\n }\n \n-# The whole contents of this file is run by dot-sourcing it from\n-# inside a shell function.  It used to be that \"return\"s we see\n-# below were not inside any function, and expected to return\n-# to the function that dot-sourced us.\n-#\n-# However, older (9.x) versions of FreeBSD /bin/sh misbehave on such a\n-# construct and continue to run the statements that follow such a \"return\".\n-# As a work-around, we introduce an extra layer of a function\n-# here, and immediately call it after defining it.\n-git_rebase__interactive () {\n+init_basic_state () {\n+\torig_head=$(git rev-parse --verify HEAD) || die \"$(gettext \"No HEAD?\")\"\n+\tmkdir -p \"$state_dir\" || die \"$(eval_gettext \"Could not create temporary \\$state_dir\")\"\n+\trm -f \"$(git rev-parse --git-path REBASE_HEAD)\"\n \n-case \"$action\" in\n-continue)\n-\tif test ! -d \"$rewritten\"\n-\tthen\n-\t\texec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \\\n-\t\t\t--continue\n-\tfi\n-\t# do we have anything to commit?\n-\tif git diff-index --cached --quiet HEAD --\n-\tthen\n-\t\t# Nothing to commit -- skip this commit\n+\t: > \"$state_dir\"/interactive || die \"$(gettext \"Could not mark as interactive\")\"\n+\twrite_basic_state\n+}\n \n-\t\ttest ! -f \"$GIT_DIR\"/CHERRY_PICK_HEAD ||\n-\t\trm \"$GIT_DIR\"/CHERRY_PICK_HEAD ||\n-\t\tdie \"$(gettext \"Could not remove CHERRY_PICK_HEAD\")\"\n-\telse\n-\t\tif ! test -f \"$author_script\"\n+# Initiate an action which is first parameter.\n+# Returns 0 if the action was able to complete\n+# or 1 if further processing is required.\n+initiate_action () {\n+\tcase $1 in\n+\tcontinue)\n+\t\tif test ! -d \"$rewritten\"\n+\t\tthen\n+\t\t\texec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \\\n+\t\t\t\t--continue\n+\t\tfi\n+\t\t# do we have anything to commit?\n+\t\tif git diff-index --cached --quiet HEAD --\n \t\tthen\n-\t\t\tgpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote \"$gpg_sign_opt\")}\n-\t\t\tdie \"$(eval_gettext \"\\\n+\t\t\t# Nothing to commit -- skip this commit\n+\t\t\ttest ! -f \"$GIT_DIR\"/CHERRY_PICK_HEAD ||\n+\t\t\trm \"$GIT_DIR\"/CHERRY_PICK_HEAD ||\n+\t\t\tdie \"$(gettext \"Could not remove CHERRY_PICK_HEAD\")\"\n+\t\telse\n+\t\t\tif ! test -f \"$author_script\"\n+\t\t\tthen\n+\t\t\t\tgpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote \"$gpg_sign_opt\")}\n+\t\t\t\tdie \"$(eval_gettext \"\\\n You have staged changes in your working tree.\n If these changes are meant to be\n squashed into the previous commit, run:\n@@ -788,137 +804,231 @@ In both cases, once you're done, continue with:\n \n   git rebase --continue\n \")\"\n-\t\tfi\n-\t\t. \"$author_script\" ||\n-\t\t\tdie \"$(gettext \"Error trying to find the author identity to amend commit\")\"\n-\t\tif test -f \"$amend\"\n-\t\tthen\n-\t\t\tcurrent_head=$(git rev-parse --verify HEAD)\n-\t\t\ttest \"$current_head\" = $(cat \"$amend\") ||\n-\t\t\tdie \"$(gettext \"\\\n-You have uncommitted changes in your working tree. Please commit them\n-first and then run 'git rebase --continue' again.\")\"\n-\t\t\tdo_with_author git commit --amend --no-verify -F \"$msg\" -e \\\n-\t\t\t\t${gpg_sign_opt:+\"$gpg_sign_opt\"} $allow_empty_message ||\n+\t\t\tfi\n+\t\t\t. \"$author_script\" ||\n+\t\t\t\tdie \"$(gettext \"Error trying to find the author identity to amend commit\")\"\n+\t\t\tif test -f \"$amend\"\n+\t\t\tthen\n+\t\t\t\tcurrent_head=$(git rev-parse --verify HEAD)\n+\t\t\t\ttest \"$current_head\" = $(cat \"$amend\") ||\n+\t\t\t\tdie \"$(gettext \"\\\n+You have uncommitted changes in your working tree.\n+Please commit them first and then run:\n+    'git rebase --continue' again.\")\"\n+\t\t\t\tdo_with_author git commit --amend --no-verify \\\n+\t\t\t\t    -F \"$msg\" \\\n+\t\t\t\t    -e ${gpg_sign_opt:+\"$gpg_sign_opt\"} \\\n+\t\t\t\t    $allow_empty_message ||\n \t\t\t\tdie \"$(gettext \"Could not commit staged changes.\")\"\n-\t\telse\n-\t\t\tdo_with_author git commit --no-verify -F \"$msg\" -e \\\n-\t\t\t\t${gpg_sign_opt:+\"$gpg_sign_opt\"} $allow_empty_message ||\n+\t\t\telse\n+\t\t\t\tdo_with_author git commit --no-verify \\\n+\t\t\t\t    -F \"$msg\" \\\n+\t\t\t\t    -e ${gpg_sign_opt:+\"$gpg_sign_opt\"} \\\n+\t\t\t\t    $allow_empty_message ||\n \t\t\t\tdie \"$(gettext \"Could not commit staged changes.\")\"\n+\t\t\tfi\n \t\tfi\n-\tfi\n \n-\tif test -r \"$state_dir\"/stopped-sha\n-\tthen\n-\t\trecord_in_rewritten \"$(cat \"$state_dir\"/stopped-sha)\"\n-\tfi\n+\t\tif test -r \"$state_dir\"/stopped-sha\n+\t\tthen\n+\t\t\trecord_in_rewritten \"$(cat \"$state_dir\"/stopped-sha)\"\n+\t\tfi\n \n-\trequire_clean_work_tree \"rebase\"\n-\tdo_rest\n-\treturn 0\n-\t;;\n-skip)\n-\tgit rerere clear\n+\t\trequire_clean_work_tree \"rebase\"\n+\t\tdo_rest\n+\t\treturn 0 # done\n+\t\t;;\n+\tskip)\n+\t\tgit rerere clear\n \n-\tif test ! -d \"$rewritten\"\n-\tthen\n-\t\texec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \\\n-\t\t\t--continue\n-\tfi\n-\tdo_rest\n-\treturn 0\n-\t;;\n-edit-todo)\n-\tgit stripspace --strip-comments <\"$todo\" >\"$todo\".new\n-\tmv -f \"$todo\".new \"$todo\"\n-\tcollapse_todo_ids\n-\tappend_todo_help\n-\tgettext \"\n+\t\tif test ! -d \"$rewritten\"\n+\t\tthen\n+\t\t\texec git rebase--helper ${force_rebase:+--no-ff} \\\n+\t\t\t\t$allow_empty_message --continue\n+\t\tfi\n+\t\tdo_rest\n+\t\treturn 0 # done\n+\t\t;;\n+\tedit-todo)\n+\t\tgit stripspace --strip-comments <\"$todo\" >\"$todo\".new\n+\t\tmv -f \"$todo\".new \"$todo\"\n+\t\tcollapse_todo_ids\n+\t\tappend_todo_help\n+\t\tgettext \"\n You are editing the todo file of an ongoing interactive rebase.\n To continue rebase after editing, run:\n     git rebase --continue\n \n+\t\" | git stripspace --comment-lines >>\"$todo\"\n+\n+\t\tgit_sequence_editor \"$todo\" ||\n+\t\t\tdie \"$(gettext \"Could not execute editor\")\"\n+\t\texpand_todo_ids\n+\n+\t\texit\n+\t\t;;\n+\tshow-current-patch)\n+\t\texec git show REBASE_HEAD --\n+\t\t;;\n+\t*)\n+\t\treturn 1 # continue\n+\t\t;;\n+\tesac\n+}\n+\n+# Complete the action\n+complete_action() {\n+\n+\ttest -s \"$todo\" || echo noop >> \"$todo\"\n+\ttest -z \"$autosquash\" || git rebase--helper --rearrange-squash || exit\n+\ttest -n \"$cmd\" && git rebase--helper --add-exec-commands \"$cmd\"\n+\n+\ttodocount=$(git stripspace --strip-comments <\"$todo\" | wc -l)\n+\ttodocount=${todocount##* }\n+\n+\tcat >>\"$todo\" <<EOF\n+\n+$comment_char $(eval_ngettext \\\n+\t\"Rebase \\$shortrevisions onto \\$shortonto (\\$todocount command)\" \\\n+\t\"Rebase \\$shortrevisions onto \\$shortonto (\\$todocount commands)\" \\\n+\t\"$todocount\")\n+EOF\n+\n+\tappend_todo_help\n+\tgettext \"\n+However, if you remove everything, the rebase will be aborted.\n+\n \" | git stripspace --comment-lines >>\"$todo\"\n \n+\tif test -z \"$keep_empty\"\n+\tthen\n+\t\tprintf '%s\\n' \"$comment_char \\\n+\t\t    $(gettext \"Note that empty commits are commented out\")\" \\\n+\t\t    >>\"$todo\"\n+\tfi\n+\n+\thas_action \"$todo\" ||\n+\t\treturn 2\n+\n+\tcp \"$todo\" \"$todo\".backup\n+\tcollapse_todo_ids\n \tgit_sequence_editor \"$todo\" ||\n-\t\tdie \"$(gettext \"Could not execute editor\")\"\n+\t\tdie_abort \"$(gettext \"Could not execute editor\")\"\n+\n+\thas_action \"$todo\" ||\n+\t\treturn 2\n+\n+\tgit rebase--helper --check-todo-list || {\n+\t\tret=$?\n+\t\tcheckout_onto\n+\t\texit $ret\n+\t}\n+\n \texpand_todo_ids\n \n-\texit\n-\t;;\n-show-current-patch)\n-\texec git show REBASE_HEAD --\n-\t;;\n-esac\n+\ttest -d \"$rewritten\" || test -n \"$force_rebase\" ||\n+\tonto=\"$(git rebase--helper --skip-unnecessary-picks)\" ||\n+\tdie \"Could not skip unnecessary pick commands\"\n \n-comment_for_reflog start\n+\tcheckout_onto\n \n-if test ! -z \"$switch_to\"\n-then\n-\tGIT_REFLOG_ACTION=\"$GIT_REFLOG_ACTION: checkout $switch_to\"\n-\toutput git checkout \"$switch_to\" -- ||\n-\t\tdie \"$(eval_gettext \"Could not checkout \\$switch_to\")\"\n+\tif test -z \"$rebase_root\" && test ! -d \"$rewritten\"\n+\tthen\n+\t\trequire_clean_work_tree \"rebase\"\n+\t\texec git rebase--helper ${force_rebase:+--no-ff} \\\n+\t\t\t$allow_empty_message --continue\n+\telse\n+\t\tdo_rest\n+\tfi\n+}\n \n-\tcomment_for_reflog start\n-fi\n+git_rebase__interactive () {\n+\tinitiate_action \"$action\"\n+\tret=$?\n+\tif test $ret = 0; then\n+\t\treturn 0\n+\tfi\n+\n+\tsetup_reflog_action\n+\tinit_basic_state\n+\n+\tmerges_option=\"--no-merges --cherry-pick\"\n+\n+\tshorthead=$(git rev-parse --short $orig_head)\n+\tshortonto=$(git rev-parse --short $onto)\n+\tif test -z \"$rebase_root\"\n+\t\t# this is now equivalent to ! -z \"$upstream\"\n+\tthen\n+\t\tshortupstream=$(git rev-parse --short $upstream)\n+\t\trevisions=$upstream...$orig_head\n+\t\tshortrevisions=$shortupstream..$shorthead\n+\telse\n+\t\trevisions=$onto...$orig_head\n+\t\tshortrevisions=$shorthead\n+\tfi\n+\n+\tgit rebase--helper --make-script ${keep_empty:+--keep-empty} \\\n+\t\t$revisions ${restrict_revision+^$restrict_revision} >\"$todo\" ||\n+\t    die \"$(gettext \"Could not generate todo list\")\"\n+\n+\tcomplete_action\n+}\n+\n+git_rebase__interactive__preserve_merges () {\n+\tinitiate_action \"$action\"\n+\tret=$?\n+\tif test $ret == 0; then\n+\t\treturn 0\n+\tfi\n \n-orig_head=$(git rev-parse --verify HEAD) || die \"$(gettext \"No HEAD?\")\"\n-mkdir -p \"$state_dir\" || die \"$(eval_gettext \"Could not create temporary \\$state_dir\")\"\n-rm -f \"$(git rev-parse --git-path REBASE_HEAD)\"\n+\tsetup_reflog_action\n+\tinit_basic_state\n \n-: > \"$state_dir\"/interactive || die \"$(gettext \"Could not mark as interactive\")\"\n-write_basic_state\n-if test t = \"$preserve_merges\"\n-then\n \tif test -z \"$rebase_root\"\n \tthen\n \t\tmkdir \"$rewritten\" &&\n \t\tfor c in $(git merge-base --all $orig_head $upstream)\n \t\tdo\n \t\t\techo $onto > \"$rewritten\"/$c ||\n-\t\t\t\tdie \"$(gettext \"Could not init rewritten commits\")\"\n+\t\t\t    die \"$(gettext \"Could not init rewritten commits\")\"\n \t\tdone\n \telse\n \t\tmkdir \"$rewritten\" &&\n \t\techo $onto > \"$rewritten\"/root ||\n \t\t\tdie \"$(gettext \"Could not init rewritten commits\")\"\n \tfi\n+\n \t# No cherry-pick because our first pass is to determine\n \t# parents to rewrite and skipping dropped commits would\n \t# prematurely end our probe\n \tmerges_option=\n-else\n-\tmerges_option=\"--no-merges --cherry-pick\"\n-fi\n-\n-shorthead=$(git rev-parse --short $orig_head)\n-shortonto=$(git rev-parse --short $onto)\n-if test -z \"$rebase_root\"\n-\t# this is now equivalent to ! -z \"$upstream\"\n-then\n-\tshortupstream=$(git rev-parse --short $upstream)\n-\trevisions=$upstream...$orig_head\n-\tshortrevisions=$shortupstream..$shorthead\n-else\n-\trevisions=$onto...$orig_head\n-\tshortrevisions=$shorthead\n-fi\n-if test t != \"$preserve_merges\"\n-then\n-\tgit rebase--helper --make-script ${keep_empty:+--keep-empty} \\\n-\t\t$revisions ${restrict_revision+^$restrict_revision} >\"$todo\" ||\n-\tdie \"$(gettext \"Could not generate todo list\")\"\n-else\n+\n+\tshorthead=$(git rev-parse --short $orig_head)\n+\tshortonto=$(git rev-parse --short $onto)\n+\tif test -z \"$rebase_root\"\n+\t\t# this is now equivalent to ! -z \"$upstream\"\n+\tthen\n+\t\tshortupstream=$(git rev-parse --short $upstream)\n+\t\trevisions=$upstream...$orig_head\n+\t\tshortrevisions=$shortupstream..$shorthead\n+\telse\n+\t\trevisions=$onto...$orig_head\n+\t\tshortrevisions=$shorthead\n+\tfi\n+\n+\t# The 'rev-list .. | sed'\n+\t#   requires %m to parse; where as the the instruction\n+\t#   requires %H to parse\n \tformat=$(git config --get rebase.instructionFormat)\n-\t# the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse\n \tgit rev-list $merges_option --format=\"%m%H ${format:-%s}\" \\\n \t\t--reverse --left-right --topo-order \\\n \t\t$revisions ${restrict_revision+^$restrict_revision} | \\\n \t\tsed -n \"s/^>//p\" |\n \twhile read -r sha1 rest\n \tdo\n-\n-\t\tif test -z \"$keep_empty\" && is_empty_commit $sha1 && ! is_merge_commit $sha1\n+\t\tif test -z \"$keep_empty\" \\\n+\t\t\t&& is_empty_commit $sha1 \\\n+\t\t\t&& ! is_merge_commit $sha1\n \t\tthen\n \t\t\tcomment_out=\"$comment_char \"\n \t\telse\n@@ -928,7 +1038,8 @@ else\n \t\tif test -z \"$rebase_root\"\n \t\tthen\n \t\t\tpreserve=t\n-\t\t\tfor p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)\n+\t\t\tfor p in $(git rev-list --parents -1 $sha1 | \\\n+\t\t\t\tcut -d' ' -s -f2-)\n \t\t\tdo\n \t\t\t\tif test -f \"$rewritten\"/$p\n \t\t\t\tthen\n@@ -944,11 +1055,7 @@ else\n \t\t\tprintf '%s\\n' \"${comment_out}pick $sha1 $rest\" >>\"$todo\"\n \t\tfi\n \tdone\n-fi\n \n-# Watch for commits that been dropped by --cherry-pick\n-if test t = \"$preserve_merges\"\n-then\n \tmkdir \"$dropped\"\n \t# Save all non-cherry-picked changes\n \tgit rev-list $revisions --left-right --cherry-pick | \\\n@@ -961,76 +1068,18 @@ then\n \t\tif test -f \"$rewritten\"/$rev &&\n \t\t   ! sane_grep \"$rev\" \"$state_dir\"/not-cherry-picks >/dev/null\n \t\tthen\n-\t\t\t# Use -f2 because if rev-list is telling us this commit is\n-\t\t\t# not worthwhile, we don't want to track its multiple heads,\n-\t\t\t# just the history of its first-parent for others that will\n-\t\t\t# be rebasing on top of it\n-\t\t\tgit rev-list --parents -1 $rev | cut -d' ' -s -f2 > \"$dropped\"/$rev\n+\t\t\t# Use -f2 because if rev-list is telling us this commit\n+\t\t\t# is not worthwhile, we don't want to track its\n+\t\t\t# multiple heads, just the history of its first-parent\n+\t\t\t# for others that will be rebasing on top of it.\n+\t\t\tgit rev-list --parents -1 $rev | \\\n+\t\t\t\tcut -d' ' -s -f2 > \"$dropped\"/$rev\n \t\t\tsha1=$(git rev-list -1 $rev)\n-\t\t\tsane_grep -v \"^[a-z][a-z]* $sha1\" <\"$todo\" > \"${todo}2\" ; mv \"${todo}2\" \"$todo\"\n+\t\t\tsane_grep -v \"^[a-z][a-z]* $sha1\" <\"$todo\" > \"${todo}2\"\n+\t\t\tmv \"${todo}2\" \"$todo\"\n \t\t\trm \"$rewritten\"/$rev\n \t\tfi\n \tdone\n-fi\n-\n-test -s \"$todo\" || echo noop >> \"$todo\"\n-test -z \"$autosquash\" || git rebase--helper --rearrange-squash || exit\n-test -n \"$cmd\" && git rebase--helper --add-exec-commands \"$cmd\"\n-\n-todocount=$(git stripspace --strip-comments <\"$todo\" | wc -l)\n-todocount=${todocount##* }\n-\n-cat >>\"$todo\" <<EOF\n-\n-$comment_char $(eval_ngettext \\\n-\t\"Rebase \\$shortrevisions onto \\$shortonto (\\$todocount command)\" \\\n-\t\"Rebase \\$shortrevisions onto \\$shortonto (\\$todocount commands)\" \\\n-\t\"$todocount\")\n-EOF\n-append_todo_help\n-gettext \"\n-However, if you remove everything, the rebase will be aborted.\n-\n-\" | git stripspace --comment-lines >>\"$todo\"\n-\n-if test -z \"$keep_empty\"\n-then\n-\tprintf '%s\\n' \"$comment_char $(gettext \"Note that empty commits are commented out\")\" >>\"$todo\"\n-fi\n-\n-\n-has_action \"$todo\" ||\n-\treturn 2\n-\n-cp \"$todo\" \"$todo\".backup\n-collapse_todo_ids\n-git_sequence_editor \"$todo\" ||\n-\tdie_abort \"$(gettext \"Could not execute editor\")\"\n-\n-has_action \"$todo\" ||\n-\treturn 2\n-\n-git rebase--helper --check-todo-list || {\n-\tret=$?\n-\tcheckout_onto\n-\texit $ret\n-}\n-\n-expand_todo_ids\n-\n-test -d \"$rewritten\" || test -n \"$force_rebase\" ||\n-onto=\"$(git rebase--helper --skip-unnecessary-picks)\" ||\n-die \"Could not skip unnecessary pick commands\"\n-\n-checkout_onto\n-if test -z \"$rebase_root\" && test ! -d \"$rewritten\"\n-then\n-\trequire_clean_work_tree \"rebase\"\n-\texec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \\\n-\t\t--continue\n-fi\n-do_rest\n \n+\tcomplete_action\n }\n-# ... and then we call the whole thing.\n-git_rebase__interactive\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex a1f6e5de6..b32282f4c 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -196,8 +196,20 @@ run_specific_rebase () {\n \t\texport GIT_EDITOR\n \t\tautosquash=\n \tfi\n-\t. git-rebase--$type\n-\tret=$?\n+\tif test \"$type\" = interactive\n+\tthen\n+\t\t. git-rebase--interactive\n+\t\tif test \"$preserve_merges\" = t\n+\t\tthen\n+\t\t\tgit_rebase__interactive__preserve_merges\n+\t\telse\n+\t\t\tgit_rebase__interactive\n+\t\tfi\n+\t\tret=$?\n+\telse\n+\t\t. git-rebase--$type\n+\t\tret=$?\n+\tfi\n \tif test $ret -eq 0\n \tthen\n \t\tfinish_rebase\n-- \n2.16.2\n\n"},{"id":"342450","messageId":"xmqqy3ilnrkn.fsf@gitster-ct.c.googlers.com","threadId":"48102","inReplyTo":"c169a69be3c61fd1e90eaf79febccef2afdfbd3b.1521653702.git.wink@saville.com","subject":"Re: [RFC PATCH v2 1/1] rebase-interactive: Add git_rebase__interactive__preserve_merges","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-03-21T19:42:32Z","receivedAt":"2018-03-21T19:42:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Wink Saville <wink@saville.com> writes:\n\n> Refactor git_rebase__interactive__preserve_merges out of\n> git_rebase__interactive resulting in fewer conditionals making\n> both routines are simpler.\n>\n> Changed run_specific_rebase in git-rebase to dispatch to the appropriate\n> function after sourcing git-rebase--interactive.\n> ---\n\nI think this will become (more) reviewable if it is split into two\npatches (at least).  A preliminary patch that does the style changes\nand line wrapping (left below) as step #1, and all the rest on top\nas step #2.\n\n> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\n> index 331c8dfea..65ff75654 100644\n> --- a/git-rebase--interactive.sh\n> +++ b/git-rebase--interactive.sh\n> @@ -1,5 +1,7 @@\n> -# This shell script fragment is sourced by git-rebase to implement\n> -# its interactive mode.  \"git rebase --interactive\" makes it easy\n> +#!/bin/sh\n\nAddition of #! implies that this might be invoked as the top-level\nscript; is that the case now?  I did not get such an impression from\nthe proposed log message and it is still always dot-sourced (in\nwhich case #! gives a wrong signal to the readers).\n\n> +# This shell script fragment is sourced by git-rebase--interactive\n> +# and git-rebase--interactive--preserve-merges in support of the\n> +# interactive mode.  \"git rebase --interactive\" makes it easy\n>  # to fix up commits in the middle of a series and rearrange commits.\n>  #\n>  # Copyright (c) 2006 Johannes E. Schindelin\n> @@ -7,6 +9,7 @@\n>  # The original idea comes from Eric W. Biederman, in\n>  # https://public-inbox.org/git/m1odwkyuf5.fsf_-_@ebiederm.dsl.xmission.com/\n>  #\n> +\n>  # The file containing rebase commands, comments, and empty lines.\n\nWhy?\n\n> @@ -274,7 +290,8 @@ pick_one () {\n>  \n>  \tcase \"$1\" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac\n>  \tcase \"$force_rebase\" in '') ;; ?*) ff= ;; esac\n> -\toutput git rev-parse --verify $sha1 || die \"$(eval_gettext \"Invalid commit name: \\$sha1\")\"\n> +\toutput git rev-parse --verify $sha1 ||\n> +\t\tdie \"$(eval_gettext \"Invalid commit name: \\$sha1\")\"\n\nJust linewrapping.\n\n> @@ -287,8 +304,8 @@ pick_one () {\n>  \t\t\t${gpg_sign_opt:+$(git rev-parse --sq-quote \"$gpg_sign_opt\")} \\\n>  \t\t\t\"$strategy_args\" $empty_args $ff \"$@\"\n>  \n> -\t# If cherry-pick dies it leaves the to-be-picked commit unrecorded. Reschedule\n> -\t# previous task so this commit is not lost.\n> +\t# If cherry-pick dies it leaves the to-be-picked commit unrecorded.\n> +\t# Reschedule previous task so this commit is not lost.\n\nDitto.\n\n> @@ -307,17 +324,15 @@ pick_one_preserving_merges () {\n>  \tesac\n>  \tsha1=$(git rev-parse $sha1)\n>  \n> -\tif test -f \"$state_dir\"/current-commit\n> +\tif test -f \"$state_dir\"/current-commit && test \"$fast_forward\" = t\n>  \tthen\n> -\t\tif test \"$fast_forward\" = t\n> -\t\tthen\n> -\t\t\twhile read current_commit\n> -\t\t\tdo\n> -\t\t\t\tgit rev-parse HEAD > \"$rewritten\"/$current_commit\n> -\t\t\tdone <\"$state_dir\"/current-commit\n> -\t\t\trm \"$state_dir\"/current-commit ||\n> -\t\t\t\tdie \"$(gettext \"Cannot write current commit's replacement sha1\")\"\n> -\t\tfi\n> +\t\twhile read current_commit\n> +\t\tdo\n> +\t\t\tgit rev-parse HEAD > \"$rewritten\"/$current_commit\n> +\t\tdone <\"$state_dir\"/current-commit\n> +\t\trm \"$state_dir\"/current-commit ||\n> +\t\t    die \"$(gettext \\\n> +\t\t\t\"Cannot write current commit's replacement sha1\")\"\n>  \tfi\n\nGood code simplification that turns\n\n\tif A\n\t\tif B\n\t\t\tdo this thing\n\t\tfi\n\tfi\n\ninto\n\n\tif A & B\n\t\tdo this thing\n\tfi\n\n> @@ -337,10 +352,10 @@ pick_one_preserving_merges () {\n>  \t\tif test -f \"$rewritten\"/$p\n>  \t\tthen\n>  \t\t\tnew_p=$(cat \"$rewritten\"/$p)\n> -\n> -\t\t\t# If the todo reordered commits, and our parent is marked for\n> -\t\t\t# rewriting, but hasn't been gotten to yet, assume the user meant to\n> -\t\t\t# drop it on top of the current HEAD\n> +\t\t\t# If the todo reordered commits, and our parent is\n> +\t\t\t# marked for rewriting, but hasn't been gotten to yet,\n> +\t\t\t# assume the user meant to drop it on top of the\n> +\t\t\t# current HEAD\n\nJust line wrapping.\n\n> @@ -379,7 +394,7 @@ pick_one_preserving_merges () {\n>  \t\tthen\n>  \t\t\t# detach HEAD to current parent\n>  \t\t\toutput git checkout $first_parent 2> /dev/null ||\n> -\t\t\t\tdie \"$(eval_gettext \"Cannot move HEAD to \\$first_parent\")\"\n> +\t\t\t   die \"$(eval_gettext \"Cannot move HEAD to \\$first_parent\")\"\n>  \t\tfi\n\nDitto.\n\n> @@ -553,7 +568,7 @@ do_next () {\n>  \tpick|p)\n>  \t\tcomment_for_reflog pick\n>  \n> -\t\tmark_action_done\n> +\t\tmark_action_done $sha1 \"$rest\"\n\nThis demands more attention from the readers than all the changes we\nhave seen so far which were just line wrapping and whitespace\nchanges.  That is why it is better to leave these changes to a\nseparate patch after preliminary clean-up.  It allows reviewers'\neyes coast over the clean-up step, and then lets them focus on the\nmore \"meaningful\" changes  like this one.\n\n> @@ -637,7 +652,7 @@ you are able to reword the commit.\")\"\n>  \t\tread -r command rest < \"$todo\"\n>  \t\tmark_action_done\n>  \t\teval_gettextln \"Executing: \\$rest\"\n> -\t\t\"${SHELL:-@SHELL_PATH@}\" -c \"$rest\" # Actual execution\n> +\t\t\"${SHELL:-/bin/sh}\" -c \"$rest\" # Actual execution\n\nWhy?  This change is not justified in the proposed log message.\n\n"},{"id":"342461","messageId":"CAKk8isqopygpS0BfPi7Xa3jVTacptup-WKusZ3rzRzgU_WDaZg@mail.gmail.com","threadId":"48102","inReplyTo":"xmqqy3ilnrkn.fsf@gitster-ct.c.googlers.com","subject":"Re: [RFC PATCH v2 1/1] rebase-interactive: Add git_rebase__interactive__preserve_merges","fromName":"Wink Saville","fromEmail":"wink@saville.com","sentAt":"2018-03-21T21:49:06Z","receivedAt":"2018-03-21T21:49:34Z","isPatch":true,"sender":{"key":"wink@saville.com","avatar":"https://avatars.githubusercontent.com/u/1024284?v=4"},"body":"On Wed, Mar 21, 2018 at 12:42 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Wink Saville <wink@saville.com> writes:\n>\n>> Refactor git_rebase__interactive__preserve_merges out of\n>> git_rebase__interactive resulting in fewer conditionals making\n>> both routines are simpler.\n>>\n>> Changed run_specific_rebase in git-rebase to dispatch to the appropriate\n>> function after sourcing git-rebase--interactive.\n>> ---\n>\n> I think this will become (more) reviewable if it is split into two\n> patches (at least).  A preliminary patch that does the style changes\n> and line wrapping (left below) as step #1, and all the rest on top\n> as step #2.\n\nYes, I will break this into several commits\n\n>\n>> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\n>> index 331c8dfea..65ff75654 100644\n>> --- a/git-rebase--interactive.sh\n>> +++ b/git-rebase--interactive.sh\n>> @@ -1,5 +1,7 @@\n>> -# This shell script fragment is sourced by git-rebase to implement\n>> -# its interactive mode.  \"git rebase --interactive\" makes it easy\n>> +#!/bin/sh\n>\n> Addition of #! implies that this might be invoked as the top-level\n> script; is that the case now?  I did not get such an impression from\n> the proposed log message and it is still always dot-sourced (in\n> which case #! gives a wrong signal to the readers).\n\nWill remove adding the shebang\n\n>> +# This shell script fragment is sourced by git-rebase--interactive\n>> +# and git-rebase--interactive--preserve-merges in support of the\n>> +# interactive mode.  \"git rebase --interactive\" makes it easy\n>>  # to fix up commits in the middle of a series and rearrange commits.\n>>  #\n>>  # Copyright (c) 2006 Johannes E. Schindelin\n>> @@ -7,6 +9,7 @@\n>>  # The original idea comes from Eric W. Biederman, in\n>>  # https://public-inbox.org/git/m1odwkyuf5.fsf_-_@ebiederm.dsl.xmission.com/\n>>  #\n>> +\n>>  # The file containing rebase commands, comments, and empty lines.\n>\n> Why?\n\nWill remove the blank line.\n\n>> @@ -274,7 +290,8 @@ pick_one () {\n>>\n>>       case \"$1\" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac\n>>       case \"$force_rebase\" in '') ;; ?*) ff= ;; esac\n>> -     output git rev-parse --verify $sha1 || die \"$(eval_gettext \"Invalid commit name: \\$sha1\")\"\n>> +     output git rev-parse --verify $sha1 ||\n>> +             die \"$(eval_gettext \"Invalid commit name: \\$sha1\")\"\n>\n> Just linewrapping.\n\nWill be leaving for now\n\n>\n>> @@ -287,8 +304,8 @@ pick_one () {\n>>                       ${gpg_sign_opt:+$(git rev-parse --sq-quote \"$gpg_sign_opt\")} \\\n>>                       \"$strategy_args\" $empty_args $ff \"$@\"\n>>\n>> -     # If cherry-pick dies it leaves the to-be-picked commit unrecorded. Reschedule\n>> -     # previous task so this commit is not lost.\n>> +     # If cherry-pick dies it leaves the to-be-picked commit unrecorded.\n>> +     # Reschedule previous task so this commit is not lost.\n>\n> Ditto.\n\nWill be leaving for now\n\n>\n>> @@ -307,17 +324,15 @@ pick_one_preserving_merges () {\n>>       esac\n>>       sha1=$(git rev-parse $sha1)\n>>\n>> -     if test -f \"$state_dir\"/current-commit\n>> +     if test -f \"$state_dir\"/current-commit && test \"$fast_forward\" = t\n>>       then\n>> -             if test \"$fast_forward\" = t\n>> -             then\n>> -                     while read current_commit\n>> -                     do\n>> -                             git rev-parse HEAD > \"$rewritten\"/$current_commit\n>> -                     done <\"$state_dir\"/current-commit\n>> -                     rm \"$state_dir\"/current-commit ||\n>> -                             die \"$(gettext \"Cannot write current commit's replacement sha1\")\"\n>> -             fi\n>> +             while read current_commit\n>> +             do\n>> +                     git rev-parse HEAD > \"$rewritten\"/$current_commit\n>> +             done <\"$state_dir\"/current-commit\n>> +             rm \"$state_dir\"/current-commit ||\n>> +                 die \"$(gettext \\\n>> +                     \"Cannot write current commit's replacement sha1\")\"\n>>       fi\n>\n> Good code simplification that turns\n>\n>         if A\n>                 if B\n>                         do this thing\n>                 fi\n>         fi\n>\n> into\n>\n>         if A & B\n>                 do this thing\n>         fi\n\nWill be keeping this in a future commit\n\n>\n>> @@ -337,10 +352,10 @@ pick_one_preserving_merges () {\n>>               if test -f \"$rewritten\"/$p\n>>               then\n>>                       new_p=$(cat \"$rewritten\"/$p)\n>> -\n>> -                     # If the todo reordered commits, and our parent is marked for\n>> -                     # rewriting, but hasn't been gotten to yet, assume the user meant to\n>> -                     # drop it on top of the current HEAD\n>> +                     # If the todo reordered commits, and our parent is\n>> +                     # marked for rewriting, but hasn't been gotten to yet,\n>> +                     # assume the user meant to drop it on top of the\n>> +                     # current HEAD\n>\n> Just line wrapping.\n\nWill be leaving for now\n\n>\n>> @@ -379,7 +394,7 @@ pick_one_preserving_merges () {\n>>               then\n>>                       # detach HEAD to current parent\n>>                       output git checkout $first_parent 2> /dev/null ||\n>> -                             die \"$(eval_gettext \"Cannot move HEAD to \\$first_parent\")\"\n>> +                        die \"$(eval_gettext \"Cannot move HEAD to \\$first_parent\")\"\n>>               fi\n>\n> Ditto.\n\nWill be leaving for now\n\n>\n>> @@ -553,7 +568,7 @@ do_next () {\n>>       pick|p)\n>>               comment_for_reflog pick\n>>\n>> -             mark_action_done\n>> +             mark_action_done $sha1 \"$rest\"\n>\n> This demands more attention from the readers than all the changes we\n> have seen so far which were just line wrapping and whitespace\n> changes.  That is why it is better to leave these changes to a\n> separate patch after preliminary clean-up.  It allows reviewers'\n> eyes coast over the clean-up step, and then lets them focus on the\n> more \"meaningful\" changes  like this one.\n>\n>> @@ -637,7 +652,7 @@ you are able to reword the commit.\")\"\n>>               read -r command rest < \"$todo\"\n>>               mark_action_done\n>>               eval_gettextln \"Executing: \\$rest\"\n>> -             \"${SHELL:-@SHELL_PATH@}\" -c \"$rest\" # Actual execution\n>> +             \"${SHELL:-/bin/sh}\" -c \"$rest\" # Actual execution\n> Why?  This change is not justified in the proposed log message.\n\nLeft over from testing, will be removed.\n\n>\n\nJunio, thanks for the review.\n\nAs you suggest in v3 I'm going to break the change into several commits\nbut leave everything in one file as it is here in v2. If desired we can break\nit into several files as a last step.\n\nI'm currently contemplating not touching long lines. In this file long lines\nwere acceptable in the past and rather than introduce many changes to\nfix them I think it might be best to leave them. Also, there is a proposal\nthat a GSOC might convert one or more of the git-rebase--* files into C,\nin which case these files could be removed.\n\nBut if that doesn't come to past, I believe my goal of simplication and fixing:\n  \"not ok 24 - exchange two commits with -p # TODO known breakage\"\nIn t3404-rebase-interactive.sh is worth while.\n"},{"id":"342485","messageId":"xmqqvadpm4m0.fsf@gitster-ct.c.googlers.com","threadId":"48102","inReplyTo":"CAKk8isqopygpS0BfPi7Xa3jVTacptup-WKusZ3rzRzgU_WDaZg@mail.gmail.com","subject":"Re: [RFC PATCH v2 1/1] rebase-interactive: Add git_rebase__interactive__preserve_merges","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-03-21T22:43:51Z","receivedAt":"2018-03-21T22:44:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Wink Saville <wink@saville.com> writes:\n\n>> Good code simplification that turns\n>>\n>>         if A\n>>                 if B\n>>                         do this thing\n>>                 fi\n>>         fi\n>>\n>> into\n>>\n>>         if A & B\n>>                 do this thing\n>>         fi\n>\n> Will be keeping this in a future commit\n\nI think this one is simple enough to be in the \"prelim clean-up\"\nchange, so that you can reduce the size of the remaining stuff that\nreally needs focused review.\n\n> But if that doesn't come to past, I believe my goal of simplication and fixing:\n>   \"not ok 24 - exchange two commits with -p # TODO known breakage\"\n> In t3404-rebase-interactive.sh is worth while.\n\nOh, thanks for working on this.  \n"}]}