{"thread":{"id":"25842","subject":"[PATCH/RFC 00/20] Refactor rebase","startedAt":"2010-11-25T19:57:43Z","lastAt":"2010-11-30T07:29:05Z","messageCount":29,"participants":["Martin von Zweigbergk","Michael J Gruber","Sverre Rabbelier","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":20},"messages":[{"id":"156575","messageId":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":null,"subject":"[PATCH/RFC 00/20] Refactor rebase","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:43Z","receivedAt":"2010-11-25T19:57:43Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"This is a first draft of my attempt to refactor the rebase code. I\nhave tried to refactor it as Hannes suggested, namely \"to write a\ncommand line processor, git-rebase.sh, that sets shell variables from\noptions that it collects from various sources, then dispatches to one\nof git-rebase--interactive.sh, git-rebase--merge.sh, or\ngit-rebase--am.sh (the latter two would be stripped-down copies of the\ncurrent git-rebase.sh).\"\n\n\nPatches 01-04 try to make git-rebase.sh more readable and extensible.\n\nPatches 05-16 factor out common code between git-rebase.sh and\ngit-rebase--interactive.sh.\n\nPatches 17-20 finally achieve, I hope, what Hannes suggested.\n\n\nI have aligned a lot of the error checking and error messages, but I\nstill have barely gotten to align any of the command line options\nsupported by 'git rebase' and 'git rebase -i'. How do you think I\nshould continue? Some specific questions:\n\n1. What should -v do? Interactive rebase currently prints most\ncommands it is about to execute, while non-interactive rebase only\nprints a header to the diffstat. Is there any reason they should be\ndifferent? If not, what should they print?\n\n2. Interactive rebase currently saves most command line options when\nthe rebase is initiated and then reads then back on '--continue'\netc. Non-interactive rebase does not store any options and allows them\nto be passed on the command line when the rebase is continued\ninstead. Any reason for the difference? What do we want?\n\n\nAll feedback would be greatly appreciated! I'm new to the Git code,\nnew to development on Linux and even quite new to bash, so please\nreview very carefully. Thanks!\n\n\nMartin von Zweigbergk (20):\n  rebase: clearer names for directory variables\n  rebase: refactor reading of state\n  rebase: read state outside loop\n  rebase: remove unused rebase state 'prev_head'\n  rebase: act on command line outside parsing loop\n  rebase: collect check for existing rebase\n  rebase: stricter check on arguments\n  rebase: align variable names\n  rebase: align variable content\n  rebase: factor out command line option processing\n  rebase -i: remove now unnecessary directory checks\n  rebase: reorder validation steps\n  rebase: factor out reference parsing\n  rebase: factor out clean work tree check\n  rebase: factor out call to pre-rebase hook\n  rebase -i: support --stat\n  rebase: improve detection of rebase in progress\n  rebase -m: extract code to new source file\n  rebase: extract am code to new source file\n  rebase: show consistent conflict resolution hint\n\n .gitignore                 |    2 +\n Makefile                   |    2 +\n git-rebase--am.sh          |   34 +++\n git-rebase--interactive.sh |  554 ++++++++++++++++----------------------------\n git-rebase--merge.sh       |  154 ++++++++++++\n git-rebase.sh              |  434 ++++++++++++-----------------------\n 6 files changed, 538 insertions(+), 642 deletions(-)\n create mode 100644 git-rebase--am.sh\n create mode 100644 git-rebase--merge.sh\n\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156583","messageId":"1290715083-16919-2-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 01/20] rebase: clearer names for directory variables","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:44Z","receivedAt":"2010-11-25T19:57:44Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"Instead of using the old variable name 'dotest' for\n\"$GIT_DIR\"/rebase-merge and no variable for \"$GIT_DIR\"/rebase-apply,\nintroduce two variables 'merge_dir' and 'apply_dir' for these paths.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase.sh |  141 +++++++++++++++++++++++++++++----------------------------\n 1 files changed, 71 insertions(+), 70 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 933ca49..a529bab 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -46,7 +46,8 @@ unset newbase\n strategy=recursive\n strategy_opts=\n do_merge=\n-dotest=\"$GIT_DIR\"/rebase-merge\n+merge_dir=\"$GIT_DIR\"/rebase-merge\n+apply_dir=\"$GIT_DIR\"/rebase-apply\n prec=4\n verbose=\n diffstat=$(git config --bool rebase.stat)\n@@ -57,7 +58,7 @@ allow_rerere_autoupdate=\n \n continue_merge () {\n \ttest -n \"$prev_head\" || die \"prev_head must be defined\"\n-\ttest -d \"$dotest\" || die \"$dotest directory does not exist\"\n+\ttest -d \"$merge_dir\" || die \"$merge_dir directory does not exist\"\n \n \tunmerged=$(git ls-files -u)\n \tif test -n \"$unmerged\"\n@@ -67,7 +68,7 @@ continue_merge () {\n \t\tdie \"$RESOLVEMSG\"\n \tfi\n \n-\tcmt=`cat \"$dotest/current\"`\n+\tcmt=`cat \"$merge_dir/current\"`\n \tif ! git diff-index --quiet --ignore-submodules HEAD --\n \tthen\n \t\tif ! git commit --no-verify -C \"$cmt\"\n@@ -80,7 +81,7 @@ continue_merge () {\n \t\tthen\n \t\t\tprintf \"Committed: %0${prec}d \" $msgnum\n \t\tfi\n-\t\techo \"$cmt $(git rev-parse HEAD^0)\" >> \"$dotest/rewritten\"\n+\t\techo \"$cmt $(git rev-parse HEAD^0)\" >> \"$merge_dir/rewritten\"\n \telse\n \t\tif test -z \"$GIT_QUIET\"\n \t\tthen\n@@ -92,22 +93,22 @@ continue_merge () {\n \n \tprev_head=`git rev-parse HEAD^0`\n \t# save the resulting commit so we can read-tree on it later\n-\techo \"$prev_head\" > \"$dotest/prev_head\"\n+\techo \"$prev_head\" > \"$merge_dir/prev_head\"\n \n \t# onto the next patch:\n \tmsgnum=$(($msgnum + 1))\n-\techo \"$msgnum\" >\"$dotest/msgnum\"\n+\techo \"$msgnum\" >\"$merge_dir/msgnum\"\n }\n \n call_merge () {\n-\tcmt=\"$(cat \"$dotest/cmt.$1\")\"\n-\techo \"$cmt\" > \"$dotest/current\"\n+\tcmt=\"$(cat \"$merge_dir/cmt.$1\")\"\n+\techo \"$cmt\" > \"$merge_dir/current\"\n \thd=$(git rev-parse --verify HEAD)\n \tcmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)\n-\tmsgnum=$(cat \"$dotest/msgnum\")\n-\tend=$(cat \"$dotest/end\")\n+\tmsgnum=$(cat \"$merge_dir/msgnum\")\n+\tend=$(cat \"$merge_dir/end\")\n \teval GITHEAD_$cmt='\"${cmt_name##refs/heads/}~$(($end - $msgnum))\"'\n-\teval GITHEAD_$hd='$(cat \"$dotest/onto_name\")'\n+\teval GITHEAD_$hd='$(cat \"$merge_dir/onto_name\")'\n \texport GITHEAD_$cmt GITHEAD_$hd\n \tif test -n \"$GIT_QUIET\"\n \tthen\n@@ -137,9 +138,9 @@ call_merge () {\n \n move_to_original_branch () {\n \ttest -z \"$head_name\" &&\n-\t\thead_name=\"$(cat \"$dotest\"/head-name)\" &&\n-\t\tonto=\"$(cat \"$dotest\"/onto)\" &&\n-\t\torig_head=\"$(cat \"$dotest\"/orig-head)\"\n+\t\thead_name=\"$(cat \"$merge_dir\"/head-name)\" &&\n+\t\tonto=\"$(cat \"$merge_dir\"/onto)\" &&\n+\t\torig_head=\"$(cat \"$merge_dir\"/orig-head)\"\n \tcase \"$head_name\" in\n \trefs/*)\n \t\tmessage=\"rebase finished: $head_name onto $onto\"\n@@ -153,12 +154,12 @@ move_to_original_branch () {\n \n finish_rb_merge () {\n \tmove_to_original_branch\n-\tgit notes copy --for-rewrite=rebase < \"$dotest\"/rewritten\n+\tgit notes copy --for-rewrite=rebase < \"$merge_dir\"/rewritten\n \tif test -x \"$GIT_DIR\"/hooks/post-rewrite &&\n-\t\ttest -s \"$dotest\"/rewritten; then\n-\t\t\"$GIT_DIR\"/hooks/post-rewrite rebase < \"$dotest\"/rewritten\n+\t\ttest -s \"$merge_dir\"/rewritten; then\n+\t\t\"$GIT_DIR\"/hooks/post-rewrite rebase < \"$merge_dir\"/rewritten\n \tfi\n-\trm -r \"$dotest\"\n+\trm -r \"$merge_dir\"\n \tsay All done.\n }\n \n@@ -182,7 +183,7 @@ is_interactive () {\n \t\texport GIT_EDITOR\n \tfi\n \n-\ttest -n \"$interactive_rebase\" || test -f \"$dotest\"/interactive\n+\ttest -n \"$interactive_rebase\" || test -f \"$merge_dir\"/interactive\n }\n \n run_pre_rebase_hook () {\n@@ -194,7 +195,7 @@ run_pre_rebase_hook () {\n \tfi\n }\n \n-test -f \"$GIT_DIR\"/rebase-apply/applying &&\n+test -f \"$apply_dir\"/applying &&\n \tdie 'It looks like git-am is in progress. Cannot rebase.'\n \n is_interactive \"$@\" && exec git-rebase--interactive \"$@\"\n@@ -209,7 +210,7 @@ do\n \t\tOK_TO_SKIP_PRE_REBASE=\n \t\t;;\n \t--continue)\n-\t\ttest -d \"$dotest\" -o -d \"$GIT_DIR\"/rebase-apply ||\n+\t\ttest -d \"$merge_dir\" -o -d \"$apply_dir\" ||\n \t\t\tdie \"No rebase in progress?\"\n \n \t\tgit update-index --ignore-submodules --refresh &&\n@@ -218,13 +219,13 @@ do\n \t\t\techo \"mark them as resolved using git add\"\n \t\t\texit 1\n \t\t}\n-\t\tif test -d \"$dotest\"\n+\t\tif test -d \"$merge_dir\"\n \t\tthen\n-\t\t\tprev_head=$(cat \"$dotest/prev_head\")\n-\t\t\tend=$(cat \"$dotest/end\")\n-\t\t\tmsgnum=$(cat \"$dotest/msgnum\")\n-\t\t\tonto=$(cat \"$dotest/onto\")\n-\t\t\tGIT_QUIET=$(cat \"$dotest/quiet\")\n+\t\t\tprev_head=$(cat \"$merge_dir/prev_head\")\n+\t\t\tend=$(cat \"$merge_dir/end\")\n+\t\t\tmsgnum=$(cat \"$merge_dir/msgnum\")\n+\t\t\tonto=$(cat \"$merge_dir/onto\")\n+\t\t\tGIT_QUIET=$(cat \"$merge_dir/quiet\")\n \t\t\tcontinue_merge\n \t\t\twhile test \"$msgnum\" -le \"$end\"\n \t\t\tdo\n@@ -234,28 +235,28 @@ do\n \t\t\tfinish_rb_merge\n \t\t\texit\n \t\tfi\n-\t\thead_name=$(cat \"$GIT_DIR\"/rebase-apply/head-name) &&\n-\t\tonto=$(cat \"$GIT_DIR\"/rebase-apply/onto) &&\n-\t\torig_head=$(cat \"$GIT_DIR\"/rebase-apply/orig-head) &&\n-\t\tGIT_QUIET=$(cat \"$GIT_DIR\"/rebase-apply/quiet)\n+\t\thead_name=$(cat \"$apply_dir\"/head-name) &&\n+\t\tonto=$(cat \"$apply_dir\"/onto) &&\n+\t\torig_head=$(cat \"$apply_dir\"/orig-head) &&\n+\t\tGIT_QUIET=$(cat \"$apply_dir\"/quiet)\n \t\tgit am --resolved --3way --resolvemsg=\"$RESOLVEMSG\" &&\n \t\tmove_to_original_branch\n \t\texit\n \t\t;;\n \t--skip)\n-\t\ttest -d \"$dotest\" -o -d \"$GIT_DIR\"/rebase-apply ||\n+\t\ttest -d \"$merge_dir\" -o -d \"$apply_dir\" ||\n \t\t\tdie \"No rebase in progress?\"\n \n \t\tgit reset --hard HEAD || exit $?\n-\t\tif test -d \"$dotest\"\n+\t\tif test -d \"$merge_dir\"\n \t\tthen\n \t\t\tgit rerere clear\n-\t\t\tprev_head=$(cat \"$dotest/prev_head\")\n-\t\t\tend=$(cat \"$dotest/end\")\n-\t\t\tmsgnum=$(cat \"$dotest/msgnum\")\n+\t\t\tprev_head=$(cat \"$merge_dir/prev_head\")\n+\t\t\tend=$(cat \"$merge_dir/end\")\n+\t\t\tmsgnum=$(cat \"$merge_dir/msgnum\")\n \t\t\tmsgnum=$(($msgnum + 1))\n-\t\t\tonto=$(cat \"$dotest/onto\")\n-\t\t\tGIT_QUIET=$(cat \"$dotest/quiet\")\n+\t\t\tonto=$(cat \"$merge_dir/onto\")\n+\t\t\tGIT_QUIET=$(cat \"$merge_dir/quiet\")\n \t\t\twhile test \"$msgnum\" -le \"$end\"\n \t\t\tdo\n \t\t\t\tcall_merge \"$msgnum\"\n@@ -264,31 +265,31 @@ do\n \t\t\tfinish_rb_merge\n \t\t\texit\n \t\tfi\n-\t\thead_name=$(cat \"$GIT_DIR\"/rebase-apply/head-name) &&\n-\t\tonto=$(cat \"$GIT_DIR\"/rebase-apply/onto) &&\n-\t\torig_head=$(cat \"$GIT_DIR\"/rebase-apply/orig-head) &&\n-\t\tGIT_QUIET=$(cat \"$GIT_DIR\"/rebase-apply/quiet)\n+\t\thead_name=$(cat \"$apply_dir\"/head-name) &&\n+\t\tonto=$(cat \"$apply_dir\"/onto) &&\n+\t\torig_head=$(cat \"$apply_dir\"/orig-head) &&\n+\t\tGIT_QUIET=$(cat \"$apply_dir\"/quiet)\n \t\tgit am -3 --skip --resolvemsg=\"$RESOLVEMSG\" &&\n \t\tmove_to_original_branch\n \t\texit\n \t\t;;\n \t--abort)\n-\t\ttest -d \"$dotest\" -o -d \"$GIT_DIR\"/rebase-apply ||\n+\t\ttest -d \"$merge_dir\" -o -d \"$apply_dir\" ||\n \t\t\tdie \"No rebase in progress?\"\n \n \t\tgit rerere clear\n \n-\t\ttest -d \"$dotest\" || dotest=\"$GIT_DIR\"/rebase-apply\n+\t\ttest -d \"$merge_dir\" || merge_dir=\"$apply_dir\"\n \n-\t\thead_name=\"$(cat \"$dotest\"/head-name)\" &&\n+\t\thead_name=\"$(cat \"$merge_dir\"/head-name)\" &&\n \t\tcase \"$head_name\" in\n \t\trefs/*)\n \t\t\tgit symbolic-ref HEAD $head_name ||\n \t\t\tdie \"Could not move back to $head_name\"\n \t\t\t;;\n \t\tesac\n-\t\tgit reset --hard $(cat \"$dotest/orig-head\")\n-\t\trm -r \"$dotest\"\n+\t\tgit reset --hard $(cat \"$merge_dir/orig-head\")\n+\t\trm -r \"$merge_dir\"\n \t\texit\n \t\t;;\n \t--onto)\n@@ -387,31 +388,31 @@ test $# -gt 2 && usage\n \n if test $# -eq 0 && test -z \"$rebase_root\"\n then\n-\ttest -d \"$dotest\" -o -d \"$GIT_DIR\"/rebase-apply || usage\n-\ttest -d \"$dotest\" -o -f \"$GIT_DIR\"/rebase-apply/rebasing &&\n+\ttest -d \"$merge_dir\" -o -d \"$apply_dir\" || usage\n+\ttest -d \"$merge_dir\" -o -f \"$apply_dir\"/rebasing &&\n \t\tdie 'A rebase is in progress, try --continue, --skip or --abort.'\n fi\n \n-# Make sure we do not have $GIT_DIR/rebase-apply\n+# Make sure we do not have $apply_dir or $merge_dir\n if test -z \"$do_merge\"\n then\n-\tif mkdir \"$GIT_DIR\"/rebase-apply 2>/dev/null\n+\tif mkdir \"$apply_dir\" 2>/dev/null\n \tthen\n-\t\trmdir \"$GIT_DIR\"/rebase-apply\n+\t\trmdir \"$apply_dir\"\n \telse\n \t\techo >&2 '\n It seems that I cannot create a rebase-apply directory, and\n I wonder if you are in the middle of patch application or another\n rebase.  If that is not the case, please\n-\trm -fr '\"$GIT_DIR\"'/rebase-apply\n+\trm -fr '\"$apply_dir\"'\n and run me again.  I am stopping in case you still have something\n valuable there.'\n \t\texit 1\n \tfi\n else\n-\tif test -d \"$dotest\"\n+\tif test -d \"$merge_dir\"\n \tthen\n-\t\tdie \"previous rebase directory $dotest still exists.\" \\\n+\t\tdie \"previous rebase directory $merge_dir still exists.\" \\\n \t\t\t'Try git rebase (--continue | --abort | --skip)'\n \tfi\n fi\n@@ -559,35 +560,35 @@ then\n \tgit am $git_am_opt --rebasing --resolvemsg=\"$RESOLVEMSG\" &&\n \tmove_to_original_branch\n \tret=$?\n-\ttest 0 != $ret -a -d \"$GIT_DIR\"/rebase-apply &&\n-\t\techo $head_name > \"$GIT_DIR\"/rebase-apply/head-name &&\n-\t\techo $onto > \"$GIT_DIR\"/rebase-apply/onto &&\n-\t\techo $orig_head > \"$GIT_DIR\"/rebase-apply/orig-head &&\n-\t\techo \"$GIT_QUIET\" > \"$GIT_DIR\"/rebase-apply/quiet\n+\ttest 0 != $ret -a -d \"$apply_dir\" &&\n+\t\techo $head_name > \"$apply_dir/head-name\" &&\n+\t\techo $onto > \"$apply_dir/onto\" &&\n+\t\techo $orig_head > \"$apply_dir/orig-head\" &&\n+\t\techo \"$GIT_QUIET\" > \"$apply_dir/quiet\"\n \texit $ret\n fi\n \n # start doing a rebase with git-merge\n # this is rename-aware if the recursive (default) strategy is used\n \n-mkdir -p \"$dotest\"\n-echo \"$onto\" > \"$dotest/onto\"\n-echo \"$onto_name\" > \"$dotest/onto_name\"\n+mkdir -p \"$merge_dir\"\n+echo \"$onto\" > \"$merge_dir/onto\"\n+echo \"$onto_name\" > \"$merge_dir/onto_name\"\n prev_head=$orig_head\n-echo \"$prev_head\" > \"$dotest/prev_head\"\n-echo \"$orig_head\" > \"$dotest/orig-head\"\n-echo \"$head_name\" > \"$dotest/head-name\"\n-echo \"$GIT_QUIET\" > \"$dotest/quiet\"\n+echo \"$prev_head\" > \"$merge_dir/prev_head\"\n+echo \"$orig_head\" > \"$merge_dir/orig-head\"\n+echo \"$head_name\" > \"$merge_dir/head-name\"\n+echo \"$GIT_QUIET\" > \"$merge_dir/quiet\"\n \n msgnum=0\n for cmt in `git rev-list --reverse --no-merges \"$revisions\"`\n do\n \tmsgnum=$(($msgnum + 1))\n-\techo \"$cmt\" > \"$dotest/cmt.$msgnum\"\n+\techo \"$cmt\" > \"$merge_dir/cmt.$msgnum\"\n done\n \n-echo 1 >\"$dotest/msgnum\"\n-echo $msgnum >\"$dotest/end\"\n+echo 1 >\"$merge_dir/msgnum\"\n+echo $msgnum >\"$merge_dir/end\"\n \n end=$msgnum\n msgnum=1\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156576","messageId":"1290715083-16919-3-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 02/20] rebase: refactor reading of state","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:45Z","receivedAt":"2010-11-25T19:57:45Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"The code reading the state saved in $merge_dir or $rebase_dir is\ncurrently spread out in many places, making it harder to read and to\nintroduce additional state. Extract this code into one method that reads\nthe state.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase.sh |   53 +++++++++++++++++++++++------------------------------\n 1 files changed, 23 insertions(+), 30 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex a529bab..a325dd9 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -56,6 +56,22 @@ rebase_root=\n force_rebase=\n allow_rerere_autoupdate=\n \n+read_state () {\n+\tif test -d \"$merge_dir\"\n+\tthen\n+\t\tstate_dir=\"$merge_dir\"\n+\t\tprev_head=$(cat \"$merge_dir\"/prev_head) &&\n+\t\tend=$(cat \"$merge_dir\"/end) &&\n+\t\tmsgnum=$(cat \"$merge_dir\"/msgnum)\n+\telse\n+\t\tstate_dir=\"$apply_dir\"\n+\tfi &&\n+\thead_name=$(cat \"$state_dir\"/head-name) &&\n+\tonto=$(cat \"$state_dir\"/onto) &&\n+\torig_head=$(cat \"$state_dir\"/orig-head) &&\n+\tGIT_QUIET=$(cat \"$state_dir\"/quiet)\n+}\n+\n continue_merge () {\n \ttest -n \"$prev_head\" || die \"prev_head must be defined\"\n \ttest -d \"$merge_dir\" || die \"$merge_dir directory does not exist\"\n@@ -137,10 +153,6 @@ call_merge () {\n }\n \n move_to_original_branch () {\n-\ttest -z \"$head_name\" &&\n-\t\thead_name=\"$(cat \"$merge_dir\"/head-name)\" &&\n-\t\tonto=\"$(cat \"$merge_dir\"/onto)\" &&\n-\t\torig_head=\"$(cat \"$merge_dir\"/orig-head)\"\n \tcase \"$head_name\" in\n \trefs/*)\n \t\tmessage=\"rebase finished: $head_name onto $onto\"\n@@ -219,13 +231,9 @@ do\n \t\t\techo \"mark them as resolved using git add\"\n \t\t\texit 1\n \t\t}\n+\t\tread_state\n \t\tif test -d \"$merge_dir\"\n \t\tthen\n-\t\t\tprev_head=$(cat \"$merge_dir/prev_head\")\n-\t\t\tend=$(cat \"$merge_dir/end\")\n-\t\t\tmsgnum=$(cat \"$merge_dir/msgnum\")\n-\t\t\tonto=$(cat \"$merge_dir/onto\")\n-\t\t\tGIT_QUIET=$(cat \"$merge_dir/quiet\")\n \t\t\tcontinue_merge\n \t\t\twhile test \"$msgnum\" -le \"$end\"\n \t\t\tdo\n@@ -235,10 +243,6 @@ do\n \t\t\tfinish_rb_merge\n \t\t\texit\n \t\tfi\n-\t\thead_name=$(cat \"$apply_dir\"/head-name) &&\n-\t\tonto=$(cat \"$apply_dir\"/onto) &&\n-\t\torig_head=$(cat \"$apply_dir\"/orig-head) &&\n-\t\tGIT_QUIET=$(cat \"$apply_dir\"/quiet)\n \t\tgit am --resolved --3way --resolvemsg=\"$RESOLVEMSG\" &&\n \t\tmove_to_original_branch\n \t\texit\n@@ -248,15 +252,11 @@ do\n \t\t\tdie \"No rebase in progress?\"\n \n \t\tgit reset --hard HEAD || exit $?\n+\t\tread_state\n \t\tif test -d \"$merge_dir\"\n \t\tthen\n \t\t\tgit rerere clear\n-\t\t\tprev_head=$(cat \"$merge_dir/prev_head\")\n-\t\t\tend=$(cat \"$merge_dir/end\")\n-\t\t\tmsgnum=$(cat \"$merge_dir/msgnum\")\n \t\t\tmsgnum=$(($msgnum + 1))\n-\t\t\tonto=$(cat \"$merge_dir/onto\")\n-\t\t\tGIT_QUIET=$(cat \"$merge_dir/quiet\")\n \t\t\twhile test \"$msgnum\" -le \"$end\"\n \t\t\tdo\n \t\t\t\tcall_merge \"$msgnum\"\n@@ -265,10 +265,6 @@ do\n \t\t\tfinish_rb_merge\n \t\t\texit\n \t\tfi\n-\t\thead_name=$(cat \"$apply_dir\"/head-name) &&\n-\t\tonto=$(cat \"$apply_dir\"/onto) &&\n-\t\torig_head=$(cat \"$apply_dir\"/orig-head) &&\n-\t\tGIT_QUIET=$(cat \"$apply_dir\"/quiet)\n \t\tgit am -3 --skip --resolvemsg=\"$RESOLVEMSG\" &&\n \t\tmove_to_original_branch\n \t\texit\n@@ -278,18 +274,15 @@ do\n \t\t\tdie \"No rebase in progress?\"\n \n \t\tgit rerere clear\n-\n-\t\ttest -d \"$merge_dir\" || merge_dir=\"$apply_dir\"\n-\n-\t\thead_name=\"$(cat \"$merge_dir\"/head-name)\" &&\n+\t\tread_state\n \t\tcase \"$head_name\" in\n \t\trefs/*)\n \t\t\tgit symbolic-ref HEAD $head_name ||\n \t\t\tdie \"Could not move back to $head_name\"\n \t\t\t;;\n \t\tesac\n-\t\tgit reset --hard $(cat \"$merge_dir/orig-head\")\n-\t\trm -r \"$merge_dir\"\n+\t\tgit reset --hard $orig_head\n+\t\trm -r \"$state_dir\"\n \t\texit\n \t\t;;\n \t--onto)\n@@ -572,12 +565,12 @@ fi\n # this is rename-aware if the recursive (default) strategy is used\n \n mkdir -p \"$merge_dir\"\n-echo \"$onto\" > \"$merge_dir/onto\"\n echo \"$onto_name\" > \"$merge_dir/onto_name\"\n prev_head=$orig_head\n echo \"$prev_head\" > \"$merge_dir/prev_head\"\n-echo \"$orig_head\" > \"$merge_dir/orig-head\"\n echo \"$head_name\" > \"$merge_dir/head-name\"\n+echo \"$onto\" > \"$merge_dir/onto\"\n+echo \"$orig_head\" > \"$merge_dir/orig-head\"\n echo \"$GIT_QUIET\" > \"$merge_dir/quiet\"\n \n msgnum=0\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156577","messageId":"1290715083-16919-4-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 03/20] rebase: read state outside loop","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:46Z","receivedAt":"2010-11-25T19:57:46Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"The 'onto_name' state is used in 'git rebase --merge' is currently read\nonce for each commit that need to be applied. It doesn't change between\neach iteration, however, so it should be moved out of the loop. This also\nmakes the code more readable. Also remove the unused variable 'end'.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase.sh |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex a325dd9..b1fadb6 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -61,6 +61,7 @@ read_state () {\n \tthen\n \t\tstate_dir=\"$merge_dir\"\n \t\tprev_head=$(cat \"$merge_dir\"/prev_head) &&\n+\t\tonto_name=$(cat \"$merge_dir\"/onto_name) &&\n \t\tend=$(cat \"$merge_dir\"/end) &&\n \t\tmsgnum=$(cat \"$merge_dir\"/msgnum)\n \telse\n@@ -122,9 +123,8 @@ call_merge () {\n \thd=$(git rev-parse --verify HEAD)\n \tcmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)\n \tmsgnum=$(cat \"$merge_dir/msgnum\")\n-\tend=$(cat \"$merge_dir/end\")\n \teval GITHEAD_$cmt='\"${cmt_name##refs/heads/}~$(($end - $msgnum))\"'\n-\teval GITHEAD_$hd='$(cat \"$merge_dir/onto_name\")'\n+\teval GITHEAD_$hd='$onto_name'\n \texport GITHEAD_$cmt GITHEAD_$hd\n \tif test -n \"$GIT_QUIET\"\n \tthen\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156592","messageId":"1290715083-16919-5-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 04/20] rebase: remove unused rebase state 'prev_head'","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:47Z","receivedAt":"2010-11-25T19:57:47Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"The rebase state 'prev_head' is not used. Remove it.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase.sh |    8 --------\n 1 files changed, 0 insertions(+), 8 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex b1fadb6..aaee06b 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -60,7 +60,6 @@ read_state () {\n \tif test -d \"$merge_dir\"\n \tthen\n \t\tstate_dir=\"$merge_dir\"\n-\t\tprev_head=$(cat \"$merge_dir\"/prev_head) &&\n \t\tonto_name=$(cat \"$merge_dir\"/onto_name) &&\n \t\tend=$(cat \"$merge_dir\"/end) &&\n \t\tmsgnum=$(cat \"$merge_dir\"/msgnum)\n@@ -74,7 +73,6 @@ read_state () {\n }\n \n continue_merge () {\n-\ttest -n \"$prev_head\" || die \"prev_head must be defined\"\n \ttest -d \"$merge_dir\" || die \"$merge_dir directory does not exist\"\n \n \tunmerged=$(git ls-files -u)\n@@ -108,10 +106,6 @@ continue_merge () {\n \ttest -z \"$GIT_QUIET\" &&\n \tGIT_PAGER='' git log --format=%s -1 \"$cmt\"\n \n-\tprev_head=`git rev-parse HEAD^0`\n-\t# save the resulting commit so we can read-tree on it later\n-\techo \"$prev_head\" > \"$merge_dir/prev_head\"\n-\n \t# onto the next patch:\n \tmsgnum=$(($msgnum + 1))\n \techo \"$msgnum\" >\"$merge_dir/msgnum\"\n@@ -566,8 +560,6 @@ fi\n \n mkdir -p \"$merge_dir\"\n echo \"$onto_name\" > \"$merge_dir/onto_name\"\n-prev_head=$orig_head\n-echo \"$prev_head\" > \"$merge_dir/prev_head\"\n echo \"$head_name\" > \"$merge_dir/head-name\"\n echo \"$onto\" > \"$merge_dir/onto\"\n echo \"$orig_head\" > \"$merge_dir/orig-head\"\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156584","messageId":"1290715083-16919-6-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 05/20] rebase: act on command line outside parsing loop","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:48Z","receivedAt":"2010-11-25T19:57:48Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"To later be able to use the command line processing in git-rebase.sh for\nboth interactive and non-interactive rebases, move anything that is\nspecific to non-interactive rebase outside of the parsing loop. Keep only\nparsing and validation of command line options in the loop.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\nYou may want to try '--ignore-all-space' on this patch.\n\n git-rebase--interactive.sh |  300 ++++++++++++++++++++++----------------------\n git-rebase.sh              |  131 ++++++++++---------\n 2 files changed, 219 insertions(+), 212 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex a5ffd9a..8cbdd3f 100755\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -866,152 +866,158 @@ first and then run 'git rebase --continue' again.\"\n \t\t;;\n \t--)\n \t\tshift\n-\t\ttest -z \"$REBASE_ROOT\" -a $# -ge 1 -a $# -le 2 ||\n-\t\ttest ! -z \"$REBASE_ROOT\" -a $# -le 1 || usage\n-\t\ttest -d \"$DOTEST\" &&\n-\t\t\tdie \"Interactive rebase already started\"\n-\n-\t\tgit var GIT_COMMITTER_IDENT >/dev/null ||\n-\t\t\tdie \"You need to set your committer info first\"\n-\n-\t\tif test -z \"$REBASE_ROOT\"\n-\t\tthen\n-\t\t\tUPSTREAM_ARG=\"$1\"\n-\t\t\tUPSTREAM=$(git rev-parse --verify \"$1\") || die \"Invalid base\"\n-\t\t\ttest -z \"$ONTO\" && ONTO=$UPSTREAM\n-\t\t\tshift\n-\t\telse\n-\t\t\tUPSTREAM=\n-\t\t\tUPSTREAM_ARG=--root\n-\t\t\ttest -z \"$ONTO\" &&\n-\t\t\t\tdie \"You must specify --onto when using --root\"\n-\t\tfi\n-\t\trun_pre_rebase_hook \"$UPSTREAM_ARG\" \"$@\"\n-\n-\t\tcomment_for_reflog start\n-\n-\t\trequire_clean_work_tree \"rebase\" \"Please commit or stash them.\"\n-\n-\t\tif test ! -z \"$1\"\n-\t\tthen\n-\t\t\toutput git checkout \"$1\" ||\n-\t\t\t\tdie \"Could not checkout $1\"\n-\t\tfi\n+\t\tbreak\n+\t\t;;\n+\tesac\n+\tshift\n+done\n \n-\t\tHEAD=$(git rev-parse --verify HEAD) || die \"No HEAD?\"\n-\t\tmkdir \"$DOTEST\" || die \"Could not create temporary $DOTEST\"\n+test -z \"$REBASE_ROOT\" -a $# -ge 1 -a $# -le 2 ||\n+test ! -z \"$REBASE_ROOT\" -a $# -le 1 || usage\n+test -d \"$DOTEST\" &&\n+\tdie \"Interactive rebase already started\"\n \n-\t\t: > \"$DOTEST\"/interactive || die \"Could not mark as interactive\"\n-\t\tgit symbolic-ref HEAD > \"$DOTEST\"/head-name 2> /dev/null ||\n-\t\t\techo \"detached HEAD\" > \"$DOTEST\"/head-name\n+git var GIT_COMMITTER_IDENT >/dev/null ||\n+\tdie \"You need to set your committer info first\"\n \n-\t\techo $HEAD > \"$DOTEST\"/head\n-\t\tcase \"$REBASE_ROOT\" in\n-\t\t'')\n-\t\t\trm -f \"$DOTEST\"/rebase-root ;;\n-\t\t*)\n-\t\t\t: >\"$DOTEST\"/rebase-root ;;\n-\t\tesac\n-\t\techo $ONTO > \"$DOTEST\"/onto\n-\t\ttest -z \"$STRATEGY\" || echo \"$STRATEGY\" > \"$DOTEST\"/strategy\n-\t\ttest t = \"$VERBOSE\" && : > \"$DOTEST\"/verbose\n-\t\tif test t = \"$PRESERVE_MERGES\"\n-\t\tthen\n-\t\t\tif test -z \"$REBASE_ROOT\"\n-\t\t\tthen\n-\t\t\t\tmkdir \"$REWRITTEN\" &&\n-\t\t\t\tfor c in $(git merge-base --all $HEAD $UPSTREAM)\n-\t\t\t\tdo\n-\t\t\t\t\techo $ONTO > \"$REWRITTEN\"/$c ||\n-\t\t\t\t\t\tdie \"Could not init rewritten commits\"\n-\t\t\t\tdone\n-\t\t\telse\n-\t\t\t\tmkdir \"$REWRITTEN\" &&\n-\t\t\t\techo $ONTO > \"$REWRITTEN\"/root ||\n-\t\t\t\t\tdie \"Could not init rewritten commits\"\n-\t\t\tfi\n-\t\t\t# No cherry-pick because our first pass is to determine\n-\t\t\t# parents to rewrite and skipping dropped commits would\n-\t\t\t# prematurely end our probe\n-\t\t\tMERGES_OPTION=\n-\t\t\tfirst_after_upstream=\"$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)\"\n-\t\telse\n-\t\t\tMERGES_OPTION=\"--no-merges --cherry-pick\"\n-\t\tfi\n-\n-\t\tSHORTHEAD=$(git rev-parse --short $HEAD)\n-\t\tSHORTONTO=$(git rev-parse --short $ONTO)\n-\t\tif test -z \"$REBASE_ROOT\"\n-\t\t\t# this is now equivalent to ! -z \"$UPSTREAM\"\n-\t\tthen\n-\t\t\tSHORTUPSTREAM=$(git rev-parse --short $UPSTREAM)\n-\t\t\tREVISIONS=$UPSTREAM...$HEAD\n-\t\t\tSHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD\n-\t\telse\n-\t\t\tREVISIONS=$ONTO...$HEAD\n-\t\t\tSHORTREVISIONS=$SHORTHEAD\n-\t\tfi\n-\t\tgit rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \\\n-\t\t\t--abbrev=7 --reverse --left-right --topo-order \\\n-\t\t\t$REVISIONS | \\\n-\t\t\tsed -n \"s/^>//p\" |\n-\t\twhile read -r shortsha1 rest\n+if test -z \"$REBASE_ROOT\"\n+then\n+\tUPSTREAM_ARG=\"$1\"\n+\tUPSTREAM=$(git rev-parse --verify \"$1\") || die \"Invalid base\"\n+\ttest -z \"$ONTO\" && ONTO=$UPSTREAM\n+\tshift\n+else\n+\tUPSTREAM=\n+\tUPSTREAM_ARG=--root\n+\ttest -z \"$ONTO\" &&\n+\tdie \"You must specify --onto when using --root\"\n+fi\n+run_pre_rebase_hook \"$UPSTREAM_ARG\" \"$@\"\n+\n+comment_for_reflog start\n+\n+require_clean_work_tree \"rebase\" \"Please commit or stash them.\"\n+\n+if test ! -z \"$1\"\n+then\n+\toutput git checkout \"$1\" ||\n+\t\tdie \"Could not checkout $1\"\n+fi\n+\n+HEAD=$(git rev-parse --verify HEAD) || die \"No HEAD?\"\n+mkdir \"$DOTEST\" || die \"Could not create temporary $DOTEST\"\n+\n+: > \"$DOTEST\"/interactive || die \"Could not mark as interactive\"\n+git symbolic-ref HEAD > \"$DOTEST\"/head-name 2> /dev/null ||\n+\techo \"detached HEAD\" > \"$DOTEST\"/head-name\n+\n+echo $HEAD > \"$DOTEST\"/head\n+case \"$REBASE_ROOT\" in\n+'')\n+\trm -f \"$DOTEST\"/rebase-root ;;\n+*)\n+\t: >\"$DOTEST\"/rebase-root ;;\n+esac\n+echo $ONTO > \"$DOTEST\"/onto\n+test -z \"$STRATEGY\" || echo \"$STRATEGY\" > \"$DOTEST\"/strategy\n+test t = \"$VERBOSE\" && : > \"$DOTEST\"/verbose\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 $HEAD $UPSTREAM)\n \t\tdo\n-\t\t\tif test t != \"$PRESERVE_MERGES\"\n-\t\t\tthen\n-\t\t\t\tprintf '%s\\n' \"pick $shortsha1 $rest\" >> \"$TODO\"\n-\t\t\telse\n-\t\t\t\tsha1=$(git rev-parse $shortsha1)\n-\t\t\t\tif test -z \"$REBASE_ROOT\"\n-\t\t\t\tthen\n-\t\t\t\t\tpreserve=t\n-\t\t\t\t\tfor p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)\n-\t\t\t\t\tdo\n-\t\t\t\t\t\tif test -f \"$REWRITTEN\"/$p -a \\( $p != $ONTO -o $sha1 = $first_after_upstream \\)\n-\t\t\t\t\t\tthen\n-\t\t\t\t\t\t\tpreserve=f\n-\t\t\t\t\t\tfi\n-\t\t\t\t\tdone\n-\t\t\t\telse\n-\t\t\t\t\tpreserve=f\n-\t\t\t\tfi\n-\t\t\t\tif test f = \"$preserve\"\n-\t\t\t\tthen\n-\t\t\t\t\ttouch \"$REWRITTEN\"/$sha1\n-\t\t\t\t\tprintf '%s\\n' \"pick $shortsha1 $rest\" >> \"$TODO\"\n-\t\t\t\tfi\n-\t\t\tfi\n+\t\t\techo $ONTO > \"$REWRITTEN\"/$c ||\n+\t\t\t\tdie \"Could not init rewritten commits\"\n \t\tdone\n-\n-\t\t# Watch for commits that been dropped by --cherry-pick\n-\t\tif test t = \"$PRESERVE_MERGES\"\n+\telse\n+\t\tmkdir \"$REWRITTEN\" &&\n+\t\techo $ONTO > \"$REWRITTEN\"/root ||\n+\t\t\tdie \"Could not init rewritten commits\"\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+\tfirst_after_upstream=\"$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)\"\n+else\n+\tMERGES_OPTION=\"--no-merges --cherry-pick\"\n+fi\n+\n+SHORTHEAD=$(git rev-parse --short $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...$HEAD\n+\tSHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD\n+else\n+\tREVISIONS=$ONTO...$HEAD\n+\tSHORTREVISIONS=$SHORTHEAD\n+fi\n+git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \\\n+\t--abbrev=7 --reverse --left-right --topo-order \\\n+\t$REVISIONS | \\\n+\tsed -n \"s/^>//p\" |\n+while read -r shortsha1 rest\n+do\n+\tif test t != \"$PRESERVE_MERGES\"\n+\tthen\n+\t\tprintf '%s\\n' \"pick $shortsha1 $rest\" >> \"$TODO\"\n+\telse\n+\t\tsha1=$(git rev-parse $shortsha1)\n+\t\tif test -z \"$REBASE_ROOT\"\n \t\tthen\n-\t\t\tmkdir \"$DROPPED\"\n-\t\t\t# Save all non-cherry-picked changes\n-\t\t\tgit rev-list $REVISIONS --left-right --cherry-pick | \\\n-\t\t\t\tsed -n \"s/^>//p\" > \"$DOTEST\"/not-cherry-picks\n-\t\t\t# Now all commits and note which ones are missing in\n-\t\t\t# not-cherry-picks and hence being dropped\n-\t\t\tgit rev-list $REVISIONS |\n-\t\t\twhile read rev\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\"/$rev -a \"$(sane_grep \"$rev\" \"$DOTEST\"/not-cherry-picks)\" = \"\"\n+\t\t\t\tif test -f \"$REWRITTEN\"/$p -a \\( $p != $ONTO -o $sha1 = $first_after_upstream \\)\n \t\t\t\tthen\n-\t\t\t\t\t# Use -f2 because if rev-list is telling us this commit is\n-\t\t\t\t\t# not worthwhile, we don't want to track its multiple heads,\n-\t\t\t\t\t# just the history of its first-parent for others that will\n-\t\t\t\t\t# be rebasing on top of it\n-\t\t\t\t\tgit rev-list --parents -1 $rev | cut -d' ' -s -f2 > \"$DROPPED\"/$rev\n-\t\t\t\t\tshort=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)\n-\t\t\t\t\tsane_grep -v \"^[a-z][a-z]* $short\" <\"$TODO\" > \"${TODO}2\" ; mv \"${TODO}2\" \"$TODO\"\n-\t\t\t\t\trm \"$REWRITTEN\"/$rev\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' \"pick $shortsha1 $rest\" >> \"$TODO\"\n \t\tfi\n+\tfi\n+done\n \n-\t\ttest -s \"$TODO\" || echo noop >> \"$TODO\"\n-\t\ttest -n \"$AUTOSQUASH\" && rearrange_squash \"$TODO\"\n-\t\tcat >> \"$TODO\" << EOF\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\" > \"$DOTEST\"/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 -a \"$(sane_grep \"$rev\" \"$DOTEST\"/not-cherry-picks)\" = \"\"\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\tshort=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)\n+\t\t\tsane_grep -v \"^[a-z][a-z]* $short\" <\"$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 -n \"$AUTOSQUASH\" && rearrange_squash \"$TODO\"\n+cat >> \"$TODO\" << EOF\n \n # Rebase $SHORTREVISIONS onto $SHORTONTO\n #\n@@ -1028,22 +1034,18 @@ first and then run 'git rebase --continue' again.\"\n #\n EOF\n \n-\t\thas_action \"$TODO\" ||\n-\t\t\tdie_abort \"Nothing to do\"\n+has_action \"$TODO\" ||\n+\tdie_abort \"Nothing to do\"\n \n-\t\tcp \"$TODO\" \"$TODO\".backup\n-\t\tgit_editor \"$TODO\" ||\n-\t\t\tdie_abort \"Could not execute editor\"\n+cp \"$TODO\" \"$TODO\".backup\n+git_editor \"$TODO\" ||\n+\tdie_abort \"Could not execute editor\"\n \n-\t\thas_action \"$TODO\" ||\n-\t\t\tdie_abort \"Nothing to do\"\n+has_action \"$TODO\" ||\n+\tdie_abort \"Nothing to do\"\n \n-\t\ttest -d \"$REWRITTEN\" || test -n \"$NEVER_FF\" || skip_unnecessary_picks\n+test -d \"$REWRITTEN\" || test -n \"$NEVER_FF\" || skip_unnecessary_picks\n \n-\t\toutput git checkout $ONTO || die_abort \"could not detach HEAD\"\n-\t\tgit update-ref ORIG_HEAD $HEAD\n-\t\tdo_rest\n-\t\t;;\n-\tesac\n-\tshift\n-done\n+output git checkout $ONTO || die_abort \"could not detach HEAD\"\n+git update-ref ORIG_HEAD $HEAD\n+do_rest\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex aaee06b..52e1c6e 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -55,6 +55,7 @@ git_am_opt=\n rebase_root=\n force_rebase=\n allow_rerere_autoupdate=\n+action=\n \n read_state () {\n \tif test -d \"$merge_dir\"\n@@ -215,69 +216,10 @@ do\n \t--verify)\n \t\tOK_TO_SKIP_PRE_REBASE=\n \t\t;;\n-\t--continue)\n-\t\ttest -d \"$merge_dir\" -o -d \"$apply_dir\" ||\n-\t\t\tdie \"No rebase in progress?\"\n-\n-\t\tgit update-index --ignore-submodules --refresh &&\n-\t\tgit diff-files --quiet --ignore-submodules || {\n-\t\t\techo \"You must edit all merge conflicts and then\"\n-\t\t\techo \"mark them as resolved using git add\"\n-\t\t\texit 1\n-\t\t}\n-\t\tread_state\n-\t\tif test -d \"$merge_dir\"\n-\t\tthen\n-\t\t\tcontinue_merge\n-\t\t\twhile test \"$msgnum\" -le \"$end\"\n-\t\t\tdo\n-\t\t\t\tcall_merge \"$msgnum\"\n-\t\t\t\tcontinue_merge\n-\t\t\tdone\n-\t\t\tfinish_rb_merge\n-\t\t\texit\n-\t\tfi\n-\t\tgit am --resolved --3way --resolvemsg=\"$RESOLVEMSG\" &&\n-\t\tmove_to_original_branch\n-\t\texit\n-\t\t;;\n-\t--skip)\n-\t\ttest -d \"$merge_dir\" -o -d \"$apply_dir\" ||\n-\t\t\tdie \"No rebase in progress?\"\n-\n-\t\tgit reset --hard HEAD || exit $?\n-\t\tread_state\n-\t\tif test -d \"$merge_dir\"\n-\t\tthen\n-\t\t\tgit rerere clear\n-\t\t\tmsgnum=$(($msgnum + 1))\n-\t\t\twhile test \"$msgnum\" -le \"$end\"\n-\t\t\tdo\n-\t\t\t\tcall_merge \"$msgnum\"\n-\t\t\t\tcontinue_merge\n-\t\t\tdone\n-\t\t\tfinish_rb_merge\n-\t\t\texit\n-\t\tfi\n-\t\tgit am -3 --skip --resolvemsg=\"$RESOLVEMSG\" &&\n-\t\tmove_to_original_branch\n-\t\texit\n-\t\t;;\n-\t--abort)\n-\t\ttest -d \"$merge_dir\" -o -d \"$apply_dir\" ||\n-\t\t\tdie \"No rebase in progress?\"\n-\n-\t\tgit rerere clear\n-\t\tread_state\n-\t\tcase \"$head_name\" in\n-\t\trefs/*)\n-\t\t\tgit symbolic-ref HEAD $head_name ||\n-\t\t\tdie \"Could not move back to $head_name\"\n-\t\t\t;;\n-\t\tesac\n-\t\tgit reset --hard $orig_head\n-\t\trm -r \"$state_dir\"\n-\t\texit\n+\t--continue|--skip|--abort)\n+\t\taction=${1##--}\n+\t\tshift\n+\t\tbreak\n \t\t;;\n \t--onto)\n \t\ttest 2 -le \"$#\" || usage\n@@ -373,6 +315,69 @@ do\n done\n test $# -gt 2 && usage\n \n+if test -n \"$action\"\n+then\n+\ttest -d \"$merge_dir\" -o -d \"$apply_dir\" || die \"No rebase in progress?\"\n+fi\n+\n+case \"$action\" in\n+continue)\n+\tgit update-index --ignore-submodules --refresh &&\n+\tgit diff-files --quiet --ignore-submodules || {\n+\t\techo \"You must edit all merge conflicts and then\"\n+\t\techo \"mark them as resolved using git add\"\n+\t\texit 1\n+\t}\n+\tread_state\n+\tif test -d \"$merge_dir\"\n+\tthen\n+\t\tcontinue_merge\n+\t\twhile test \"$msgnum\" -le \"$end\"\n+\t\tdo\n+\t\t\tcall_merge \"$msgnum\"\n+\t\t\tcontinue_merge\n+\t\tdone\n+\t\tfinish_rb_merge\n+\t\texit\n+\tfi\n+\tgit am --resolved --3way --resolvemsg=\"$RESOLVEMSG\" &&\n+\tmove_to_original_branch\n+\texit\n+\t;;\n+skip)\n+\tgit reset --hard HEAD || exit $?\n+\tread_state\n+\tif test -d \"$merge_dir\"\n+\tthen\n+\t\tgit rerere clear\n+\t\tmsgnum=$(($msgnum + 1))\n+\t\twhile test \"$msgnum\" -le \"$end\"\n+\t\tdo\n+\t\t\tcall_merge \"$msgnum\"\n+\t\t\tcontinue_merge\n+\t\tdone\n+\t\tfinish_rb_merge\n+\t\texit\n+\tfi\n+\tgit am -3 --skip --resolvemsg=\"$RESOLVEMSG\" &&\n+\tmove_to_original_branch\n+\texit\n+\t;;\n+abort)\n+\tgit rerere clear\n+\tread_state\n+\tcase \"$head_name\" in\n+\trefs/*)\n+\t\tgit symbolic-ref HEAD $head_name ||\n+\t\tdie \"Could not move back to $head_name\"\n+\t\t;;\n+\tesac\n+\tgit reset --hard $orig_head\n+\trm -r \"$state_dir\"\n+\texit\n+\t;;\n+esac\n+\n if test $# -eq 0 && test -z \"$rebase_root\"\n then\n \ttest -d \"$merge_dir\" -o -d \"$apply_dir\" || usage\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156591","messageId":"1290715083-16919-7-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 06/20] rebase: collect check for existing rebase","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:49Z","receivedAt":"2010-11-25T19:57:49Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"Put the code that checks for rebase in progress in one place.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase.sh |   56 +++++++++++++++++++++++++-------------------------------\n 1 files changed, 25 insertions(+), 31 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 52e1c6e..2358e2f 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -318,6 +318,31 @@ test $# -gt 2 && usage\n if test -n \"$action\"\n then\n \ttest -d \"$merge_dir\" -o -d \"$apply_dir\" || die \"No rebase in progress?\"\n+else\n+\t# Make sure we do not have $apply_dir or $merge_dir\n+\tif test -z \"$do_merge\"\n+\tthen\n+\t\tif mkdir \"$apply_dir\" 2>/dev/null\n+\t\tthen\n+\t\t\trmdir \"$apply_dir\"\n+\t\telse\n+\t\t\techo >&2 '\n+It seems that I cannot create a rebase-apply directory, and\n+I wonder if you are in the middle of patch application or another\n+rebase.  If that is not the case, please\n+\trm -fr '\"$apply_dir\"'\n+and run me again.  I am stopping in case you still have something\n+valuable there.'\n+\t\texit 1\n+\t\tfi\n+\telse\n+\t\tif test -d \"$merge_dir\"\n+\t\tthen\n+\t\t\tdie \"previous rebase directory $merge_dir still exists.\" \\\n+\t\t\t\t'Try git rebase (--continue | --abort | --skip)'\n+\t\tfi\n+\tfi\n+\ttest $# -eq 0 && test -z \"$rebase_root\" && usage\n fi\n \n case \"$action\" in\n@@ -378,37 +403,6 @@ abort)\n \t;;\n esac\n \n-if test $# -eq 0 && test -z \"$rebase_root\"\n-then\n-\ttest -d \"$merge_dir\" -o -d \"$apply_dir\" || usage\n-\ttest -d \"$merge_dir\" -o -f \"$apply_dir\"/rebasing &&\n-\t\tdie 'A rebase is in progress, try --continue, --skip or --abort.'\n-fi\n-\n-# Make sure we do not have $apply_dir or $merge_dir\n-if test -z \"$do_merge\"\n-then\n-\tif mkdir \"$apply_dir\" 2>/dev/null\n-\tthen\n-\t\trmdir \"$apply_dir\"\n-\telse\n-\t\techo >&2 '\n-It seems that I cannot create a rebase-apply directory, and\n-I wonder if you are in the middle of patch application or another\n-rebase.  If that is not the case, please\n-\trm -fr '\"$apply_dir\"'\n-and run me again.  I am stopping in case you still have something\n-valuable there.'\n-\t\texit 1\n-\tfi\n-else\n-\tif test -d \"$merge_dir\"\n-\tthen\n-\t\tdie \"previous rebase directory $merge_dir still exists.\" \\\n-\t\t\t'Try git rebase (--continue | --abort | --skip)'\n-\tfi\n-fi\n-\n require_clean_work_tree \"rebase\" \"Please commit or stash them.\"\n \n if test -z \"$rebase_root\"\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156590","messageId":"1290715083-16919-8-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 07/20] rebase: stricter check on arguments","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:50Z","receivedAt":"2010-11-25T19:57:50Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"To align git-rebase.sh better with git-rebase--interactive.sh, be\nstricter about checking that, when used, '--continue', '--skip' and\n'--abort' is the only argument.\n\nSince $strategy and $verbose are currently saved only by interactive\nrebase, checking that they are not passed on the command line would\nbreak any existing uses of 'git rebase --strategy=<x> --continue'.\nInstead, relax the check and let the options be ignored by interactive\nrebase once refactored (the relaxation will not be effective until\nfurther refactoring, however).\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase.sh |    4 ++++\n 1 files changed, 4 insertions(+), 0 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 2358e2f..feda4be 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -317,6 +317,10 @@ test $# -gt 2 && usage\n \n if test -n \"$action\"\n then\n+\ttest $# -eq 0 &&\n+\ttest -z \"$onto\" &&\n+\ttest -z \"$preserve_merges\" ||\n+\tusage\n \ttest -d \"$merge_dir\" -o -d \"$apply_dir\" || die \"No rebase in progress?\"\n else\n \t# Make sure we do not have $apply_dir or $merge_dir\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156595","messageId":"1290715083-16919-9-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 08/20] rebase: align variable names","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:51Z","receivedAt":"2010-11-25T19:57:51Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"Use the same names for variables that git-rebase--interactive.sh will\nlater inherit from git-rebase.sh.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase--interactive.sh |  116 ++++++++++++++++++++++----------------------\n git-rebase.sh              |    8 ++--\n 2 files changed, 62 insertions(+), 62 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex 8cbdd3f..41a9eb1 100755\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -105,15 +105,15 @@ AMEND=\"$DOTEST\"/amend\n REWRITTEN_LIST=\"$DOTEST\"/rewritten-list\n REWRITTEN_PENDING=\"$DOTEST\"/rewritten-pending\n \n-PRESERVE_MERGES=\n-STRATEGY=\n-ONTO=\n-VERBOSE=\n+preserve_merges=\n+strategy=\n+onto=\n+verbose=\n OK_TO_SKIP_PRE_REBASE=\n-REBASE_ROOT=\n-AUTOSQUASH=\n-test \"$(git config --bool rebase.autosquash)\" = \"true\" && AUTOSQUASH=t\n-NEVER_FF=\n+rebase_root=\n+autosquash=\n+test \"$(git config --bool rebase.autosquash)\" = \"true\" && autosquash=t\n+force_rebase=\n \n GIT_CHERRY_PICK_HELP=\"\\\n hint: after resolving the conflicts, mark the corrected paths\n@@ -125,7 +125,7 @@ warn () {\n }\n \n output () {\n-\tcase \"$VERBOSE\" in\n+\tcase \"$verbose\" in\n \t'')\n \t\toutput=$(\"$@\" 2>&1 )\n \t\tstatus=$?\n@@ -177,7 +177,7 @@ mark_action_done () {\n \tthen\n \t\tlast_count=$count\n \t\tprintf \"Rebasing (%d/%d)\\r\" $count $total\n-\t\ttest -z \"$VERBOSE\" || echo\n+\t\ttest -z \"$verbose\" || echo\n \tfi\n }\n \n@@ -228,11 +228,11 @@ do_with_author () {\n pick_one () {\n \tff=--ff\n \tcase \"$1\" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac\n-\tcase \"$NEVER_FF\" in '') ;; ?*) ff= ;; esac\n+\tcase \"$force_rebase\" in '') ;; ?*) ff= ;; esac\n \toutput git rev-parse --verify $sha1 || die \"Invalid commit name: $sha1\"\n \ttest -d \"$REWRITTEN\" &&\n \t\tpick_one_preserving_merges \"$@\" && return\n-\tif test -n \"$REBASE_ROOT\"\n+\tif test -n \"$rebase_root\"\n \tthen\n \t\toutput git cherry-pick \"$@\"\n \t\treturn\n@@ -339,7 +339,7 @@ pick_one_preserving_merges () {\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\tif ! do_with_author output \\\n-\t\t\t\tgit merge $STRATEGY -m \"$msg\" $new_parents\n+\t\t\t\tgit merge $strategy -m \"$msg\" $new_parents\n \t\t\tthen\n \t\t\t\tprintf \"%s\\n\" \"$msg\" > \"$GIT_DIR\"/MERGE_MSG\n \t\t\t\tdie_with_patch $sha1 \"Error redoing merge $sha1\"\n@@ -618,11 +618,11 @@ skip_unnecessary_picks () {\n \t\t# fd=3 means we skip the command\n \t\tcase \"$fd,$command\" in\n \t\t3,pick|3,p)\n-\t\t\t# pick a commit whose parent is current $ONTO -> skip\n+\t\t\t# pick a commit whose parent is current $onto -> skip\n \t\t\tsha1=${rest%% *}\n \t\t\tcase \"$(git rev-parse --verify --quiet \"$sha1\"^)\" in\n-\t\t\t\"$ONTO\"*)\n-\t\t\t\tONTO=$sha1\n+\t\t\t\"$onto\"*)\n+\t\t\t\tonto=$sha1\n \t\t\t\t;;\n \t\t\t*)\n \t\t\t\tfd=1\n@@ -641,7 +641,7 @@ skip_unnecessary_picks () {\n \tmv -f \"$TODO\".new \"$TODO\" &&\n \tcase \"$(peek_next_command)\" in\n \tsquash|s|fixup|f)\n-\t\trecord_in_rewritten \"$ONTO\"\n+\t\trecord_in_rewritten \"$onto\"\n \t\t;;\n \tesac ||\n \tdie \"Could not skip unnecessary pick commands\"\n@@ -650,17 +650,17 @@ skip_unnecessary_picks () {\n # check if no other options are set\n is_standalone () {\n \ttest $# -eq 2 -a \"$2\" = '--' &&\n-\ttest -z \"$ONTO\" &&\n-\ttest -z \"$PRESERVE_MERGES\" &&\n-\ttest -z \"$STRATEGY\" &&\n-\ttest -z \"$VERBOSE\"\n+\ttest -z \"$onto\" &&\n+\ttest -z \"$preserve_merges\" &&\n+\ttest -z \"$strategy\" &&\n+\ttest -z \"$verbose\"\n }\n \n get_saved_options () {\n-\ttest -d \"$REWRITTEN\" && PRESERVE_MERGES=t\n-\ttest -f \"$DOTEST\"/strategy && STRATEGY=\"$(cat \"$DOTEST\"/strategy)\"\n-\ttest -f \"$DOTEST\"/verbose && VERBOSE=t\n-\ttest -f \"$DOTEST\"/rebase-root && REBASE_ROOT=t\n+\ttest -d \"$REWRITTEN\" && preserve_merges=t\n+\ttest -f \"$DOTEST\"/strategy && strategy=\"$(cat \"$DOTEST\"/strategy)\"\n+\ttest -f \"$DOTEST\"/verbose && verbose=t\n+\ttest -f \"$DOTEST\"/rebase-root && rebase_root=t\n }\n \n # Rearrange the todo list that has both \"pick sha1 msg\" and\n@@ -827,11 +827,11 @@ first and then run 'git rebase --continue' again.\"\n \t-s)\n \t\tcase \"$#,$1\" in\n \t\t*,*=*)\n-\t\t\tSTRATEGY=\"-s \"$(expr \"z$1\" : 'z-[^=]*=\\(.*\\)') ;;\n+\t\t\tstrategy=\"-s \"$(expr \"z$1\" : 'z-[^=]*=\\(.*\\)') ;;\n \t\t1,*)\n \t\t\tusage ;;\n \t\t*)\n-\t\t\tSTRATEGY=\"-s $2\"\n+\t\t\tstrategy=\"-s $2\"\n \t\t\tshift ;;\n \t\tesac\n \t\t;;\n@@ -839,29 +839,29 @@ first and then run 'git rebase --continue' again.\"\n \t\t# we use merge anyway\n \t\t;;\n \t-v)\n-\t\tVERBOSE=t\n+\t\tverbose=t\n \t\t;;\n \t-p)\n-\t\tPRESERVE_MERGES=t\n+\t\tpreserve_merges=t\n \t\t;;\n \t-i)\n \t\t# yeah, we know\n \t\t;;\n \t--no-ff)\n-\t\tNEVER_FF=t\n+\t\tforce_rebase=t\n \t\t;;\n \t--root)\n-\t\tREBASE_ROOT=t\n+\t\trebase_root=t\n \t\t;;\n \t--autosquash)\n-\t\tAUTOSQUASH=t\n+\t\tautosquash=t\n \t\t;;\n \t--no-autosquash)\n-\t\tAUTOSQUASH=\n+\t\tautosquash=\n \t\t;;\n \t--onto)\n \t\tshift\n-\t\tONTO=$(parse_onto \"$1\") ||\n+\t\tonto=$(parse_onto \"$1\") ||\n \t\t\tdie \"Does not point to a valid commit: $1\"\n \t\t;;\n \t--)\n@@ -872,25 +872,25 @@ first and then run 'git rebase --continue' again.\"\n \tshift\n done\n \n-test -z \"$REBASE_ROOT\" -a $# -ge 1 -a $# -le 2 ||\n-test ! -z \"$REBASE_ROOT\" -a $# -le 1 || usage\n+test -z \"$rebase_root\" -a $# -ge 1 -a $# -le 2 ||\n+test ! -z \"$rebase_root\" -a $# -le 1 || usage\n test -d \"$DOTEST\" &&\n \tdie \"Interactive rebase already started\"\n \n git var GIT_COMMITTER_IDENT >/dev/null ||\n \tdie \"You need to set your committer info first\"\n \n-if test -z \"$REBASE_ROOT\"\n+if test -z \"$rebase_root\"\n then\n \tUPSTREAM_ARG=\"$1\"\n \tUPSTREAM=$(git rev-parse --verify \"$1\") || die \"Invalid base\"\n-\ttest -z \"$ONTO\" && ONTO=$UPSTREAM\n+\ttest -z \"$onto\" && onto=$UPSTREAM\n \tshift\n else\n \tUPSTREAM=\n \tUPSTREAM_ARG=--root\n-\ttest -z \"$ONTO\" &&\n-\tdie \"You must specify --onto when using --root\"\n+\ttest -z \"$onto\" &&\n+\t\tdie \"You must specify --onto when using --root\"\n fi\n run_pre_rebase_hook \"$UPSTREAM_ARG\" \"$@\"\n \n@@ -912,28 +912,28 @@ git symbolic-ref HEAD > \"$DOTEST\"/head-name 2> /dev/null ||\n \techo \"detached HEAD\" > \"$DOTEST\"/head-name\n \n echo $HEAD > \"$DOTEST\"/head\n-case \"$REBASE_ROOT\" in\n+case \"$rebase_root\" in\n '')\n \trm -f \"$DOTEST\"/rebase-root ;;\n *)\n \t: >\"$DOTEST\"/rebase-root ;;\n esac\n-echo $ONTO > \"$DOTEST\"/onto\n-test -z \"$STRATEGY\" || echo \"$STRATEGY\" > \"$DOTEST\"/strategy\n-test t = \"$VERBOSE\" && : > \"$DOTEST\"/verbose\n-if test t = \"$PRESERVE_MERGES\"\n+echo $onto > \"$DOTEST\"/onto\n+test -z \"$strategy\" || echo \"$strategy\" > \"$DOTEST\"/strategy\n+test t = \"$verbose\" && : > \"$DOTEST\"/verbose\n+if test t = \"$preserve_merges\"\n then\n-\tif test -z \"$REBASE_ROOT\"\n+\tif test -z \"$rebase_root\"\n \tthen\n \t\tmkdir \"$REWRITTEN\" &&\n \t\tfor c in $(git merge-base --all $HEAD $UPSTREAM)\n \t\tdo\n-\t\t\techo $ONTO > \"$REWRITTEN\"/$c ||\n+\t\t\techo $onto > \"$REWRITTEN\"/$c ||\n \t\t\t\tdie \"Could not init rewritten commits\"\n \t\tdone\n \telse\n \t\tmkdir \"$REWRITTEN\" &&\n-\t\techo $ONTO > \"$REWRITTEN\"/root ||\n+\t\techo $onto > \"$REWRITTEN\"/root ||\n \t\t\tdie \"Could not init rewritten commits\"\n \tfi\n \t# No cherry-pick because our first pass is to determine\n@@ -946,15 +946,15 @@ else\n fi\n \n SHORTHEAD=$(git rev-parse --short $HEAD)\n-SHORTONTO=$(git rev-parse --short $ONTO)\n-if test -z \"$REBASE_ROOT\"\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...$HEAD\n \tSHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD\n else\n-\tREVISIONS=$ONTO...$HEAD\n+\tREVISIONS=$onto...$HEAD\n \tSHORTREVISIONS=$SHORTHEAD\n fi\n git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \\\n@@ -963,17 +963,17 @@ git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \\\n \tsed -n \"s/^>//p\" |\n while read -r shortsha1 rest\n do\n-\tif test t != \"$PRESERVE_MERGES\"\n+\tif test t != \"$preserve_merges\"\n \tthen\n \t\tprintf '%s\\n' \"pick $shortsha1 $rest\" >> \"$TODO\"\n \telse\n \t\tsha1=$(git rev-parse $shortsha1)\n-\t\tif test -z \"$REBASE_ROOT\"\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 -a \\( $p != $ONTO -o $sha1 = $first_after_upstream \\)\n+\t\t\t\tif test -f \"$REWRITTEN\"/$p -a \\( $p != $onto -o $sha1 = $first_after_upstream \\)\n \t\t\t\tthen\n \t\t\t\t\tpreserve=f\n \t\t\t\tfi\n@@ -990,7 +990,7 @@ do\n done\n \n # Watch for commits that been dropped by --cherry-pick\n-if test t = \"$PRESERVE_MERGES\"\n+if test t = \"$preserve_merges\"\n then\n \tmkdir \"$DROPPED\"\n \t# Save all non-cherry-picked changes\n@@ -1016,7 +1016,7 @@ then\n fi\n \n test -s \"$TODO\" || echo noop >> \"$TODO\"\n-test -n \"$AUTOSQUASH\" && rearrange_squash \"$TODO\"\n+test -n \"$autosquash\" && rearrange_squash \"$TODO\"\n cat >> \"$TODO\" << EOF\n \n # Rebase $SHORTREVISIONS onto $SHORTONTO\n@@ -1044,8 +1044,8 @@ git_editor \"$TODO\" ||\n has_action \"$TODO\" ||\n \tdie_abort \"Nothing to do\"\n \n-test -d \"$REWRITTEN\" || test -n \"$NEVER_FF\" || skip_unnecessary_picks\n+test -d \"$REWRITTEN\" || test -n \"$force_rebase\" || skip_unnecessary_picks\n \n-output git checkout $ONTO || die_abort \"could not detach HEAD\"\n+output git checkout $onto || die_abort \"could not detach HEAD\"\n git update-ref ORIG_HEAD $HEAD\n do_rest\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex feda4be..a5ede42 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -42,7 +42,7 @@ When you have resolved this problem run \\\"git rebase --continue\\\".\n If you would prefer to skip this patch, instead run \\\"git rebase --skip\\\".\n To restore the original branch and stop rebasing run \\\"git rebase --abort\\\".\n \"\n-unset newbase\n+unset onto\n strategy=recursive\n strategy_opts=\n do_merge=\n@@ -223,7 +223,7 @@ do\n \t\t;;\n \t--onto)\n \t\ttest 2 -le \"$#\" || usage\n-\t\tnewbase=\"$2\"\n+\t\tonto=\"$2\"\n \t\tshift\n \t\t;;\n \t-M|-m|--m|--me|--mer|--merg|--merge)\n@@ -419,7 +419,7 @@ then\n \tunset root_flag\n \tupstream_arg=\"$upstream_name\"\n else\n-\ttest -z \"$newbase\" && die \"--root must be used with --onto\"\n+\ttest -z \"$onto\" && die \"--root must be used with --onto\"\n \tunset upstream_name\n \tunset upstream\n \troot_flag=\"--root\"\n@@ -427,7 +427,7 @@ else\n fi\n \n # Make sure the branch to rebase onto is valid.\n-onto_name=${newbase-\"$upstream_name\"}\n+onto_name=${onto-\"$upstream_name\"}\n case \"$onto_name\" in\n *...*)\n \tif\tleft=${onto_name%...*} right=${onto_name#*...} &&\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156578","messageId":"1290715083-16919-10-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 09/20] rebase: align variable content","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:52Z","receivedAt":"2010-11-25T19:57:52Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"Make sure to interpret variables with the same name in the same way in\ngit-rebase.sh and git-rebase--interactive.sh\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase--interactive.sh |   14 ++++++++++----\n git-rebase.sh              |    4 +++-\n 2 files changed, 13 insertions(+), 5 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex 41a9eb1..886f80b 100755\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -827,11 +827,11 @@ first and then run 'git rebase --continue' again.\"\n \t-s)\n \t\tcase \"$#,$1\" in\n \t\t*,*=*)\n-\t\t\tstrategy=\"-s \"$(expr \"z$1\" : 'z-[^=]*=\\(.*\\)') ;;\n+\t\t\tstrategy=$(expr \"z$1\" : 'z-[^=]*=\\(.*\\)') ;;\n \t\t1,*)\n \t\t\tusage ;;\n \t\t*)\n-\t\t\tstrategy=\"-s $2\"\n+\t\t\tstrategy=\"$2\"\n \t\t\tshift ;;\n \t\tesac\n \t\t;;\n@@ -860,9 +860,9 @@ first and then run 'git rebase --continue' again.\"\n \t\tautosquash=\n \t\t;;\n \t--onto)\n+\t\ttest 2 -le \"$#\" || usage\n+\t\tonto=\"$2\"\n \t\tshift\n-\t\tonto=$(parse_onto \"$1\") ||\n-\t\t\tdie \"Does not point to a valid commit: $1\"\n \t\t;;\n \t--)\n \t\tshift\n@@ -872,6 +872,12 @@ first and then run 'git rebase --continue' again.\"\n \tshift\n done\n \n+if test -n \"$onto\"\n+then\n+\tonto=$(parse_onto \"$onto\") || die \"Does not point to a valid commit: $1\"\n+fi\n+test -n \"$strategy\" && strategy=\"-s $strategy\"\n+\n test -z \"$rebase_root\" -a $# -ge 1 -a $# -le 2 ||\n test ! -z \"$rebase_root\" -a $# -le 1 || usage\n test -d \"$DOTEST\" &&\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex a5ede42..ed1d4f5 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -43,7 +43,7 @@ If you would prefer to skip this patch, instead run \\\"git rebase --skip\\\".\n To restore the original branch and stop rebasing run \\\"git rebase --abort\\\".\n \"\n unset onto\n-strategy=recursive\n+strategy=\n strategy_opts=\n do_merge=\n merge_dir=\"$GIT_DIR\"/rebase-merge\n@@ -125,6 +125,7 @@ call_merge () {\n \tthen\n \t\tGIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY\n \tfi\n+\ttest -z \"$strategy\" && strategy=recursive\n \teval 'git-merge-$strategy' $strategy_opts '\"$cmt^\" -- \"$hd\" \"$cmt\"'\n \trv=$?\n \tcase \"$rv\" in\n@@ -245,6 +246,7 @@ do\n \t\tesac\n \t\tstrategy_opts=\"$strategy_opts $(git rev-parse --sq-quote \"--$newopt\")\"\n \t\tdo_merge=t\n+\t\ttest -z \"$strategy\" && strategy=recursive\n \t\t;;\n \t-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\\\n \t\t--strateg=*|--strategy=*|\\\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156589","messageId":"1290715083-16919-11-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 10/20] rebase: factor out command line option processing","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:53Z","receivedAt":"2010-11-25T19:57:53Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"Factor out the command line processing in git-rebase--interactive.sh\nto git-rebase.sh. Store the options in variables in git-rebase.sh and\nexport them before calling git-rebase--interactive.sh.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase--interactive.sh |  223 ++++++++++++-------------------------------\n git-rebase.sh              |   45 +++++----\n 2 files changed, 88 insertions(+), 180 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex 886f80b..6389a9f 100755\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -10,29 +10,6 @@\n # The original idea comes from Eric W. Biederman, in\n # http://article.gmane.org/gmane.comp.version-control.git/22407\n \n-OPTIONS_KEEPDASHDASH=\n-OPTIONS_SPEC=\"\\\n-git-rebase [-i] [options] [--] <upstream> [<branch>]\n-git-rebase [-i] (--continue | --abort | --skip)\n---\n- Available options are\n-v,verbose          display a diffstat of what changed upstream\n-onto=              rebase onto given branch instead of upstream\n-p,preserve-merges  try to recreate merges instead of ignoring them\n-s,strategy=        use the given merge strategy\n-no-ff              cherry-pick all commits, even if unchanged\n-m,merge            always used (no-op)\n-i,interactive      always used (no-op)\n- Actions:\n-continue           continue rebasing process\n-abort              abort rebasing process and restore original branch\n-skip               skip current patch and continue rebasing process\n-no-verify          override pre-rebase hook from stopping the operation\n-verify             allow pre-rebase hook to run\n-root               rebase all reachable commmits up to the root(s)\n-autosquash         move commits that begin with squash!/fixup! under -i\n-\"\n-\n . git-sh-setup\n require_work_tree\n \n@@ -105,16 +82,6 @@ AMEND=\"$DOTEST\"/amend\n REWRITTEN_LIST=\"$DOTEST\"/rewritten-list\n REWRITTEN_PENDING=\"$DOTEST\"/rewritten-pending\n \n-preserve_merges=\n-strategy=\n-onto=\n-verbose=\n-OK_TO_SKIP_PRE_REBASE=\n-rebase_root=\n-autosquash=\n-test \"$(git config --bool rebase.autosquash)\" = \"true\" && autosquash=t\n-force_rebase=\n-\n GIT_CHERRY_PICK_HELP=\"\\\n hint: after resolving the conflicts, mark the corrected paths\n hint: with 'git add <paths>' and run 'git rebase --continue'\"\n@@ -647,15 +614,6 @@ skip_unnecessary_picks () {\n \tdie \"Could not skip unnecessary pick commands\"\n }\n \n-# check if no other options are set\n-is_standalone () {\n-\ttest $# -eq 2 -a \"$2\" = '--' &&\n-\ttest -z \"$onto\" &&\n-\ttest -z \"$preserve_merges\" &&\n-\ttest -z \"$strategy\" &&\n-\ttest -z \"$verbose\"\n-}\n-\n get_saved_options () {\n \ttest -d \"$REWRITTEN\" && preserve_merges=t\n \ttest -f \"$DOTEST\"/strategy && strategy=\"$(cat \"$DOTEST\"/strategy)\"\n@@ -743,134 +701,77 @@ parse_onto () {\n \tgit rev-parse --verify \"$1^0\"\n }\n \n-while test $# != 0\n-do\n-\tcase \"$1\" in\n-\t--no-verify)\n-\t\tOK_TO_SKIP_PRE_REBASE=yes\n-\t\t;;\n-\t--verify)\n-\t\tOK_TO_SKIP_PRE_REBASE=\n-\t\t;;\n-\t--continue)\n-\t\tis_standalone \"$@\" || usage\n-\t\tget_saved_options\n-\t\tcomment_for_reflog continue\n-\n-\t\ttest -d \"$DOTEST\" || die \"No interactive rebase running\"\n-\n-\t\t# Sanity check\n-\t\tgit rev-parse --verify HEAD >/dev/null ||\n-\t\t\tdie \"Cannot read HEAD\"\n-\t\tgit update-index --ignore-submodules --refresh &&\n-\t\t\tgit diff-files --quiet --ignore-submodules ||\n-\t\t\tdie \"Working tree is dirty\"\n-\n-\t\t# do we have anything to commit?\n-\t\tif git diff-index --cached --quiet --ignore-submodules HEAD --\n+case \"$action\" in\n+continue)\n+\tget_saved_options\n+\tcomment_for_reflog continue\n+\n+\ttest -d \"$DOTEST\" || die \"No interactive rebase running\"\n+\n+\t# Sanity check\n+\tgit rev-parse --verify HEAD >/dev/null ||\n+\t\tdie \"Cannot read HEAD\"\n+\tgit update-index --ignore-submodules --refresh &&\n+\t\tgit diff-files --quiet --ignore-submodules ||\n+\t\tdie \"Working tree is dirty\"\n+\n+\t# do we have anything to commit?\n+\tif git diff-index --cached --quiet --ignore-submodules HEAD --\n+\tthen\n+\t\t: Nothing to commit -- skip this\n+\telse\n+\t\t. \"$AUTHOR_SCRIPT\" ||\n+\t\t\tdie \"Cannot find the author identity\"\n+\t\tamend=\n+\t\tif test -f \"$AMEND\"\n \t\tthen\n-\t\t\t: Nothing to commit -- skip this\n-\t\telse\n-\t\t\t. \"$AUTHOR_SCRIPT\" ||\n-\t\t\t\tdie \"Cannot find the author identity\"\n-\t\t\tamend=\n-\t\t\tif test -f \"$AMEND\"\n-\t\t\tthen\n-\t\t\t\tamend=$(git rev-parse --verify HEAD)\n-\t\t\t\ttest \"$amend\" = $(cat \"$AMEND\") ||\n-\t\t\t\tdie \"\\\n+\t\t\tamend=$(git rev-parse --verify HEAD)\n+\t\t\ttest \"$amend\" = $(cat \"$AMEND\") ||\n+\t\t\tdie \"\\\n You have uncommitted changes in your working tree. Please, commit them\n first and then run 'git rebase --continue' again.\"\n-\t\t\t\tgit reset --soft HEAD^ ||\n-\t\t\t\tdie \"Cannot rewind the HEAD\"\n-\t\t\tfi\n-\t\t\tdo_with_author git commit --no-verify -F \"$MSG\" -e || {\n-\t\t\t\ttest -n \"$amend\" && git reset --soft $amend\n-\t\t\t\tdie \"Could not commit staged changes.\"\n-\t\t\t}\n+\t\t\tgit reset --soft HEAD^ ||\n+\t\t\tdie \"Cannot rewind the HEAD\"\n \t\tfi\n+\t\tdo_with_author git commit --no-verify -F \"$MSG\" -e || {\n+\t\t\ttest -n \"$amend\" && git reset --soft $amend\n+\t\t\tdie \"Could not commit staged changes.\"\n+\t\t}\n+\tfi\n \n-\t\trecord_in_rewritten \"$(cat \"$DOTEST\"/stopped-sha)\"\n+\trecord_in_rewritten \"$(cat \"$DOTEST\"/stopped-sha)\"\n \n-\t\trequire_clean_work_tree \"rebase\"\n-\t\tdo_rest\n-\t\t;;\n-\t--abort)\n-\t\tis_standalone \"$@\" || usage\n-\t\tget_saved_options\n-\t\tcomment_for_reflog abort\n-\n-\t\tgit rerere clear\n-\t\ttest -d \"$DOTEST\" || die \"No interactive rebase running\"\n-\n-\t\tHEADNAME=$(cat \"$DOTEST\"/head-name)\n-\t\tHEAD=$(cat \"$DOTEST\"/head)\n-\t\tcase $HEADNAME in\n-\t\trefs/*)\n-\t\t\tgit symbolic-ref HEAD $HEADNAME\n-\t\t\t;;\n-\t\tesac &&\n-\t\toutput git reset --hard $HEAD &&\n-\t\trm -rf \"$DOTEST\"\n-\t\texit\n-\t\t;;\n-\t--skip)\n-\t\tis_standalone \"$@\" || usage\n-\t\tget_saved_options\n-\t\tcomment_for_reflog skip\n+\trequire_clean_work_tree \"rebase\"\n+\tdo_rest\n+\t;;\n+abort)\n+\tget_saved_options\n+\tcomment_for_reflog abort\n \n-\t\tgit rerere clear\n-\t\ttest -d \"$DOTEST\" || die \"No interactive rebase running\"\n+\tgit rerere clear\n+\ttest -d \"$DOTEST\" || die \"No interactive rebase running\"\n \n-\t\toutput git reset --hard && do_rest\n-\t\t;;\n-\t-s)\n-\t\tcase \"$#,$1\" in\n-\t\t*,*=*)\n-\t\t\tstrategy=$(expr \"z$1\" : 'z-[^=]*=\\(.*\\)') ;;\n-\t\t1,*)\n-\t\t\tusage ;;\n-\t\t*)\n-\t\t\tstrategy=\"$2\"\n-\t\t\tshift ;;\n-\t\tesac\n-\t\t;;\n-\t-m)\n-\t\t# we use merge anyway\n-\t\t;;\n-\t-v)\n-\t\tverbose=t\n-\t\t;;\n-\t-p)\n-\t\tpreserve_merges=t\n-\t\t;;\n-\t-i)\n-\t\t# yeah, we know\n-\t\t;;\n-\t--no-ff)\n-\t\tforce_rebase=t\n-\t\t;;\n-\t--root)\n-\t\trebase_root=t\n-\t\t;;\n-\t--autosquash)\n-\t\tautosquash=t\n-\t\t;;\n-\t--no-autosquash)\n-\t\tautosquash=\n-\t\t;;\n-\t--onto)\n-\t\ttest 2 -le \"$#\" || usage\n-\t\tonto=\"$2\"\n-\t\tshift\n-\t\t;;\n-\t--)\n-\t\tshift\n-\t\tbreak\n+\tHEADNAME=$(cat \"$DOTEST\"/head-name)\n+\tHEAD=$(cat \"$DOTEST\"/head)\n+\tcase $HEADNAME in\n+\trefs/*)\n+\t\tgit symbolic-ref HEAD $HEADNAME\n \t\t;;\n-\tesac\n-\tshift\n-done\n+\tesac &&\n+\toutput git reset --hard $HEAD &&\n+\trm -rf \"$DOTEST\"\n+\texit\n+\t;;\n+skip)\n+\tget_saved_options\n+\tcomment_for_reflog skip\n+\n+\tgit rerere clear\n+\ttest -d \"$DOTEST\" || die \"No interactive rebase running\"\n+\n+\toutput git reset --hard && do_rest\n+\t;;\n+esac\n \n if test -n \"$onto\"\n then\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex ed1d4f5..df4e184 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -56,6 +56,9 @@ rebase_root=\n force_rebase=\n allow_rerere_autoupdate=\n action=\n+preserve_merges=\n+autosquash=\n+test \"$(git config --bool rebase.autosquash)\" = \"true\" && autosquash=t\n \n read_state () {\n \tif test -d \"$merge_dir\"\n@@ -171,27 +174,14 @@ finish_rb_merge () {\n \tsay All done.\n }\n \n-is_interactive () {\n-\twhile test $# != 0\n-\tdo\n-\t\tcase \"$1\" in\n-\t\t\t-i|--interactive)\n-\t\t\t\tinteractive_rebase=explicit\n-\t\t\t\tbreak\n-\t\t\t;;\n-\t\t\t-p|--preserve-merges)\n-\t\t\t\tinteractive_rebase=implied\n-\t\t\t;;\n-\t\tesac\n-\t\tshift\n-\tdone\n-\n+run_interactive_rebase () {\n \tif [ \"$interactive_rebase\" = implied ]; then\n \t\tGIT_EDITOR=:\n \t\texport GIT_EDITOR\n \tfi\n-\n-\ttest -n \"$interactive_rebase\" || test -f \"$merge_dir\"/interactive\n+\texport onto autosquash strategy strategy_opts verbose rebase_root \\\n+\tforce_rebase action preserve_merges OK_TO_SKIP_PRE_REBASE\n+\texec git-rebase--interactive \"$@\"\n }\n \n run_pre_rebase_hook () {\n@@ -206,8 +196,6 @@ run_pre_rebase_hook () {\n test -f \"$apply_dir\"/applying &&\n \tdie 'It looks like git-am is in progress. Cannot rebase.'\n \n-is_interactive \"$@\" && exec git-rebase--interactive \"$@\"\n-\n while test $# != 0\n do\n \tcase \"$1\" in\n@@ -227,6 +215,19 @@ do\n \t\tonto=\"$2\"\n \t\tshift\n \t\t;;\n+\t-i|--interactive)\n+\t\tinteractive_rebase=explicit\n+\t\t;;\n+\t-p|--preserve-merges)\n+\t\tpreserve_merges=t\n+\t\ttest -z \"$interactive_rebase\" && interactive_rebase=implied\n+\t\t;;\n+\t--autosquash)\n+\t\tautosquash=t\n+\t\t;;\n+\t--no-autosquash)\n+\t\tautosquash=\n+\t\t;;\n \t-M|-m|--m|--me|--mer|--merg|--merge)\n \t\tdo_merge=t\n \t\t;;\n@@ -351,6 +352,10 @@ valuable there.'\n \ttest $# -eq 0 && test -z \"$rebase_root\" && usage\n fi\n \n+test -f \"$merge_dir\"/interactive && interactive_rebase=explicit\n+\n+test -n \"$action\" && test -n \"$interactive_rebase\" && run_interactive_rebase\n+\n case \"$action\" in\n continue)\n \tgit update-index --ignore-submodules --refresh &&\n@@ -409,6 +414,8 @@ abort)\n \t;;\n esac\n \n+test -n \"$interactive_rebase\" && run_interactive_rebase \"$@\"\n+\n require_clean_work_tree \"rebase\" \"Please commit or stash them.\"\n \n if test -z \"$rebase_root\"\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156593","messageId":"1290715083-16919-12-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 11/20] rebase -i: remove now unnecessary directory checks","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:54Z","receivedAt":"2010-11-25T19:57:54Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"Remove directory checks from git-rebase--interactive.sh that are done in\ngit-rebase.sh.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase--interactive.sh |    6 ------\n git-rebase.sh              |    3 ++-\n 2 files changed, 2 insertions(+), 7 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex 6389a9f..07c10f3 100755\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -706,8 +706,6 @@ continue)\n \tget_saved_options\n \tcomment_for_reflog continue\n \n-\ttest -d \"$DOTEST\" || die \"No interactive rebase running\"\n-\n \t# Sanity check\n \tgit rev-parse --verify HEAD >/dev/null ||\n \t\tdie \"Cannot read HEAD\"\n@@ -749,7 +747,6 @@ abort)\n \tcomment_for_reflog abort\n \n \tgit rerere clear\n-\ttest -d \"$DOTEST\" || die \"No interactive rebase running\"\n \n \tHEADNAME=$(cat \"$DOTEST\"/head-name)\n \tHEAD=$(cat \"$DOTEST\"/head)\n@@ -767,7 +764,6 @@ skip)\n \tcomment_for_reflog skip\n \n \tgit rerere clear\n-\ttest -d \"$DOTEST\" || die \"No interactive rebase running\"\n \n \toutput git reset --hard && do_rest\n \t;;\n@@ -781,8 +777,6 @@ test -n \"$strategy\" && strategy=\"-s $strategy\"\n \n test -z \"$rebase_root\" -a $# -ge 1 -a $# -le 2 ||\n test ! -z \"$rebase_root\" -a $# -le 1 || usage\n-test -d \"$DOTEST\" &&\n-\tdie \"Interactive rebase already started\"\n \n git var GIT_COMMITTER_IDENT >/dev/null ||\n \tdie \"You need to set your committer info first\"\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex df4e184..2b19d2f 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -324,7 +324,8 @@ then\n \ttest -z \"$onto\" &&\n \ttest -z \"$preserve_merges\" ||\n \tusage\n-\ttest -d \"$merge_dir\" -o -d \"$apply_dir\" || die \"No rebase in progress?\"\n+\ttest -d \"$apply_dir\" -a -z \"$interactive_rebase\" ||\n+\ttest -d \"$merge_dir\" || die \"No rebase in progress?\"\n else\n \t# Make sure we do not have $apply_dir or $merge_dir\n \tif test -z \"$do_merge\"\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156594","messageId":"1290715083-16919-13-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 12/20] rebase: reorder validation steps","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:55Z","receivedAt":"2010-11-25T19:57:55Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"Reorder validation steps in preparation for the validation to be factored\nout from git-rebase--interactive.sh into git-rebase.sh.\n\nThe main functional difference is that the pre-rebase hook will no longer\nbe run if the work tree is dirty.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase--interactive.sh |    4 ++--\n git-rebase.sh              |   10 +++++-----\n 2 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex 07c10f3..f07472a 100755\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -793,12 +793,12 @@ else\n \ttest -z \"$onto\" &&\n \t\tdie \"You must specify --onto when using --root\"\n fi\n+require_clean_work_tree \"rebase\" \"Please commit or stash them.\"\n+\n run_pre_rebase_hook \"$UPSTREAM_ARG\" \"$@\"\n \n comment_for_reflog start\n \n-require_clean_work_tree \"rebase\" \"Please commit or stash them.\"\n-\n if test ! -z \"$1\"\n then\n \toutput git checkout \"$1\" ||\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 2b19d2f..5b0b73a 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -417,8 +417,6 @@ esac\n \n test -n \"$interactive_rebase\" && run_interactive_rebase \"$@\"\n \n-require_clean_work_tree \"rebase\" \"Please commit or stash them.\"\n-\n if test -z \"$rebase_root\"\n then\n \t# The upstream head must be given.  Make sure it is valid.\n@@ -460,9 +458,6 @@ case \"$onto_name\" in\n \t;;\n esac\n \n-# If a hook exists, give it a chance to interrupt\n-run_pre_rebase_hook \"$upstream_arg\" \"$@\"\n-\n # If the branch to rebase is given, that is the branch we will rebase\n # $branch_name -- branch being rebased, or HEAD (already detached)\n # $orig_head -- commit object name of tip of the branch before rebasing\n@@ -500,6 +495,8 @@ case \"$#\" in\n esac\n orig_head=$branch\n \n+require_clean_work_tree \"rebase\" \"Please commit or stash them.\"\n+\n # Now we are rebasing commits $upstream..$branch (or with --root,\n # everything leading up to $branch) on top of $onto\n \n@@ -521,6 +518,9 @@ then\n \tfi\n fi\n \n+# If a hook exists, give it a chance to interrupt\n+run_pre_rebase_hook \"$upstream_arg\" \"$@\"\n+\n # Detach HEAD and reset the tree\n say \"First, rewinding head to replay your work on top of it...\"\n git checkout -q \"$onto^0\" || die \"could not detach HEAD\"\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156579","messageId":"1290715083-16919-14-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 13/20] rebase: factor out reference parsing","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:56Z","receivedAt":"2010-11-25T19:57:56Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"Remove the parsing and validation of references (onto, upstream, branch)\nfrom git-rebase--interactive.sh and rely on the information exported from\ngit-rebase.sh.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase--interactive.sh |   59 +++++++------------------------------------\n git-rebase.sh              |   12 +++++---\n 2 files changed, 17 insertions(+), 54 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex f07472a..fe56d98 100755\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -682,25 +682,6 @@ rearrange_squash () {\n \trm -f \"$1.sq\" \"$1.rearranged\"\n }\n \n-LF='\n-'\n-parse_onto () {\n-\tcase \"$1\" in\n-\t*...*)\n-\t\tif\tleft=${1%...*} right=${1#*...} &&\n-\t\t\tonto=$(git merge-base --all ${left:-HEAD} ${right:-HEAD})\n-\t\tthen\n-\t\t\tcase \"$onto\" in\n-\t\t\t?*\"$LF\"?* | '')\n-\t\t\t\texit 1 ;;\n-\t\t\tesac\n-\t\t\techo \"$onto\"\n-\t\t\texit 0\n-\t\tfi\n-\tesac\n-\tgit rev-parse --verify \"$1^0\"\n-}\n-\n case \"$action\" in\n continue)\n \tget_saved_options\n@@ -769,48 +750,28 @@ skip)\n \t;;\n esac\n \n-if test -n \"$onto\"\n-then\n-\tonto=$(parse_onto \"$onto\") || die \"Does not point to a valid commit: $1\"\n-fi\n test -n \"$strategy\" && strategy=\"-s $strategy\"\n \n-test -z \"$rebase_root\" -a $# -ge 1 -a $# -le 2 ||\n-test ! -z \"$rebase_root\" -a $# -le 1 || usage\n-\n git var GIT_COMMITTER_IDENT >/dev/null ||\n \tdie \"You need to set your committer info first\"\n \n-if test -z \"$rebase_root\"\n-then\n-\tUPSTREAM_ARG=\"$1\"\n-\tUPSTREAM=$(git rev-parse --verify \"$1\") || die \"Invalid base\"\n-\ttest -z \"$onto\" && onto=$UPSTREAM\n-\tshift\n-else\n-\tUPSTREAM=\n-\tUPSTREAM_ARG=--root\n-\ttest -z \"$onto\" &&\n-\t\tdie \"You must specify --onto when using --root\"\n-fi\n require_clean_work_tree \"rebase\" \"Please commit or stash them.\"\n \n-run_pre_rebase_hook \"$UPSTREAM_ARG\" \"$@\"\n+run_pre_rebase_hook \"$upstream_arg\" \"$@\"\n \n comment_for_reflog start\n \n-if test ! -z \"$1\"\n+if test ! -z \"$switch_to\"\n then\n-\toutput git checkout \"$1\" ||\n-\t\tdie \"Could not checkout $1\"\n+\toutput git checkout \"$switch_to\" ||\n+\t\tdie \"Could not checkout $switch_to\"\n fi\n \n HEAD=$(git rev-parse --verify HEAD) || die \"No HEAD?\"\n mkdir \"$DOTEST\" || die \"Could not create temporary $DOTEST\"\n \n : > \"$DOTEST\"/interactive || die \"Could not mark as interactive\"\n-git symbolic-ref HEAD > \"$DOTEST\"/head-name 2> /dev/null ||\n-\techo \"detached HEAD\" > \"$DOTEST\"/head-name\n+echo \"$head_name\" > \"$DOTEST\"/head-name\n \n echo $HEAD > \"$DOTEST\"/head\n case \"$rebase_root\" in\n@@ -827,7 +788,7 @@ then\n \tif test -z \"$rebase_root\"\n \tthen\n \t\tmkdir \"$REWRITTEN\" &&\n-\t\tfor c in $(git merge-base --all $HEAD $UPSTREAM)\n+\t\tfor c in $(git merge-base --all $HEAD $upstream)\n \t\tdo\n \t\t\techo $onto > \"$REWRITTEN\"/$c ||\n \t\t\t\tdie \"Could not init rewritten commits\"\n@@ -841,7 +802,7 @@ then\n \t# parents to rewrite and skipping dropped commits would\n \t# prematurely end our probe\n \tMERGES_OPTION=\n-\tfirst_after_upstream=\"$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)\"\n+\tfirst_after_upstream=\"$(git rev-list --reverse --first-parent $upstream..$HEAD | head -n 1)\"\n else\n \tMERGES_OPTION=\"--no-merges --cherry-pick\"\n fi\n@@ -849,10 +810,10 @@ fi\n SHORTHEAD=$(git rev-parse --short $HEAD)\n SHORTONTO=$(git rev-parse --short $onto)\n if test -z \"$rebase_root\"\n-\t# this is now equivalent to ! -z \"$UPSTREAM\"\n+\t# this is now equivalent to ! -z \"$upstream\"\n then\n-\tSHORTUPSTREAM=$(git rev-parse --short $UPSTREAM)\n-\tREVISIONS=$UPSTREAM...$HEAD\n+\tSHORTUPSTREAM=$(git rev-parse --short $upstream)\n+\tREVISIONS=$upstream...$HEAD\n \tSHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD\n else\n \tREVISIONS=$onto...$HEAD\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 5b0b73a..17b5042 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -180,7 +180,8 @@ run_interactive_rebase () {\n \t\texport GIT_EDITOR\n \tfi\n \texport onto autosquash strategy strategy_opts verbose rebase_root \\\n-\tforce_rebase action preserve_merges OK_TO_SKIP_PRE_REBASE\n+\tforce_rebase action preserve_merges OK_TO_SKIP_PRE_REBASE upstream \\\n+\tupstream_arg switch_to head_name\n \texec git-rebase--interactive \"$@\"\n }\n \n@@ -415,8 +416,6 @@ abort)\n \t;;\n esac\n \n-test -n \"$interactive_rebase\" && run_interactive_rebase \"$@\"\n-\n if test -z \"$rebase_root\"\n then\n \t# The upstream head must be given.  Make sure it is valid.\n@@ -427,7 +426,7 @@ then\n \tunset root_flag\n \tupstream_arg=\"$upstream_name\"\n else\n-\ttest -z \"$onto\" && die \"--root must be used with --onto\"\n+\ttest -z \"$onto\" && die \"You must specify --onto when using --root\"\n \tunset upstream_name\n \tunset upstream\n \troot_flag=\"--root\"\n@@ -454,7 +453,8 @@ case \"$onto_name\" in\n \tfi\n \t;;\n *)\n-\tonto=$(git rev-parse --verify \"${onto_name}^0\") || exit\n+\tonto=$(git rev-parse --verify \"${onto_name}^0\") ||\n+\tdie \"Does not point to a valid commit: $1\"\n \t;;\n esac\n \n@@ -495,6 +495,8 @@ case \"$#\" in\n esac\n orig_head=$branch\n \n+test -n \"$interactive_rebase\" && run_interactive_rebase \"$@\"\n+\n require_clean_work_tree \"rebase\" \"Please commit or stash them.\"\n \n # Now we are rebasing commits $upstream..$branch (or with --root,\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156582","messageId":"1290715083-16919-15-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 14/20] rebase: factor out clean work tree check","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:57Z","receivedAt":"2010-11-25T19:57:57Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"Remove the check for clean work tree from git-rebase--interactive.sh and\nrely on the check in git-rebase.sh.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase--interactive.sh |    2 --\n git-rebase.sh              |    4 ++--\n 2 files changed, 2 insertions(+), 4 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex fe56d98..36bf259 100755\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -755,8 +755,6 @@ test -n \"$strategy\" && strategy=\"-s $strategy\"\n git var GIT_COMMITTER_IDENT >/dev/null ||\n \tdie \"You need to set your committer info first\"\n \n-require_clean_work_tree \"rebase\" \"Please commit or stash them.\"\n-\n run_pre_rebase_hook \"$upstream_arg\" \"$@\"\n \n comment_for_reflog start\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 17b5042..9d398eb 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -495,10 +495,10 @@ case \"$#\" in\n esac\n orig_head=$branch\n \n-test -n \"$interactive_rebase\" && run_interactive_rebase \"$@\"\n-\n require_clean_work_tree \"rebase\" \"Please commit or stash them.\"\n \n+test -n \"$interactive_rebase\" && run_interactive_rebase \"$@\"\n+\n # Now we are rebasing commits $upstream..$branch (or with --root,\n # everything leading up to $branch) on top of $onto\n \n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156580","messageId":"1290715083-16919-16-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 15/20] rebase: factor out call to pre-rebase hook","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:58Z","receivedAt":"2010-11-25T19:57:58Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"Remove the call to the pre-rebase hook from\ngit-rebase--interactive.sh and rely on the call in\ngit-rebase.sh.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase--interactive.sh |   14 --------------\n git-rebase.sh              |   15 ++++++++-------\n 2 files changed, 8 insertions(+), 21 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex 36bf259..d60977d 100755\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -110,18 +110,6 @@ commit_message () {\n \tgit cat-file commit \"$1\" | sed \"1,/^$/d\"\n }\n \n-run_pre_rebase_hook () {\n-\tif test -z \"$OK_TO_SKIP_PRE_REBASE\" &&\n-\t   test -x \"$GIT_DIR/hooks/pre-rebase\"\n-\tthen\n-\t\t\"$GIT_DIR/hooks/pre-rebase\" ${1+\"$@\"} || {\n-\t\t\techo >&2 \"The pre-rebase hook refused to rebase.\"\n-\t\t\texit 1\n-\t\t}\n-\tfi\n-}\n-\n-\n ORIG_REFLOG_ACTION=\"$GIT_REFLOG_ACTION\"\n \n comment_for_reflog () {\n@@ -755,8 +743,6 @@ test -n \"$strategy\" && strategy=\"-s $strategy\"\n git var GIT_COMMITTER_IDENT >/dev/null ||\n \tdie \"You need to set your committer info first\"\n \n-run_pre_rebase_hook \"$upstream_arg\" \"$@\"\n-\n comment_for_reflog start\n \n if test ! -z \"$switch_to\"\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 9d398eb..11cea3c 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -180,9 +180,8 @@ run_interactive_rebase () {\n \t\texport GIT_EDITOR\n \tfi\n \texport onto autosquash strategy strategy_opts verbose rebase_root \\\n-\tforce_rebase action preserve_merges OK_TO_SKIP_PRE_REBASE upstream \\\n-\tupstream_arg switch_to head_name\n-\texec git-rebase--interactive \"$@\"\n+\tforce_rebase action preserve_merges upstream switch_to head_name\n+\texec git-rebase--interactive\n }\n \n run_pre_rebase_hook () {\n@@ -497,15 +496,15 @@ orig_head=$branch\n \n require_clean_work_tree \"rebase\" \"Please commit or stash them.\"\n \n-test -n \"$interactive_rebase\" && run_interactive_rebase \"$@\"\n-\n # Now we are rebasing commits $upstream..$branch (or with --root,\n # everything leading up to $branch) on top of $onto\n \n # Check if we are already based on $onto with linear history,\n-# but this should be done only when upstream and onto are the same.\n+# but this should be done only when upstream and onto are the same\n+# and if this is not an interactive rebase.\n mb=$(git merge-base \"$onto\" \"$branch\")\n-if test \"$upstream\" = \"$onto\" && test \"$mb\" = \"$onto\" &&\n+if test -z \"$interactive_rebase\" && test \"$upstream\" = \"$onto\" &&\n+\ttest \"$mb\" = \"$onto\" &&\n \t# linear history?\n \t! (git rev-list --parents \"$onto\"..\"$branch\" | sane_grep \" .* \") > /dev/null\n then\n@@ -523,6 +522,8 @@ fi\n # If a hook exists, give it a chance to interrupt\n run_pre_rebase_hook \"$upstream_arg\" \"$@\"\n \n+test -n \"$interactive_rebase\" && run_interactive_rebase\n+\n # Detach HEAD and reset the tree\n say \"First, rewinding head to replay your work on top of it...\"\n git checkout -q \"$onto^0\" || die \"could not detach HEAD\"\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156585","messageId":"1290715083-16919-17-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 16/20] rebase -i: support --stat","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:57:59Z","receivedAt":"2010-11-25T19:57:59Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"Move up the code that displays the diffstat if '--stat' is passed, so\nthat it will be executed before calling git-rebase--interactive.sh.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase.sh |   14 +++++++-------\n 1 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 11cea3c..43cab41 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -522,13 +522,6 @@ fi\n # If a hook exists, give it a chance to interrupt\n run_pre_rebase_hook \"$upstream_arg\" \"$@\"\n \n-test -n \"$interactive_rebase\" && run_interactive_rebase\n-\n-# Detach HEAD and reset the tree\n-say \"First, rewinding head to replay your work on top of it...\"\n-git checkout -q \"$onto^0\" || die \"could not detach HEAD\"\n-git update-ref ORIG_HEAD $branch\n-\n if test -n \"$diffstat\"\n then\n \tif test -n \"$verbose\"\n@@ -539,6 +532,13 @@ then\n \tGIT_PAGER='' git diff --stat --summary \"$mb\" \"$onto\"\n fi\n \n+test -n \"$interactive_rebase\" && run_interactive_rebase\n+\n+# Detach HEAD and reset the tree\n+say \"First, rewinding head to replay your work on top of it...\"\n+git checkout -q \"$onto^0\" || die \"could not detach HEAD\"\n+git update-ref ORIG_HEAD $branch\n+\n # If the $onto is a proper descendant of the tip of the branch, then\n # we just fast-forwarded.\n if test \"$mb\" = \"$branch\"\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156581","messageId":"1290715083-16919-18-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 17/20] rebase: improve detection of rebase in progress","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:58:00Z","receivedAt":"2010-11-25T19:58:00Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"Detect early on if a rebase is in progress and what kind of rebase it\nis. This prepares for further refactoring where plain (am) rebase will\nbe dispatched to git-rebase--am.sh and merge rebase will be dispatched\nto git-rebase--merge.sh.\n\nThe idea is to use the same variables whether the type of rebase was\ndetected from rebase-apply/ or rebase-merge/ directories or from on\nthe command line options.\n\nAlso show a consistent error message independent of the kind of rebase\nthat was in progress. Also remove the obsolete wording about an being\nin the middle of a 'patch application', since that (an existing\n\"$GIT_DIR\"/rebase-apply/applying) aborts 'git rebase' at an earlier\nstage.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase.sh |   74 ++++++++++++++++++++++++++++++++++++--------------------\n 1 files changed, 47 insertions(+), 27 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 43cab41..d233da6 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -59,16 +59,19 @@ action=\n preserve_merges=\n autosquash=\n test \"$(git config --bool rebase.autosquash)\" = \"true\" && autosquash=t\n+# Non-empty if a rebase was in progress when 'git rebase' was invoked\n+in_progress=\n+# One of {am, merge, interactive}\n+type=\n+# One of {\"$GIT_DIR\"/rebase-apply, \"$GIT_DIR\"/rebase-merge}\n+state_dir=\n \n read_state () {\n-\tif test -d \"$merge_dir\"\n+\tif test \"$type\" = merge\n \tthen\n-\t\tstate_dir=\"$merge_dir\"\n \t\tonto_name=$(cat \"$merge_dir\"/onto_name) &&\n \t\tend=$(cat \"$merge_dir\"/end) &&\n \t\tmsgnum=$(cat \"$merge_dir\"/msgnum)\n-\telse\n-\t\tstate_dir=\"$apply_dir\"\n \tfi &&\n \thead_name=$(cat \"$state_dir\"/head-name) &&\n \tonto=$(cat \"$state_dir\"/onto) &&\n@@ -196,6 +199,23 @@ run_pre_rebase_hook () {\n test -f \"$apply_dir\"/applying &&\n \tdie 'It looks like git-am is in progress. Cannot rebase.'\n \n+if test -d \"$apply_dir\"\n+then\n+\ttype=am\n+\tstate_dir=\"$apply_dir\"\n+elif test -d \"$merge_dir\"\n+then\n+\tif test -f \"$merge_dir\"/interactive\n+\tthen\n+\t\ttype=interactive\n+\t\tinteractive_rebase=explicit\n+\telse\n+\t\ttype=merge\n+\tfi\n+\tstate_dir=\"$merge_dir\"\n+fi\n+test -n \"$type\" && in_progress=t\n+\n while test $# != 0\n do\n \tcase \"$1\" in\n@@ -324,37 +344,24 @@ then\n \ttest -z \"$onto\" &&\n \ttest -z \"$preserve_merges\" ||\n \tusage\n-\ttest -d \"$apply_dir\" -a -z \"$interactive_rebase\" ||\n-\ttest -d \"$merge_dir\" || die \"No rebase in progress?\"\n+\ttest -z \"$in_progress\" && die \"No rebase in progress?\"\n else\n-\t# Make sure we do not have $apply_dir or $merge_dir\n-\tif test -z \"$do_merge\"\n+\t# Make sure we do not have a rebase in progress\n+\tif test -n \"$in_progress\"\n \tthen\n-\t\tif mkdir \"$apply_dir\" 2>/dev/null\n-\t\tthen\n-\t\t\trmdir \"$apply_dir\"\n-\t\telse\n-\t\t\techo >&2 '\n-It seems that I cannot create a rebase-apply directory, and\n-I wonder if you are in the middle of patch application or another\n-rebase.  If that is not the case, please\n-\trm -fr '\"$apply_dir\"'\n+\t\tdie '\n+It seems that there is already a \"${state_dir##*/}\" directory, and\n+I wonder if you are in the middle of another rebase.  If that is the\n+case, please try\n+\tgit rebase (--continue | --abort | --skip)\n+If that is not the case, please\n+\trm -fr '\"$state_dir\"'\n and run me again.  I am stopping in case you still have something\n valuable there.'\n-\t\texit 1\n-\t\tfi\n-\telse\n-\t\tif test -d \"$merge_dir\"\n-\t\tthen\n-\t\t\tdie \"previous rebase directory $merge_dir still exists.\" \\\n-\t\t\t\t'Try git rebase (--continue | --abort | --skip)'\n-\t\tfi\n \tfi\n \ttest $# -eq 0 && test -z \"$rebase_root\" && usage\n fi\n \n-test -f \"$merge_dir\"/interactive && interactive_rebase=explicit\n-\n test -n \"$action\" && test -n \"$interactive_rebase\" && run_interactive_rebase\n \n case \"$action\" in\n@@ -415,6 +422,19 @@ abort)\n \t;;\n esac\n \n+if test -n \"$interactive_rebase\"\n+then\n+\ttype=interactive\n+\tstate_dir=\"$merge_dir\"\n+elif test -n \"$do_merge\"\n+then\n+\ttype=merge\n+\tstate_dir=\"$merge_dir\"\n+else\n+\ttype=am\n+\tstate_dir=\"$apply_dir\"\n+fi\n+\n if test -z \"$rebase_root\"\n then\n \t# The upstream head must be given.  Make sure it is valid.\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156586","messageId":"1290715083-16919-19-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 18/20] rebase -m: extract code to new source file","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:58:01Z","receivedAt":"2010-11-25T19:58:01Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"Extract the code for merge-based rebase to git-rebase--merge.sh.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n .gitignore           |    1 +\n Makefile             |    1 +\n git-rebase--merge.sh |  154 +++++++++++++++++++++++++++++++++++++++++++++\n git-rebase.sh        |  168 +++++---------------------------------------------\n 4 files changed, 172 insertions(+), 152 deletions(-)\n create mode 100644 git-rebase--merge.sh\n\ndiff --git a/.gitignore b/.gitignore\nindex b279de3..8f68f8a 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -103,6 +103,7 @@\n /git-read-tree\n /git-rebase\n /git-rebase--interactive\n+/git-rebase--merge\n /git-receive-pack\n /git-reflog\n /git-relink\ndiff --git a/Makefile b/Makefile\nindex 8357106..213ceaf 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -397,6 +397,7 @@ SCRIPT_SH += git-mergetool.sh\n SCRIPT_SH += git-pull.sh\n SCRIPT_SH += git-quiltimport.sh\n SCRIPT_SH += git-rebase--interactive.sh\n+SCRIPT_SH += git-rebase--merge.sh\n SCRIPT_SH += git-rebase.sh\n SCRIPT_SH += git-repack.sh\n SCRIPT_SH += git-request-pull.sh\ndiff --git a/git-rebase--merge.sh b/git-rebase--merge.sh\nnew file mode 100644\nindex 0000000..8cfdcf1\n--- /dev/null\n+++ b/git-rebase--merge.sh\n@@ -0,0 +1,154 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2010 Junio C Hamano.\n+#\n+\n+. git-sh-setup\n+\n+prec=4\n+\n+read_state () {\n+\tonto_name=$(cat \"$state_dir\"/onto_name) &&\n+\tend=$(cat \"$state_dir\"/end) &&\n+\tmsgnum=$(cat \"$state_dir\"/msgnum)\n+}\n+\n+continue_merge () {\n+\ttest -d \"$state_dir\" || die \"$state_dir directory does not exist\"\n+\n+\tunmerged=$(git ls-files -u)\n+\tif test -n \"$unmerged\"\n+\tthen\n+\t\techo \"You still have unmerged paths in your index\"\n+\t\techo \"did you forget to use git add?\"\n+\t\tdie \"$RESOLVEMSG\"\n+\tfi\n+\n+\tcmt=`cat \"$state_dir/current\"`\n+\tif ! git diff-index --quiet --ignore-submodules HEAD --\n+\tthen\n+\t\tif ! git commit --no-verify -C \"$cmt\"\n+\t\tthen\n+\t\t\techo \"Commit failed, please do not call \\\"git commit\\\"\"\n+\t\t\techo \"directly, but instead do one of the following: \"\n+\t\t\tdie \"$RESOLVEMSG\"\n+\t\tfi\n+\t\tif test -z \"$GIT_QUIET\"\n+\t\tthen\n+\t\t\tprintf \"Committed: %0${prec}d \" $msgnum\n+\t\tfi\n+\t\techo \"$cmt $(git rev-parse HEAD^0)\" >> \"$state_dir/rewritten\"\n+\telse\n+\t\tif test -z \"$GIT_QUIET\"\n+\t\tthen\n+\t\t\tprintf \"Already applied: %0${prec}d \" $msgnum\n+\t\tfi\n+\tfi\n+\ttest -z \"$GIT_QUIET\" &&\n+\tGIT_PAGER='' git log --format=%s -1 \"$cmt\"\n+\n+\t# onto the next patch:\n+\tmsgnum=$(($msgnum + 1))\n+\techo \"$msgnum\" >\"$state_dir/msgnum\"\n+}\n+\n+call_merge () {\n+\tcmt=\"$(cat \"$state_dir/cmt.$1\")\"\n+\techo \"$cmt\" > \"$state_dir/current\"\n+\thd=$(git rev-parse --verify HEAD)\n+\tcmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)\n+\tmsgnum=$(cat \"$state_dir/msgnum\")\n+\teval GITHEAD_$cmt='\"${cmt_name##refs/heads/}~$(($end - $msgnum))\"'\n+\teval GITHEAD_$hd='$onto_name'\n+\texport GITHEAD_$cmt GITHEAD_$hd\n+\tif test -n \"$GIT_QUIET\"\n+\tthen\n+\t\tGIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY\n+\tfi\n+\ttest -z \"$strategy\" && strategy=recursive\n+\teval 'git-merge-$strategy' $strategy_opts '\"$cmt^\" -- \"$hd\" \"$cmt\"'\n+\trv=$?\n+\tcase \"$rv\" in\n+\t0)\n+\t\tunset GITHEAD_$cmt GITHEAD_$hd\n+\t\treturn\n+\t\t;;\n+\t1)\n+\t\tgit rerere $allow_rerere_autoupdate\n+\t\tdie \"$RESOLVEMSG\"\n+\t\t;;\n+\t2)\n+\t\techo \"Strategy: $rv $strategy failed, try another\" 1>&2\n+\t\tdie \"$RESOLVEMSG\"\n+\t\t;;\n+\t*)\n+\t\tdie \"Unknown exit code ($rv) from command:\" \\\n+\t\t\t\"git-merge-$strategy $cmt^ -- HEAD $cmt\"\n+\t\t;;\n+\tesac\n+}\n+\n+finish_rb_merge () {\n+\tmove_to_original_branch\n+\tgit notes copy --for-rewrite=rebase < \"$state_dir\"/rewritten\n+\tif test -x \"$GIT_DIR\"/hooks/post-rewrite &&\n+\t\ttest -s \"$state_dir\"/rewritten; then\n+\t\t\"$GIT_DIR\"/hooks/post-rewrite rebase < \"$state_dir\"/rewritten\n+\tfi\n+\trm -r \"$state_dir\"\n+\tsay All done.\n+}\n+\n+case \"$action\" in\n+continue)\n+\tread_state\n+\tcontinue_merge\n+\twhile test \"$msgnum\" -le \"$end\"\n+\tdo\n+\t\tcall_merge \"$msgnum\"\n+\t\tcontinue_merge\n+\tdone\n+\tfinish_rb_merge\n+\texit\n+\t;;\n+skip)\n+\tread_state\n+\tgit rerere clear\n+\tmsgnum=$(($msgnum + 1))\n+\twhile test \"$msgnum\" -le \"$end\"\n+\tdo\n+\t\tcall_merge \"$msgnum\"\n+\t\tcontinue_merge\n+\tdone\n+\tfinish_rb_merge\n+\texit\n+\t;;\n+esac\n+\n+mkdir -p \"$state_dir\"\n+echo \"$onto_name\" > \"$state_dir/onto_name\"\n+echo \"$head_name\" > \"$state_dir/head-name\"\n+echo \"$onto\" > \"$state_dir/onto\"\n+echo \"$orig_head\" > \"$state_dir/orig-head\"\n+echo \"$GIT_QUIET\" > \"$state_dir/quiet\"\n+\n+msgnum=0\n+for cmt in `git rev-list --reverse --no-merges \"$revisions\"`\n+do\n+\tmsgnum=$(($msgnum + 1))\n+\techo \"$cmt\" > \"$state_dir/cmt.$msgnum\"\n+done\n+\n+echo 1 >\"$state_dir/msgnum\"\n+echo $msgnum >\"$state_dir/end\"\n+\n+end=$msgnum\n+msgnum=1\n+\n+while test \"$msgnum\" -le \"$end\"\n+do\n+\tcall_merge \"$msgnum\"\n+\tcontinue_merge\n+done\n+\n+finish_rb_merge\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex d233da6..0773968 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -48,7 +48,6 @@ strategy_opts=\n do_merge=\n merge_dir=\"$GIT_DIR\"/rebase-merge\n apply_dir=\"$GIT_DIR\"/rebase-apply\n-prec=4\n verbose=\n diffstat=$(git config --bool rebase.stat)\n git_am_opt=\n@@ -66,94 +65,13 @@ type=\n # One of {\"$GIT_DIR\"/rebase-apply, \"$GIT_DIR\"/rebase-merge}\n state_dir=\n \n-read_state () {\n-\tif test \"$type\" = merge\n-\tthen\n-\t\tonto_name=$(cat \"$merge_dir\"/onto_name) &&\n-\t\tend=$(cat \"$merge_dir\"/end) &&\n-\t\tmsgnum=$(cat \"$merge_dir\"/msgnum)\n-\tfi &&\n+read_basic_state () {\n \thead_name=$(cat \"$state_dir\"/head-name) &&\n \tonto=$(cat \"$state_dir\"/onto) &&\n \torig_head=$(cat \"$state_dir\"/orig-head) &&\n \tGIT_QUIET=$(cat \"$state_dir\"/quiet)\n }\n \n-continue_merge () {\n-\ttest -d \"$merge_dir\" || die \"$merge_dir directory does not exist\"\n-\n-\tunmerged=$(git ls-files -u)\n-\tif test -n \"$unmerged\"\n-\tthen\n-\t\techo \"You still have unmerged paths in your index\"\n-\t\techo \"did you forget to use git add?\"\n-\t\tdie \"$RESOLVEMSG\"\n-\tfi\n-\n-\tcmt=`cat \"$merge_dir/current\"`\n-\tif ! git diff-index --quiet --ignore-submodules HEAD --\n-\tthen\n-\t\tif ! git commit --no-verify -C \"$cmt\"\n-\t\tthen\n-\t\t\techo \"Commit failed, please do not call \\\"git commit\\\"\"\n-\t\t\techo \"directly, but instead do one of the following: \"\n-\t\t\tdie \"$RESOLVEMSG\"\n-\t\tfi\n-\t\tif test -z \"$GIT_QUIET\"\n-\t\tthen\n-\t\t\tprintf \"Committed: %0${prec}d \" $msgnum\n-\t\tfi\n-\t\techo \"$cmt $(git rev-parse HEAD^0)\" >> \"$merge_dir/rewritten\"\n-\telse\n-\t\tif test -z \"$GIT_QUIET\"\n-\t\tthen\n-\t\t\tprintf \"Already applied: %0${prec}d \" $msgnum\n-\t\tfi\n-\tfi\n-\ttest -z \"$GIT_QUIET\" &&\n-\tGIT_PAGER='' git log --format=%s -1 \"$cmt\"\n-\n-\t# onto the next patch:\n-\tmsgnum=$(($msgnum + 1))\n-\techo \"$msgnum\" >\"$merge_dir/msgnum\"\n-}\n-\n-call_merge () {\n-\tcmt=\"$(cat \"$merge_dir/cmt.$1\")\"\n-\techo \"$cmt\" > \"$merge_dir/current\"\n-\thd=$(git rev-parse --verify HEAD)\n-\tcmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)\n-\tmsgnum=$(cat \"$merge_dir/msgnum\")\n-\teval GITHEAD_$cmt='\"${cmt_name##refs/heads/}~$(($end - $msgnum))\"'\n-\teval GITHEAD_$hd='$onto_name'\n-\texport GITHEAD_$cmt GITHEAD_$hd\n-\tif test -n \"$GIT_QUIET\"\n-\tthen\n-\t\tGIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY\n-\tfi\n-\ttest -z \"$strategy\" && strategy=recursive\n-\teval 'git-merge-$strategy' $strategy_opts '\"$cmt^\" -- \"$hd\" \"$cmt\"'\n-\trv=$?\n-\tcase \"$rv\" in\n-\t0)\n-\t\tunset GITHEAD_$cmt GITHEAD_$hd\n-\t\treturn\n-\t\t;;\n-\t1)\n-\t\tgit rerere $allow_rerere_autoupdate\n-\t\tdie \"$RESOLVEMSG\"\n-\t\t;;\n-\t2)\n-\t\techo \"Strategy: $rv $strategy failed, try another\" 1>&2\n-\t\tdie \"$RESOLVEMSG\"\n-\t\t;;\n-\t*)\n-\t\tdie \"Unknown exit code ($rv) from command:\" \\\n-\t\t\t\"git-merge-$strategy $cmt^ -- HEAD $cmt\"\n-\t\t;;\n-\tesac\n-}\n-\n move_to_original_branch () {\n \tcase \"$head_name\" in\n \trefs/*)\n@@ -166,25 +84,17 @@ move_to_original_branch () {\n \tesac\n }\n \n-finish_rb_merge () {\n-\tmove_to_original_branch\n-\tgit notes copy --for-rewrite=rebase < \"$merge_dir\"/rewritten\n-\tif test -x \"$GIT_DIR\"/hooks/post-rewrite &&\n-\t\ttest -s \"$merge_dir\"/rewritten; then\n-\t\t\"$GIT_DIR\"/hooks/post-rewrite rebase < \"$merge_dir\"/rewritten\n-\tfi\n-\trm -r \"$merge_dir\"\n-\tsay All done.\n-}\n-\n-run_interactive_rebase () {\n+run_specific_rebase () {\n \tif [ \"$interactive_rebase\" = implied ]; then\n \t\tGIT_EDITOR=:\n \t\texport GIT_EDITOR\n \tfi\n \texport onto autosquash strategy strategy_opts verbose rebase_root \\\n-\tforce_rebase action preserve_merges upstream switch_to head_name\n-\texec git-rebase--interactive\n+\tforce_rebase action preserve_merges upstream switch_to head_name \\\n+\tin_progress state_dir head_name orig_head GIT_QUIET revisions \\\n+\tRESOLVEMSG\n+\texport -f move_to_original_branch\n+\ttest \"$type\" != am && exec git-rebase--$type\n }\n \n run_pre_rebase_hook () {\n@@ -362,7 +272,7 @@ valuable there.'\n \ttest $# -eq 0 && test -z \"$rebase_root\" && usage\n fi\n \n-test -n \"$action\" && test -n \"$interactive_rebase\" && run_interactive_rebase\n+test -n \"$action\" && test -n \"$interactive_rebase\" && run_specific_rebase\n \n case \"$action\" in\n continue)\n@@ -372,44 +282,23 @@ continue)\n \t\techo \"mark them as resolved using git add\"\n \t\texit 1\n \t}\n-\tread_state\n-\tif test -d \"$merge_dir\"\n-\tthen\n-\t\tcontinue_merge\n-\t\twhile test \"$msgnum\" -le \"$end\"\n-\t\tdo\n-\t\t\tcall_merge \"$msgnum\"\n-\t\t\tcontinue_merge\n-\t\tdone\n-\t\tfinish_rb_merge\n-\t\texit\n-\tfi\n+\tread_basic_state\n+\trun_specific_rebase\n \tgit am --resolved --3way --resolvemsg=\"$RESOLVEMSG\" &&\n \tmove_to_original_branch\n \texit\n \t;;\n skip)\n \tgit reset --hard HEAD || exit $?\n-\tread_state\n-\tif test -d \"$merge_dir\"\n-\tthen\n-\t\tgit rerere clear\n-\t\tmsgnum=$(($msgnum + 1))\n-\t\twhile test \"$msgnum\" -le \"$end\"\n-\t\tdo\n-\t\t\tcall_merge \"$msgnum\"\n-\t\t\tcontinue_merge\n-\t\tdone\n-\t\tfinish_rb_merge\n-\t\texit\n-\tfi\n+\tread_basic_state\n+\trun_specific_rebase\n \tgit am -3 --skip --resolvemsg=\"$RESOLVEMSG\" &&\n \tmove_to_original_branch\n \texit\n \t;;\n abort)\n \tgit rerere clear\n-\tread_state\n+\tread_basic_state\n \tcase \"$head_name\" in\n \trefs/*)\n \t\tgit symbolic-ref HEAD $head_name ||\n@@ -552,7 +441,7 @@ then\n \tGIT_PAGER='' git diff --stat --summary \"$mb\" \"$onto\"\n fi\n \n-test -n \"$interactive_rebase\" && run_interactive_rebase\n+test -n \"$interactive_rebase\" && run_specific_rebase\n \n # Detach HEAD and reset the tree\n say \"First, rewinding head to replay your work on top of it...\"\n@@ -591,33 +480,8 @@ then\n \texit $ret\n fi\n \n+\n # start doing a rebase with git-merge\n # this is rename-aware if the recursive (default) strategy is used\n \n-mkdir -p \"$merge_dir\"\n-echo \"$onto_name\" > \"$merge_dir/onto_name\"\n-echo \"$head_name\" > \"$merge_dir/head-name\"\n-echo \"$onto\" > \"$merge_dir/onto\"\n-echo \"$orig_head\" > \"$merge_dir/orig-head\"\n-echo \"$GIT_QUIET\" > \"$merge_dir/quiet\"\n-\n-msgnum=0\n-for cmt in `git rev-list --reverse --no-merges \"$revisions\"`\n-do\n-\tmsgnum=$(($msgnum + 1))\n-\techo \"$cmt\" > \"$merge_dir/cmt.$msgnum\"\n-done\n-\n-echo 1 >\"$merge_dir/msgnum\"\n-echo $msgnum >\"$merge_dir/end\"\n-\n-end=$msgnum\n-msgnum=1\n-\n-while test \"$msgnum\" -le \"$end\"\n-do\n-\tcall_merge \"$msgnum\"\n-\tcontinue_merge\n-done\n-\n-finish_rb_merge\n+run_specific_rebase\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156588","messageId":"1290715083-16919-20-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 19/20] rebase: extract am code to new source file","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:58:02Z","receivedAt":"2010-11-25T19:58:02Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"Extract the code for am-based rebase to git-rebase--am.sh.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n .gitignore        |    1 +\n Makefile          |    1 +\n git-rebase--am.sh |   34 ++++++++++++++++++++++++++++++++++\n git-rebase.sh     |   34 +++-------------------------------\n 4 files changed, 39 insertions(+), 31 deletions(-)\n create mode 100644 git-rebase--am.sh\n\ndiff --git a/.gitignore b/.gitignore\nindex 8f68f8a..22b7907 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -102,6 +102,7 @@\n /git-quiltimport\n /git-read-tree\n /git-rebase\n+/git-rebase--am\n /git-rebase--interactive\n /git-rebase--merge\n /git-receive-pack\ndiff --git a/Makefile b/Makefile\nindex 213ceaf..62e9e1e 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -396,6 +396,7 @@ SCRIPT_SH += git-merge-resolve.sh\n SCRIPT_SH += git-mergetool.sh\n SCRIPT_SH += git-pull.sh\n SCRIPT_SH += git-quiltimport.sh\n+SCRIPT_SH += git-rebase--am.sh\n SCRIPT_SH += git-rebase--interactive.sh\n SCRIPT_SH += git-rebase--merge.sh\n SCRIPT_SH += git-rebase.sh\ndiff --git a/git-rebase--am.sh b/git-rebase--am.sh\nnew file mode 100644\nindex 0000000..162dd6c\n--- /dev/null\n+++ b/git-rebase--am.sh\n@@ -0,0 +1,34 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2010 Junio C Hamano.\n+#\n+\n+. git-sh-setup\n+\n+case \"$action\" in\n+continue)\n+\tgit am --resolved --3way --resolvemsg=\"$RESOLVEMSG\" &&\n+\tmove_to_original_branch\n+\texit\n+\t;;\n+skip)\n+\tgit am --skip --3way --resolvemsg=\"$RESOLVEMSG\" &&\n+\tmove_to_original_branch\n+\texit\n+\t;;\n+esac\n+\n+test -n \"$rebase_root\" && root_flag=--root\n+\n+git format-patch -k --stdout --full-index --ignore-if-in-upstream \\\n+\t--src-prefix=a/ --dst-prefix=b/ \\\n+\t--no-renames $root_flag \"$revisions\" |\n+git am $git_am_opt --rebasing --resolvemsg=\"$RESOLVEMSG\" &&\n+move_to_original_branch\n+ret=$?\n+test 0 != $ret -a -d \"$state_dir\" &&\n+\techo $head_name > \"$state_dir/head-name\" &&\n+\techo $onto > \"$state_dir/onto\" &&\n+\techo $orig_head > \"$state_dir/orig-head\" &&\n+\techo \"$GIT_QUIET\" > \"$state_dir/quiet\"\n+exit $ret\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex 0773968..e2e97af 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -92,9 +92,9 @@ run_specific_rebase () {\n \texport onto autosquash strategy strategy_opts verbose rebase_root \\\n \tforce_rebase action preserve_merges upstream switch_to head_name \\\n \tin_progress state_dir head_name orig_head GIT_QUIET revisions \\\n-\tRESOLVEMSG\n+\tRESOLVEMSG git_am_opt\n \texport -f move_to_original_branch\n-\ttest \"$type\" != am && exec git-rebase--$type\n+\texec git-rebase--$type\n }\n \n run_pre_rebase_hook () {\n@@ -284,17 +284,11 @@ continue)\n \t}\n \tread_basic_state\n \trun_specific_rebase\n-\tgit am --resolved --3way --resolvemsg=\"$RESOLVEMSG\" &&\n-\tmove_to_original_branch\n-\texit\n \t;;\n skip)\n \tgit reset --hard HEAD || exit $?\n \tread_basic_state\n \trun_specific_rebase\n-\tgit am -3 --skip --resolvemsg=\"$RESOLVEMSG\" &&\n-\tmove_to_original_branch\n-\texit\n \t;;\n abort)\n \tgit rerere clear\n@@ -331,14 +325,12 @@ then\n \tshift\n \tupstream=`git rev-parse --verify \"${upstream_name}^0\"` ||\n \tdie \"invalid upstream $upstream_name\"\n-\tunset root_flag\n \tupstream_arg=\"$upstream_name\"\n else\n \ttest -z \"$onto\" && die \"You must specify --onto when using --root\"\n \tunset upstream_name\n \tunset upstream\n-\troot_flag=\"--root\"\n-\tupstream_arg=\"$root_flag\"\n+\tupstream_arg=--root\n fi\n \n # Make sure the branch to rebase onto is valid.\n@@ -464,24 +456,4 @@ else\n \trevisions=\"$upstream..$orig_head\"\n fi\n \n-if test -z \"$do_merge\"\n-then\n-\tgit format-patch -k --stdout --full-index --ignore-if-in-upstream \\\n-\t\t--src-prefix=a/ --dst-prefix=b/ \\\n-\t\t--no-renames $root_flag \"$revisions\" |\n-\tgit am $git_am_opt --rebasing --resolvemsg=\"$RESOLVEMSG\" &&\n-\tmove_to_original_branch\n-\tret=$?\n-\ttest 0 != $ret -a -d \"$apply_dir\" &&\n-\t\techo $head_name > \"$apply_dir/head-name\" &&\n-\t\techo $onto > \"$apply_dir/onto\" &&\n-\t\techo $orig_head > \"$apply_dir/orig-head\" &&\n-\t\techo \"$GIT_QUIET\" > \"$apply_dir/quiet\"\n-\texit $ret\n-fi\n-\n-\n-# start doing a rebase with git-merge\n-# this is rename-aware if the recursive (default) strategy is used\n-\n run_specific_rebase\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156587","messageId":"1290715083-16919-21-git-send-email-martin.von.zweigbergk@gmail.com","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"[PATCH/RFC 20/20] rebase: show consistent conflict resolution hint","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T19:58:03Z","receivedAt":"2010-11-25T19:58:03Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"When rebase stops due to conflict, interactive rebase currently\ndisplays a different hint to the user than non-interactive rebase\ndoes. Use the same message latter message for both types of rebase.\n\nSigned-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n---\n git-rebase--interactive.sh |    4 +---\n 1 files changed, 1 insertions(+), 3 deletions(-)\n\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex d60977d..b810197 100755\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -82,9 +82,7 @@ AMEND=\"$DOTEST\"/amend\n REWRITTEN_LIST=\"$DOTEST\"/rewritten-list\n REWRITTEN_PENDING=\"$DOTEST\"/rewritten-pending\n \n-GIT_CHERRY_PICK_HELP=\"\\\n-hint: after resolving the conflicts, mark the corrected paths\n-hint: with 'git add <paths>' and run 'git rebase --continue'\"\n+GIT_CHERRY_PICK_HELP=\"$RESOLVEMSG\"\n export GIT_CHERRY_PICK_HELP\n \n warn () {\n-- \n1.7.3.2.864.gbbb96\n"},{"id":"156596","messageId":"alpine.DEB.1.10.1011252120450.17721@debian","threadId":"25842","inReplyTo":"1290715083-16919-1-git-send-email-martin.von.zweigbergk@gmail.com","subject":"Re: [PATCH/RFC 00/20] Refactor rebase","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-25T20:23:31Z","receivedAt":"2010-11-25T20:23:31Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"\nI forgot to say that the patches should be applied on pu.\n\n/Martin\n"},{"id":"156623","messageId":"4CEF67AB.6050700@drmicha.warpmail.net","threadId":"25842","inReplyTo":"1290715083-16919-5-git-send-email-martin.von.zweigbergk@gmail.com","subject":"Re: [PATCH/RFC 04/20] rebase: remove unused rebase state 'prev_head'","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-11-26T07:54:19Z","receivedAt":"2010-11-26T07:54:19Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Martin von Zweigbergk venit, vidit, dixit 25.11.2010 20:57:\n> The rebase state 'prev_head' is not used. Remove it.\n> \n> Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n> ---\n\nThe actual value of prev_head was never used. But the check for its\nnon-nullness made sure that git-rev-parse HEAD^0 succeeded when\n$merge_dir was created. Have you made sure that we don't need that check?\n\nMichael\n"},{"id":"156626","messageId":"AANLkTikyQTA3b8+subR2FTL9zFBt_dGqNxjsjP+fwE-n@mail.gmail.com","threadId":"25842","inReplyTo":"alpine.DEB.1.10.1011252120450.17721@debian","subject":"Re: [PATCH/RFC 00/20] Refactor rebase","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-11-26T14:10:56Z","receivedAt":"2010-11-26T14:10:56Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Thu, Nov 25, 2010 at 21:23, Martin von Zweigbergk\n<martin.von.zweigbergk@gmail.com> wrote:\n> I forgot to say that the patches should be applied on pu.\n\nThis is undesirable. In general you should base your patches on\nmaster, unless they depend on a multiple topics in next, in which case\nit's acceptable to base them on next (or directly on that particular\ntopic, if there's only one).\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"156703","messageId":"alpine.DEB.1.10.1011261919540.17721@debian","threadId":"25842","inReplyTo":"4CEF67AB.6050700@drmicha.warpmail.net","subject":"Re: [PATCH/RFC 04/20] rebase: remove unused rebase state 'prev_head'","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-26T18:45:49Z","receivedAt":"2010-11-26T18:45:49Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"\nOn Fri, 26 Nov 2010, Michael J Gruber wrote:\n\n> Martin von Zweigbergk venit, vidit, dixit 25.11.2010 20:57:\n> > The rebase state 'prev_head' is not used. Remove it.\n> > \n> > Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n> > ---\n> \n> The actual value of prev_head was never used. But the check for its\n> non-nullness made sure that git-rev-parse HEAD^0 succeeded when\n> $merge_dir was created. Have you made sure that we don't need that check?\n\nIn continue_merge, the value written to prev_head is the output from\n`git rev-parse HEAD^0`. The value written to prev_head when the rebase\nis initiated seems to be `git rev-parse -q --verify` for some\nreference. In the latter case, the rebase is aborted if the exit code\nfrom rev-parse is non-zero. The prev_head file is only deleted when\nthe whole $merge_dir is deleted.\n\nUnless I'm mistaken, the above taken together seems to mean that\n$prev_head can only be empty if the output of rev-parse is empty. I'm\nstill way to unfamiliar with the Git C code to be able to figure out\nif and when that may happen, but I'm sure you guys can help. The most\nlikely candidate I could think of was an orphan branch (same thing as\nan unborn branch?), but even in that case was the output non-empty\n(`git rev-parse HEAD^0` simply resulted in 'HEAD^0').\n\nDo you see any case where we do need the check?\n\n\n/Martin\n"},{"id":"156704","messageId":"alpine.DEB.1.10.1011261954350.17721@debian","threadId":"25842","inReplyTo":"AANLkTikyQTA3b8+subR2FTL9zFBt_dGqNxjsjP+fwE-n@mail.gmail.com","subject":"Re: [PATCH/RFC 00/20] Refactor rebase","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-11-26T19:16:46Z","receivedAt":"2010-11-26T19:16:46Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"On Fri, 26 Nov 2010, Sverre Rabbelier wrote:\n\n> Heya,\n> \n> On Thu, Nov 25, 2010 at 21:23, Martin von Zweigbergk\n> <martin.von.zweigbergk@gmail.com> wrote:\n> > I forgot to say that the patches should be applied on pu.\n> \n> This is undesirable. In general you should base your patches on\n> master, unless they depend on a multiple topics in next, in which case\n> it's acceptable to base them on next (or directly on that particular\n> topic, if there's only one).\n\nThey touch the same code as 729ec9e (rebase --abort: do not update\nbranch ref), 7baf9c4 (rebase: support --verify) and 92c62a3 (Porcelain\nscripts: Rewrite cryptic \"needs update\" error message). However, it is\nonly 7baf9c4 that would have to be more or less redone if I did not\nbase the patch set on it. Do I understand correctly that I should\ntherefore have based them directly off of 7baf9c4?\n\nI suppose it is not worth resending this time. Tell me if you think\notherwise.\n\n/Martin\n"},{"id":"156705","messageId":"AANLkTi=UbW5r3zY6j=erA7RzDWLYEe=z84=Qt+QarVCp@mail.gmail.com","threadId":"25842","inReplyTo":"alpine.DEB.1.10.1011261954350.17721@debian","subject":"Re: [PATCH/RFC 00/20] Refactor rebase","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-11-27T01:24:56Z","receivedAt":"2010-11-27T01:24:56Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Fri, Nov 26, 2010 at 20:16, Martin von Zweigbergk\n<martin.von.zweigbergk@gmail.com> wrote:\n> They touch the same code as 729ec9e (rebase --abort: do not update\n> branch ref), 7baf9c4 (rebase: support --verify) and 92c62a3 (Porcelain\n> scripts: Rewrite cryptic \"needs update\" error message). However, it is\n> only 7baf9c4 that would have to be more or less redone if I did not\n> base the patch set on it. Do I understand correctly that I should\n> therefore have based them directly off of 7baf9c4?\n\nYes, I think that'd be preferable, unless Junio disagrees?\n\n> I suppose it is not worth resending this time. Tell me if you think\n> otherwise.\n\nYeah, you can just wait to rebase with the next iteration.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"156842","messageId":"7v7hfv262a.fsf@alter.siamese.dyndns.org","threadId":"25842","inReplyTo":"4CEF67AB.6050700@drmicha.warpmail.net","subject":"Re: [PATCH/RFC 04/20] rebase: remove unused rebase state 'prev_head'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-11-29T21:06:21Z","receivedAt":"2010-11-29T21:06:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael J Gruber <git@drmicha.warpmail.net> writes:\n\n> Martin von Zweigbergk venit, vidit, dixit 25.11.2010 20:57:\n>> The rebase state 'prev_head' is not used. Remove it.\n>> \n>> Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n>> ---\n>\n> The actual value of prev_head was never used. But the check for its\n> non-nullness made sure that git-rev-parse HEAD^0 succeeded when\n> $merge_dir was created. Have you made sure that we don't need that check?\n\nI think we are Ok.\n\nIt was a bit sloppy of 9e4bc7d (rebase: cleanup rebasing with --merge,\n2006-06-24) to use the output from `git-rev-parse HEAD^0`, which would\ngive you \"HEAD^0\" as string when HEAD does not exist.  Even though the\ncommand itself will exit with non-zero status, the exit status was never\nchecked.  After 9e4bc7d (rebase: cleanup rebasing with --merge,\n2006-06-24), we didn't seem to have any reason to use $prev_head, iow,\nthis change was probably way overdue.\n"},{"id":"156882","messageId":"4CF4A7C1.3000202@drmicha.warpmail.net","threadId":"25842","inReplyTo":"7v7hfv262a.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH/RFC 04/20] rebase: remove unused rebase state 'prev_head'","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-11-30T07:29:05Z","receivedAt":"2010-11-30T07:29:05Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Junio C Hamano venit, vidit, dixit 29.11.2010 22:06:\n> Michael J Gruber <git@drmicha.warpmail.net> writes:\n> \n>> Martin von Zweigbergk venit, vidit, dixit 25.11.2010 20:57:\n>>> The rebase state 'prev_head' is not used. Remove it.\n>>>\n>>> Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>\n>>> ---\n>>\n>> The actual value of prev_head was never used. But the check for its\n>> non-nullness made sure that git-rev-parse HEAD^0 succeeded when\n>> $merge_dir was created. Have you made sure that we don't need that check?\n> \n> I think we are Ok.\n> \n> It was a bit sloppy of 9e4bc7d (rebase: cleanup rebasing with --merge,\n> 2006-06-24) to use the output from `git-rev-parse HEAD^0`, which would\n> give you \"HEAD^0\" as string when HEAD does not exist.  Even though the\n> command itself will exit with non-zero status, the exit status was never\n> checked.  After 9e4bc7d (rebase: cleanup rebasing with --merge,\n> 2006-06-24), we didn't seem to have any reason to use $prev_head, iow,\n> this change was probably way overdue.\n\nGood! I just wanted to make sure that it wasn't used in some opaque way.\n\nMichael\n"}]}