From: Stephan Beyer <hidden> Date: 2016-06-15 22:45:02
Hi,
for those who are interested in git-sequencer: here's the latest
prototype, that should be able to apply to master.
An outline of the differences to the last sequencer prototype patchset:
- typofixes, minor bugfixes
- simplifications (seen due to builtin-ification)
- introduced --allow-dirty
that is used by the git-am migration, to allow
usage of git-am on dirty index
- set ("keep") ORIG_HEAD; somehow experimental
In the last patchset I mentioned the issue, that the prototype is slow
as hell. I know some bottlenecks, but I have not even tried to change
that, because this is no issue for the builtin.
I paste the experiments that I did on my test machine some time ago:
git-am: Apply 100 (trivial) patches
original: 5.1s
prototype-based: 17s (wtf!)
builtin-based: 2.8s
git-rebase--interactive: Pick 100 (trivial) commits
original: 4.8s
prototype-based: 10.1s
builtin-based: 1.7s
Those times don't have any methodic value, it's just to get an impression.
Nevertheless some information about that:
- performance was only tested one or two times
- /proc/cpuinfo says my machine is an AMD 64 X2 with 4013 BogoMIPS
- /bin/sh is dash (if the propaganda is true, bash is even slower)
- the changes of the patches are equivalent to those of the commits
Regards,
Stephan
Stephan Beyer (5):
Add git-sequencer shell prototype
Add git-sequencer documentation
Add git-sequencer test suite (t3350)
Migrate git-am to use git-sequencer
Migrate rebase-i to sequencer
.gitignore | 1 +
Documentation/git-sequencer.txt | 676 +++++++++++++
Makefile | 1 +
command-list.txt | 1 +
git-am.sh | 632 +++++--------
git-rebase--interactive.sh | 436 ++-------
git-rebase.sh | 7 +-
git-sequencer.sh | 2042 +++++++++++++++++++++++++++++++++++++++
t/t3350-sequencer.sh | 838 ++++++++++++++++
t/t3404-rebase-interactive.sh | 8 +-
t/t4150-am.sh | 4 +-
11 files changed, 3889 insertions(+), 757 deletions(-)
create mode 100644 Documentation/git-sequencer.txt
create mode 100755 git-sequencer.sh
create mode 100755 t/t3350-sequencer.sh
From: Stephan Beyer <hidden> Date: 2016-06-15 22:45:02
The migration of pure rebase-i to sequencer is simply done by
generating the todo list, but with a comment marker (`#')
before the description, and then feed it to git sequencer.
For git-rebase-i -p (preserving merges) merges should be
rewritten. For this, the sequencer instructions "mark", "merge"
and "reset" are used.
Mentored-by: Christian Couder [off-list ref]
Mentored-by: Daniel Barkalow [off-list ref]
Signed-off-by: Stephan Beyer <redacted>
---
git-rebase--interactive.sh | 436 ++++++++++-------------------------------
t/t3404-rebase-interactive.sh | 8 +-
2 files changed, 110 insertions(+), 334 deletions(-)
@@ -42,11 +42,6 @@ STRATEGY=ONTO=VERBOSE=-GIT_CHERRY_PICK_HELP=" After resolving the conflicts,-markthecorrectedpathswith'git add <paths>',and-run'git rebase --continue'"-exportGIT_CHERRY_PICK_HELP- warn(){echo"$*">&2}
@@ -74,48 +69,6 @@ require_clean_work_tree () {die"Working tree is dirty"}-ORIG_REFLOG_ACTION="$GIT_REFLOG_ACTION"--comment_for_reflog(){-case"$ORIG_REFLOG_ACTION"in-''|rebase*)-GIT_REFLOG_ACTION="rebase -i ($1)"-exportGIT_REFLOG_ACTION-;;-esac-}--last_count=-mark_action_done(){-sed-e1q<"$TODO">>"$DONE"-sed-e1d<"$TODO">>"$TODO".new-mv-f"$TODO".new"$TODO"-count=$(grep-c'^[^#]'<"$DONE")-total=$(($count+$(grep-c'^[^#]'<"$TODO")))-iftest"$last_count"!="$count"-then-last_count=$count-printf"Rebasing (%d/%d)\r"$count$total-test-z"$VERBOSE"||echo-fi-}--make_patch(){-parent_sha1=$(gitrev-parse--verify"$1"^)||-die"Cannot get patch for $1^"-gitdiff-tree-p"$parent_sha1".."$1">"$DOTEST"/patch-test-f"$DOTEST"/message||-gitcat-filecommit"$1"|sed"1,/^$/d">"$DOTEST"/message-test-f"$DOTEST"/author-script||-get_author_ident_from_commit"$1">"$DOTEST"/author-script-}--die_with_patch(){-make_patch"$1"-gitrerere-die"$2"-}- die_abort(){rm-rf"$DOTEST"die"$1"
@@ -125,48 +78,20 @@ has_action () {grep'^[^#]'"$1">/dev/null}-pick_one(){-no_ff=-case"$1"in-n)sha1=$2;no_ff=t;;*)sha1=$1;;esac-outputgitrev-parse--verify$sha1||die"Invalid commit name: $sha1"-test-d"$REWRITTEN"&&-pick_one_preserving_merges"$@"&&return-parent_sha1=$(gitrev-parse--verify$sha1^)||-die"Could not get the parent of $sha1"-current_sha1=$(gitrev-parse--verifyHEAD)-iftest"$no_ff$current_sha1"="$parent_sha1";then-outputgitreset--hard$sha1-test"a$1"=a-n&&outputgitreset--soft$current_sha1-sha1=$(gitrev-parse--short$sha1)-outputwarnFastforwardto$sha1-else-outputgitcherry-pick"$@"-fi-}--pick_one_preserving_merges(){-case"$1"in-n)sha1=$2;;*)sha1=$1;;esac+create_todo_preserving_merges(){+shortsha1=$sha1sha1=$(gitrev-parse$sha1)-iftest-f"$DOTEST"/current-commit-then-current_commit=$(cat"$DOTEST"/current-commit)&&-gitrev-parseHEAD>"$REWRITTEN"/$current_commit&&-rm"$DOTEST"/current-commit||-die"Cannot write current commit's replacement sha1"-fi--# rewrite parents; if none were rewritten, we can fast-forward.-fast_forward=tpreserve=tnew_parents=+first_parent=forpin$(gitrev-list--parents-1$sha1|cut-d' '-f2-)do+# check if we've already seen this parentiftest-f"$REWRITTEN"/$pthenpreserve=fnew_p=$(cat"$REWRITTEN"/$p)-test$p!=$new_p&&fast_forward=fcase"$new_parents"in*$new_p*);;# do nothing; that parent is already there
@@ -177,185 +102,46 @@ pick_one_preserving_merges () {elsenew_parents="$new_parents$p"fi+test-n"$first_parent"||first_parent=$pdone-case$fast_forwardin-t)-outputwarn"Fast forward to $sha1"-test$preserve=f||echo$sha1>"$REWRITTEN"/$sha1-;;-f)-test"a$1"=a-n&&die"Refusing to squash a merge: $sha1"--first_parent=$(expr"$new_parents":' \([^ ]*\)')-# detach HEAD to current parent-outputgitcheckout$first_parent2>/dev/null||-die"Cannot move HEAD to $first_parent"--echo$sha1>"$DOTEST"/current-commit-case"$new_parents"in-' '*' '*)-# redo merge-author_script=$(get_author_ident_from_commit$sha1)-eval"$author_script"-msg="$(gitcat-filecommit$sha1|sed-e'1,/^$/d')"-# No point in merging the first parent, that's HEAD-new_parents=${new_parents# $first_parent}-if!GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME"\-GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL"\-GIT_AUTHOR_DATE="$GIT_AUTHOR_DATE"\-outputgitmerge$STRATEGY-m"$msg"\-$new_parents-then-gitrerere-printf"%s\n""$msg">"$GIT_DIR"/MERGE_MSG-dieErrorredoingmerge$sha1-fi-;;-*)-outputgitcherry-pick"$@"||-die_with_patch$sha1"Could not pick $sha1"-;;-esac-;;-esac-}+# We do not have parent, so ignore this commit+testt=$preserve&&return-nth_string(){-case"$1"in-*1[0-9]|*[04-9])echo"$1"th;;-*1)echo"$1"st;;-*2)echo"$1"nd;;-*3)echo"$1"rd;;-esac-}+# We always write a mark, because we do not know if there will+# be a "reset" or "merge"+# Filter the unneeded marks out afterwards.+echo"mark :$mark"+mark=$(($mark+1))-make_squash_message(){-iftest-f"$SQUASH_MSG";then-COUNT=$(($(sed-n"s/^# This is [^0-9]*\([1-9][0-9]*\).*/\1/p"\-<"$SQUASH_MSG"|sed-ne'$p')+1))-echo"# This is a combination of $COUNT commits."-sed-e1d-e'2,/^./{-/^$/d-}'<"$SQUASH_MSG"-else-COUNT=2-echo"# This is a combination of two commits."-echo"# The first commit's message is:"-echo-gitcat-filecommitHEAD|sed-e'1,/^$/d'-fi-echo-echo"# This is the $(nth_string$COUNT) commit message:"-echo-gitcat-filecommit$1|sed-e'1,/^$/d'-}+new_first_parent=$(expr"$new_parents":' \([^ ]*\)')-peek_next_command(){-sed-n"1s/ .*$//p"<"$TODO"-}+# Reset if needed+test-z"$first_parent"-o"$first_parent"=$lastsha1||+echo"reset $new_first_parent"-do_next(){-rm-f"$DOTEST"/message"$DOTEST"/author-script\-"$DOTEST"/amend||exit-readcommandsha1rest<"$TODO"-case"$command"in-'#'*|'')-mark_action_done-;;-pick|p)-comment_for_reflogpick+echo":$mark">"$REWRITTEN"/$sha1-mark_action_done-pick_one$sha1||-die_with_patch$sha1"Could not apply $sha1... $rest"-;;-edit|e)-comment_for_reflogedit--mark_action_done-pick_one$sha1||-die_with_patch$sha1"Could not apply $sha1... $rest"-make_patch$sha1-:>"$DOTEST"/amend-warn"Stopped at $sha1... $rest"-warn"You can amend the commit now, with"-warn-warn" git commit --amend"-warn-warn"Once you are satisfied with your changes, run"-warn-warn" git rebase --continue"-warn-exit0-;;-squash|s)-comment_for_reflogsquash--has_action"$DONE"||-die"Cannot 'squash' without a previous commit"--mark_action_done-make_squash_message$sha1>"$MSG"-case"$(peek_next_command)"in-squash|s)-EDIT_COMMIT=-USE_OUTPUT=output-cp"$MSG""$SQUASH_MSG"-;;-*)-EDIT_COMMIT=-e-USE_OUTPUT=-rm-f"$SQUASH_MSG"||exit-;;-esac--failed=f-author_script=$(get_author_ident_from_commitHEAD)-outputgitreset--softHEAD^-pick_one-n$sha1||failed=t-echo"$author_script">"$DOTEST"/author-script-iftest$failed=f-then-# This is like --amend, but with a different message-eval"$author_script"-GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME"\-GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL"\-GIT_AUTHOR_DATE="$GIT_AUTHOR_DATE"\-$USE_OUTPUTgitcommit--no-verify-F"$MSG"$EDIT_COMMIT||failed=t-fi-iftest$failed=t-then-cp"$MSG""$GIT_DIR"/MERGE_MSG-warn-warn"Could not apply $sha1... $rest"-die_with_patch$sha1""-fi+# Merge or pick+case"$new_parents"in+' '*' '*)+new_parents=${new_parents# $new_first_parent}+printf'merge%s -C %s%s\t%s\n'"$STRATEGY"\+"$shortsha1""$new_parents""$rest";;*)-warn"Unknown command: $command$sha1$rest"-die_with_patch$sha1"Please fix this in the file $TODO."+printf'pick %s\t%s\n'"$shortsha1""$rest";;esac-test-s"$TODO"&&return-comment_for_reflogfinish&&+lastsha1="$sha1"+return0+}++update_refs_and_exit(){HEADNAME=$(cat"$DOTEST"/head-name)&&OLDHEAD=$(cat"$DOTEST"/head)&&SHORTONTO=$(gitrev-parse--short$(cat"$DOTEST"/onto))&&-iftest-d"$REWRITTEN"-then-test-f"$DOTEST"/current-commit&&-current_commit=$(cat"$DOTEST"/current-commit)&&-gitrev-parseHEAD>"$REWRITTEN"/$current_commit-iftest-f"$REWRITTEN"/$OLDHEAD-then-NEWHEAD=$(cat"$REWRITTEN"/$OLDHEAD)-else-NEWHEAD=$OLDHEAD-fi-else-NEWHEAD=$(gitrev-parseHEAD)-fi&&+NEWHEAD=$(gitrev-parseHEAD)&&case$HEADNAMEinrefs/*)message="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO)"&&
@@ -373,13 +159,6 @@ do_next () {exit}-do_rest(){-while:-do-do_next-done-}-# check if no other options are set is_standalone(){test$#-eq2-a"$2"='--'&&
@@ -395,80 +174,47 @@ get_saved_options () {test-f"$DOTEST"/verbose&&VERBOSE=t}-whiletest$#!=0-do-case"$1"in---continue)-is_standalone"$@"||usage-get_saved_options-comment_for_reflogcontinue--test-d"$DOTEST"||die"No interactive rebase running"--# Sanity check-gitrev-parse--verifyHEAD>/dev/null||-die"Cannot read HEAD"-gitupdate-index--ignore-submodules--refresh&&-gitdiff-files--quiet--ignore-submodules||-die"Working tree is dirty"--# do we have anything to commit?-ifgitdiff-index--cached--quiet--ignore-submodulesHEAD--+run_sequencer(){+gitsequencer--caller='git rebase -i|--abort|--continue|--skip'"$@"+case"$?"in+0)+iftest"$1"=--abortthen-:Nothingtocommit--skipthis+rm-rf"$DOTEST"+exitelse-."$DOTEST"/author-script||-die"Cannot find the author identity"-iftest-f"$DOTEST"/amend-then-gitreset--softHEAD^||-die"Cannot rewind the HEAD"-fi-exportGIT_AUTHOR_NAMEGIT_AUTHOR_EMAILGIT_AUTHOR_DATE&&-gitcommit--no-verify-F"$DOTEST"/message-e||-die"Could not commit staged changes."+update_refs_and_exitfi--require_clean_work_tree-do_rest;;---abort)-is_standalone"$@"||usage-get_saved_options-comment_for_reflogabort--gitrerereclear-test-d"$DOTEST"||die"No interactive rebase running"--HEADNAME=$(cat"$DOTEST"/head-name)-HEAD=$(cat"$DOTEST"/head)-case$HEADNAMEin-refs/*)-gitsymbolic-refHEAD$HEADNAME-;;-esac&&-outputgitreset--hard$HEAD&&-rm-rf"$DOTEST"-exit+2)+# pause+exit0;;---skip)-is_standalone"$@"||usage-get_saved_options-comment_for_reflogskip--gitrerereclear-test-d"$DOTEST"||die"No interactive rebase running"+3)+# conflict+exit1+;;+*)+die_abort'git-sequencer died unexpected.'+;;+esac+}-outputgitreset--hard&&do_rest+whiletest$#!=0+do+case"$1"in+--abort|--continue|--skip)+is_standalone"$@"||usage+run_sequencer"$1";;-s)case"$#,$1"in*,*=*)-STRATEGY="-s "$(expr"z$1":'z-[^=]*=\(.*\)');;+STRATEGY=" -s "$(expr"z$1":'z-[^=]*=\(.*\)');;1,*)usage;;*)-STRATEGY="-s $2"+STRATEGY=" -s $2"shift;;esac;;
@@ -494,12 +240,12 @@ dotest$#-eq1-o$#-eq2||usagetest-d"$DOTEST"&&die"Interactive rebase already started"+gitsequencer--status>/dev/null2>&1&&+die"Sequencer already started. Cannot run rebase."gitvarGIT_COMMITTER_IDENT>/dev/null||die"You need to set your committer info first"-comment_for_reflogstart-require_clean_work_treeUPSTREAM=$(gitrev-parse--verify"$1")||die"Invalid base"
@@ -516,42 +262,72 @@ doHEAD=$(gitrev-parse--verifyHEAD)||die"No HEAD?"mkdir"$DOTEST"||die"Could not create temporary $DOTEST"-:>"$DOTEST"/interactive||die"Could not mark as interactive"+:>"$DOTEST"/interactive||die_abort"Could not mark as interactive"gitsymbolic-refHEAD>"$DOTEST"/head-name2>/dev/null||echo"detached HEAD">"$DOTEST"/head-nameecho$HEAD>"$DOTEST"/head-echo$UPSTREAM>"$DOTEST"/upstreamecho$ONTO>"$DOTEST"/ontotest-z"$STRATEGY"||echo"$STRATEGY">"$DOTEST"/strategytestt="$VERBOSE"&&:>"$DOTEST"/verboseiftestt="$PRESERVE_MERGES"then+lastsha1=# $REWRITTEN contains files for each commit that is-# reachable by at least one merge base of $HEAD and-# $UPSTREAM. They are not necessarily rewritten, but-# their children might be.-# This ensures that commits on merged, but otherwise-# unrelated side branches are left alone. (Think "X"-# in the man page's example.)+# reachable on the way between $UPSTREAM and $HEAD.+# The filename is the SHA1 of the old value and the+# content is the SHA1 or :mark of the new one.mkdir"$REWRITTEN"&&forcin$(gitmerge-base--all$HEAD$UPSTREAM)do+test-n"$lastsha1"||lastsha1=$cecho$ONTO>"$REWRITTEN"/$c||die"Could not init rewritten commits"done-MERGES_OPTION=-else-MERGES_OPTION=--no-merges+gitrev-list--abbrev-commit--abbrev=7\+--pretty=format:"%m%h # %s"--topo-order\+--reverse--cherry-pick$UPSTREAM...$HEAD|\+sed-n-e"s/^>//p">"$DOTEST"/commit-list++mark=0+whileread-rsha1rest+do+create_todo_preserving_merges+done<"$DOTEST"/commit-list>"$TODO"++# We now have more "mark :..." lines than needed.+# Remove the unused. This is just a step to keep+# the list clean.+keep_marks=$(sed-e"/^mark :/d"<"$TODO"|+sed-n-e's/^[^#]* :\([0-9][0-9]*\).*$/:\1:/p')+whileread-rline+do+case"$line"in+'mark :'*)+case"$keep_marks "in+*${line#mark }:*)+echo"$line"+;;+esac+;;+*)+printf'%s\n'"$line"+;;+esac+done<"$TODO">"$TODO".new+mv"$TODO".new"$TODO"+fi+iftest-z"$PRESERVE_MERGES"+then+gitrev-list--no-merges--abbrev-commit--abbrev=7\+--pretty=format:"%mpick %h # %s"\+--reverse--cherry-pick$UPSTREAM...$HEAD|\+sed-n-e"s/^>//p">"$TODO"fiSHORTUPSTREAM=$(gitrev-parse--short$UPSTREAM)SHORTHEAD=$(gitrev-parse--short$HEAD)SHORTONTO=$(gitrev-parse--short$ONTO)-gitrev-list$MERGES_OPTION--pretty=oneline--abbrev-commit\---abbrev=7--reverse--left-right--cherry-pick\-$UPSTREAM...$HEAD|\-sed-n"s/^>/pick /p">"$TODO"cat>>"$TODO"<<EOF# Rebase $SHORTUPSTREAM..$SHORTHEAD onto $SHORTONTO
@@ -577,7 +353,7 @@ EOFdie_abort"Nothing to do"gitupdate-refORIG_HEAD$HEAD-outputgitcheckout$ONTO&&do_rest+run_sequencer--onto"$ONTO""$TODO";;esacshift
@@ -0,0 +1,838 @@+#!/bin/sh+#+# Copyright (c) 2008 Stephan Beyer+#+# `setup' is based on t3404* by Johannes Schindelin.++test_description='gitsequencer++Thesearebasicusagetestsforgitsequencer.+'+../test-lib.sh++# set up two branches like this:+#+# A - B - C - D - E+# \+# F - G - H+# \+# I+#+# where B, D and G touch increment value in file1.+# The others generate empty file[23456].++SEQDIR=".git/sequencer"+SEQMARK="refs/sequencer-marks"+MARKDIR=".git/$SEQMARK"++test_expect_success'setup''+:>file1&&+gitaddfile1&&+test_tick&&+gitcommit-m"generate empty file1"&&+gittagA&&+echo1>file1&&+test_tick&&+gitcommit-m"write 1 into file1"file1&&+gittagB&&+:>file2&&+gitaddfile2&&+test_tick&&+gitcommit-m"generate empty file2"&&+gittagC&&+echo2>file1&&+test_tick&&+gitcommit-m"write 2 into file1"file1&&+gittagD&&+:>file3&&+gitaddfile3&&+test_tick&&+gitcommit-m"generate empty file3"&&+gittagE&&+gitcheckout-bbranch1A&&+:>file4&&+gitaddfile4&&+test_tick&&+gitcommit-m"generate empty file4"&&+gittagF&&+echo3>file1&&+test_tick&&+gitcommit-m"write 3 into file1"file1&&+gittagG&&+:>file5&&+gitaddfile5&&+test_tick&&+gitcommit-m"generate empty file5"&&+gittagH&&+gitcheckout-bbranch2F&&+:>file6&&+gitaddfile6&&+test_tick&&+gitcommit-m"generate empty file6"&&+gittagI&&+gitdiff-p--rawC..D>patchD.raw&&+gitdiff-p--rawA..F>patchF.raw&&+gitformat-patch--stdoutA..B>patchB&&+gitformat-patch--stdoutB..C>patchC&&+gitformat-patch--stdoutC..D>patchD&&+gitformat-patch--stdoutA..F>patchF&&+gitformat-patch--stdoutF..G>patchG+'++orig_author="$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"++# Functions to verify exit status of sequencer.+# Do not just use "test_must_fail git sequencer ..."!+expect_fail(){+"$@"+test$?-eq1+}+expect_continue(){+"$@"+test$?-eq2+}+expect_conflict(){+"$@"+test$?-eq3+}+++# Other test helpers:++# Test if commit $1 has author $2+expect_author(){+test"$2"="$(gitcat-filecommit"$1"|+sed-n-e"s/^author \(.*\)> .*$/\1>/p")"+}++# Test if commit $1 has commit message in file $2+# Side effect: overwrites actual+expect_msg(){+gitcat-filecommit"$1"|sed-e"1,/^$/d">actual&&+test_cmp"$2"actual+}++# Test that no marks are set.+no_marks_set(){+iftest-e"$MARKDIR"+then+rmdir"$MARKDIR"+fi+}++test_expect_success'fail on empty TODO from stdin''+expect_failgitsequencer<file6&&+!test-d"$SEQDIR"+'++# Generate fake editor+#+# Simple and practical concept:+# We use only a small string identifier for "editor sessions".+# Each sessions knows what to do and perhaps defines+# which session to choose next.+echo"#!$SHELL_PATH">fake-editor.sh+cat>>fake-editor.sh<<\EOF+test-ffake-editor-session||exit1+#test -t 1 || exit 1+# This test could be useful, but as the test-lib is not always+# verbose, this will fail.+next=ok+readthis<fake-editor-session+case"$this"in+commitmsg)+echo'echo 2 >file1'+;;+squashCE)+echo'generate file2 and file3'+;;+squashCI)+echo'generate file2 and file6'+next=squashDCE+;;+squashDCE)+echo'generate file2 and file3 and write 2 into file1'+next=merge1+;;+merge1)+echo'A typed merge message.'+;;+merge2)+test"$(sed-n-e1p"$1")"='test merge'&&+echo'cleanup merge'||+echoerror+sed-e1d"$1"+;;+editXXXXXXXXX)+printf'last edited'+;;+edit*)+printf'edited: '+cat"$1"+next="${this}X"+;;+nochange)+cat"$1"+;;+ok|fail)+echo'-- THIS IS UNEXPECTED --'+next=fail+;;+*)+echo'I do not know.'+;;+esac>"$1".tmp+mv"$1".tmp"$1"+echo$next>fake-editor-session+exit0+EOF+chmoda+xfake-editor.sh+test_set_editor"$(pwd)/fake-editor.sh"++next_session(){+echo"$1">fake-editor-session+}++# check if fake-editor-session is ok.+# If "$1" is set to anything, it will set the+# next session to "ok", which is nice for+# test_expect_failure.+session_ok(){+test"ok"=$(catfake-editor-session)+ret=$?+test-n"$1"&&next_sessionok+return$ret+}+++cat>todotest1<<EOF+pickC+squashE+refrefs/tags/CE+EOF++test_expect_success'"pick", "squash", "ref" from stdin''+next_sessionsquashCE&&+gitsequencer<todotest1&&+!test-d"$SEQDIR"&&+session_ok&&+test-ffile2&&+test-ffile3&&+test$(gitrev-parseCE)=$(gitrev-parseHEAD)&&+test$(gitrev-parseI)=$(gitrev-parseHEAD^)+'++cat>todotest2<<EOF+# This is a test++resetI# go back to I++EOF++test_expect_success'"reset" from file with comments and blank lines''+gitsequencertodotest2&&+session_ok&&+test$(gitrev-parseI)=$(gitrev-parseHEAD)+'++cat>todotest1<<EOF+pickC+EOF++test_expect_success'--onto <branch> keeps branch''+gitcheckout-btest-branchA&&+gitcheckoutmaster&&+gitsequencer--ontotest-branch<todotest1&&+session_ok&&+test"$(gitsymbolic-ref-qHEAD)"="refs/heads/test-branch"&&+test"$(gitrev-parsetest-branch^)"="$(gitrev-parseA)"+'++test_expect_success'--onto commit (detached HEAD) works''+gitsequencer--ontoA<todotest1&&+session_ok&&+test_must_failgitsymbolic-ref-qHEAD&&+test"$(gitrev-parseHEAD)"="$(gitrev-parsetest-branch)"+'++echo'pick -R C'>>todotest1++test_expect_success'pick -R works''+gitcheckoutA&&+gitsequencertodotest1&&+session_ok&&+!test-ffile2+'++mkdirtestdir+cat>testdir/script<<EOF+#!/bin/sh+test-s../file1+EOF+chmod755testdir/script+cat>todotest1<<EOF+run--test-sfile1# this will fail+pickB+run--dirtestdir--test-s../file1+pickD+run--dir=testdir./script+EOF++test_expect_success'"run" insn works''+gitcheckoutA&&+expect_conflictgitsequencertodotest1&&+:>newfile&&+gitaddnewfile&&+next_sessionnochange&&+gitsequencer--continue&&+session_ok&&+test-fnewfile+'++echothisdoesnotexist>>todotest1++test_expect_success'junk is conflict''+gitcheckoutA&&+expect_conflictgitsequencertodotest1&&+test-d"$SEQDIR"&&+gitsequencer--abort&&+!test-d"$SEQDIR"&&+session_ok&&+test$(gitrev-parseA)=$(gitrev-parseHEAD)+'++GIT_AUTHOR_NAME="Another 'ant' Thor"+GIT_AUTHOR_EMAIL="a.thor@example.com"+GIT_COMMITTER_NAME="Co M Miter"+GIT_COMMITTER_EMAIL="c.miter@example.com"+exportGIT_AUTHOR_NAMEGIT_AUTHOR_EMAILGIT_COMMITTER_NAMEGIT_COMMITTER_EMAIL+yet_another="Max Min <mm@example.com>"++cat>todotest1<<EOF+patchpatchB# write 1 into file1+patch-kpatchC# generate file2+patchpatchD.raw# write 2 into file1+EOF++echo'write 1 into file1'>expected1+echo'[PATCH] generate empty file2'>expected2+echo'echo 2 >file1'>expected3++test_expect_success'"patch" insn works''+gitcheckoutA&&+next_sessioncommitmsg&&+gitsequencertodotest1&&+!test-d"$SEQDIR"&&+session_ok&&+test"$(gitrev-parseHEAD~3)"="$(gitrev-parseA)"&&+test"$(gitshowHEAD~2:file1)"="1"&&+test-z"$(gitshowHEAD^:file2)"&&+test"$(gitshowHEAD:file1)"="2"&&+expect_authorHEAD~2"$orig_author"&&+expect_authorHEAD~1"$orig_author"&&+expect_authorHEAD~0"$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"&&+expect_msgHEAD~2expected1&&+expect_msgHEAD~1expected2&&+expect_msgHEAD~0expected3+'++cat>todotest1<<EOF+pickB# write 1 into file1+pause+pickC# generate file2+EOF++echo'generate empty file2'>expected1+echo'write 1 into file1'>expected2++test_expect_success"pick ; pause insns and --continue works"'+gitcheckoutA&&+expect_continuegitsequencertodotest1&&+session_ok&&+echo5>file1&&+gitaddfile1&&+next_sessionnochange&&+gitsequencer--continue&&+test"$(gitshowHEAD:file1)"=5&&+test-z"$(gitshowHEAD:file2)"&&+expect_msgHEADexpected1&&+expect_msgHEAD^expected2&&+session_ok+'++cat>todotest1<<EOF+editB# write 1 into file1+pickC# generate file2+EOF++test_expect_success"edit insn and --continue works"'+gitcheckoutA&&+expect_continuegitsequencertodotest1&&+session_ok&&+echo5>file1&&+gitaddfile1&&+next_sessionnochange&&+gitsequencer--continue&&+test"$(gitshowHEAD:file1)"=5&&+test-z"$(gitshowHEAD:file2)"&&+expect_msgHEADexpected1&&+expect_msgHEAD^expected2&&+session_ok+'++cat>todotest1<<EOF+patchpatchB# write 1 into file1+pickH# generate file5+mark:1+patchpatchC# generate file2+squashI# generate file6+patchpatchD# write 2 into file1+refrefs/tags/CID+mark:2+reset:1# reset to new H+patchpatchD# write 2 into file1+squashCE# generate file2 and file3+refrefs/tags/DCE+merge:2# merge :2 into HEAD+patchpatchF# generate file4+EOF++test_expect_success'all insns work without options''+gitcheckoutA&&+next_sessionsquashCI&&+no_marks_set&&+gitsequencertodotest1&&+no_marks_set&&+test"$(gitshowHEAD:file1)"="2"&&+test-z"$(gitshowHEAD:file2)"&&+test-z"$(gitshowHEAD:file3)"&&+test-z"$(gitshowHEAD:file4)"&&+test-z"$(gitshowHEAD:file5)"&&+test-z"$(gitshowHEAD:file6)"&&+echo"$(gitrev-parseDCE)">expected&&+echo"$(gitrev-parseCID)">>expected&&+gitcat-filecommitHEAD^|sed-n-e"s/^parent //p">actual&&+test_cmpexpectedactual&&+session_ok+'++cat>todotest1<<EOF+merge--standardDCE+EOF++echo"Merge DCE into HEAD">expected1++test_expect_success'merge --standard works''+gitcheckoutCID&&+gitsequencertodotest1&&+expect_msgHEADexpected1&&+session_ok+'++cat>todotest1<<EOF+merge--standard--message="foo"DCE+EOF+++test_expect_success'merge --standard --message="foo" is conflict''+gitcheckoutCID&&+expect_conflictgitsequencertodotest1&&+gitsequencer--abort&&+session_ok+'++forcommandin'pick ''patch patch''squash ''merge --standard '+do+cat>todotest1<<EOF+patchpatchB# 1 into file1+${command}G# 3 into file1+patch-3patchF# empty file4+EOF++test_expect_success"conflict test: ${command%% *} and --abort"'+gitcheckoutA&&+expect_conflictgitsequencertodotest1&&+session_ok&&+test-d"$SEQDIR"&&+gitsequencer--abort&&+session_ok&&+test$(gitrev-parseHEAD)=$(gitrev-parseA)+'++test_expect_success"conflict test: ${command%% *} and --continue"'+gitcheckoutA&&+expect_conflictgitsequencertodotest1&&+session_ok&&+test-d"$SEQDIR"&&+## XXX: It would be perfect if we could remove the if+{iftest"${command%% *}"!="patch"+thengrep"^<<<<<<<"file1;fi}&&+echo3>file1&&+gitaddfile1&&+next_sessionnochange&&+gitsequencer--continue&&+session_ok&&+!test-d"$SEQDIR"&&+test"$(gitshowHEAD:file1)"="3"&&+test-ffile4+'++test_expect_success"conflict test: ${command%% *} and --skip"'+gitcheckoutA&&+expect_conflictgitsequencertodotest1&&+session_ok&&+test-d"$SEQDIR"&&+gitsequencer--skip&&+session_ok&&+!test-d"$SEQDIR"&&+test"$(gitshowHEAD:file1)"="1"&&+test-ffile4+'+done++echo'file5-gen'>commitmsg++cat>todotest1<<EOF+patch--signoffpatchB+pause+pick--author="$yet_another"--file="commitmsg"--signoffH+mark:1+patch--message="file2-gen"patchC+squash--signoff--author="$yet_another"I+pause+patch--message="echo 2 >file1"patchD+mark:2+reset:1+patch--author="$yet_another"patchD+squash--signoff--message="generate file[23]"CE+merge--signoff--message="test merge"--author="$yet_another":2+pause+refrefs/tags/a_merge+patch--message="Generate file4 and write 23 into it"patchF.raw+pause+pickI+EOF++cat>expected1<<EOF+write1intofile++Signed-off-by:$GIT_COMMITTER_NAME<$GIT_COMMITTER_EMAIL>+EOF++test_expect_success'insns work with options and another author 1''+gitcheckoutA&&+no_marks_set&&++# patch --signoff patchB # write 1 into file1+# pause+expect_continuegitsequencertodotest1&&+test"Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"=\+"$(gitcat-filecommitHEAD|grep"^Signed-off-by")"&&+expect_authorHEAD"$orig_author"&&+test-d"$SEQDIR"&&+session_ok+'++cat>expected1<<EOF+file5-gen++Signed-off-by:$GIT_COMMITTER_NAME<$GIT_COMMITTER_EMAIL>+EOF++cat>expected2<<EOF+file2-gen++generateemptyfile6++Signed-off-by:$GIT_COMMITTER_NAME<$GIT_COMMITTER_EMAIL>+EOF++test_expect_success'insns work with options and another author 2''+:>file7&&+gitaddfile7&&+next_sessionnochange&&+gitcommit--amend&&+session_ok&&++next_sessionnochange&&+expect_continuegitsequencer--continue&&+session_ok&&++# amended commit+test"Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"=\+"$(gitcat-filecommitHEAD^^|grep"^Signed-off-by")"&&+expect_authorHEAD^^"$orig_author"&&+test-z"$(gitshowHEAD:file7)"&&++# pick --author="$yet_another" --file="commitmsg" --signoff H+expect_authorHEAD^"$yet_another"&&+expect_msgHEAD^expected1&&+test-z"$(gitshowHEAD:file5)"&&++# mark :1+test"$(gitrev-parse"$SEQMARK/1")"="$(gitrev-parseHEAD^)"&&++# patch --message="file2-gen" patchC+# squash --signoff --author="$yet_another" I # generate file6+# pause+test-z"$(gitshowHEAD:file2)"&&+test-z"$(gitshowHEAD:file6)"&&+gitls-files|grep"^file2"&&+gitls-files|grep"^file6"&&+expect_msgHEADexpected2&&+expect_authorHEAD"$yet_another"+'++echo'echo 2 >file1'>expected1++cat>expected2<<EOF+generatefile[23]++Signed-off-by:$GIT_COMMITTER_NAME<$GIT_COMMITTER_EMAIL>+EOF++cat>expected3<<EOF+testmerge++Signed-off-by:$GIT_COMMITTER_NAME<$GIT_COMMITTER_EMAIL>+EOF++cat>expected4<<EOF+file1+file2+file3+file5+file6+file7+EOF++test_expect_success'insns work with options and another author 3''+# do not change anything+expect_continuegitsequencer--continue&&+session_ok&&++# patch --message="echo 2 >file1" patchD+# mark :2+commit="$(gitrev-parse--verify"$SEQMARK/2")"&&+expect_author"$commit""$orig_author"&&+expect_msg"$commit"expected1&&++# reset :1+# patch --author="$yet_another" patchD # write 2 into file1+# squash --signoff --message="generate file[23]" CE+expect_authorHEAD^"$yet_another"&&+expect_msgHEAD^expected2&&++# merge --signoff --message="test merge" --author="$yet_another" :2+# pause+expect_authorHEAD"$yet_another"&&+expect_msgHEADexpected3&&+gitls-files>actual&&+test_cmpexpected4actual+'++cat>expected_merge<<EOF+cleanupmerge++Signed-off-by:$GIT_COMMITTER_NAME<$GIT_COMMITTER_EMAIL>+EOF++echo'Generate file4 and write 23 into it'>expected2++test_expect_success'insns work with options and another author 4''+gitrmfile5file6file7&&+next_sessionmerge2&&+expect_continuegitsequencer--continue&&+session_ok&&++# ref refs/tags/a_merge+expect_authora_merge"$yet_another"&&+expect_msga_mergeexpected_merge&&++# patch --message="Generate file4 and write 23 into it" patchF.raw+# pause+gitls-files|grep"^file4"&&+echo23>file4&&+gitaddfile4&&+next_sessionnochange&&+gitsequencer--continue&&+session_ok&&+no_marks_set&&+test"$(gitshowHEAD:file1)"="2"&&+test"$(gitshowHEAD:file4)"="23"&&+expect_msgHEAD^expected2&&+expect_authorHEAD^"$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"&&++# pick I+test-z"$(gitshowHEAD:file6)"&&+gitls-files|grep"^file6"&&+session_ok+'++# almost the same to test --quiet+cat>todotest1<<EOF+patchpatchB+pickH+mark:1+patchpatchC+squash--message="a squash"I+patchpatchD+mark:2+reset:1+patchpatchD+squash--message="another squash"CE+merge--message="test merge":2+pause+patchpatchF+EOF++test_expect_failure'--quiet works''+gitcheckoutA&&+expect_continuegitsequencer--quiettodotest1>actual&&+session_ok&&+!test-sactual+'++test_expect_failure'--quiet works on continue''+gitsequencer--continue>>actual&&+session_ok&&+!test-sactual+'++echo'merge --strategy=ours --reuse-commit=a_merge branch1 branch2 CE CID'>todotest1++test_expect_success'merge multiple branches and --reuse-commit works''+gitcheckout-bmerge-multiplemaster&&+gitsequencertodotest1&&+session_ok&&+expect_msgHEADexpected_merge&&+gitrev-parseHEAD^>expected&&+gitrev-parsebranch1>>expected&&+gitrev-parsebranch2>>expected&&+gitrev-parseCE>>expected&&+gitrev-parseCID>>expected&&+gitcat-filecommitHEAD|sed-n-e"s/^parent //p">actual&&+test_cmpexpectedactual&&+!test-ffile6+'++echo'pick --mainline=5 merge-multiple'>todotest1++test_expect_success'pick --mainline works''+gitcheckout-bmainlineCID&&+gitsequencertodotest1&&+session_ok&&+expect_msgHEADexpected_merge&&+!test-ffile6&&+test-ffile3&&+test-ffile2&&+test"$(gitshowHEAD:file1)"=2+'++cat>todotest1<<EOF+pickC# file2+mark:1+patchpatchB# write 1 into file1+patchpatchD# write 2 into file1+pickI# file6+squash--message="2 in file1 and file6 exists"--signoff--from:1+EOF++cat>expected1<<EOF+2infile1andfile6exists++Signed-off-by:$GIT_COMMITTER_NAME<$GIT_COMMITTER_EMAIL>+EOF++test_expect_success'squash --from works''+gitcheckoutA&&+gitsequencer<todotest1&&+session_ok&&+test"$(gitrev-parseA)"="$(gitrev-parseHEAD~2)"&&+test"$(gitshowHEAD:file1)"="2"&&+test-z"$(gitshowHEAD:file6)"&&+expect_msgHEADexpected1+'++cat>todotest1<<EOF+patchpatchB# write 1 into file1+pickH# generate file5+mark:1+patchpatchC# generate file2+squash--message="file5"I# generate file6+patchpatchD# write 2 into file1+mark:2+reset:1# reset to new H+patchpatchD# write 2 into file1+squash--message="CE"CE# generate file2 and file3+merge--standard:2# merge :2 into HEAD+patchpatchF# generate file4+EOF+cptodotest1todotest2+cattodotest1|sed-e's/^\(patch\|pick\|squash\|merge\) /&--edit /'>todotest3+echo'squash --message="doesnt work either" --from :1'>>todotest1+echo'squash --include-merges --message="stupid" --from :1'>>todotest2++test_expect_success'squash --from conflicts with merge in between''+gitcheckoutA&&+expect_conflictgitsequencertodotest1&&+gitsequencer--abort&&+session_ok&&+!test-d"$SEQDIR"+'++test_expect_success'squash --include-merges --from succeeds with merge in between''+gitcheckoutA&&+gitsequencertodotest2&&+session_ok&&+test"$(gitrev-parseHEAD~3)"="$(gitrev-parseA)"+'++test_expect_success'patch|pick|squash|merge --edit works''+gitcheckoutA&&+next_sessioneditX&&+gitsequencertodotest3&&+session_ok+'++cat>todotest1<<EOF+patchpatchB+pause+EOF++test_expect_success'batch mode fails on pause insn''+gitcheckoutA&&+expect_failgitsequencer--batchtodotest1&&+session_ok&&+!test-d"$SEQDIR"+'++cat>todotest1<<EOF+patchpatchB+pickG+EOF++test_expect_success'batch mode fails on conflict''+gitcheckoutA&&+expect_failgitsequencer--batch<todotest1&&+session_ok&&+!test-d"$SEQDIR"&&+test-z"$(gitshowHEAD:file1)"+'++cat>todotest1<<EOF+patchpatchB+pause+EOF++test_expect_success'--caller works''+gitcheckoutA&&+expect_continuegitsequencer\+--caller="this works|abrt||skip"todotest1&&+expect_failgitsequencer--abort&&+expect_failgitsequencer--skip&&+gitsequencer--continue&&+session_ok+'++test_done
From: Stephan Beyer <hidden> Date: 2016-06-15 22:45:02
git-sequencer is planned as a backend for user scripts
that execute a sequence of git instructions and perhaps
need manual intervention, for example git-rebase or git-am.
Mentored-by: Christian Couder [off-list ref]
Mentored-by: Daniel Barkalow [off-list ref]
Signed-off-by: Stephan Beyer <redacted>
---
.gitignore | 1 +
Makefile | 1 +
command-list.txt | 1 +
git-sequencer.sh | 2042 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 2045 insertions(+), 0 deletions(-)
create mode 100755 git-sequencer.sh
@@ -0,0 +1,2042 @@+#!/bin/sh+# A git sequencer prototype.++SUBDIRECTORY_OK=Yes+OPTIONS_KEEPDASHDASH=+OPTIONS_SPEC="\+gitsequencer[options][--][<file>]+gitsequencer(--continue|--abort|--skip|--edit|--status)+--+Optionstostartasequencingprocess+allow-dirtyrunevenifworkingtreeisdirty+B,batchruninbatch-mode+onto=checkoutthegivencommitorbranchfirst+no-advicesuppressadvicewhenpausing(conflicts,etc)+q,quietsuppressoutput+v,verbosebemoreverbose+Optionstorestart/changeasequencingprocessorshowinformation+continuecontinuepausedsequencerprocess+abortrestoreoriginalbranchandabort+skipskipcurrentpatchandcontinue+statusshowthestatusofthesequencingprocess+editinvokeeditortoletuseredittheremaininginsns+Optionstobeusedbyuserscripts+caller=provideinformationstring:name|abort|cont|skip+"++.git-sh-setup+require_work_tree++gitvarGIT_COMMITTER_IDENT>/dev/null||+die'You need to set your committer info first'++SEQ_DIR="$GIT_DIR/sequencer"+TODO="$SEQ_DIR/todo"+DONE="$SEQ_DIR/done"+MSG="$SEQ_DIR/message"+PATCH="$SEQ_DIR/patch"+AUTHOR_SCRIPT="$SEQ_DIR/author-script"+ORIG_AUTHOR_SCRIPT="$SEQ_DIR/author-script.orig"+CALLER_SCRIPT="$SEQ_DIR/caller-script"+WHY_FILE="$SEQ_DIR/why"+MARK_PREFIX='refs/sequencer-marks'++warn(){+printf"%s\n""$*">&2+}++cleanup(){+forrefin$(gitfor-each-ref--format='%(refname)'"$MARK_PREFIX")+do+gitupdate-ref-d"$ref""$ref"||return+done+test-z"$ORIG_HEAD"||gitupdate-refORIG_HEAD"$ORIG_HEAD"+rm-rf"$SEQ_DIR"+}++print_advice(){+case"$ADVICE,$WHY"in+t,conflict)+echo"+Afterresolvingtheconflicts,markthecorrectedpathswith++gitadd<paths>++andrun++$(print_caller--continue)++Note,thatyourworkingtreemustmatchtheindex."+;;+t,pause)+echo"+Youcannoweditfilesandaddthemtotheindex.+Onceyouaresatisfiedwithyourchanges,run++$(print_caller--continue)++Ifyouonlywanttochangethecommitmessage,run+gitcommit--amendbefore."+;;+t,run)+echo"+Runningfailed:+$@++Youcannowfixtheproblem.Whenmanualrunspass,+addthechangestotheindexandinvoke++$(print_caller--continue)"+;;+t,todo)+echo"+Fixwithgitsequencer--editorabortwith$(print_caller--abort)."+;;+esac+}++# Die if there has been a conflict+die_to_continue(){+warn"$*"+test-z"$BATCHMODE"||+die_abort'Aborting, because of batch mode.'+test-n"$WHY"||WHY=conflict+echo"$WHY">"$WHY_FILE"+print_advice+test-z"$ORIG_HEAD"||gitupdate-refORIG_HEAD"$ORIG_HEAD"+exit3+}++die_abort(){+restore+cleanup+die"$1"+}++perform(){+case"$VERBOSE"in+0)+"$@">/dev/null+;;+1)+output=$("$@"2>&1)+status=$?+test$status-ne0&&printf'%s\n'"$output"+return$status+;;+2)+"$@"+;;+esac+}++# test if working tree is dirty+require_clean_work_tree(){+iftest-z"$ALLOW_DIRTY"+then+gitrev-parse--verifyHEAD>/dev/null&&+gitupdate-index--ignore-submodules--refresh&&+gitdiff-files--quiet--ignore-submodules||+die'Working tree is dirty.'+fi+gitdiff-index--cached--quietHEAD--ignore-submodules--||+die'Index is dirty'+}++ORIG_REFLOG_ACTION="$GIT_REFLOG_ACTION"++comment_for_reflog(){+iftest-z"$ORIG_REFLOG_ACTION"+then+GIT_REFLOG_ACTION='sequencer'+test-z"$CALLER"||+GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION ($CALLER)"+exportGIT_REFLOG_ACTION+fi+}++# Get commit message from commit $1+commit_message(){+gitcat-filecommit"$1"|sed-e'1,/^$/d'+}++LAST_COUNT=+remove_from_todo(){+sed-e1q<"$TODO">>"$DONE"+sed-e1d<"$TODO">"$TODO.new"+mv-f"$TODO.new""$TODO"+todo_ack"$TODO"+iftest"$VERBOSE"-gt0+then+count=$(grep-c'^[^#]'<"$DONE")+total=$(expr"$count"+"$(grep-c'^[^#]'<"$TODO")")+iftest"$LAST_COUNT"!="$count"+then+LAST_COUNT="$count"+test"$VERBOSE"-eq1-a-t1-o"$VERBOSE"-gt1&&+printf'Sequencing (%d/%d)\r'"$count""$total"+test"$VERBOSE"-lt2||echo+fi+fi+}++# Generate message and author script files+save_commit_data(){+test-f"$MSG"||+commit_message"$1">"$MSG"+test-f"$AUTHOR_SCRIPT"||+get_author_ident_from_commit"$1">"$AUTHOR_SCRIPT"+}++# Generate a patch and die with "conflict" status code+die_with_patch(){+save_commit_data"$1"+performgitrerere+die_to_continue"$2"+}++reset_almost_hard(){+performgitread-tree--reset-u$ALLOW_DIRTY"$1"&&+performgitreset"$1"+}++restore(){+# XXX: We should undo all "ref" invocations, but that's left to be+# done in the builtin-sequencer.+readHEADNAME<"$SEQ_DIR/head-name"+case$HEADNAMEin+refs/*)+gitsymbolic-refHEAD"$HEADNAME"+;;+esac&&+reset_almost_hard"$ORIG_HEAD"+}++has_action(){+grep'^[^#]'"$1">/dev/null+}++# Check if text file $1 contains a commit message+has_message(){+test-n"$(sed-n-e'/^Signed-off-by:/d;/^[^#]/p'<"$1")"+}++# Count parents of commit $1+count_parents(){+gitcat-filecommit"$1"|sed-n-e'1,/^$/p'|grep-c'^parent'+}++# Evaluate the author script to get author information to+# apply it with "with_author git foo" then.+get_current_author(){+iftest-f"$AUTHOR_SCRIPT"+then+."$AUTHOR_SCRIPT"+else+."$ORIG_AUTHOR_SCRIPT"+fi||die_abort'Author script is damaged. This must not happen!'+}++# Run command with author information+with_author(){+GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME"\+GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL"\+GIT_AUTHOR_DATE="$GIT_AUTHOR_DATE"\+"$@"+}++# clean WHY_FILE and reset WHY+clean_why(){+rm-f"$WHY_FILE"+WHY=+}++# Usage: pick_one (cherry-pick|revert) [-*|--edit] sha1+pick_one(){+what="$1"+shift++case"$what,$1"in+revert,*)+test"$1"!='--edit'&&+what='revert --no-edit'+;;+cherry-pick,-*)+;;+cherry-pick,*)+# fast forward+iftest"$(gitrev-parse--verify"$1^"2>/dev/null)"=\+"$(gitrev-parse--verifyHEAD)"+then+reset_almost_hard"$1"+return+fi+;;+esac+$use_performgit$what"$@"+}++nth_string(){+case"$1"in+*1[0-9]|*[04-9])+echo"$1th"+;;+*1)+echo"$1st"+;;+*2)+echo"$1nd"+;;+*3)+echo"$1rd"+;;+esac+}++make_squash_message(){+iftest-f"$squash_msg"+then+count=$(($(sed-n-e's/^# This is [^0-9]*\([1-9][0-9]*\).*/\1/p'\+<"$squash_msg"|sed-n-e'$p')+1))+echo"# This is a combination of $count commits."+sed-e'1d'-e'2,/^./{+/^$/d+}'<"$squash_msg"+else+count=2+echo'# This is a combination of 2 commits.'+echo'# The first commit message is:'+echo+commit_messageHEAD+fi+echo+echo"# This is the $(nth_string"$count") commit message:"+echo+commit_message"$1"+}++make_squash_message_multiple(){+revlist=$(gitrev-list--reverse"$sha1..HEAD")+count=$(echo"$revlist"|wc-l)+squash_i=0+echo"# This is a combination of $count commits."+forcur_sha1in$revlist+do+squash_i=$(($squash_i+1))+iftest-f"$squash_msg"+then+count=$(($count+$(sed-n-e\+'s/^# This is [^0-9]*\([1-9][0-9]*\).*/\1/p'\+<"$squash_msg"|sed-n-e'$p')+1))+sed-e'1d'-e'2,/^./{+/^$/d+}'<"$squash_msg"+fi+echo+echo"# This is the $(nth_string"$squash_i") commit message:"+echo+commit_message"$cur_sha1"+done+}++peek_next_command(){+sed-n-e'/^#/d'-e'1s/ .*$//p'<"$TODO"+}++# If $1 is a mark, make a ref from it; otherwise keep it.+# Note on marks:+# * :0 is allowed+# * :01 is the same as :1+mark_to_ref(){+arg="$1"+ref=$(expr"x$arg":'x:0*\([0-9][0-9]*\)$')+test-n"$ref"&&+arg="$MARK_PREFIX/$ref"+printf'%s\n'"$arg"+}++mark_to_commit(){+gitrev-parse--verify"$(mark_to_ref"$1")"+}+++fallback_3way(){+# Cleanup if not done before.+rm-fr"$PATCH-merge-"*++# First see if the patch records the index info that we can use.+performgitapply--build-fake-ancestor"$PATCH-merge-index""$PATCH"&&+GIT_INDEX_FILE="$PATCH-merge-index"gitwrite-tree>"$PATCH-merge-base"||+die_to_continue'Repository lacks necessary blobs to fall back on 3-way merge. Please hand-edit.'++test"$VERBOSE"-eq0||+echo'Using index info to reconstruct a base tree...'+GIT_INDEX_FILE="$PATCH-merge-index"gitapply--cached"$PATCH"||+die_to_continue'Patch does not apply to blobs recorded in its index.'++his_tree=$(GIT_INDEX_FILE="$PATCH-merge-index"gitwrite-tree)&&+orig_tree=$(cat"$PATCH-merge-base")&&+rm-fr"$PATCH-merge-"*||+die_to_continue'Writing new tree failed.'++test"$VERBOSE"-eq0||+echo'Falling back to patching base and 3-way merge...'++# This is not so wrong. Depending on which base we picked,+# orig_tree may be wildly different from ours, but his_tree+# has the same set of wildly different changes in parts the+# patch did not touch, so recursive ends up canceling them,+# saying that we reverted all those changes.++evalGITHEAD_$his_tree='"$firstline"'+exportGITHEAD_$his_tree+performgitmerge-recursive"$orig_tree"--HEAD"$his_tree"||{+performgitrerere+die_to_continue'Failed to merge in the changes.'+}+}++# Run hook "$@" (with arguments) if executable+run_hook(){+test-z"$1"||return+hookname="$1"+hook="$GIT_DIR/hooks/$hookname"+shift+iftest-x"$hook"+then+"$hook""$@"||+die_to_continue"Hook $hookname failed."+fi+}++# Add Signed-off-by: line if general option --signoff is given+dashdash_signoff(){+add_signoff=+iftest-n"$SIGNOFF"+then+last_signed_off_by=$(+sed-n-e'/^Signed-off-by: /p'<"$MSG"|sed-n-e'$p'+)+test"$last_signed_off_by"="$SIGNOFF"||+add_signoff=$(+test''="$last_signed_off_by"&&echo+echo"$SIGNOFF"+)+fi+{+test-s"$MSG"&&cat"$MSG"+test-n"$add_signoff"&&echo"$add_signoff"+}>"$MSG.new"+mv"$MSG.new""$MSG"+}+++### --caller-related functions++# Show string for caller invocation for --abort/--continue/--skip+print_caller_info(){+case"$1"in+--abort)+echo"$CALLER_ABRT"+;;+--continue)+echo"$CALLER_CONT"+;;+--skip)+echo"$CALLER_SKIP"+;;+*)+warn'Internal error: Unknown print_caller argument!'+;;+esac+}++# Print the program to invoke to (--)abort/continue/skip+print_caller(){+caller_info=$(print_caller_info"$1")+iftest-n"$CALLERCOMPARE"-a-n"$caller_info"+then+test-n"$CALLER"&&printf"$CALLER "+echo"$caller_info"+else+echo"git sequencer $1"+fi+}++# Test if --caller was set correctly+# $1 must be abort/continue/skip+test_caller(){+caller_info=$(print_caller_info"--$1")+test-n"$CALLERCOMPARE"-a\+"$CALLERCOMPARE"!="$CALLERSTRING"-a\+-n"$caller_info"&&+die"You must use '$CALLER$caller_info' to $1!"+}++# Generate $CALLER_SCRIPT file from "git foo|--abort|--continue|--skip"+# string $1+generate_caller_script(){+echo"$1"|sed-e's/^\(.*\)|\(.*\)|\(.*\)|\(.*\)$/\+CALLERCOMPARE="\0"\+CALLER="\1"\+CALLER_ABRT="\2"\+CALLER_CONT="\3"\+CALLER_SKIP="\4"/'>"$CALLER_SCRIPT"+}++# Run caller script and set GIT_CHERRY_PICK_HELP+assure_caller(){+test-r"$CALLER_SCRIPT"&&+."$CALLER_SCRIPT"++# we do not want cherry-pick to print *any* help+GIT_CHERRY_PICK_HELP=""+exportGIT_CHERRY_PICK_HELP+}+++### Helpers for check_* functions:++# Print a warning on todo checking+todo_warn(){+printf'Warning at line %d, %s: %s\n'"$line""$command""$*"+}++# Raise an error on todo checking+todo_error(){+printf'Error at line %d, %s: %s\n'"$line""$command""$*"+retval=1+}++# Test if $1 is a commit on todo checking+commit_check(){+test"$(gitcat-file-t"$1"2>/dev/null)"=commit||+todo_error"'$1' is not a commit."+}++# A helper function to check if $1 is a an available mark during check_*+arg_is_mark_check(){+forcur_markin$available_marks+do+test"$cur_mark"-eq"${1#:}"&&return+done+todo_error"Mark $1 is not yet defined."+}++# A helper function for check_* and mark usage:+# check if "$1" is a commit or a defined mark+arg_is_mark_or_commit_check(){+ifexpr"x$1":'x:[0-9][0-9]*$'>/dev/null+then+arg_is_mark_check"$1"+else+commit_check"$1"+fi+}+++### Author script functions++# Take "Name <e-mail>" in stdin and outputs author script+make_author_script_from_string(){+sed-e"s/'/'"'\\'"''/g"\+-e's/^\(.*\) <\(.*\)>.*$/GIT_AUTHOR_NAME='\''\1'\''\+GIT_AUTHOR_EMAIL='\''\2'\''\+GIT_AUTHOR_DATE=/'+}+++### General option functions (and options spec)++OPTIONS_GENERAL='Generaloptions+author=overrideauthor+C,reuse-commit=reusemessageandauthorshipdatafromcommit+F,file=takecommitmessagefromgivenfile+m,message=specifycommitmessage+M,reuse-message=reusemessagefromcommit+signoffaddsignoff+e,editinvokeeditortoeditcommitmessage'++# Check if option is a general option+check_general_option(){+general_shift=1+case"$1"in+--signoff)+return0+;;+--author)+general_shift=2+author_opt="t$author_opt"+expr"x$2":'x.* <.*>'>/dev/null||+todo_error"Author \"$2\" not in the correct format \"Name <e-mail>\"."+;;+-m)+general_shift=2+msg_opt="t$msg_opt"+;;+-C)+general_shift=2+msg_opt="t$msg_opt"+author_opt="t$author_opt"+commit_check"$2"+;;+-M)+general_shift=2+msg_opt="t$msg_opt"+commit_check"$2"+;;+-F)+general_shift=2+msg_opt="t$msg_opt"+test-r"$2"||+todo_error"Cannot read file '$2'."+;;+-e)+test-z"$BATCHMODE"||+todo_error'--batch and --edit options do not make sense together.'+;;+*)+return1+;;+esac+}++# Set a general option variable or return 1+handle_general_option(){+general_shift=1+case"$1"in+--signoff)+SIGNOFF=$(gitvarGIT_COMMITTER_IDENT|sed-e'+s/>.*/>/+s/^/Signed-off-by:/')+;;+--author)+general_shift=2+AUTHOR=t+echo"$2"|+make_author_script_from_string>"$AUTHOR_SCRIPT"+;;+-m)+general_shift=2+MESSAGE="$2"+;;+-C)+general_shift=2+AUTHOR=t+get_author_ident_from_commit"$2">"$AUTHOR_SCRIPT"+MESSAGE=$(commit_message"$2")+;;+-M)+general_shift=2+MESSAGE=$(commit_message"$2")+;;+-F)+general_shift=2+MESSAGE=$(cat"$2")+;;+-e)+EDIT=--edit+;;+*)+return1+;;+esac+}+++### Functions for checking and realizing TODO instructions+# Note that options_*, check_* and insn_* function names are reserved.++options_pause="\+pause+--+"++# Check the "pause" instruction+check_pause(){+shift+test-z"$BATCHMODE"||+todo_error'"pause" instruction and --batch do not make sense together.'+test$#-eq0||+todo_error'The pause instruction takes no arguments.'+return0+}++# Realize the "pause" instruction+insn_pause(){+save_commit_dataHEAD+echo'pause'>"$WHY_FILE"+WHY=pauseprint_advice+test-z"$ORIG_HEAD"||gitupdate-refORIG_HEAD"$ORIG_HEAD"+exit2+}+++options_run="\+run[--dir=<path>][--]<cmd><args>...+--+dir=changedirectorybeforerunningcommand+"++# Check the "run" instruction+check_run(){+whiletest$#-gt0+do+case"$1"in+--dir)+test-e"$2"||+todo_error"Path $2 does not exist."+test-d"$2"||+todo_error"Path $2 is not a directory."+shift2+;;+--)+shift+break+;;+-*)+todo_error"Unknown option $1"+;;+esac+done+# we don't check if cmd exists+return0+}++# Realize the "run" instruction+insn_run(){+runpath=./+whiletest$#-gt0+do+case"$1"in+--dir)+runpath="$2"+shift2+;;+--)+shift+break+;;+esac+done++savepath="$PWD"+cd"$runpath"+"$@"+success="$?"+cd"$savepath"++iftest"$success"-ne0+then+test-z"$BATCHMODE"||+die_abort"Running $1 failed. Aborting because of batch mode."+save_commit_dataHEAD+echo'run'>"$WHY_FILE"+WHY=runprint_advice"$@"+test-z"$ORIG_HEAD"||gitupdate-refORIG_HEAD"$ORIG_HEAD"+exit3+fi+}+++options_patch="\+patch[options]<file>+--+3,3wayfallbackto3-waymerge+kpasstogit-mailinfo(keepsubject)+npasstogit-mailinfo(noutf8)+$OPTIONS_GENERAL+Optionspassedtogit-apply+R,reversereversechanges+context=ensurecontextof...lines+p=remove...leadingslashes+unidiff-zerobypassunidiffchecks+exclude=donotapplychangestogivenfiles+no-addignoreadditionsofpatch+whitespace=setwhitespaceerrorbehavior+inaccurate-eofsupportinaccurateEOFs+uno-op(backwardcompatibility)+binaryno-op(backwardcompatibility)+"++# Check the "patch" instruction+check_patch(){+whiletest$#-gt1+do+case"$1"in+-3|-k|-n|-u|--binary|-R|--reverse|--unidiff-zero|--no-add|--inaccurate-eof)+:+;;+-p|--whitespace|--exclude|--context)+shift+;;+--)+shift+break+;;+-*)+check_general_option"$@"||+todo_warn"Unknown option $1"+;;+*)+todo_error"Wrong number of arguments. ($# given, 1 wanted)"+break+;;+esac+shift$general_shift+done++iftest-f"$1"-a-r"$1"+then+grep-e'^diff'"$1">/dev/null||+todo_error"File '$1' contains no patch."+else+todo_error"Cannot open file '$1'."+fi+return0+}++# Realize the "patch" instruction+insn_patch(){+apply_opts=+mailinfo_opts=+threeway=++# temporary files+infofile="$SEQ_DIR/patch-info"+msgfile="$SEQ_DIR/patch-msg"++whiletest"$#"-gt1+do+case"$1"in+-3)+threeway=t+;;+-k|-n)+mailinfo_opts="$mailinfo_opts$1"+;;+-u|--binary)+:Donothing.Itisthereduetob/conly.+;;+-R|--reverse|--unidiff-zero|--no-add|--inaccurate-eof)+apply_opts="$apply_opts$1"+;;+-p)+shift+apply_opts="$apply_opts -p$1"+;;+--whitespace|--exclude)+apply_opts="$apply_opts$1=$2"+shift+;;+--context)+shift+apply_opts="$apply_opts -C$1"+;;+--)+shift+break+;;+*)+handle_general_option"$@"+;;+esac+shift$general_shift+done++filename="$1"++gitmailinfo$mailinfo_opts"$msgfile""$PATCH"\+<"$filename">"$infofile"||+die_abort'Could not read or parse mail'++# if author not set by option, read author information of patch+iftest-z"$AUTHOR"+then+cp"$ORIG_AUTHOR_SCRIPT""$AUTHOR_SCRIPT"+sed-e"s/'/'"'\\'"''/g"-n-e'+s/^Author:\(.*\)$/GIT_AUTHOR_NAME='\''\1'\''/p;+s/^Email:\(.*\)$/GIT_AUTHOR_EMAIL='\''\1'\''/p;+s/^Date:\(.*\)$/GIT_AUTHOR_DATE='\''\1'\''/p+'<"$infofile">>"$AUTHOR_SCRIPT"+# If sed's result is empty, we keep the original+# author script by appending.+fi++# Ignore every mail that's not containing a patch+test-s"$PATCH"||{+warn'Does not contain patch!'+return0+}++edit_msg=+ifgrep-e'^Subject:'"$infofile">/dev/null+then+# add subject to commit message+sed-n-e'/^Subject:/ s/Subject: //p'<"$infofile"+echo+echo+cat"$msgfile"+else+cat"$msgfile"+edit_msg=t+fi|gitstripspace>"$MSG"+rm-f"$infofile""$msgfile"++firstline=$(sed-e'1q'<"$MSG")++get_current_author++test-n"$MESSAGE"&&printf'%s\n'"$MESSAGE">"$MSG"+test-z"$firstline"&&firstline=$(sed-e'1q'<"$MSG")++dashdash_signoff++with_authorrun_hookapplypatch-msg"$MSG"+failed=+gitapply$apply_opts--index"$PATCH"||failed=t++iftest-n"$failed"-a-n"$threeway"&&(with_authorfallback_3way)+then+# Applying the patch to an earlier tree and merging the+# result may have produced the same tree as ours.+gitdiff-index--quiet--cachedHEAD--&&{+echo'No changes -- Patch already applied.'+return0+# XXX: do we want that?+}+# clear apply_status -- we have successfully merged.+failed=+fi++iftest-n"$failed"+then+die_to_continue"Patch failed: $firstline"+# XXX: We actually needed a git-apply flag that creates+# conflict markers and sets the DIFF_STATUS_UNMERGED flag.+fi++with_authorrun_hookpre-applypatch++test-n"$EDIT"&&edit_msg=t+if!has_message"$MSG"||test-n"$edit_msg"+then+echo"+# Please enter the commit message for the applied patch.+# (Comment lines starting with '#' will not be included)" >>"$MSG"++git_editor"$MSG"||+die_with_patchHEAD'Editor returned error.'+has_message"$MSG"||+die_with_patchHEAD'No commit message given.'+fi++tree=$(gitwrite-tree)&&+parent=$(gitrev-parse--verifyHEAD)&&+commit=$(with_authorgitcommit-tree"$tree"-p"$parent"<"$MSG")&&+gitupdate-ref-m"$GIT_REFLOG_ACTION: $firstline"HEAD"$commit""$parent"||+die_to_continue'Could not commit tree.'++test-x"$GIT_DIR/hooks/post-applypatch"&&+with_author"$GIT_DIR/hooks/post-applypatch"++return0+}+++options_pick="\+pick[options]<commit>+--+R,reverserevertintroducedchanges+mainline=specifyparentnumbertouseformergecommits+$OPTIONS_GENERAL+"++# Check the "pick" instruction+check_pick(){+mainline=+whiletest$#-gt1+do+case"$1"in+-R)+;;+--mainline)+shift+mainline="$1"+test"$mainline"-gt0||{+todo_error'--mainline needs an integer beginning from 1.'+mainline=+}+;;+--)+shift+break+;;+-*)+check_general_option"$@"||+todo_warn"Unknown option $1"+;;+*)+todo_error"Wrong number of arguments. ($# given, 1 wanted)"+break+;;+esac+shift$general_shift+done++iftest-n"$mainline"+then+parents=$(count_parents"$1")+test"$parents"-lt"$mainline"&&+todo_error"Commit has only $parents (less than $mainline) parents."+test"$parents"-eq1&&+todo_warn'Commit is not a merge at all.'+fi++commit_check"$1"++return0+}++# Realize the "pick" instruction+insn_pick(){+op=cherry-pick+mainline=+whiletest$#-gt1+do+case"$1"in+-R)+op=revert+;;+--mainline)+mainline="$1$2"+shift+;;+--)+shift+break+;;+-*)+handle_general_option"$@"+;;+esac+shift$general_shift+done++sha1=$(gitrev-parse--verify"$1")++edit_msg="$EDIT"++# Don't edit on pick, but later, if author or message given.+test-n"$AUTHOR"-o-n"$MESSAGE"&&edit_msg=++# Be kind to users and ignore --mainline=1 on non-merge commits+test-n"$mainline"-a2-gt$(count_parents"$sha1")&&mainline=++use_perform=+test-n"$edit_msg"||+use_perform=perform++pick_one"$op"$edit_msg$mainline$sha1||+die_with_patch$sha1"Could not apply $sha1."++test-n"$EDIT"||+use_perform=perform++get_current_author+signoff=+test-n"$SIGNOFF"&&signoff=-s+iftest-n"$AUTHOR"-a-n"$MESSAGE"+then+# this is just because we only want to do ONE amending commit+$use_performgitcommit--amend$EDIT$signoff--no-verify\+--author"$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"\+--message="$MESSAGE"+eliftest-n"$AUTHOR"+then+# correct author if AUTHOR is set+$use_performgitcommit--amend$EDIT--no-verify-CHEAD\+--author"$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"+eliftest-n"$MESSAGE"+then+# correct commit message if MESSAGE is set+$use_performgitcommit--amend$EDIT$signoff--no-verify\+-CHEAD--message="$MESSAGE"+eliftest-n"$SIGNOFF"+then+# only add signoff+$use_performgitcommit--amend$EDIT$signoff--no-verify\+-CHEAD+fi++return0+}++options_edit="\+edit<commit>+--+"++# Check the "edit" instruction+check_edit(){+shift+test-z"$BATCHMODE"||+todo_error'"edit" instruction and --batch do not make sense together.'+test$#-eq1||+todo_error"Wrong number of arguments. ($# given, 1 wanted)"+return0+}++# Realize the "edit" instruction+insn_edit(){+shift+insn_pick"$1"+echo'# pausing'>>"$DONE"+insn_pause+}+++options_squash="\+squash<commit>+squash[options]--from<mark>+--+fromsquashallcommitsfrom<mark>+collect-signoffscollectSigned-off-by:lines+include-mergesdonotfailonmergecommits+$OPTIONS_GENERAL+"++# Check the "squash" instruction+check_squash(){+from=+collect=+merges=+whiletest$#-gt1+do+case"$1"in+--from)+from=t+;;+--collect-signoffs)+collect=t+todo_warn'Not yet implemented.'+;;+--include-merges)+merges=t+;;+--)+shift+break+;;+*)+check_general_option"$@"||+todo_error"Unknown option $1"+;;+esac+shift$general_shift+done++# in --from mode?+iftest-n"$from"+then+test-z"$merges"&&+cat"$DONE""$TODO"|+sed-n-e'/^[ \t]*mark[ \t]*:\{0,1\}'"${1#:}"'\($\|[^0-9]\)/,'"$line"'p'|+grep'^[ \t]*merge'>/dev/null&&+todo_error"$1..HEAD contains a merge commit. You may try --include-merges."++arg_is_mark_check"$1"+else+test-n"$merges"&&+todo_error'--include-merges only makes sense with --from <mark>.'+test-n"$collect"&&+todo_error'--collect-signoffs only makes sense with --from <mark>.'++commit_check"$1"+fi++return0+}++# Realize the "squash" instruction+insn_squash(){+squash_msg="$MSG-squash"+from=+whiletest$#-gt1+do+case"$1"in+--from)+from=t+;;+--collect-signoffs)+warn'--collect-signoffs is not implemented.'+# XXX+;;+--include-merges)+:# This has to be done during check_squash+;;+--)+shift+break+;;+*)+handle_general_option"$@"+;;+esac+shift$general_shift+done++iftest-n"$from"+then+sha1=$(mark_to_commit":${1#:}")+else+sha1=$(gitrev-parse--verify"$1")+fi++# Hm, somehow I don't think --skip on a conflicting squash+# may be useful, but if someone wants to do it, it should+# do the obvious: skip what squash would do.+echo"$(gitrev-parseHEAD)">"$SEQ_DIR/skiphead"++iftest-n"$MESSAGE"+then+printf'%s\n'"$MESSAGE">"$MSG"+else+iftest-n"$from"+then+make_squash_message_multiple"$sha1">"$MSG"+else+make_squash_message"$sha1">"$MSG"+fi+fi++case"$(peek_next_command)"in+squash)+edit_commit=+use_perform=perform+cp"$MSG""$squash_msg"+;;+*)+edit_commit=-e+use_perform=+rm-f"$squash_msg"+;;+esac++test-n"$MESSAGE"&&edit_commit=+test-n"$EDIT"&&edit_commit=-e++# is --author (or equivalent) set?+iftest-n"$AUTHOR"+then+# evaluate author script+get_current_author+else+# if --author is not given, we get the authorship+# information from the commit before.+eval"$(get_author_ident_from_commitHEAD)"+# but we do not write an author script+fi++# --from or not+failed=+iftest-n"$from"+then+performgitreset--soft"$sha1"+else+performgitreset--softHEAD^++pick_onecherry-pick-n"$sha1"||failed=t+fi++dashdash_signoff++iftest-z"$failed"+then+# This is like --amend, but with a different message+with_author$use_performgitcommit--no-verify\+-F"$MSG"$edit_commit||failed=t+else+cp"$MSG""$GIT_DIR/SQUASH_MSG"+warn+die_with_patch$sha1"Could not apply $sha1."+fi++return0+}+++options_mark="\+mark<mark>+--+"++# Check the "mark" instruction+check_mark(){+shift+test$#-eq1||+todo_error"Wrong number of arguments. ($# given, 1 wanted)"+my_mark=$(expr"x${1#:}":'x0*\([0-9][0-9]*\)$')+test-n"$my_mark"||+todo_error"Mark $1 not an integer."+expr"x$available_marks ":" $my_mark ">/dev/null&&+todo_error"Mark :$my_mark already defined. Choose another integer."+available_marks="$available_marks$my_mark"++return0+}++# Realize the "mark" instruction+insn_mark(){+shift+given="$1"++mark=$(mark_to_ref":${given#:}")+gitupdate-ref"$mark"HEAD+return0+}+++options_merge="\+merge[options]<commit-ish>...+--+standardgeneratedefaultcommitmessage+s,strategy=usemergestrategy...+$OPTIONS_GENERAL+"++# Check the "merge" instruction+check_merge(){+whiletest$#-gt1+do+case"$1"in+--standard)+msg_opt="t$msg_opt"+;;+-s)+shift+;;+--)+shift+break+;;+-*)+check_general_option"$@"||+todo_error"Unknown option $1"+;;+esac+shift$general_shift+done++test$#-gt0||+todo_error'What are my parents? Need new parents!'++whiletest$#-gt0+do+arg_is_mark_or_commit_check"$1"+shift+done+return0+}++# Realize the "merge" instruction+insn_merge(){+standard=++whiletest$#-gt1+do+case"$1"in+--standard)+standard=t+;;+-s)+shift+strategy="-s $1"+;;+--)+shift+break+;;+-*)+handle_general_option"$@"+;;+esac+shift$general_shift+done++new_parents=+forpin"$@"+do+new_parents="$new_parents$(mark_to_ref$p)"+done+new_parents="${new_parents# }"++get_current_author++iftest-n"$standard"+then+forcur_parentin$new_parents+do+printf'%s\t\t%s'\+"$(gitrev-parse"$cur_parent")""$cur_parent"+done|gitfmt-merge-msg>"$MSG"+fi++test-n"$MESSAGE"&&+printf'%s\n'"$MESSAGE">"$MSG"++dashdash_signoff+if!has_message"$MSG"||test-n"$EDIT"+then+echo"+# Please enter the merge commit message.+# (Comment lines starting with '#' will not be included)" >>"$MSG"++git_editor"$MSG"||+die_with_patchHEAD'Editor returned error.'+has_message"$MSG"||+die_with_patchHEAD'No commit message given.'+fi++if!performgitmerge--no-commit$strategy$new_parents+then+performgitrerere+cp"$MSG""$GIT_DIR/MERGE_MSG"+die_to_continue"Error merging $new_parents."+fi+with_authorperformgitcommit-F"$MSG"--no-verify+return0+}+++options_reset="\+reset<commit-ish>+--+"++# Check the "reset" instruction+check_reset(){+shift+test$#-eq1||+todo_error"Wrong number of arguments. ($# given, 1 wanted)"+arg_is_mark_or_commit_check"$1"++return0+}++# Realize the "reset" instruction+insn_reset(){+shift+reset_almost_hard"$(mark_to_commit"$1")"+}+++options_ref="\+ref<ref>+--+"++# Check the "ref" instruction+check_ref(){+shift+test$#-eq1||+todo_error"Wrong number of arguments. ($# given, 1 wanted)"+return0+}++# Realize the "ref" instruction+insn_ref(){+shift+performgitupdate-ref"$1"HEAD+}+++### Instruction main loop++# Run check_* or insn_* with massaged options+# Usage: run_insn (check|do) <insn> <insn options>+run_insn(){+c_or_i="$1"+insn="$2"+shift+shift+eval"option_spec=\"\$options_$insn\""+eval"$(printf"%s""$option_spec"|+gitrev-parse--parseopt--"$@"||+echoreturn1)"+case"$c_or_i"in+check)+check_$insn"$@"+;;+do)+insn_$insn"$@"+;;+esac+}++# Execute the first line of the current TODO file+execute_next(){+read-rcommandrol<"$TODO"+test"$VERBOSE"-gt1&&+printf'Next line: %s\n'"$command$rol"++remove_from_todo+case"$command"in+'#'*|'')+;;+*)+comment_for_reflog$command+# reset general options+rm-f"$AUTHOR_SCRIPT""$MSG"+echo'HEAD'>"$SEQ_DIR/skiphead"+general_shift=1+AUTHOR=+EDIT=+MESSAGE=+SIGNOFF=+# XXX: eval is evil!+eval"run_insn do $command$rol"||+die_to_continue'An unexpected error occured.'+;;+esac+}++# Execute the rest of the TODO file and finish+execute_rest(){+whilehas_action"$TODO"+do+execute_next+done++comment_for_reflogfinish+iftest-n"$ONTO"+then+gitupdate-ref-m"$GIT_REFLOG_ACTION: $ONTO""$ONTO"HEAD&&+gitsymbolic-refHEAD"$ONTO"+fi&&+cleanup+exit+}++# We don't need to check a todo file if it has not changed+# since it has last been acknowledged to be sane.+todo_has_changed(){+test-f"$1.sum"||return0+test"$(githash-object"$1")"!="$(cat"$1.sum")"+}++# acknowledge todo file to be sane+todo_ack(){+githash-object"$1">"$1.sum"+}++# Main loop to check instructions+todo_check(){+todo="$TODO"+test-n"$1"&&todo="$1"+todo_has_changed"$todo"||return0++test"$VERBOSE"-eq1-a-t1-o"$VERBOSE"-gt1&&+printf'Checking...\r'+test"$VERBOSE"-lt2||echo+available_marks=' '+forcur_markin$(gitfor-each-ref--format='%(refname)'"$MARK_PREFIX")+do+available_marks="$available_marks${cur_mark##*/}"+done++retval=0+line=1+whileread-rcommandrol+do+case"$command"in+'#'*|'')+;;+*)+eval'test -n "$options_'"$command"'"'||{+retval=1+todo_error"Unknown $command instruction"+continue+}++general_shift=1+msg_opt=+author_opt=+eval"run_insn check $command$rol"||+todo_error"Unknown option used"+expr"$msg_opt":'ttt*'>/dev/null&&+todo_error'You can only provide one commit message option.'+expr"$author_opt":'ttt*'>/dev/null&&+todo_error'You can only provide one author option.'+;;+esac+line=$(expr"$line"+1)+done<"$todo"+test$retval-ne0||todo_ack"$todo"+return$retval+}++prepare_editable_todo(){+echo'# ALREADY DONE:'+sed-e's/^/# /'<"$DONE"+echo'# '+echo"$markline"+cat"$TODO"+}++# expand shortcuts in TODO file $1+expand_shortcuts(){+sed-e'+s/^[\t]*p\>/pick/;+s/^[\t]*e\>/edit/;+s/^[\t]*s\>/squash/;+'<"$1">"$TODO.cut"+mv"$TODO.cut""$1"+}++get_saved_options(){+readALLOW_DIRTY<"$SEQ_DIR/allow-dirty"+readVERBOSE<"$SEQ_DIR/verbose"+readADVICE<"$SEQ_DIR/advice"+readONTO<"$SEQ_DIR/onto"+readORIG_HEAD<"$SEQ_DIR/head"+test-f"$WHY_FILE"&&+readWHY<"$WHY_FILE"+return0+}++# Realize sequencer invocation+do_startup(){+test-d"$SEQ_DIR"&&+die'sequencer already started'++require_clean_work_tree++ORIG_HEAD=$(gitrev-parse--verifyHEAD)||+die'No HEAD?'++mkdir"$SEQ_DIR"||+die"Could not create temporary $SEQ_DIR"++# save options+echo"$ALLOW_DIRTY">"$SEQ_DIR/allow-dirty"+echo"$VERBOSE">"$SEQ_DIR/verbose"+echo"$ADVICE">"$SEQ_DIR/advice"+test-n"$CALLERSTRING"&&+generate_caller_script"$CALLERSTRING"+# generate empty DONE and "onto" file+:>"$DONE"+:>"$SEQ_DIR/onto"++iftest-n"$BATCHMODE"+then+GIT_CHERRY_PICK_HELP=' Aborting (batch mode)'+exportGIT_CHERRY_PICK_HELP+else+assure_caller+fi++comment_for_reflogstart++# save old head before checking out the given <branch>+gitsymbolic-refHEAD>"$SEQ_DIR/head-name"2>/dev/null||+echo'detached HEAD'>"$SEQ_DIR/head-name"+echo$ORIG_HEAD>"$SEQ_DIR/head"+# do it here so that die_abort can work ;)++iftest-n"$ONTO"+then+# if ONTO is a branch name, then keep it, otherwise+# we don't care anymore and erase ONTO.+ifgit-show-ref--quiet--verify--"refs/heads/${ONTO##*/}"+then+ONTO="refs/heads/${ONTO##*/}"+echo"$ONTO">"$SEQ_DIR/onto"+performgitcheckout"$(gitrev-parse"$ONTO")"||+die_abort"Could not checkout branch $ONTO"+else+performgitcheckout"$ONTO"||+die_abort"Could not checkout commit $ONTO"+ONTO=+fi+fi++(gitvarGIT_AUTHOR_IDENT||gitvarCOMMITTER_IDENT)|+make_author_script_from_string>"$ORIG_AUTHOR_SCRIPT"++# read from file or from stdin?+iftest-z"$1"+then+:>"$TODO"||+die_abort"Could not generate TODO file $TODO"+whileread-rline+do+printf'%s\n'"$line">>"$TODO"||+die_abort"Could not append to TODO file $TODO"+done+else+cp"$1""$TODO"||+die_abort"Could not find TODO file $1."+fi+expand_shortcuts"$TODO"++has_action"$TODO"||die_abort'Nothing to do'+todo_check||WHY=tododie_to_continue"TODO file contains errors."++execute_rest+exit+}++# Realize --continue.+do_continue(){+test-d"$SEQ_DIR"||die'No sequencer running'+test_caller'continue'++expand_shortcuts"$TODO"+todo_check||WHY=tododie_to_continue"TODO file contains errors."++comment_for_reflogcontinue++gitrev-parse--verifyHEAD>/dev/null||+die_to_continue'Cannot read HEAD'++get_saved_options+iftest-z"$ALLOW_DIRTY"+then+gitupdate-index--ignore-submodules--refresh&&+gitdiff-files--quiet--ignore-submodules||+die_to_continue'Working tree is dirty. (Use git add or git stash first?)'+fi++# do we have anything to commit? (staged changes)+if!gitdiff-index--cached--quiet--ignore-submodulesHEAD--+then+get_current_author++# After "pause", we should amend (merge-safe!).+# On conflict, we do not have a commit to amend, so we+# should just commit.+case"$WHY"in+pause|run)+with_authorgitcommit--amend--no-verify-F"$MSG"-e||+die_to_continue'Could not commit staged changes.'+;;+conflict)+with_authorgitcommit--no-verify-F"$MSG"-e||+die_to_continue'Could not commit staged changes.'+echo'# resolved CONFLICTS of the last instruction'>>"$DONE"+;;+*)+die_to_continue'There are staged changes. Do not know what to do with them.'+esac+fi++require_clean_work_tree+clean_why+execute_rest+exit+}++# Realize --abort.+do_abort(){+test-d"$SEQ_DIR"||die'No sequencer running'+test_caller'abort'+get_saved_options++comment_for_reflogabort+performgitrerereclear+restore+cleanup+exit+}++# Realize --skip.+do_skip(){+test-d"$SEQ_DIR"||die'No sequencer running'+test_caller'skip'++expand_shortcuts"$TODO"+todo_check||WHY=tododie_to_continue"TODO file contains errors."+get_saved_options++comment_for_reflogskip+performgitrerereclear+clean_why++reset_almost_hard"$(cat"$SEQ_DIR/skiphead")"&&+echo'# SKIPPED the last instruction'>>"$DONE"&&+execute_rest+exit+}++# Realize --edit.+do_edit(){+test-d"$SEQ_DIR"||die'No sequencer running'++markline='### BEGIN EDITING BELOW THIS LINE ###'+prepare_editable_todo>"$TODO.new"+iftodo_has_changed"$TODO"+then+sane=+else+sane=t+todo_ack"$TODO.new"+fi++# XXX: does not make sense+# when input does not come from a terminal+git_editor"$TODO.new"||+die'Editor returned an error.'++iftest-t0-a-t1+then+sane=t+echo+# interactive:+untilhas_action"$TODO.new"&&todo_check"$TODO.new"+do+has_action"$TODO.new"||echo'TODO file empty.'+printf'What to do with the file? [c]orrect/[e]dit again/[r]ewind/[s]ave/[?] '+readreply+case"$reply"in+[cC]*)+git_editor"$TODO.new"+expand_shortcuts"$TODO.new"+;;+[eE]*)+prepare_editable_todo>"$TODO.new"+git_editor"$TODO.new"+expand_shortcuts"$TODO.new"+;;+[rRxXqQ]*)+rm-f"$TODO.new""$TODO.new.sum"+exit0+;;+[sS]*)+test"$WHY"!='pause'||+echo'todo'>"$WHY_FILE"+sane=+break+;;+[?hH]*)+cat<<EOF++Help:+s-saveTODOfileandexit+c-respawneditortocorrectTODOfile+e-dropchangesandrespawneditoronoriginalTODOfile+r-dropchangesandexitasifnothinghappened+?-printthishelp+EOF+;;+esac+echo+done+else+# defaults:+has_action"$TODO.new"||{+echo"Nothing to do"+exit+}+todo_check"$TODO.new"||+die'TODO file contains errors. Aborting.'+fi+cp"$TODO""$TODO.old"+ifgrep"^$markline""$TODO.new">/dev/null+then+sed-e"1,/^$markline/d"<"$TODO.new">"$TODO"+else+cp"$TODO.new""$TODO"+fi+rm-f"$TODO.new""$TODO.new.sum"+test-z"$sane"||todo_ack"$TODO"+echo+echo'TODO file contains:'+echo+cat"$TODO"+exit0+}++# Realize --status.+do_status(){+test-d"$SEQ_DIR"||die'No sequencer running.'+get_saved_options++ifhas_action"$DONE"+then+echo'Already done (or tried):'+sed-e's/^/ /'<"$DONE"+echo+fi+case"$WHY"in+pause)+echo'Intentionally paused.'+;;+run)+echo'Interrupted because running failed.'+;;+conflict)+echo'Interrupted by conflict at'+sed-n-e's/^/ /;$p'<"$DONE"+;;+todo)+echo'Interrupted because of errors in the TODO file.'+;;+*)+echo'Current state is broken.'+esac+test"$VERBOSE"-gt1&&echo'Running verbosely.'+test"$VERBOSE"-lt1&&echo'Running quietly.'+test-n"$ONTO"&&+echo"Sequencing on branch ${ONTO##*/}."+ifhas_action"$TODO"+then+echo++echo'Still to do:'+sed-e's/^/ /'<"$TODO"+fi+iftest"$WHY"=todo+then+echo+echo'But there are errors. To edit, run:'+echo' git sequencer --edit'+else+echo+echo'To abort & restore, invoke:'+echo" $(print_caller--abort)"+echo'To continue, invoke:'+echo" $(print_caller--continue)"+test"$WHY"='pause'-o"$WHY"='run'||{+echo'To skip the current instruction, invoke:'+echo" $(print_caller--skip)"+}+fi+exit0+}++is_standalone(){+test$#-eq2&&+test"$2"='--'&&+test-z"$ALLOW_DIRTY"&&+test-z"$BATCHMODE"&&+test"$ADVICE"=t&&+test-z"$onto"&&+test"$VERBOSE"-eq1+}+++### Option handling and startup++onto=+BATCHMODE=+ALLOW_DIRTY=+CALLERSTRING=+VERBOSE=1+ADVICE=t+CALLER=+CALLER_ABRT=+CALLER_CONT=+CALLER_SKIP=+whiletest$#-gt0+do+case"$1"in+--continue)+is_standalone"$@"||usage+assure_caller+do_continue+;;+--abort)+is_standalone"$@"||usage+assure_caller+do_abort+;;+--skip)+is_standalone"$@"||usage+assure_caller+do_skip+;;+--status)+is_standalone"$@"||usage+assure_caller+do_status+;;+--edit)+is_standalone"$@"||usage+do_edit+;;+--caller)+###############################################################+# This feature is for user scripts only. (Hence undocumented.)+# User scripts should pass an argument like:+# --caller="git foo|abrt|go|next"+# on every git sequencer call. (It is only ignored on+# --edit and --status.)+# So git sequencer knows that+# "git foo abrt" will abort,+# "git foo go" will continue and+# "git foo next" will skip the sequencing process.+# This is useful if your user script does some extra+# preparations or cleanup before/after calling+# git sequencer --caller="..." --abort|--continue|--skip+#+# Running git-sequencer without the same --caller string+# fails then, until the sequencing process has finished or+# aborted.+#+# Btw, --caller="my_tiny_script.sh|-a||" will be+# interpreted, that users must invoke "my_tiny_script.sh -a"+# to abort, but can invoke "git sequencer --continue" and+# "git sequencer --skip" to continue or skip.+# And it is also possible to provide three different scripts+# by --caller="|script 1|tool 2|util 3".+#+# If your user script does not need any special+# abort/continue/skip behavior, then just do NOT pass+# the --caller option.+###############################################################+shift+expr"x$1":'x.*|.*|.*|.*$'>/dev/null||+die'Wrong --caller format.'+CALLERSTRING="$1"+;;+--allow-dirty)+ALLOW_DIRTY='HEAD'+# this means: true+;;+-B)+BATCHMODE=t+# XXX: we still have abort on editor invokations+;;+--no-advice)+ADVICE=f+;;+--onto)+shift+ONTO="$1"+test$(gitcat-file-t"$ONTO")='commit'||+die"$ONTO is no commit or branch."+;;+-q)+VERBOSE=0+ADVICE=f+# XXX: If there were no editors,+# we could just do exec >/dev/null+;;+-v)+VERBOSE=2+# or increment it if we have several verbosity steps+;;+--)+shift+break+;;+*)+die"$1 currently not implemented."+;;+esac+shift+done+test$#-gt1&&usage++do_startup"$1"
From: Stephan Beyer <hidden> Date: 2016-06-15 22:45:02
In principle a migration to git-sequencer is straightforward:
Put all the mail from the mbox or Maildir into .git/rebase-apply
and let the "patch" instruction of sequencer do the rest of the
work.
The git am --interactive part is a little more tricky.
To get this working, "pause" instructions are put after every
"patch" instruction and then be_interactive() swoops in,
that allows the user to input his choice.
Also a slight behavior change, that can be seen in the diff of
the test cases, should be mentioned: If git-am has nothing to
do, the user does not have to remove .git/rebase-apply or run
git-am --skip manually. It automatically aborts instead, which
seems to be an improvement.
Mentored-by: Christian Couder [off-list ref]
Mentored-by: Daniel Barkalow [off-list ref]
Signed-off-by: Stephan Beyer <redacted>
---
git-am.sh | 632 ++++++++++++++++++++-------------------------------------
git-rebase.sh | 7 +-
t/t4150-am.sh | 4 +-
3 files changed, 220 insertions(+), 423 deletions(-)
@@ -34,103 +34,148 @@ cd_to_toplevel gitvarGIT_COMMITTER_IDENT>/dev/null||die"You need to set your committer info first"-stop_here(){-echo"$1">"$dotest/next"-exit1+cleanup(){+gitgc--auto+rm-fr"$dotest"}-stop_here_user_resolve(){-if[-n"$resolvemsg"];then-printf'%s\n'"$resolvemsg"-stop_here$1-fi-cmdline="git am"-iftest''!="$interactive"-then-cmdline="$cmdline -i"-fi-iftest''!="$threeway"-then-cmdline="$cmdline -3"-fi-echo"When you have resolved this problem run \"$cmdline --resolved\"."-echo"If you would prefer to skip this patch, instead run \"$cmdline --skip\"."-echo"To restore the original branch and stop patching run \"$cmdline --abort\"."--stop_here$1+die_abort(){+cleanup+die"$1"}-go_next(){-rm-f"$dotest/$msgnum""$dotest/msg""$dotest/msg-clean"\-"$dotest/patch""$dotest/info"-echo"$next">"$dotest/next"-this=$next-}+be_interactive(){+msg="$GIT_DIR/sequencer/message"+patch="$GIT_DIR/sequencer/patch"+# we rely on sequencer here++test-t0||+die"cannot be interactive without stdin connected to a terminal."+action=$(cat"$dotest/interactive")+whiletest"$action"=again+do+echo+echo"Commit Body is:"+echo"--------------------------"+cat"$msg"+echo"--------------------------"+iftest-z"$1"+then+printf"Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all "+else+echo'Patch does not apply cleanly!'+printf"Apply+fix? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all "+fi-cannot_fallback(){-echo"$1"-echo"Cannot fall back to three-way merge."-exit1+readreply+case"$reply"in+[yY]*)+return0+;;+[nN]*)+# pretend we never tried to apply+to=HEAD+testconflict="$1"||+to=HEAD^+gitread-tree-m-uHEAD$to+gitreset-q$to>/dev/null+return1+;;+[eE]*)+git_editor"$msg"+gitcommit--amend--file="$msg"--no-verify>/dev/null+;;+[vV]*)+LESS=-S${PAGER:-less}"$patch"+;;+[aA]*)+echo'accept'>"$dotest/interactive"+return0+;;+*)+:+;;+esac+done+test"$action"=accept&&+sed-n-e'1s/^/Applying &/p'<"$msg"+return0}-fall_back_3way(){-O_OBJECT=`cd"$GIT_OBJECT_DIRECTORY"&&pwd`--rm-fr"$dotest"/patch-merge-*-mkdir"$dotest/patch-merge-tmp-dir"--# First see if the patch records the index info that we can use.-gitapply--build-fake-ancestor"$dotest/patch-merge-tmp-index"\-"$dotest/patch"&&-GIT_INDEX_FILE="$dotest/patch-merge-tmp-index"\-gitwrite-tree>"$dotest/patch-merge-base+"||-cannot_fallback"Repository lacks necessary blobs to fall back on 3-way merge."--echoUsingindexinfotoreconstructabasetree...-ifGIT_INDEX_FILE="$dotest/patch-merge-tmp-index"\-gitapply$binary--cached<"$dotest/patch"-then-mv"$dotest/patch-merge-base+""$dotest/patch-merge-base"-mv"$dotest/patch-merge-tmp-index""$dotest/patch-merge-index"-else-cannot_fallback"Did you hand edit your patch?-Itdoesnotapplytoblobsrecordedinitsindex."-fi--test-f"$dotest/patch-merge-index"&&-his_tree=$(GIT_INDEX_FILE="$dotest/patch-merge-index"gitwrite-tree)&&-orig_tree=$(cat"$dotest/patch-merge-base")&&-rm-fr"$dotest"/patch-merge-*||exit1--echoFallingbacktopatchingbaseand3-waymerge...+print_continue_info(){+echo'When you have resolved this problem run "git am --resolved".'+echo'If you would prefer to skip this patch, instead run "git am --skip".'+echo'To restore the original branch and stop patching run "git am --abort".'+}-# This is not so wrong. Depending on which base we picked,-# orig_tree may be wildly different from ours, but his_tree-# has the same set of wildly different changes in parts the-# patch did not touch, so recursive ends up canceling them,-# saying that we reverted all those changes.+run_sequencer(){+gitsequencer$seqopts--caller='git am|--abort|--resolved|--skip'"$@"+case"$?"in+0)+cleanup+exit0+;;+2|3)+ret=$?+print_continue_info+exit$(($ret-2))+;;+*)+die_abort'git-sequencer died unexpected. Aborting.'+;;+esac+}-evalGITHEAD_$his_tree='"$FIRSTLINE"'-exportGITHEAD_$his_tree-git-merge-recursive$orig_tree--HEAD$his_tree||{-gitrerere-echoFailedtomergeinthechanges.-exit1-}-unsetGITHEAD_$his_tree+run_sequencer_i(){+command="$1"+whiletrue+do+output=$(gitsequencer$seqopts\+--caller='git am -i|--abort|--resolved|--skip'\+$command2>&1)+case"$?"in+0)+cleanup+exit0+;;+2)+iftest-f"$dotest/conflict"+then+rm"$dotest/conflict"+else+be_interactive+fi+;;+3)+:>"$dotest/conflict"+be_interactiveconflict+iftest$?-eq0+then+printf'%s\n'"$output"1>&2+print_continue_info+exit1+fi+;;+*)+die_abort"$output"+;;+esac+seqopts=+command=--continue+done}prec=4dotest="$GIT_DIR/rebase-apply"+todofile="$dotest/todo"sign=utf8=tkeep=skip=interactive=resolved=binary=rebasing=abort=-resolvemsg=resume=-git_apply_opt=+opts=whiletest$#!=0docase"$1"in-i|--interactive)-interactive=t;;+interactive=_i;;-b|--binary)binary=t;;-3|--3way)
@@ -168,363 +213,118 @@ doshiftdone-# If the dotest directory exists, but we have finished applying all the-# patches in them, clear it out.-iftest-d"$dotest"&&-last=$(cat"$dotest/last")&&-next=$(cat"$dotest/next")&&-test$#!=0&&-test"$next"-gt"$last"-then-rm-fr"$dotest"-fi-iftest-d"$dotest"then-case"$#,$skip$resolved$abort"in-0,*t*)-# Explicit resume command and we do not have file, so-# we are happy.-:;;-0,)-# No file input but without resume parameters; catch-# user error to feed us a patch from standard input-# when there is already $dotest. This is somewhat-# unreliable -- stdin could be /dev/null for example-# and the caller did not intend to feed us a patch but-# wanted to continue unattended.-tty-s-;;-*)-false-;;-esac||-die"previous rebase directory $dotest still exists but mbox given."-resume=yes+test"$#"!=0&&+die"previous rebase directory $dotest still exists but mbox given."-case"$skip,$abort"in-t,)-gitrerereclear-gitread-tree--reset-uHEADHEAD-orig_head=$(cat"$GIT_DIR/ORIG_HEAD")-gitresetHEAD-gitupdate-refORIG_HEAD$orig_head-;;-,t)-gitrerereclear-gitread-tree--reset-uHEADORIG_HEAD-gitresetORIG_HEAD-rm-fr"$dotest"-exit;;-esac-else-# Make sure we are not given --skip, --resolved, nor --abort-test"$skip$resolved$abort"=""||-die"Resolve operation not in progress, we are not resuming."+test-f"$dotest/interactive"&&+interactive=_iaction=$(cat"$dotest/interactive")-# Start afresh.-mkdir-p"$dotest"||exit+# No file input but without resume parameters; catch+# user error to feed us a patch from standard input+# when there is already $dotest. This is somewhat+# unreliable -- stdin could be /dev/null for example+# and the caller did not intend to feed us a patch but+# wanted to continue unattended.+test-z"$abort$resolved$skip"&&tty-s-iftest-n"$prefix"&&test$#!=0-then-first=t-forarg-do-test-n"$first"&&{-setx-first=-}-case"$arg"in-/*)-set"$@""$arg";;-*)-set"$@""$prefix$arg";;-esac-done-shift-fi-gitmailsplit-d"$prec"-o"$dotest"-b--"$@">"$dotest/last"||{-rm-fr"$dotest"-exit1-}+test-n"$abort"&&run_sequencer$interactive--abort+test-n"$resolved"&&run_sequencer$interactive--continue+test-n"$skip"&&run_sequencer$interactive--skip-# -b, -s, -u, -k and --whitespace flags are kept for the-# resuming session after a patch failure.-# -3 and -i can and must be given when resuming.-echo"$binary">"$dotest/binary"-echo" $ws">"$dotest/whitespace"-echo"$sign">"$dotest/sign"-echo"$utf8">"$dotest/utf8"-echo"$keep">"$dotest/keep"-echo1>"$dotest/next"-iftest-n"$rebasing"-then-:>"$dotest/rebasing"-else-:>"$dotest/applying"-gitupdate-refORIG_HEADHEAD-fi+die"$dotest still exists. Use git am --abort/--skip/--resolved."fi-case"$resolved"in-'')-files=$(gitdiff-index--cached--name-onlyHEAD--)||exit-if["$files"];then-echo"Dirty index: cannot apply patches (dirty: $files)">&2-exit1-fi-esac+# Make sure we are not given --skip, --resolved, nor --abort+test-z"$abort$resolved$skip"||+die'git-am is not in progress. You cannot use --abort/--skip/--resolved then.'-iftest"$(cat"$dotest/binary")"=t-then-binary=--allow-binary-replacement-fi-iftest"$(cat"$dotest/utf8")"=t-then-utf8=-u-else-utf8=-n-fi-iftest"$(cat"$dotest/keep")"=t-then-keep=-k-fi-ws=`cat"$dotest/whitespace"`-iftest"$(cat"$dotest/sign")"=t+# sequencer running?+gitsequencer--status>/dev/null2>&1&&+die"Sequencer already started. Cannot run git-am."++# Start afresh.+mkdir-p"$dotest"||+die"Could not create $dotest directory."++iftest-n"$prefix"&&test$#!=0then-SIGNOFF=`git-varGIT_COMMITTER_IDENT|sed-e'-s/>.*/>/-s/^/Signed-off-by:/'-`-else-SIGNOFF=+first=t+forarg+do+test-n"$first"&&{+setx+first=+}+case"$arg"in+/*)+set"$@""$arg";;+*)+set"$@""$prefix$arg";;+esac+done+shiftfi+last=$(gitmailsplit-d"$prec"-o"$dotest"-b--"$@")||{+cleanup+exit1+}+this=1-last=`cat"$dotest/last"`-this=`cat"$dotest/next"`-iftest"$skip"=t-then-this=`expr"$this"+1`-resume=+files=$(gitdiff-index--cached--name-onlyHEAD--)||exit+if["$files"];then+echo"Dirty index: cannot apply patches (dirty: $files)">&2+exit1fi-iftest"$this"-gt"$last"+test-n"$interactive"&&echo'again'>"$dotest/interactive"++# converting our options to git-sequencer file insn options+test-n"$binary"&&opts="$opts --binary"+test-n"$utf8"||opts="$opts -n"+test-n"$keep"&&opts="$opts -k"+test-n"$sign"&&opts="$opts --signoff"+test-n"$threeway"&&opts="$opts -3"++# these files are created for tab completion scripts+iftest-n"$rebasing"then-echoNothingtodo.-rm-fr"$dotest"-exit+:>"$dotest/rebasing"+else+:>"$dotest/applying"+gitupdate-refORIG_HEADHEADfi+# create todofile+:>"$todofile"||+die_abort"Cannot create $todofile"whiletest"$this"-le"$last"do-msgnum=`printf"%0${prec}d"$this`-next=`expr"$this"+1`-test-f"$dotest/$msgnum"||{-resume=-go_next-continue-}--# If we are not resuming, parse and extract the patch information-# into separate files:-# - info records the authorship and title-# - msg is the rest of commit log message-# - patch is the patch body.-#-# When we are resuming, these files are either already prepared-# by the user, or the user can tell us to do so by --resolved flag.-case"$resume"in-'')-gitmailinfo$keep$utf8"$dotest/msg""$dotest/patch"\-<"$dotest/$msgnum">"$dotest/info"||-stop_here$this--# skip pine's internal folder data-grep'^Author: Mail System Internal Data$'\-<"$dotest"/info>/dev/null&&-go_next&&continue--test-s"$dotest/patch"||{-echo"Patch is empty. Was it split wrong?"-stop_here$this-}-iftest-f"$dotest/rebasing"&&-commit=$(sed-e's/^From \([0-9a-f]*\) .*/\1/'\--eq"$dotest/$msgnum")&&-test"$(gitcat-file-t"$commit")"=commit-then-gitcat-filecommit"$commit"|-sed-e'1,/^$/d'>"$dotest/msg-clean"-else-SUBJECT="$(sed-n'/^Subject/ s/Subject: //p'"$dotest/info")"-case"$keep_subject"in-k)SUBJECT="[PATCH] $SUBJECT";;esac--(printf'%s\n\n'"$SUBJECT";cat"$dotest/msg")|-gitstripspace>"$dotest/msg-clean"-fi-;;-esac--GIT_AUTHOR_NAME="$(sed-n'/^Author/ s/Author: //p'"$dotest/info")"-GIT_AUTHOR_EMAIL="$(sed-n'/^Email/ s/Email: //p'"$dotest/info")"-GIT_AUTHOR_DATE="$(sed-n'/^Date/ s/Date: //p'"$dotest/info")"--iftest-z"$GIT_AUTHOR_EMAIL"-then-echo"Patch does not have a valid e-mail address."-stop_here$this-fi--exportGIT_AUTHOR_NAMEGIT_AUTHOR_EMAILGIT_AUTHOR_DATE--case"$resume"in-'')-iftest''!="$SIGNOFF"-then-LAST_SIGNED_OFF_BY=`-sed-ne'/^Signed-off-by: /p'\-"$dotest/msg-clean"|-sed-ne'$p'-`-ADD_SIGNOFF=`-test"$LAST_SIGNED_OFF_BY"="$SIGNOFF"||{-test''="$LAST_SIGNED_OFF_BY"&&echo-echo"$SIGNOFF"-}`-else-ADD_SIGNOFF=-fi-{-iftest-s"$dotest/msg-clean"-then-cat"$dotest/msg-clean"-fi-iftest''!="$ADD_SIGNOFF"-then-echo"$ADD_SIGNOFF"-fi-}>"$dotest/final-commit"-;;-*)-case"$resolved$interactive"in-tt)-# This is used only for interactive view option.-gitdiff-index-p--cachedHEAD-->"$dotest/patch"-;;-esac-esac--resume=-iftest"$interactive"=t-then-test-t0||-die"cannot be interactive without stdin connected to a terminal."-action=again-whiletest"$action"=again-do-echo"Commit Body is:"-echo"--------------------------"-cat"$dotest/final-commit"-echo"--------------------------"-printf"Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all "-readreply-case"$reply"in-[yY]*)action=yes;;-[aA]*)action=yesinteractive=;;-[nN]*)action=skip;;-[eE]*)git_editor"$dotest/final-commit"-action=again;;-[vV]*)action=again-LESS=-S${PAGER:-less}"$dotest/patch";;-*)action=again;;-esac-done-else-action=yes-fi-FIRSTLINE=$(sed1q"$dotest/final-commit")+msgnum=$(printf"%0${prec}d"$this)+this=$(($this+1))-iftest$action=skip-then-go_next+# This ignores every mail that does not contain a patch.+grep'^diff'"$dotest/$msgnum">/dev/null||continue-fi--iftest-x"$GIT_DIR"/hooks/applypatch-msg-then-"$GIT_DIR"/hooks/applypatch-msg"$dotest/final-commit"||-stop_here$this-fi--printf'Applying: %s\n'"$FIRSTLINE"-case"$resolved"in-'')-gitapply$git_apply_opt$binary--index"$dotest/patch"-apply_status=$?-;;-t)-# Resolved means the user did all the hard work, and-# we do not have to do any patch application. Just-# trust what the user has in the index file and the-# working tree.-resolved=-gitdiff-index--quiet--cachedHEAD--&&{-echo"No changes - did you forget to use 'git add'?"-stop_here_user_resolve$this-}-unmerged=$(gitls-files-u)-iftest-n"$unmerged"-then-echo"You still have unmerged paths in your index"-echo"did you forget to use 'git add'?"-stop_here_user_resolve$this-fi-apply_status=0-gitrerere-;;-esac--iftest$apply_status=1&&test"$threeway"=t-then-if(fall_back_3way)-then-# Applying the patch to an earlier tree and merging the-# result may have produced the same tree as ours.-gitdiff-index--quiet--cachedHEAD--&&{-echoNochanges--Patchalreadyapplied.-go_next-continue-}-# clear apply_status -- we have successfully merged.-apply_status=0-fi-fi-iftest$apply_status!=0-then-echoPatchfailedat$msgnum.-stop_here_user_resolve$this-fi--iftest-x"$GIT_DIR"/hooks/pre-applypatch-then-"$GIT_DIR"/hooks/pre-applypatch||stop_here$this-fi--tree=$(gitwrite-tree)&&-parent=$(gitrev-parse--verifyHEAD)&&-commit=$(gitcommit-tree$tree-p$parent<"$dotest/final-commit")&&-gitupdate-ref-m"$GIT_REFLOG_ACTION: $FIRSTLINE"HEAD$commit$parent||-stop_here$this--iftest-x"$GIT_DIR"/hooks/post-applypatch-then-"$GIT_DIR"/hooks/post-applypatch-fi--go_next+extra=+test-n"$rebasing"&&+commit=$(sed-e's/^From \([0-9a-f]*\) .*/\1/'\+-eq"$dotest/$msgnum")&&+test"$(gitcat-file-t"$commit")"=commit&&+extra=" -C $commit"++subject=$(sed-n'1,/^Subject:/s/Subject: *\(\[.*\]\)\{0,1\} *//p'\+<"$dotest/$msgnum")+test-n"$interactive"||+printf'run -- printf '\''Applying: %%s\\n'\'' '\''%s'\''\n'\+"$(printf'%s\n'"$subject"|+sed"s/'/'\\\\''/g")" >>"$todofile"+printf'patch%s%s "%s" # %s\n'"$opts""$extra""$dotest/$msgnum"\+"$subject">>"$todofile"+test-z"$interactive"||echo'pause'>>"$todofile"done-gitgc--auto--rm-fr"$dotest"+seqopts="--no-advice --allow-dirty"+run_sequencer$interactive"$todofile"
@@ -212,14 +212,12 @@ test_expect_success 'am takes patches from a Pine mailbox' '' test_expect_success'am fails on mail without patch''-test_must_failgitam<failmail&&-rm-r.git/rebase-apply/+test_must_failgitam<failmail' test_expect_success'am fails on empty patch''echo"---">>failmail&&test_must_failgitam<failmail&&-gitam--skip&&!test-d.git/rebase-apply'
@@ -0,0 +1,676 @@+git-sequencer(1)+================++NAME+----+git-sequencer - Execute a sequence of git instructions++SYNOPSIS+--------+[verse]+'git sequencer' [--batch] [--onto=<base>] [--allow-dirty]+ [--verbose | --no-advice | --quiet]+ [--] [<file>]+'git sequencer' --continue | --skip | --abort | --edit | --status+++DESCRIPTION+-----------+Executes a sequence of git instructions to HEAD or `<base>`.+The sequence is given by `<file>` or standard input.+Also see 'TODO FILE FORMAT' below.++Before doing anything, the TODO file is checked for correct syntax+and sanity.++In case of a conflict or request in the TODO file, 'git-sequencer' will+pause. On conflict you can use 'git-diff' to locate the markers (`<<<<<<<`)+and make edits to resolve the conflict.++For each file you edit, you need to tell git the changes by doing++ git add <file>++After resolving the conflict manually and updating the index with the+desired resolution, you can continue the sequencing process with++ git sequencer --continue++Alternatively, you can undo the 'git-sequencer' progress with++ git sequencer --abort++or skip the current instruction with++ git sequencer --skip++or correct the TODO file with++ git sequencer --edit++During pauses or when finished with the sequencing task, the current+HEAD will always be the result of the last processed instruction.+++OPTIONS+-------+<file>::+ Filename of the TODO file. If omitted, standard input is used.+ See 'TODO FILE FORMAT' below.++--allow-dirty::+ Run even if working tree is dirty.++-B::+--batch::+ Run in batch mode. If unexpected user intervention is needed+ (e.g. a conflict or the need to run an editor), 'git-sequencer' fails.+++Note that the sanity check fails, if you use this option+and an instruction like `edit` or `pause` is in the TODO file.++--onto=<base>::+ Checkout given commit or branch before sequencing.+ If you provide a branch, sequencer will make the provided+ changes on the branch, i.e. the branch will be changed.++--continue::+ Restart the sequencing process after having resolved a merge conflict.++--abort::+ Restore the original branch and abort the sequence operation.++--skip::+ Restart the sequencing process by skipping the current instruction.++--status::+ Show the current status of 'git-sequencer' and what+ operations can be done to change that status.++--edit::+ Invoke editor to edit the unprocessed part of the TODO file.+++The file is syntax- and sanity-checked afterwards, so that you can+safely run `git sequencer --skip` or `--continue` after editing.+If you nonetheless noticed that you made a mistake, you can+overwrite `.git/sequencer/todo` with `.git/sequencer/todo.old` and+rerun `git sequencer --edit`.+++If the check fails you are prompted if you want to correct your+changes, edit again, cancel editing or really want to save.++--no-advice::+ Suppress advice on intentional and unintentional pauses.++-q::+--quiet::+ Suppress output. Implies `--no-advice`.+ (Not yet implemented.)++-v::+--verbose::+ Be more verbose.+++NOTES+-----++When sequencing, it is possible, that you are changing the history of+a branch in a way that can cause problems for anyone who already has+a copy of the branch in their repository and tries to pull updates from+you. You should understand the implications of using 'git-sequencer' on+a repository that you share.++'git-sequencer' will usually be called by another git porcelain, like+linkgit:git-am[1] or linkgit:git-rebase[1].+++TODO FILE FORMAT+----------------++The TODO file contains basically one instruction per line.++Blank lines will be ignored.+All characters after a `#` character will be ignored until the end of a line.++The following instructions can be used:+++edit <commit>::+ Pick a commit and pause the sequencer process to let you+ make changes.+++This is a short form for `pick <commit> and `pause` on separate lines.+++mark <mark>::+ Set a symbolic mark for the last commit.+ `<mark>` is an unsigned integer starting at 1 and+ prefixed with a colon, e.g. `:1`.+++The marks can help if you want to refer to commits that you+created during the sequencer process, e.g. if you want to+merge such a commit.+++The set marks are removed after the sequencer has completed.+++merge [options] <commit-ish1> <commit-ish2> ... <commit-ishN>::+ Merge commits into HEAD.+++You can refer to a commit by a mark.+++If you do not provide a commit message (using `-F`, `-m`, `-C`, `-M`,+or `--standard`), an editor will be invoked.+++See the following list and 'GENERAL OPTIONS' for values of `options`:++ --standard;;+ Generate a commit message like 'Merge ... into HEAD'.+ See also linkgit:git-fmt-merge-msg[1].++ -s <strategy>;;+ --strategy=<strategy>;;+ Use the given merge strategy.+ See also linkgit:git-merge[1].+++pick [options] <commit>::+ Pick (see linkgit:git-cherry-pick[1]) a commit.+ Sequencer will pause on conflicts.+++See the following list and 'GENERAL OPTIONS' for values of `options`:++ -R;;+ --reverse;;+ Revert the changes introduced by pick <commit>.++ --mainline=<n>;;+ Allow you to pick merge commits by specifying the+ parent number (beginning from 1) to let sequencer+ replay the changes relative to the specified parent.+ ++This option does not work together with `-R`.+++patch [options] <file>::+ If file `<file>` is a pure (diff) patch, then apply the patch.+ If no `--message` option is given, an editor will+ be invoked to enter a commit message.+++If `<file>` is a linkgit:git-format-patch[1]-formatted patch,+then the patch will be commited.+++See the following list and 'GENERAL OPTIONS' for values of `options`:++ -3;;+ --3way;;+ When the patch does not apply cleanly, fall back on+ 3-way merge, if the patch records the identity of blobs+ it is supposed to apply to, and we have those blobs+ available locally.++ -k;;+ Pass `-k` flag to 'git-mailinfo' (see linkgit:git-mailinfo[1]).++ -n;;+ Pass `-n` flag to 'git-mailinfo' (see linkgit:git-mailinfo[1]).++ --exclude=<path-pattern>;;+ Do not apply changes to files matching the given path pattern.+ This can be useful when importing patchsets, where you want to+ exclude certain files or directories.++ -R;;+ --reverse;;+ Apply the patch in reverse.++ --no-add;;+ When applying a patch, ignore additions made by the+ patch. This can be used to extract the common part between+ two files by first running 'diff' on them and applying+ the result with this option, which would apply the+ deletion part but not addition part.++ --whitespace=<action>;;+ Specify behavior on whitespace errors.+ See linkgit:git-apply[1] for a detailed description.++ --context=<n>;;+ Ensure at least <n> lines of surrounding context match before+ and after each change. When fewer lines of surrounding+ context exist they all must match. By default no context is+ ever ignored.++ --inaccurate-eof;;+ Under certain circumstances, some versions of 'diff' do not+ correctly detect a missing new-line at the end of the file.+ As a result, patches created by such 'diff' programs do not+ record incomplete lines correctly.+ This option adds support for applying such patches by+ working around this bug.++ -p<n>;;+ Remove <n> leading slashes from traditional diff paths.+ The default is 1.++ --unidiff-zero;;+ By default, 'git-apply' expects that the patch being+ applied is a unified diff with at least one line of context.+ This provides good safety measures, but breaks down when+ applying a diff generated with --unified=0. To bypass these+ checks use this option.+++pause::+ Pause the sequencer process to let you manually make changes.+ For example, you can re-edit the done commit, split a commit,+ fix bugs or typos, or make further commits on top of HEAD before+ continuing.+++After you have finished your changes and added them to the index,+invoke `git sequencer --continue`.+If you only want to edit the last commit message with an editor,+run `git commit --amend` (see linkgit:git-commit[1]) before saying+`--continue`.+++ref <ref>::+ Set ref `<ref>` to the current HEAD, see also+ linkgit:git-update-ref[1].+++reset <commit-ish>::+ Go back (see linkgit:git-reset[1] `--hard`) to commit `<commit-ish>`.+ `<commit-ish>` can also be given by a mark, if prefixed with a colon.+++squash [options] <commit>::+ Add the changes introduced by `<commit>` to the last commit.+++See 'GENERAL OPTIONS' for values of `options`.++squash [options] --from <mark>::+ Squash all commits from the given mark into one commit.+ There must not be any `merge` instructions between the+ `mark` instruction and this `squash --from` instruction.+++See the following list and 'GENERAL OPTIONS' for values of `options`:++ --collect-signoffs;;+ Collect the Signed-off-by: lines of each commit and+ add them to the squashed commit message.+ (Not yet implemented.)++ --include-merges;;+ Sanity check does not fail if you have merges+ between HEAD and <mark>.+++run [--dir=<path>] [--] <cmd> <args>...::+ Run command `<cmd>` with arguments `<args>`.+ Pause (conflict-like) if exit status is non-zero.+++If `<path>` is set, sequencer will change directory to `<path>`+before running the command and change back after exit.+++GENERAL OPTIONS+---------------++Besides some special options, the instructions+`patch`, `merge`, `pick`, `squash` take the following general options:++--author=<author>::+ Override the author name and e-mail address used in the commit.+ Use `A U Thor <author@example.com>` format.++-C <commit-ish>::+--reuse-commit=<commit-ish>::+ Reuse message and authorship data from specified commit.++-M <commit-ish>+--reuse-message=<commit-ish>::+ Reuse message from specified commit.+ Note, that only the commit message is reused+ and not the authorship information.++-F <file>::+--file=<file>::+ Take the commit message from the given file.++-m <msg>::+--message=<msg>::+ Use the given `<msg>` as the commit message.++--signoff::+ Add `Signed-off-by:` line to the commit message (if not yet there),+ using the committer identity of yourself.++-e::+--edit::+ Regardless what commit message options are given,+ invoke the editor to allow editing of the commit message.+++RETURN VALUES+-------------++'git-sequencer' returns:++* `0`, if 'git-sequencer' successfully completed all the instructions+ in the TODO file or successfully aborted after+ `git sequencer --abort`,+* `2`, on user-requested pausing, e.g.+ when using the `edit` instruction.+* `3`, on pauses that are not requested, e.g.+ when there are conflicts to resolve+ or errors in the TODO file.+* any other value on error, e.g.+ running 'git-sequencer' on a bare repository.+++EXAMPLES+--------++Here are some examples that shall ease the start with the TODO+file format.+Make sure you have understood the `pick` and perhaps the `patch` command.+Those will not be explained further.++Manually editing and adding commits+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~++Sequencer allows manual intervention in between.+This can be useful to++* check if everything has gone right so far,++* split commits,++* edit changes and/or commit messages, or++* add further manual commits on top of the current one.++If you want to do one of this, either change `pick` to `edit`, or+add a `pause` line after the specific instruction.++Note that if you only want to edit the commit message in an+editor, just use the `--edit` option of your `pick` or `patch`+instruction.++`HEAD` refers to the last commit being done by sequencer.+So if you want to split a commit, repeat something like++------------+$ git reset HEAD^ # Reset index to HEAD^, but keep working tree+ # HEAD is the last commit being done by sequencer+$ git add -p # Add changes interactively to the index, and/or+$ git add file1 # Add changes from file1 to the index+$ git commit # Commit staged changes+------------++until you have no changes to commit, and then run++------------+$ git sequencer --continue # Continue sequencer process+------------++Be aware that if there are still staged changes,+'git-sequencer' will add those changes to the last commit being done.+++Squashing commits+~~~~~~~~~~~~~~~~~++Squashing commits means putting the changes of many commits into one.+If you have two commits `abcdef1` and `fa1afe1` and you want to squash them,+feed 'git-sequencer' with a TODO file like:++------------+pick abcdef1+squash fa1afe1+------------++Squash will concatenate the commit messages of `abcdef1` and `fa1afe1` and+invoke an editor so that you can edit them.+Perhaps you just want to reuse the commit message of `abcdef1` and+add a signoff. Then use:++------------+pick abcdef1+squash -C abcdef1 --signoff fa1afe1+------------++You can also squash more than two commits.+Basically you can do:++------------+pick A+squash B+squash C+squash D+squash --message "Make indentation consistent" --signoff E+------------++If somebody sent you a patch that you have not yet applied and you want+to apply it and squash it, or if you have a `pick <commit>` list generated+with something like++------------+$ git rev-list --no-merges --reverse A^..E | sed -e 's/^/pick /'`+------------++you can use the `mark` and `squash --from` instructions to+squash all commits between them into one:++------------+mark :0+pick A+pick B+pick C+pick D+pick E+squash --message "Make indentation consistent" --signoff --from :0+------------+++Branching and Merging+~~~~~~~~~~~~~~~~~~~~~++Merging branches can easily be done using the `merge` instruction.+For an example, it is more interesting to branch, pick some commits+and merge. Imagine you want to 'copy' this onto the current branch:++------------+ ...--A1--A2--A3--A4--A5---MA-A6 refs/heads/old+ | \ /+ | C1--MC--C2 refs/heads/topic+ \ /+ B1--B2--B3+------------++You want the copy to look exactly like this, except that you+are not on branch `old`, and you want to call the copy of `topic`+simply `topic2`.+Here is a way to achieve this:++------------+pick A1+mark :0 # remember this to pick further commits on trunk A++pick B1 # pick commits for trunk B+pick B2+pick B3+mark :1 # remember this for merge+# Why not just merge B3 later?+# Then you would merge the original B3 and not the copy.+# But in this example you want to merge the copy of B3.++reset :0 # go back to the copy of A1+pick A2 # go on picking the commits of trunk A+pick A3+mark :2 # remember this to pick further commits on trunk A++pick C1 # pick commits for trunk C+merge -C MC :1 # merge trunk B+pick C2+ref refs/heads/topic2 # create branch for the C trunk++reset :2 # go back to last commit of trunk A (copy of A3)+pick A4 # go on picking the commits of trunk A+pick A5+merge --standard topic2 # merge trunk C+pick A6+------------+++Proper handling of conflicts+~~~~~~~~~~~~~~~~~~~~~~~~~~~~++First of all, you are encouraged to use linkgit:git-rerere[1]:++------------+$ git config rerere.enabled true # enable rerere+------------++Sequencer invokes 'git-rerere' automatically on conflict.++If you experience conflicts, try++------------+$ git diff # Show conflicting code+$ git status # Show conflicting files+------------++Then fix these conflicts using your editor and run++------------+$ git add file1 file2 file3 # Add modified files to the index+$ git status # Make sure working tree is clean+$ git sequencer --continue # Continue sequencer process+------------++Now assume a conflict happens because you have unproperly edited+the TODO file.++Imagine your initial TODO file was:++------------+pick A+pick C+pick D+------------++But you wanted to pick B before C, and now you have this conflict on+picking C. You may first have a look at:++------------+$ git sequencer --status+------------++This will show you, what has been done, in what step the conflict+happened and what is still to do, like this:++------------+Already done (or tried):+ pick A+ pick C++Interrupted by conflict at+ pick C++Still to do:+ pick D++To abort & restore, invoke:+ git sequencer --abort+To continue, invoke:+ git sequencer --continue+To skip the current instruction, invoke:+ git sequencer --skip+------------++A good way to solve that situation is running++------------+$ git sequencer --edit+------------++and change the file to:++------------+pick B+pick C+pick D+------------++Save the file, and invoke:++------------+$ git sequencer --skip+------------++Then the conflict-ridden `pick C` will be skipped and B is picked,+before C will again be picked.+++Running tests+~~~~~~~~~~~~~++Imagine you have test programs within a `tests/` directory in your working+tree. But before running your test programs, you have to invoke `make` in+the root directory of the working tree to compile your project.++If the commit policy of your project says that after every commit the+software must be able to compile and the test suite must pass, you+are required to check this after every pick.++This example shows how 'git-sequencer' can assist you:++------------+pick A # Fix foo+run make+run --dir=tests ./test-foo+pick B # Extend bar+run make+run --dir tests -- ./test-bar --expensive-tests+pick C+run make+run --dir tests make tests+------------++Sequencer will be paused, when a run fails (i.e. on non-zero exit status).+Then it is your turn to fix the problem and make the tests pass.++Note, that on `git sequencer --continue`, 'git-sequencer' will not+repeat the failed `run` instruction.+++SEE ALSO+--------++linkgit:git-add[1],+linkgit:git-am[1],+linkgit:git-cherry-pick[1],+linkgit:git-commit[1],+linkgit:git-fmt-merge-msg[1],+linkgit:git-format-patch[1],+linkgit:git-rebase[1],+linkgit:git-rerere[1],+linkgit:git-reset[1],+linkgit:git-update-ref[1]+++Authors+-------+Written by Stephan Beyer <s-beyer@gmx.net>.+++Documentation+-------------+Documentation by Stephan Beyer and the git-list <git@vger.kernel.org>.++GIT+---+Part of the linkgit:git[1] suite
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:45:03
Hi,
On Sat, 26 Jul 2008, Stephan Beyer wrote:
In the last patchset I mentioned the issue, that the prototype is slow
as hell. I know some bottlenecks, but I have not even tried to change
that, because this is no issue for the builtin.
Why is it no issue for the builtin? Is it so much different from the
prototype?
Personally, I think if the prototype is so much slower, there is no sense
applying it into git.git, but I'd rather see you work on the builtin and
finalize it.
Ciao,
Dscho
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:45:03
Hi,
On Sat, 26 Jul 2008, Stephan Beyer wrote:
+-B::
+--batch::
+ Run in batch mode. If unexpected user intervention is needed
+ (e.g. a conflict or the need to run an editor), 'git-sequencer' fails.
Does it abort, or leave a dirty tree?
+--onto=<base>::
+ Checkout given commit or branch before sequencing.
+ If you provide a branch, sequencer will make the provided
+ changes on the branch, i.e. the branch will be changed.
Whoa, does that mean that
$ git checkout my-private-branch
$ git sequencer --onto=master
will change _master_?
+--continue::
+ Restart the sequencing process after having resolved a merge conflict.
What about 'edit'? Does it restart the sequencing process after editing a
file or commit message, too?
+--skip::
+ Restart the sequencing process by skipping the current instruction.
s/ by/,/
+--status::
+ Show the current status of 'git-sequencer' and what
+ operations can be done to change that status.
Nice.
+--edit::
+ Invoke editor to edit the unprocessed part of the TODO file.
Nice!
+If you nonetheless noticed that you made a mistake, you can
+overwrite `.git/sequencer/todo` with `.git/sequencer/todo.old` and
+rerun `git sequencer --edit`.
Speaking of "todo": there was an explicit request to change that to
"git-rebase-todo" for rebase -i, so that syntax highlighting could be
switched on.
+NOTES
+-----
+
+When sequencing, it is possible, that you are changing the history of
s/possible,/possible/ I know that mistake, being a German myself.
+a branch in a way that can cause problems for anyone who already has
+a copy of the branch in their repository and tries to pull updates from
+you. You should understand the implications of using 'git-sequencer' on
+a repository that you share.
How about this instead?
Note that sequencing will rewrite the history of the branch.
This will cause problems if you published the branch prior to
rewriting the history, as the former tip is no longer an
ancestor of the new tip.
In other words, if you rewrite an already published branch, users
that pull from you _will_ get a bogus merge.
+'git-sequencer' will usually be called by another git porcelain, like
s/another git procelain/other git programs/
+TODO FILE FORMAT
+----------------
+
+The TODO file contains basically one instruction per line.
s/basically //
+edit <commit>::
+ Pick a commit and pause the sequencer process to let you
+ make changes.
++
+This is a short form for `pick <commit> and `pause` on separate lines.
It might make sense to explain 'pick' before 'edit', then.
+mark <mark>::
+ Set a symbolic mark for the last commit.
+ `<mark>` is an unsigned integer starting at 1 and
+ prefixed with a colon, e.g. `:1`.
++
+The marks can help if you want to refer to commits that you
+created during the sequencer process, e.g. if you want to
+merge such a commit.
It might make sense to explain 'merge' before that, then.
+ --mainline=<n>;;
+ Allow you to pick merge commits by specifying the
+ parent number (beginning from 1) to let sequencer
+ replay the changes relative to the specified parent.
Why is this called "mainline", and not "parent"?
[... talking about 'patch']
+ --exclude=<path-pattern>;;
+ Do not apply changes to files matching the given path pattern.
+ This can be useful when importing patchsets, where you want to
+ exclude certain files or directories.
You might just as well support the new "--directory" option of git-apply,
too, and/or --recount.
[talking about 'squash']
+ --collect-signoffs;;
+ Collect the Signed-off-by: lines of each commit and
+ add them to the squashed commit message.
+ (Not yet implemented.)
I really have to wonder how useful that is. Or how correct, for that
matter.
+
+ --include-merges;;
+ Sanity check does not fail if you have merges
+ between HEAD and <mark>.
It may be a commit, too, right? And why does it make sense to check that
there are no merges? I mean, it is just as if I did two cherry-picks, the
second with -n, and then commit --amend it. Can make tons of sense...
+Here are some examples that shall ease the start with the TODO
+file format.
+Make sure you have understood the `pick` and perhaps the `patch` command.
+Those will not be explained further.
From: Stephan Beyer <hidden> Date: 2016-06-15 22:45:04
Hi,
Johannes Schindelin wrote:
quoted
+-B::
+--batch::
+ Run in batch mode. If unexpected user intervention is needed
+ (e.g. a conflict or the need to run an editor), 'git-sequencer' fails.
Does it abort, or leave a dirty tree?
It aborts.
Perhaps I should make this clear in the docs.
quoted
+--onto=<base>::
+ Checkout given commit or branch before sequencing.
+ If you provide a branch, sequencer will make the provided
+ changes on the branch, i.e. the branch will be changed.
Whoa, does that mean that
$ git checkout my-private-branch
$ git sequencer --onto=master
will change _master_?
Exactly.
quoted
+--continue::
+ Restart the sequencing process after having resolved a merge conflict.
What about 'edit'? Does it restart the sequencing process after editing a
file or commit message, too?
Yes. Thanks.
quoted
+If you nonetheless noticed that you made a mistake, you can
+overwrite `.git/sequencer/todo` with `.git/sequencer/todo.old` and
+rerun `git sequencer --edit`.
Speaking of "todo": there was an explicit request to change that to
"git-rebase-todo" for rebase -i, so that syntax highlighting could be
switched on.
I'd not have a problem with that, though the name "rebase" is not
necessarily correct and the syntax files had to be extended
nevertheless.
quoted
+-v::
+--verbose::
+ Be more verbose.
More?
Hehe, the note that "more" has to be defined more accurately, has been
removed. But it is still true. ;)
quoted
+a branch in a way that can cause problems for anyone who already has
+a copy of the branch in their repository and tries to pull updates from
+you. You should understand the implications of using 'git-sequencer' on
+a repository that you share.
How about this instead?
Note that sequencing will rewrite the history of the branch.
It will not necessarily rewrite history of a branch. In case of the
rebase user command, it does, of course.
This will cause problems if you published the branch prior to
rewriting the history, as the former tip is no longer an
ancestor of the new tip.
In other words, if you rewrite an already published branch, users
that pull from you _will_ get a bogus merge.
Yes, I can take that.
Well, I wanted only a short note and the user command that really
rewrites branches could have a more detailed warning.
quoted
+'git-sequencer' will usually be called by another git porcelain, like
s/another git procelain/other git programs/
Ok, I use "other git commands", since this wording seems to be the leading
one in other documentation.
quoted
+TODO FILE FORMAT
+----------------
+
+The TODO file contains basically one instruction per line.
s/basically //
Oh, this is from the times where we included some possible extensions,
like a trailing backslash.
quoted
+edit <commit>::
+ Pick a commit and pause the sequencer process to let you
+ make changes.
++
+This is a short form for `pick <commit> and `pause` on separate lines.
It might make sense to explain 'pick' before 'edit', then.
This is kept alphabetically.
When first writing that, I wondered if this makes sense:
a reference-like list should be sorted alphabetically, a tutorial-like
list should have some kind of logical structure.
I do not really care if we prefer this or that one. So I take your
reordering suggestion until somebody complains again :)
quoted
+ --mainline=<n>;;
+ Allow you to pick merge commits by specifying the
+ parent number (beginning from 1) to let sequencer
+ replay the changes relative to the specified parent.
Why is this called "mainline", and not "parent"?
Because git-cherry-pick/git-revert has "--mainline" and I did not want
to rename this.
quoted
[talking about 'squash']
+ --collect-signoffs;;
+ Collect the Signed-off-by: lines of each commit and
+ add them to the squashed commit message.
+ (Not yet implemented.)
I really have to wonder how useful that is. Or how correct, for that
matter.
This is just some kind of squashing Signed-off-by: lines.
It was requested by someone (Paolo?) in the RFC git-sequencer.txt thread.
The behavior is planned like this:
Instead of...
Message of commit 1
Signed-off-by: A
Message of commit 2
Signed-off-by: B
Message of commit 3
Signed-off-by: A
Signed-off-by: C
...the user gets...
Message of commit 1
Message of commit 2
Message of commit 3
Signed-off-by: A
Signed-off-by: B
Signed-off-by: C
using --collect-signoffs and no commit-message-changing options.
With --message="Foo" this will be:
Foo
Signed-off-by: A
Signed-off-by: B
Signed-off-by: C
For me this sounds like making sense and being useful, but I have not yet
digged so deep into the rules of signing off :)
quoted
+ --include-merges;;
+ Sanity check does not fail if you have merges
+ between HEAD and <mark>.
It may be a commit, too, right? And why does it make sense to check that
there are no merges? I mean, it is just as if I did two cherry-picks, the
second with -n, and then commit --amend it. Can make tons of sense...
I think I mean something different. With "merges" I am talking about
commits having more than one parent.
By this check I want to make sure, that the user really knows what he
does when he wants to squash the ones marked with ~ into one commit.
~~~~~~~~~~~~~
..-A---B---C---D---E---F
/
..-X---Y--
Yet I didn't really care what happens then and perhaps it should be:
..--A---S--F
/
..-X-Y-
In the prototype the squashing is done by soft-resetting to the
squash base and then commit. As I said, I did not really care if
my painted result really happens. In the builtin it will happen :)
quoted
+Here are some examples that shall ease the start with the TODO
+file format.
+Make sure you have understood the `pick` and perhaps the `patch` command.
+Those will not be explained further.
This sentence is insulting. Strike it.
The "Make sure ..." sentence? It really is insulting?
Do you think it implies the assumption that the user will not grasp
patch/pick easily?
Thanks for your reply and your other notes. (The ones I didn't comment
are just ACKed.)
Regards,
Stephan
--
Stephan Beyer [off-list ref], PGP 0x6EDDD207FCC5040F
From: Stephan Beyer <hidden> Date: 2016-06-15 22:45:04
Hi,
Johannes Schindelin wrote:
quoted
In the last patchset I mentioned the issue, that the prototype is slow
as hell. I know some bottlenecks, but I have not even tried to change
that, because this is no issue for the builtin.
Why is it no issue for the builtin? Is it so much different from the
prototype?
As Sverre pointed out and as my "experiments" tried to show: the builtin
is just fast ;-)
Personally, I think if the prototype is so much slower, there is no sense
applying it into git.git,
Right.
Regards,
Stephan
--
Stephan Beyer [off-list ref], PGP 0x6EDDD207FCC5040F
From: Stephan Beyer <hidden> Date: 2016-06-15 22:45:04
Hi,
Johannes Schindelin wrote:
Hi,
On Sat, 26 Jul 2008, Stephan Beyer wrote:
quoted
For git-rebase-i -p (preserving merges) merges should be
rewritten. For this, the sequencer instructions "mark", "merge"
and "reset" are used.
Ah, the ugliness returns.
Yet I have not seen a way that is as flexible and clean as using
mark/merge/reset and imho this is not ugly.
(I know the discussion of the Joerg Sommer patches that introduced mark,
merge and reset.)
Regards.
--
Stephan Beyer [off-list ref], PGP 0x6EDDD207FCC5040F
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:45:04
Hi,
On Wed, 30 Jul 2008, Stephan Beyer wrote:
Johannes Schindelin wrote:
quoted
quoted
+-B::
+--batch::
+ Run in batch mode. If unexpected user intervention is needed
+ (e.g. a conflict or the need to run an editor), 'git-sequencer' fails.
Does it abort, or leave a dirty tree?
It aborts.
Perhaps I should make this clear in the docs.
No, just leave it as is. The users can always ask you on the mailing
list. So my comment was totally unfounded.
quoted
quoted
+--onto=<base>::
+ Checkout given commit or branch before sequencing.
+ If you provide a branch, sequencer will make the provided
+ changes on the branch, i.e. the branch will be changed.
Whoa, does that mean that
$ git checkout my-private-branch
$ git sequencer --onto=master
will change _master_?
Exactly.
/me does not like that. I could see a new porcelain doing that, but not
the thing that will be called by rebase.
quoted
quoted
+ --include-merges;;
+ Sanity check does not fail if you have merges
+ between HEAD and <mark>.
It may be a commit, too, right? And why does it make sense to check that
there are no merges? I mean, it is just as if I did two cherry-picks, the
second with -n, and then commit --amend it. Can make tons of sense...
I think I mean something different. With "merges" I am talking about
commits having more than one parent.
Yes, I read "merges" the same way. My comment still stands.
Thanks for your reply and your other notes. (The ones I didn't comment
are just ACKed.)
The ones that _I_ did not comment on I do not necessarily agree with, but
then, I do not have the time to argue about them.
Ciao,
Dscho
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:45:04
Hi,
On Wed, 30 Jul 2008, Stephan Beyer wrote:
Johannes Schindelin wrote:
quoted
quoted
In the last patchset I mentioned the issue, that the prototype is
slow as hell. I know some bottlenecks, but I have not even tried to
change that, because this is no issue for the builtin.
Why is it no issue for the builtin? Is it so much different from the
prototype?
As Sverre pointed out and as my "experiments" tried to show: the builtin
is just fast ;-)
So why is it just so fast? Does it do things completely different than
the shell prototype you presented?
Still puzzled,
Dscho
From: Daniel Barkalow <hidden> Date: 2016-06-15 22:45:05
On Wed, 30 Jul 2008, Johannes Schindelin wrote:
On Wed, 30 Jul 2008, Stephan Beyer wrote:
quoted
Johannes Schindelin wrote:
quoted
Whoa, does that mean that
$ git checkout my-private-branch
$ git sequencer --onto=master
will change _master_?
Exactly.
/me does not like that. I could see a new porcelain doing that, but not
the thing that will be called by rebase.
Yeah, an option to change which branch is current should be called
something different. --onto is an initial reset --hard, not an initial
checkout; it specifies the branch (or commit) that the sequence of changes
are done on top of, not the branch that will contain them. "Onto" (as an
english preposition) specifies a destination, not a location, so it
doesn't make sense as the location that stuff is done.
-Daniel
*This .sig left intentionally blank*
From: Stephan Beyer <hidden> Date: 2016-06-15 22:45:05
Johannes Schindelin wrote:
On Wed, 30 Jul 2008, Stephan Beyer wrote:
quoted
Johannes Schindelin wrote:
quoted
quoted
In the last patchset I mentioned the issue, that the prototype is
slow as hell. I know some bottlenecks, but I have not even tried to
change that, because this is no issue for the builtin.
Why is it no issue for the builtin? Is it so much different from the
prototype?
As Sverre pointed out and as my "experiments" tried to show: the builtin
is just fast ;-)
So why is it just so fast? Does it do things completely different than
the shell prototype you presented?
Ah, that's the point of your question ;)
No, it's different in some minor parts, of course, but the important thing
is: it is C, not sh. That's what makes it faster.
Regards.
--
Stephan Beyer [off-list ref], PGP 0x6EDDD207FCC5040F
From: Stephan Beyer <hidden> Date: 2016-06-15 22:45:05
Hi,
Johannes Schindelin wrote:
quoted
quoted
quoted
+--onto=<base>::
+ Checkout given commit or branch before sequencing.
+ If you provide a branch, sequencer will make the provided
+ changes on the branch, i.e. the branch will be changed.
Whoa, does that mean that
$ git checkout my-private-branch
$ git sequencer --onto=master
will change _master_?
Exactly.
/me does not like that. I could see a new porcelain doing that, but not
the thing that will be called by rebase.
$ git sequencer --onto=master todofile
is equal to:
$ git checkout $(git rev-parse master) # detached HEAD
$ git sequencer todofile
And when successfully finished:
$ git update-ref refs/heads/master HEAD # reattach branch
Yet this seemed to be useful.
(But perhaps the name --onto is wrong...)
quoted
quoted
quoted
+ --include-merges;;
+ Sanity check does not fail if you have merges
+ between HEAD and <mark>.
It may be a commit, too, right? And why does it make sense to check that
there are no merges? I mean, it is just as if I did two cherry-picks, the
second with -n, and then commit --amend it. Can make tons of sense...
I think I mean something different. With "merges" I am talking about
commits having more than one parent.
Yes, I read "merges" the same way. My comment still stands.
If you really mean that it's the same as doing two cherry-picks and
squashing the second into the first, I don't get what your comment has
in common with merges.
If you mean squashing a merge and some cherry-picks on top of that merge
into one merge commit: that is possible. It's only checked that no merges
are *in between* currently.
In graphics: squashing
..--M--X--Y- ..-A--M--X--Y
/ /
..- ..-
is allowed is only allowed with
--include-merges
Regards.
--
Stephan Beyer [off-list ref], PGP 0x6EDDD207FCC5040F