All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/31] Refactor rebase
@ 2010-12-28  9:30 Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 01/31] rebase: clearer names for directory variables Martin von Zweigbergk
                   ` (32 more replies)
  0 siblings, 33 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

For the past two months, I have been working on refactoring the rebase
code. See [1] for background information. I have been trying to polish
the patch set for some time, but now I don't think I will get much
further without your help.

My goals with this series were:

 (1) Make it easier to add new features to git rebase by reducing the
 amount of duplicated code. FWIW, this series removes about 140 lines
 non-test code.

 (2) Make the behavior (towards the user) more consistent between
 interactive and non-interactive rebase. This mainly involves error
 messages and command line options.

While not being a goal from the beginning, I have also tried to make
the code more readable. This is of course very subjective, so we'll
see - maybe in your eyes I just made things worse :-).


At a high level, I tried to do what was suggested by Johannes Sixt in
the second entry on [1], namely

"... to write a command line processor, git-rebase.sh, that sets shell
variables from options that it collects from various sources, then
dispatches to one of git-rebase--interactive.sh, git-rebase--merge.sh,
or git-rebase--am.sh (the latter two would be stripped-down copies of
the current git-rebase.sh)."


Patches 01-04 try to make git-rebase.sh more readable and extensible
by factoring out the code that reads the saved state from
.git/rebase-apply or .git/rebase-merge.

Patches 05-09 set the stage for further refactoring by aligning
git-rebase.sh and git-rebase--interactive.sh.

Patches 10-16 factor out parts from git-rebase--interactive.sh and let
it rely on the corresponding code in git-rebase.sh.

Patch 17 just removes a duplicated variable.

Patches 18 and 19 extract the am-specific and merge-specifc rebase
code into two new source files (as suggested by Hannes).

Patch 20 makes interactive rebase print the same message as
non-interactive rebase in case of conflict.

Patches 21 and 22 prepare for further refactoring by aligning
interactive and non-interactive rebase a bit more.

Patch 23 factors out part or all of the handling of --continue, --skip
and --abort from git-rebase--interactive to git-rebase.sh.

Patches 24-27 makes rebase remember more options passed on the command
line thoughout the rebase (past any conflicts).

Patches 28-31 remove some unnecessary code.


I have tried to separate pure refactoring from changes that make
functional changes, but there are still some functional changes hiding
in the "refactoring" patches. I have tried to point this out in the
commit message where applicable, but I'm sure I have missed a lot of
places.


/Martin


[1] http://thread.gmane.org/gmane.comp.version-control.git/160517


Martin von Zweigbergk (31):
  rebase: clearer names for directory variables
  rebase: refactor reading of state
  rebase: read state outside loop
  rebase: remove unused rebase state 'prev_head'
  rebase: improve detection of rebase in progress
  rebase: act on command line outside parsing loop
  rebase: stricter check of standalone sub command
  rebase: align variable names
  rebase: align variable content
  rebase: factor out command line option processing
  rebase -i: remove now unnecessary directory checks
  rebase: reorder validation steps
  rebase: factor out reference parsing
  rebase: factor out clean work tree check
  rebase: factor out call to pre-rebase hook
  rebase -i: support --stat
  rebase: remove $branch as synonym for $orig_head
  rebase: extract merge code to new source file
  rebase: extract am code to new source file
  rebase: show consistent conflict resolution hint
  rebase -i: align variable names
  rebase: make -v a tiny bit more verbose
  rebase: factor out sub command handling
  rebase: extract code for writing basic state
  rebase: remember verbose option
  rebase: remember strategy and strategy options
  rebase -m: remember allow_rerere_autoupdate option
  rebase -m: don't print exit code 2 when merge fails
  git-rebase--am: remove unnecessary --3way option
  rebase -i: don't read unused variable preserve_merges
  rebase -i: remove unnecessary state rebase-root

 .gitignore                 |    2 +
 Makefile                   |    2 +
 git-rebase--am.sh          |   30 +++
 git-rebase--interactive.sh |  589 ++++++++++++++------------------------------
 git-rebase--merge.sh       |  151 +++++++++++
 git-rebase.sh              |  477 ++++++++++++++---------------------
 t/t3403-rebase-skip.sh     |    5 +
 t/t3407-rebase-abort.sh    |   10 +
 t/t3418-rebase-continue.sh |   55 ++++
 9 files changed, 627 insertions(+), 694 deletions(-)
 create mode 100644 git-rebase--am.sh
 create mode 100644 git-rebase--merge.sh

-- 
1.7.3.2.864.gbbb96

^ permalink raw reply	[flat|nested] 118+ messages in thread

* [PATCH 01/31] rebase: clearer names for directory variables
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28 23:08   ` Junio C Hamano
  2010-12-28  9:30 ` [PATCH 02/31] rebase: refactor reading of state Martin von Zweigbergk
                   ` (31 subsequent siblings)
  32 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Instead of using the old variable name 'dotest' for
"$GIT_DIR"/rebase-merge and no variable for "$GIT_DIR"/rebase-apply,
introduce two variables 'merge_dir' and 'apply_dir' for these paths.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase.sh |  141 +++++++++++++++++++++++++++++----------------------------
 1 files changed, 71 insertions(+), 70 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index d8e1903..79f8008 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -46,7 +46,8 @@ unset newbase
 strategy=recursive
 strategy_opts=
 do_merge=
-dotest="$GIT_DIR"/rebase-merge
+merge_dir="$GIT_DIR"/rebase-merge
+apply_dir="$GIT_DIR"/rebase-apply
 prec=4
 verbose=
 diffstat=
@@ -58,7 +59,7 @@ allow_rerere_autoupdate=
 
 continue_merge () {
 	test -n "$prev_head" || die "prev_head must be defined"
-	test -d "$dotest" || die "$dotest directory does not exist"
+	test -d "$merge_dir" || die "$merge_dir directory does not exist"
 
 	unmerged=$(git ls-files -u)
 	if test -n "$unmerged"
@@ -68,7 +69,7 @@ continue_merge () {
 		die "$RESOLVEMSG"
 	fi
 
-	cmt=`cat "$dotest/current"`
+	cmt=`cat "$merge_dir/current"`
 	if ! git diff-index --quiet --ignore-submodules HEAD --
 	then
 		if ! git commit --no-verify -C "$cmt"
@@ -81,7 +82,7 @@ continue_merge () {
 		then
 			printf "Committed: %0${prec}d " $msgnum
 		fi
-		echo "$cmt $(git rev-parse HEAD^0)" >> "$dotest/rewritten"
+		echo "$cmt $(git rev-parse HEAD^0)" >> "$merge_dir/rewritten"
 	else
 		if test -z "$GIT_QUIET"
 		then
@@ -93,22 +94,22 @@ continue_merge () {
 
 	prev_head=`git rev-parse HEAD^0`
 	# save the resulting commit so we can read-tree on it later
-	echo "$prev_head" > "$dotest/prev_head"
+	echo "$prev_head" > "$merge_dir/prev_head"
 
 	# onto the next patch:
 	msgnum=$(($msgnum + 1))
-	echo "$msgnum" >"$dotest/msgnum"
+	echo "$msgnum" >"$merge_dir/msgnum"
 }
 
 call_merge () {
-	cmt="$(cat "$dotest/cmt.$1")"
-	echo "$cmt" > "$dotest/current"
+	cmt="$(cat "$merge_dir/cmt.$1")"
+	echo "$cmt" > "$merge_dir/current"
 	hd=$(git rev-parse --verify HEAD)
 	cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
-	msgnum=$(cat "$dotest/msgnum")
-	end=$(cat "$dotest/end")
+	msgnum=$(cat "$merge_dir/msgnum")
+	end=$(cat "$merge_dir/end")
 	eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
-	eval GITHEAD_$hd='$(cat "$dotest/onto_name")'
+	eval GITHEAD_$hd='$(cat "$merge_dir/onto_name")'
 	export GITHEAD_$cmt GITHEAD_$hd
 	if test -n "$GIT_QUIET"
 	then
@@ -138,9 +139,9 @@ call_merge () {
 
 move_to_original_branch () {
 	test -z "$head_name" &&
-		head_name="$(cat "$dotest"/head-name)" &&
-		onto="$(cat "$dotest"/onto)" &&
-		orig_head="$(cat "$dotest"/orig-head)"
+		head_name="$(cat "$merge_dir"/head-name)" &&
+		onto="$(cat "$merge_dir"/onto)" &&
+		orig_head="$(cat "$merge_dir"/orig-head)"
 	case "$head_name" in
 	refs/*)
 		message="rebase finished: $head_name onto $onto"
@@ -154,12 +155,12 @@ move_to_original_branch () {
 
 finish_rb_merge () {
 	move_to_original_branch
-	git notes copy --for-rewrite=rebase < "$dotest"/rewritten
+	git notes copy --for-rewrite=rebase < "$merge_dir"/rewritten
 	if test -x "$GIT_DIR"/hooks/post-rewrite &&
-		test -s "$dotest"/rewritten; then
-		"$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
+		test -s "$merge_dir"/rewritten; then
+		"$GIT_DIR"/hooks/post-rewrite rebase < "$merge_dir"/rewritten
 	fi
-	rm -r "$dotest"
+	rm -r "$merge_dir"
 	say All done.
 }
 
@@ -183,7 +184,7 @@ is_interactive () {
 		export GIT_EDITOR
 	fi
 
-	test -n "$interactive_rebase" || test -f "$dotest"/interactive
+	test -n "$interactive_rebase" || test -f "$merge_dir"/interactive
 }
 
 run_pre_rebase_hook () {
@@ -195,7 +196,7 @@ run_pre_rebase_hook () {
 	fi
 }
 
-test -f "$GIT_DIR"/rebase-apply/applying &&
+test -f "$apply_dir"/applying &&
 	die 'It looks like git-am is in progress. Cannot rebase.'
 
 is_interactive "$@" && exec git-rebase--interactive "$@"
@@ -210,7 +211,7 @@ do
 		OK_TO_SKIP_PRE_REBASE=
 		;;
 	--continue)
-		test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply ||
+		test -d "$merge_dir" -o -d "$apply_dir" ||
 			die "No rebase in progress?"
 
 		git update-index --ignore-submodules --refresh &&
@@ -219,13 +220,13 @@ do
 			echo "mark them as resolved using git add"
 			exit 1
 		}
-		if test -d "$dotest"
+		if test -d "$merge_dir"
 		then
-			prev_head=$(cat "$dotest/prev_head")
-			end=$(cat "$dotest/end")
-			msgnum=$(cat "$dotest/msgnum")
-			onto=$(cat "$dotest/onto")
-			GIT_QUIET=$(cat "$dotest/quiet")
+			prev_head=$(cat "$merge_dir/prev_head")
+			end=$(cat "$merge_dir/end")
+			msgnum=$(cat "$merge_dir/msgnum")
+			onto=$(cat "$merge_dir/onto")
+			GIT_QUIET=$(cat "$merge_dir/quiet")
 			continue_merge
 			while test "$msgnum" -le "$end"
 			do
@@ -235,28 +236,28 @@ do
 			finish_rb_merge
 			exit
 		fi
-		head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) &&
-		onto=$(cat "$GIT_DIR"/rebase-apply/onto) &&
-		orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) &&
-		GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet)
+		head_name=$(cat "$apply_dir"/head-name) &&
+		onto=$(cat "$apply_dir"/onto) &&
+		orig_head=$(cat "$apply_dir"/orig-head) &&
+		GIT_QUIET=$(cat "$apply_dir"/quiet)
 		git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
 		move_to_original_branch
 		exit
 		;;
 	--skip)
-		test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply ||
+		test -d "$merge_dir" -o -d "$apply_dir" ||
 			die "No rebase in progress?"
 
 		git reset --hard HEAD || exit $?
-		if test -d "$dotest"
+		if test -d "$merge_dir"
 		then
 			git rerere clear
-			prev_head=$(cat "$dotest/prev_head")
-			end=$(cat "$dotest/end")
-			msgnum=$(cat "$dotest/msgnum")
+			prev_head=$(cat "$merge_dir/prev_head")
+			end=$(cat "$merge_dir/end")
+			msgnum=$(cat "$merge_dir/msgnum")
 			msgnum=$(($msgnum + 1))
-			onto=$(cat "$dotest/onto")
-			GIT_QUIET=$(cat "$dotest/quiet")
+			onto=$(cat "$merge_dir/onto")
+			GIT_QUIET=$(cat "$merge_dir/quiet")
 			while test "$msgnum" -le "$end"
 			do
 				call_merge "$msgnum"
@@ -265,31 +266,31 @@ do
 			finish_rb_merge
 			exit
 		fi
-		head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) &&
-		onto=$(cat "$GIT_DIR"/rebase-apply/onto) &&
-		orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) &&
-		GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet)
+		head_name=$(cat "$apply_dir"/head-name) &&
+		onto=$(cat "$apply_dir"/onto) &&
+		orig_head=$(cat "$apply_dir"/orig-head) &&
+		GIT_QUIET=$(cat "$apply_dir"/quiet)
 		git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
 		move_to_original_branch
 		exit
 		;;
 	--abort)
-		test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply ||
+		test -d "$merge_dir" -o -d "$apply_dir" ||
 			die "No rebase in progress?"
 
 		git rerere clear
 
-		test -d "$dotest" || dotest="$GIT_DIR"/rebase-apply
+		test -d "$merge_dir" || merge_dir="$apply_dir"
 
-		head_name="$(cat "$dotest"/head-name)" &&
+		head_name="$(cat "$merge_dir"/head-name)" &&
 		case "$head_name" in
 		refs/*)
 			git symbolic-ref HEAD $head_name ||
 			die "Could not move back to $head_name"
 			;;
 		esac
-		git reset --hard $(cat "$dotest/orig-head")
-		rm -r "$dotest"
+		git reset --hard $(cat "$merge_dir/orig-head")
+		rm -r "$merge_dir"
 		exit
 		;;
 	--onto)
@@ -388,31 +389,31 @@ test $# -gt 2 && usage
 
 if test $# -eq 0 && test -z "$rebase_root"
 then
-	test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || usage
-	test -d "$dotest" -o -f "$GIT_DIR"/rebase-apply/rebasing &&
+	test -d "$merge_dir" -o -d "$apply_dir" || usage
+	test -d "$merge_dir" -o -f "$apply_dir"/rebasing &&
 		die 'A rebase is in progress, try --continue, --skip or --abort.'
 fi
 
-# Make sure we do not have $GIT_DIR/rebase-apply
+# Make sure we do not have $apply_dir or $merge_dir
 if test -z "$do_merge"
 then
-	if mkdir "$GIT_DIR"/rebase-apply 2>/dev/null
+	if mkdir "$apply_dir" 2>/dev/null
 	then
-		rmdir "$GIT_DIR"/rebase-apply
+		rmdir "$apply_dir"
 	else
 		echo >&2 '
 It seems that I cannot create a rebase-apply directory, and
 I wonder if you are in the middle of patch application or another
 rebase.  If that is not the case, please
-	rm -fr '"$GIT_DIR"'/rebase-apply
+	rm -fr '"$apply_dir"'
 and run me again.  I am stopping in case you still have something
 valuable there.'
 		exit 1
 	fi
 else
-	if test -d "$dotest"
+	if test -d "$merge_dir"
 	then
-		die "previous rebase directory $dotest still exists." \
+		die "previous rebase directory $merge_dir still exists." \
 			'Try git rebase (--continue | --abort | --skip)'
 	fi
 fi
@@ -560,35 +561,35 @@ then
 	git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
 	move_to_original_branch
 	ret=$?
-	test 0 != $ret -a -d "$GIT_DIR"/rebase-apply &&
-		echo $head_name > "$GIT_DIR"/rebase-apply/head-name &&
-		echo $onto > "$GIT_DIR"/rebase-apply/onto &&
-		echo $orig_head > "$GIT_DIR"/rebase-apply/orig-head &&
-		echo "$GIT_QUIET" > "$GIT_DIR"/rebase-apply/quiet
+	test 0 != $ret -a -d "$apply_dir" &&
+		echo $head_name > "$apply_dir/head-name" &&
+		echo $onto > "$apply_dir/onto" &&
+		echo $orig_head > "$apply_dir/orig-head" &&
+		echo "$GIT_QUIET" > "$apply_dir/quiet"
 	exit $ret
 fi
 
 # start doing a rebase with git-merge
 # this is rename-aware if the recursive (default) strategy is used
 
-mkdir -p "$dotest"
-echo "$onto" > "$dotest/onto"
-echo "$onto_name" > "$dotest/onto_name"
+mkdir -p "$merge_dir"
+echo "$onto" > "$merge_dir/onto"
+echo "$onto_name" > "$merge_dir/onto_name"
 prev_head=$orig_head
-echo "$prev_head" > "$dotest/prev_head"
-echo "$orig_head" > "$dotest/orig-head"
-echo "$head_name" > "$dotest/head-name"
-echo "$GIT_QUIET" > "$dotest/quiet"
+echo "$prev_head" > "$merge_dir/prev_head"
+echo "$orig_head" > "$merge_dir/orig-head"
+echo "$head_name" > "$merge_dir/head-name"
+echo "$GIT_QUIET" > "$merge_dir/quiet"
 
 msgnum=0
 for cmt in `git rev-list --reverse --no-merges "$revisions"`
 do
 	msgnum=$(($msgnum + 1))
-	echo "$cmt" > "$dotest/cmt.$msgnum"
+	echo "$cmt" > "$merge_dir/cmt.$msgnum"
 done
 
-echo 1 >"$dotest/msgnum"
-echo $msgnum >"$dotest/end"
+echo 1 >"$merge_dir/msgnum"
+echo $msgnum >"$merge_dir/end"
 
 end=$msgnum
 msgnum=1
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 02/31] rebase: refactor reading of state
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 01/31] rebase: clearer names for directory variables Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28 23:08   ` Junio C Hamano
  2010-12-28  9:30 ` [PATCH 03/31] rebase: read state outside loop Martin von Zweigbergk
                   ` (30 subsequent siblings)
  32 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

The code reading the state saved in $merge_dir or $rebase_dir is
currently spread out in many places, making it harder to read and to
introduce additional state. Extract this code into one method that reads
the state.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase.sh |   53 +++++++++++++++++++++++------------------------------
 1 files changed, 23 insertions(+), 30 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index 79f8008..bf144dc 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -57,6 +57,22 @@ rebase_root=
 force_rebase=
 allow_rerere_autoupdate=
 
+read_state () {
+	if test -d "$merge_dir"
+	then
+		state_dir="$merge_dir"
+		prev_head=$(cat "$merge_dir"/prev_head) &&
+		end=$(cat "$merge_dir"/end) &&
+		msgnum=$(cat "$merge_dir"/msgnum)
+	else
+		state_dir="$apply_dir"
+	fi &&
+	head_name=$(cat "$state_dir"/head-name) &&
+	onto=$(cat "$state_dir"/onto) &&
+	orig_head=$(cat "$state_dir"/orig-head) &&
+	GIT_QUIET=$(cat "$state_dir"/quiet)
+}
+
 continue_merge () {
 	test -n "$prev_head" || die "prev_head must be defined"
 	test -d "$merge_dir" || die "$merge_dir directory does not exist"
@@ -138,10 +154,6 @@ call_merge () {
 }
 
 move_to_original_branch () {
-	test -z "$head_name" &&
-		head_name="$(cat "$merge_dir"/head-name)" &&
-		onto="$(cat "$merge_dir"/onto)" &&
-		orig_head="$(cat "$merge_dir"/orig-head)"
 	case "$head_name" in
 	refs/*)
 		message="rebase finished: $head_name onto $onto"
@@ -220,13 +232,9 @@ do
 			echo "mark them as resolved using git add"
 			exit 1
 		}
+		read_state
 		if test -d "$merge_dir"
 		then
-			prev_head=$(cat "$merge_dir/prev_head")
-			end=$(cat "$merge_dir/end")
-			msgnum=$(cat "$merge_dir/msgnum")
-			onto=$(cat "$merge_dir/onto")
-			GIT_QUIET=$(cat "$merge_dir/quiet")
 			continue_merge
 			while test "$msgnum" -le "$end"
 			do
@@ -236,10 +244,6 @@ do
 			finish_rb_merge
 			exit
 		fi
-		head_name=$(cat "$apply_dir"/head-name) &&
-		onto=$(cat "$apply_dir"/onto) &&
-		orig_head=$(cat "$apply_dir"/orig-head) &&
-		GIT_QUIET=$(cat "$apply_dir"/quiet)
 		git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
 		move_to_original_branch
 		exit
@@ -249,15 +253,11 @@ do
 			die "No rebase in progress?"
 
 		git reset --hard HEAD || exit $?
+		read_state
 		if test -d "$merge_dir"
 		then
 			git rerere clear
-			prev_head=$(cat "$merge_dir/prev_head")
-			end=$(cat "$merge_dir/end")
-			msgnum=$(cat "$merge_dir/msgnum")
 			msgnum=$(($msgnum + 1))
-			onto=$(cat "$merge_dir/onto")
-			GIT_QUIET=$(cat "$merge_dir/quiet")
 			while test "$msgnum" -le "$end"
 			do
 				call_merge "$msgnum"
@@ -266,10 +266,6 @@ do
 			finish_rb_merge
 			exit
 		fi
-		head_name=$(cat "$apply_dir"/head-name) &&
-		onto=$(cat "$apply_dir"/onto) &&
-		orig_head=$(cat "$apply_dir"/orig-head) &&
-		GIT_QUIET=$(cat "$apply_dir"/quiet)
 		git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
 		move_to_original_branch
 		exit
@@ -279,18 +275,15 @@ do
 			die "No rebase in progress?"
 
 		git rerere clear
-
-		test -d "$merge_dir" || merge_dir="$apply_dir"
-
-		head_name="$(cat "$merge_dir"/head-name)" &&
+		read_state
 		case "$head_name" in
 		refs/*)
 			git symbolic-ref HEAD $head_name ||
 			die "Could not move back to $head_name"
 			;;
 		esac
-		git reset --hard $(cat "$merge_dir/orig-head")
-		rm -r "$merge_dir"
+		git reset --hard $orig_head
+		rm -r "$state_dir"
 		exit
 		;;
 	--onto)
@@ -573,12 +566,12 @@ fi
 # this is rename-aware if the recursive (default) strategy is used
 
 mkdir -p "$merge_dir"
-echo "$onto" > "$merge_dir/onto"
 echo "$onto_name" > "$merge_dir/onto_name"
 prev_head=$orig_head
 echo "$prev_head" > "$merge_dir/prev_head"
-echo "$orig_head" > "$merge_dir/orig-head"
 echo "$head_name" > "$merge_dir/head-name"
+echo "$onto" > "$merge_dir/onto"
+echo "$orig_head" > "$merge_dir/orig-head"
 echo "$GIT_QUIET" > "$merge_dir/quiet"
 
 msgnum=0
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 03/31] rebase: read state outside loop
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 01/31] rebase: clearer names for directory variables Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 02/31] rebase: refactor reading of state Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 04/31] rebase: remove unused rebase state 'prev_head' Martin von Zweigbergk
                   ` (29 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

The 'onto_name' state used in 'git rebase --merge' is currently read
once for each commit that need to be applied. It doesn't change
between each iteration, however, so it should be moved out of the
loop. This also makes the code more readable. Also remove the unused
variable 'end'.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase.sh |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index bf144dc..9be831e 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -62,6 +62,7 @@ read_state () {
 	then
 		state_dir="$merge_dir"
 		prev_head=$(cat "$merge_dir"/prev_head) &&
+		onto_name=$(cat "$merge_dir"/onto_name) &&
 		end=$(cat "$merge_dir"/end) &&
 		msgnum=$(cat "$merge_dir"/msgnum)
 	else
@@ -123,9 +124,8 @@ call_merge () {
 	hd=$(git rev-parse --verify HEAD)
 	cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
 	msgnum=$(cat "$merge_dir/msgnum")
-	end=$(cat "$merge_dir/end")
 	eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
-	eval GITHEAD_$hd='$(cat "$merge_dir/onto_name")'
+	eval GITHEAD_$hd='$onto_name'
 	export GITHEAD_$cmt GITHEAD_$hd
 	if test -n "$GIT_QUIET"
 	then
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 04/31] rebase: remove unused rebase state 'prev_head'
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (2 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 03/31] rebase: read state outside loop Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 05/31] rebase: improve detection of rebase in progress Martin von Zweigbergk
                   ` (28 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

The state stored in $GIT_DIR/rebase-merge/prev_head was introduced in
58634db (rebase: Allow merge strategies to be used when rebasing,
2006-06-21), but it was never used and should therefore be removed.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase.sh |    8 --------
 1 files changed, 0 insertions(+), 8 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index 9be831e..af9bd14 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -61,7 +61,6 @@ read_state () {
 	if test -d "$merge_dir"
 	then
 		state_dir="$merge_dir"
-		prev_head=$(cat "$merge_dir"/prev_head) &&
 		onto_name=$(cat "$merge_dir"/onto_name) &&
 		end=$(cat "$merge_dir"/end) &&
 		msgnum=$(cat "$merge_dir"/msgnum)
@@ -75,7 +74,6 @@ read_state () {
 }
 
 continue_merge () {
-	test -n "$prev_head" || die "prev_head must be defined"
 	test -d "$merge_dir" || die "$merge_dir directory does not exist"
 
 	unmerged=$(git ls-files -u)
@@ -109,10 +107,6 @@ continue_merge () {
 	test -z "$GIT_QUIET" &&
 	GIT_PAGER='' git log --format=%s -1 "$cmt"
 
-	prev_head=`git rev-parse HEAD^0`
-	# save the resulting commit so we can read-tree on it later
-	echo "$prev_head" > "$merge_dir/prev_head"
-
 	# onto the next patch:
 	msgnum=$(($msgnum + 1))
 	echo "$msgnum" >"$merge_dir/msgnum"
@@ -567,8 +561,6 @@ fi
 
 mkdir -p "$merge_dir"
 echo "$onto_name" > "$merge_dir/onto_name"
-prev_head=$orig_head
-echo "$prev_head" > "$merge_dir/prev_head"
 echo "$head_name" > "$merge_dir/head-name"
 echo "$onto" > "$merge_dir/onto"
 echo "$orig_head" > "$merge_dir/orig-head"
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 05/31] rebase: improve detection of rebase in progress
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (3 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 04/31] rebase: remove unused rebase state 'prev_head' Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28 23:08   ` Junio C Hamano
  2010-12-28  9:30 ` [PATCH 06/31] rebase: act on command line outside parsing loop Martin von Zweigbergk
                   ` (27 subsequent siblings)
  32 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Detect early on if a rebase is in progress and what type of rebase it
is (interactive, merge-based or am-based). This prepares for further
refactoring where am-based rebase will be dispatched to
git-rebase--am.sh and merge-based rebase will be dispatched to
git-rebase--merge.sh.

The idea is to use the same variables whether the type of rebase was
detected from rebase-apply/ or rebase-merge/ directories or from the
command line options. This will make the code more readable and will
later also make it easier to dispatch to the type-specific scripts.

Also show a consistent error message independent of the type of rebase
that was in progress and remove the obsolete wording about being in
the middle of a 'patch application', since that (an existing
"$GIT_DIR"/rebase-apply/applying) aborts 'git rebase' at an earlier
stage.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

Currently, the existence of rebase-merge/ is tested with 'test -d',
while the existence of rebase-apply/ is tested by creating the
directory and then deleting it again. Any good reason for this?

 git-rebase.sh |   80 +++++++++++++++++++++++++++++---------------------------
 1 files changed, 41 insertions(+), 39 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index af9bd14..718cb26 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -56,16 +56,19 @@ git_am_opt=
 rebase_root=
 force_rebase=
 allow_rerere_autoupdate=
+# Non-empty if a rebase was in progress when 'git rebase' was invoked
+in_progress=
+# One of {am, merge, interactive}
+type=
+# One of {"$GIT_DIR"/rebase-apply, "$GIT_DIR"/rebase-merge}
+state_dir=
 
 read_state () {
-	if test -d "$merge_dir"
+	if test "$type" = merge
 	then
-		state_dir="$merge_dir"
-		onto_name=$(cat "$merge_dir"/onto_name) &&
-		end=$(cat "$merge_dir"/end) &&
-		msgnum=$(cat "$merge_dir"/msgnum)
-	else
-		state_dir="$apply_dir"
+		onto_name=$(cat "$state_dir"/onto_name) &&
+		end=$(cat "$state_dir"/end) &&
+		msgnum=$(cat "$state_dir"/msgnum)
 	fi &&
 	head_name=$(cat "$state_dir"/head-name) &&
 	onto=$(cat "$state_dir"/onto) &&
@@ -207,6 +210,23 @@ test -f "$apply_dir"/applying &&
 
 is_interactive "$@" && exec git-rebase--interactive "$@"
 
+if test -d "$apply_dir"
+then
+	type=am
+	state_dir="$apply_dir"
+elif test -d "$merge_dir"
+then
+	if test -f "$merge_dir"/interactive
+	then
+		type=interactive
+		interactive_rebase=explicit
+	else
+		type=merge
+	fi
+	state_dir="$merge_dir"
+fi
+test -n "$type" && in_progress=t
+
 while test $# != 0
 do
 	case "$1" in
@@ -217,8 +237,7 @@ do
 		OK_TO_SKIP_PRE_REBASE=
 		;;
 	--continue)
-		test -d "$merge_dir" -o -d "$apply_dir" ||
-			die "No rebase in progress?"
+		test -z "$in_progress" && die "No rebase in progress?"
 
 		git update-index --ignore-submodules --refresh &&
 		git diff-files --quiet --ignore-submodules || {
@@ -243,8 +262,7 @@ do
 		exit
 		;;
 	--skip)
-		test -d "$merge_dir" -o -d "$apply_dir" ||
-			die "No rebase in progress?"
+		test -z "$in_progress" && die "No rebase in progress?"
 
 		git reset --hard HEAD || exit $?
 		read_state
@@ -265,8 +283,7 @@ do
 		exit
 		;;
 	--abort)
-		test -d "$merge_dir" -o -d "$apply_dir" ||
-			die "No rebase in progress?"
+		test -z "$in_progress" && die "No rebase in progress?"
 
 		git rerere clear
 		read_state
@@ -374,37 +391,22 @@ do
 done
 test $# -gt 2 && usage
 
-if test $# -eq 0 && test -z "$rebase_root"
+# Make sure no rebase is in progress
+if test -n "$in_progress"
 then
-	test -d "$merge_dir" -o -d "$apply_dir" || usage
-	test -d "$merge_dir" -o -f "$apply_dir"/rebasing &&
-		die 'A rebase is in progress, try --continue, --skip or --abort.'
-fi
-
-# Make sure we do not have $apply_dir or $merge_dir
-if test -z "$do_merge"
-then
-	if mkdir "$apply_dir" 2>/dev/null
-	then
-		rmdir "$apply_dir"
-	else
-		echo >&2 '
-It seems that I cannot create a rebase-apply directory, and
-I wonder if you are in the middle of patch application or another
-rebase.  If that is not the case, please
-	rm -fr '"$apply_dir"'
+	die '
+It seems that there is already a '"${state_dir##*/}"' directory, and
+I wonder if you are in the middle of another rebase.  If that is the
+case, please try
+	git rebase (--continue | --abort | --skip)
+If that is not the case, please
+	rm -fr '"$state_dir"'
 and run me again.  I am stopping in case you still have something
 valuable there.'
-		exit 1
-	fi
-else
-	if test -d "$merge_dir"
-	then
-		die "previous rebase directory $merge_dir still exists." \
-			'Try git rebase (--continue | --abort | --skip)'
-	fi
 fi
 
+test $# -eq 0 && test -z "$rebase_root" && usage
+
 require_clean_work_tree "rebase" "Please commit or stash them."
 
 if test -z "$rebase_root"
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 06/31] rebase: act on command line outside parsing loop
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (4 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 05/31] rebase: improve detection of rebase in progress Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 07/31] rebase: stricter check of standalone sub command Martin von Zweigbergk
                   ` (26 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

To later be able to use the command line processing in git-rebase.sh
for both interactive and non-interactive rebases, move anything that
is specific to non-interactive rebase outside of the parsing
loop. Keep only parsing and validation of command line options in the
loop.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

May want to view this patch with --ignore-all-space.

 git-rebase--interactive.sh |  300 ++++++++++++++++++++++----------------------
 git-rebase.sh              |  126 ++++++++++---------
 2 files changed, 217 insertions(+), 209 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index a5ffd9a..8cbdd3f 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -866,152 +866,158 @@ first and then run 'git rebase --continue' again."
 		;;
 	--)
 		shift
-		test -z "$REBASE_ROOT" -a $# -ge 1 -a $# -le 2 ||
-		test ! -z "$REBASE_ROOT" -a $# -le 1 || usage
-		test -d "$DOTEST" &&
-			die "Interactive rebase already started"
-
-		git var GIT_COMMITTER_IDENT >/dev/null ||
-			die "You need to set your committer info first"
-
-		if test -z "$REBASE_ROOT"
-		then
-			UPSTREAM_ARG="$1"
-			UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base"
-			test -z "$ONTO" && ONTO=$UPSTREAM
-			shift
-		else
-			UPSTREAM=
-			UPSTREAM_ARG=--root
-			test -z "$ONTO" &&
-				die "You must specify --onto when using --root"
-		fi
-		run_pre_rebase_hook "$UPSTREAM_ARG" "$@"
-
-		comment_for_reflog start
-
-		require_clean_work_tree "rebase" "Please commit or stash them."
-
-		if test ! -z "$1"
-		then
-			output git checkout "$1" ||
-				die "Could not checkout $1"
-		fi
+		break
+		;;
+	esac
+	shift
+done
 
-		HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?"
-		mkdir "$DOTEST" || die "Could not create temporary $DOTEST"
+test -z "$REBASE_ROOT" -a $# -ge 1 -a $# -le 2 ||
+test ! -z "$REBASE_ROOT" -a $# -le 1 || usage
+test -d "$DOTEST" &&
+	die "Interactive rebase already started"
 
-		: > "$DOTEST"/interactive || die "Could not mark as interactive"
-		git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
-			echo "detached HEAD" > "$DOTEST"/head-name
+git var GIT_COMMITTER_IDENT >/dev/null ||
+	die "You need to set your committer info first"
 
-		echo $HEAD > "$DOTEST"/head
-		case "$REBASE_ROOT" in
-		'')
-			rm -f "$DOTEST"/rebase-root ;;
-		*)
-			: >"$DOTEST"/rebase-root ;;
-		esac
-		echo $ONTO > "$DOTEST"/onto
-		test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy
-		test t = "$VERBOSE" && : > "$DOTEST"/verbose
-		if test t = "$PRESERVE_MERGES"
-		then
-			if test -z "$REBASE_ROOT"
-			then
-				mkdir "$REWRITTEN" &&
-				for c in $(git merge-base --all $HEAD $UPSTREAM)
-				do
-					echo $ONTO > "$REWRITTEN"/$c ||
-						die "Could not init rewritten commits"
-				done
-			else
-				mkdir "$REWRITTEN" &&
-				echo $ONTO > "$REWRITTEN"/root ||
-					die "Could not init rewritten commits"
-			fi
-			# No cherry-pick because our first pass is to determine
-			# parents to rewrite and skipping dropped commits would
-			# prematurely end our probe
-			MERGES_OPTION=
-			first_after_upstream="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)"
-		else
-			MERGES_OPTION="--no-merges --cherry-pick"
-		fi
-
-		SHORTHEAD=$(git rev-parse --short $HEAD)
-		SHORTONTO=$(git rev-parse --short $ONTO)
-		if test -z "$REBASE_ROOT"
-			# this is now equivalent to ! -z "$UPSTREAM"
-		then
-			SHORTUPSTREAM=$(git rev-parse --short $UPSTREAM)
-			REVISIONS=$UPSTREAM...$HEAD
-			SHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD
-		else
-			REVISIONS=$ONTO...$HEAD
-			SHORTREVISIONS=$SHORTHEAD
-		fi
-		git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
-			--abbrev=7 --reverse --left-right --topo-order \
-			$REVISIONS | \
-			sed -n "s/^>//p" |
-		while read -r shortsha1 rest
+if test -z "$REBASE_ROOT"
+then
+	UPSTREAM_ARG="$1"
+	UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base"
+	test -z "$ONTO" && ONTO=$UPSTREAM
+	shift
+else
+	UPSTREAM=
+	UPSTREAM_ARG=--root
+	test -z "$ONTO" &&
+	die "You must specify --onto when using --root"
+fi
+run_pre_rebase_hook "$UPSTREAM_ARG" "$@"
+
+comment_for_reflog start
+
+require_clean_work_tree "rebase" "Please commit or stash them."
+
+if test ! -z "$1"
+then
+	output git checkout "$1" ||
+		die "Could not checkout $1"
+fi
+
+HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?"
+mkdir "$DOTEST" || die "Could not create temporary $DOTEST"
+
+: > "$DOTEST"/interactive || die "Could not mark as interactive"
+git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
+	echo "detached HEAD" > "$DOTEST"/head-name
+
+echo $HEAD > "$DOTEST"/head
+case "$REBASE_ROOT" in
+'')
+	rm -f "$DOTEST"/rebase-root ;;
+*)
+	: >"$DOTEST"/rebase-root ;;
+esac
+echo $ONTO > "$DOTEST"/onto
+test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy
+test t = "$VERBOSE" && : > "$DOTEST"/verbose
+if test t = "$PRESERVE_MERGES"
+then
+	if test -z "$REBASE_ROOT"
+	then
+		mkdir "$REWRITTEN" &&
+		for c in $(git merge-base --all $HEAD $UPSTREAM)
 		do
-			if test t != "$PRESERVE_MERGES"
-			then
-				printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
-			else
-				sha1=$(git rev-parse $shortsha1)
-				if test -z "$REBASE_ROOT"
-				then
-					preserve=t
-					for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
-					do
-						if test -f "$REWRITTEN"/$p -a \( $p != $ONTO -o $sha1 = $first_after_upstream \)
-						then
-							preserve=f
-						fi
-					done
-				else
-					preserve=f
-				fi
-				if test f = "$preserve"
-				then
-					touch "$REWRITTEN"/$sha1
-					printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
-				fi
-			fi
+			echo $ONTO > "$REWRITTEN"/$c ||
+				die "Could not init rewritten commits"
 		done
-
-		# Watch for commits that been dropped by --cherry-pick
-		if test t = "$PRESERVE_MERGES"
+	else
+		mkdir "$REWRITTEN" &&
+		echo $ONTO > "$REWRITTEN"/root ||
+			die "Could not init rewritten commits"
+	fi
+	# No cherry-pick because our first pass is to determine
+	# parents to rewrite and skipping dropped commits would
+	# prematurely end our probe
+	MERGES_OPTION=
+	first_after_upstream="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)"
+else
+	MERGES_OPTION="--no-merges --cherry-pick"
+fi
+
+SHORTHEAD=$(git rev-parse --short $HEAD)
+SHORTONTO=$(git rev-parse --short $ONTO)
+if test -z "$REBASE_ROOT"
+	# this is now equivalent to ! -z "$UPSTREAM"
+then
+	SHORTUPSTREAM=$(git rev-parse --short $UPSTREAM)
+	REVISIONS=$UPSTREAM...$HEAD
+	SHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD
+else
+	REVISIONS=$ONTO...$HEAD
+	SHORTREVISIONS=$SHORTHEAD
+fi
+git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
+	--abbrev=7 --reverse --left-right --topo-order \
+	$REVISIONS | \
+	sed -n "s/^>//p" |
+while read -r shortsha1 rest
+do
+	if test t != "$PRESERVE_MERGES"
+	then
+		printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
+	else
+		sha1=$(git rev-parse $shortsha1)
+		if test -z "$REBASE_ROOT"
 		then
-			mkdir "$DROPPED"
-			# Save all non-cherry-picked changes
-			git rev-list $REVISIONS --left-right --cherry-pick | \
-				sed -n "s/^>//p" > "$DOTEST"/not-cherry-picks
-			# Now all commits and note which ones are missing in
-			# not-cherry-picks and hence being dropped
-			git rev-list $REVISIONS |
-			while read rev
+			preserve=t
+			for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
 			do
-				if test -f "$REWRITTEN"/$rev -a "$(sane_grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
+				if test -f "$REWRITTEN"/$p -a \( $p != $ONTO -o $sha1 = $first_after_upstream \)
 				then
-					# Use -f2 because if rev-list is telling us this commit is
-					# not worthwhile, we don't want to track its multiple heads,
-					# just the history of its first-parent for others that will
-					# be rebasing on top of it
-					git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$DROPPED"/$rev
-					short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
-					sane_grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
-					rm "$REWRITTEN"/$rev
+					preserve=f
 				fi
 			done
+		else
+			preserve=f
+		fi
+		if test f = "$preserve"
+		then
+			touch "$REWRITTEN"/$sha1
+			printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
 		fi
+	fi
+done
 
-		test -s "$TODO" || echo noop >> "$TODO"
-		test -n "$AUTOSQUASH" && rearrange_squash "$TODO"
-		cat >> "$TODO" << EOF
+# Watch for commits that been dropped by --cherry-pick
+if test t = "$PRESERVE_MERGES"
+then
+	mkdir "$DROPPED"
+	# Save all non-cherry-picked changes
+	git rev-list $REVISIONS --left-right --cherry-pick | \
+		sed -n "s/^>//p" > "$DOTEST"/not-cherry-picks
+	# Now all commits and note which ones are missing in
+	# not-cherry-picks and hence being dropped
+	git rev-list $REVISIONS |
+	while read rev
+	do
+		if test -f "$REWRITTEN"/$rev -a "$(sane_grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
+		then
+			# Use -f2 because if rev-list is telling us this commit is
+			# not worthwhile, we don't want to track its multiple heads,
+			# just the history of its first-parent for others that will
+			# be rebasing on top of it
+			git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$DROPPED"/$rev
+			short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
+			sane_grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
+			rm "$REWRITTEN"/$rev
+		fi
+	done
+fi
+
+test -s "$TODO" || echo noop >> "$TODO"
+test -n "$AUTOSQUASH" && rearrange_squash "$TODO"
+cat >> "$TODO" << EOF
 
 # Rebase $SHORTREVISIONS onto $SHORTONTO
 #
@@ -1028,22 +1034,18 @@ first and then run 'git rebase --continue' again."
 #
 EOF
 
-		has_action "$TODO" ||
-			die_abort "Nothing to do"
+has_action "$TODO" ||
+	die_abort "Nothing to do"
 
-		cp "$TODO" "$TODO".backup
-		git_editor "$TODO" ||
-			die_abort "Could not execute editor"
+cp "$TODO" "$TODO".backup
+git_editor "$TODO" ||
+	die_abort "Could not execute editor"
 
-		has_action "$TODO" ||
-			die_abort "Nothing to do"
+has_action "$TODO" ||
+	die_abort "Nothing to do"
 
-		test -d "$REWRITTEN" || test -n "$NEVER_FF" || skip_unnecessary_picks
+test -d "$REWRITTEN" || test -n "$NEVER_FF" || skip_unnecessary_picks
 
-		output git checkout $ONTO || die_abort "could not detach HEAD"
-		git update-ref ORIG_HEAD $HEAD
-		do_rest
-		;;
-	esac
-	shift
-done
+output git checkout $ONTO || die_abort "could not detach HEAD"
+git update-ref ORIG_HEAD $HEAD
+do_rest
diff --git a/git-rebase.sh b/git-rebase.sh
index 718cb26..29f1214 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -62,6 +62,8 @@ in_progress=
 type=
 # One of {"$GIT_DIR"/rebase-apply, "$GIT_DIR"/rebase-merge}
 state_dir=
+# One of {'', continue, skip, abort}, as parsed from command line
+action=
 
 read_state () {
 	if test "$type" = merge
@@ -236,66 +238,10 @@ do
 	--verify)
 		OK_TO_SKIP_PRE_REBASE=
 		;;
-	--continue)
-		test -z "$in_progress" && die "No rebase in progress?"
-
-		git update-index --ignore-submodules --refresh &&
-		git diff-files --quiet --ignore-submodules || {
-			echo "You must edit all merge conflicts and then"
-			echo "mark them as resolved using git add"
-			exit 1
-		}
-		read_state
-		if test -d "$merge_dir"
-		then
-			continue_merge
-			while test "$msgnum" -le "$end"
-			do
-				call_merge "$msgnum"
-				continue_merge
-			done
-			finish_rb_merge
-			exit
-		fi
-		git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
-		move_to_original_branch
-		exit
-		;;
-	--skip)
-		test -z "$in_progress" && die "No rebase in progress?"
-
-		git reset --hard HEAD || exit $?
-		read_state
-		if test -d "$merge_dir"
-		then
-			git rerere clear
-			msgnum=$(($msgnum + 1))
-			while test "$msgnum" -le "$end"
-			do
-				call_merge "$msgnum"
-				continue_merge
-			done
-			finish_rb_merge
-			exit
-		fi
-		git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
-		move_to_original_branch
-		exit
-		;;
-	--abort)
-		test -z "$in_progress" && die "No rebase in progress?"
-
-		git rerere clear
-		read_state
-		case "$head_name" in
-		refs/*)
-			git symbolic-ref HEAD $head_name ||
-			die "Could not move back to $head_name"
-			;;
-		esac
-		git reset --hard $orig_head
-		rm -r "$state_dir"
-		exit
+	--continue|--skip|--abort)
+		action=${1##--}
+		shift
+		break
 		;;
 	--onto)
 		test 2 -le "$#" || usage
@@ -391,6 +337,66 @@ do
 done
 test $# -gt 2 && usage
 
+test -n "$action" && test -z "$in_progress" && die "No rebase in progress?"
+
+case "$action" in
+continue)
+	git update-index --ignore-submodules --refresh &&
+	git diff-files --quiet --ignore-submodules || {
+		echo "You must edit all merge conflicts and then"
+		echo "mark them as resolved using git add"
+		exit 1
+	}
+	read_state
+	if test -d "$merge_dir"
+	then
+		continue_merge
+		while test "$msgnum" -le "$end"
+		do
+			call_merge "$msgnum"
+			continue_merge
+		done
+		finish_rb_merge
+		exit
+	fi
+	git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
+	move_to_original_branch
+	exit
+	;;
+skip)
+	git reset --hard HEAD || exit $?
+	read_state
+	if test -d "$merge_dir"
+	then
+		git rerere clear
+		msgnum=$(($msgnum + 1))
+		while test "$msgnum" -le "$end"
+		do
+			call_merge "$msgnum"
+			continue_merge
+		done
+		finish_rb_merge
+		exit
+	fi
+	git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
+	move_to_original_branch
+	exit
+	;;
+abort)
+	git rerere clear
+	read_state
+	case "$head_name" in
+	refs/*)
+		git symbolic-ref HEAD $head_name ||
+		die "Could not move back to $head_name"
+		;;
+	esac
+	git reset --hard $orig_head
+	rm -r "$state_dir"
+	exit
+	;;
+esac
+
 # Make sure no rebase is in progress
 if test -n "$in_progress"
 then
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 07/31] rebase: stricter check of standalone sub command
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (5 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 06/31] rebase: act on command line outside parsing loop Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 08/31] rebase: align variable names Martin von Zweigbergk
                   ` (25 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

The sub commands '--continue', '--skip' or '--abort' may only be used
standalone according to the documentation. Other options following the
sub command are currently not accepted, but options preceeding them
are. For example, 'git rebase --continue -v' is not accepted, while
'git rebase -v --continue' is. Tighten up the check and allow no other
options when one of these sub commands are used.

Only check that it is standalone for non-interactive rebase for
now. Once the command line processing for interactive rebase has been
replaced by the command line processing in git-rebase.sh, this check
will also apply to interactive rebase.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

Is this too simplistic? Do we forsee that we want to support passing
options when resuming a rebase? Is it better to check for each other
option that it is not passed (i.e. no '-v', no '-s' etc.)?

Might some users be depending on the current behavior, even though it
is undocumented?

 git-rebase.sh              |    4 ++--
 t/t3403-rebase-skip.sh     |    5 +++++
 t/t3407-rebase-abort.sh    |   10 ++++++++++
 t/t3418-rebase-continue.sh |    5 +++++
 4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index 29f1214..1cb0564 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -229,6 +229,7 @@ then
 fi
 test -n "$type" && in_progress=t
 
+total_argc=$#
 while test $# != 0
 do
 	case "$1" in
@@ -239,9 +240,8 @@ do
 		OK_TO_SKIP_PRE_REBASE=
 		;;
 	--continue|--skip|--abort)
+		test $total_argc -eq 1 || usage
 		action=${1##--}
-		shift
-		break
 		;;
 	--onto)
 		test 2 -le "$#" || usage
diff --git a/t/t3403-rebase-skip.sh b/t/t3403-rebase-skip.sh
index 64446e3..826500b 100755
--- a/t/t3403-rebase-skip.sh
+++ b/t/t3403-rebase-skip.sh
@@ -35,6 +35,11 @@ test_expect_success 'rebase with git am -3 (default)' '
 	test_must_fail git rebase master
 '
 
+test_expect_success 'rebase --skip can not be used with other options' '
+	test_must_fail git rebase -v --skip &&
+	test_must_fail git rebase --skip -v
+'
+
 test_expect_success 'rebase --skip with am -3' '
 	git rebase --skip
 	'
diff --git a/t/t3407-rebase-abort.sh b/t/t3407-rebase-abort.sh
index e573dc8..a6a6c40 100755
--- a/t/t3407-rebase-abort.sh
+++ b/t/t3407-rebase-abort.sh
@@ -84,6 +84,16 @@ testrebase() {
 		test_cmp reflog_before reflog_after &&
 		rm reflog_before reflog_after
 	'
+
+	test_expect_success 'rebase --abort can not be used with other options' '
+		cd "$work_dir" &&
+		# Clean up the state from the previous one
+		git reset --hard pre-rebase &&
+		test_must_fail git rebase$type master &&
+		test_must_fail git rebase -v --abort &&
+		test_must_fail git rebase --abort -v &&
+		git rebase --abort
+	'
 }
 
 testrebase "" .git/rebase-apply
diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh
index 3b0d273..1d90191 100755
--- a/t/t3418-rebase-continue.sh
+++ b/t/t3418-rebase-continue.sh
@@ -40,4 +40,9 @@ test_expect_success 'non-interactive rebase --continue works with touched file'
 	git rebase --continue
 '
 
+test_expect_success 'rebase --continue can not be used with other options' '
+	test_must_fail git rebase -v --continue &&
+	test_must_fail git rebase --continue -v
+'
+
 test_done
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 08/31] rebase: align variable names
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (6 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 07/31] rebase: stricter check of standalone sub command Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2011-01-04 19:12   ` Thomas Rast
  2010-12-28  9:30 ` [PATCH 09/31] rebase: align variable content Martin von Zweigbergk
                   ` (24 subsequent siblings)
  32 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Use the same names for variables that git-rebase--interactive.sh will
soon inherit from git-rebase.sh.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |  138 ++++++++++++++++++++++----------------------
 git-rebase.sh              |    8 +-
 2 files changed, 73 insertions(+), 73 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 8cbdd3f..310d80e 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -77,7 +77,7 @@ FIXUP_MSG="$DOTEST"/message-fixup
 
 # $REWRITTEN is the name of a directory containing 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
+# $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.)
@@ -105,15 +105,15 @@ AMEND="$DOTEST"/amend
 REWRITTEN_LIST="$DOTEST"/rewritten-list
 REWRITTEN_PENDING="$DOTEST"/rewritten-pending
 
-PRESERVE_MERGES=
-STRATEGY=
-ONTO=
-VERBOSE=
+preserve_merges=
+strategy=
+onto=
+verbose=
 OK_TO_SKIP_PRE_REBASE=
-REBASE_ROOT=
-AUTOSQUASH=
-test "$(git config --bool rebase.autosquash)" = "true" && AUTOSQUASH=t
-NEVER_FF=
+rebase_root=
+autosquash=
+test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
+force_rebase=
 
 GIT_CHERRY_PICK_HELP="\
 hint: after resolving the conflicts, mark the corrected paths
@@ -125,7 +125,7 @@ warn () {
 }
 
 output () {
-	case "$VERBOSE" in
+	case "$verbose" in
 	'')
 		output=$("$@" 2>&1 )
 		status=$?
@@ -177,7 +177,7 @@ mark_action_done () {
 	then
 		last_count=$count
 		printf "Rebasing (%d/%d)\r" $count $total
-		test -z "$VERBOSE" || echo
+		test -z "$verbose" || echo
 	fi
 }
 
@@ -228,11 +228,11 @@ do_with_author () {
 pick_one () {
 	ff=--ff
 	case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac
-	case "$NEVER_FF" in '') ;; ?*) ff= ;; esac
+	case "$force_rebase" in '') ;; ?*) ff= ;; esac
 	output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
 	test -d "$REWRITTEN" &&
 		pick_one_preserving_merges "$@" && return
-	if test -n "$REBASE_ROOT"
+	if test -n "$rebase_root"
 	then
 		output git cherry-pick "$@"
 		return
@@ -339,7 +339,7 @@ pick_one_preserving_merges () {
 			# No point in merging the first parent, that's HEAD
 			new_parents=${new_parents# $first_parent}
 			if ! do_with_author output \
-				git merge $STRATEGY -m "$msg" $new_parents
+				git merge $strategy -m "$msg" $new_parents
 			then
 				printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
 				die_with_patch $sha1 "Error redoing merge $sha1"
@@ -618,11 +618,11 @@ skip_unnecessary_picks () {
 		# fd=3 means we skip the command
 		case "$fd,$command" in
 		3,pick|3,p)
-			# pick a commit whose parent is current $ONTO -> skip
+			# pick a commit whose parent is current $onto -> skip
 			sha1=${rest%% *}
 			case "$(git rev-parse --verify --quiet "$sha1"^)" in
-			"$ONTO"*)
-				ONTO=$sha1
+			"$onto"*)
+				onto=$sha1
 				;;
 			*)
 				fd=1
@@ -641,7 +641,7 @@ skip_unnecessary_picks () {
 	mv -f "$TODO".new "$TODO" &&
 	case "$(peek_next_command)" in
 	squash|s|fixup|f)
-		record_in_rewritten "$ONTO"
+		record_in_rewritten "$onto"
 		;;
 	esac ||
 	die "Could not skip unnecessary pick commands"
@@ -650,17 +650,17 @@ skip_unnecessary_picks () {
 # check if no other options are set
 is_standalone () {
 	test $# -eq 2 -a "$2" = '--' &&
-	test -z "$ONTO" &&
-	test -z "$PRESERVE_MERGES" &&
-	test -z "$STRATEGY" &&
-	test -z "$VERBOSE"
+	test -z "$onto" &&
+	test -z "$preserve_merges" &&
+	test -z "$strategy" &&
+	test -z "$verbose"
 }
 
 get_saved_options () {
-	test -d "$REWRITTEN" && PRESERVE_MERGES=t
-	test -f "$DOTEST"/strategy && STRATEGY="$(cat "$DOTEST"/strategy)"
-	test -f "$DOTEST"/verbose && VERBOSE=t
-	test -f "$DOTEST"/rebase-root && REBASE_ROOT=t
+	test -d "$REWRITTEN" && preserve_merges=t
+	test -f "$DOTEST"/strategy && strategy="$(cat "$DOTEST"/strategy)"
+	test -f "$DOTEST"/verbose && verbose=t
+	test -f "$DOTEST"/rebase-root && rebase_root=t
 }
 
 # Rearrange the todo list that has both "pick sha1 msg" and
@@ -827,11 +827,11 @@ first and then run 'git rebase --continue' again."
 	-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
 		;;
@@ -839,29 +839,29 @@ first and then run 'git rebase --continue' again."
 		# we use merge anyway
 		;;
 	-v)
-		VERBOSE=t
+		verbose=t
 		;;
 	-p)
-		PRESERVE_MERGES=t
+		preserve_merges=t
 		;;
 	-i)
 		# yeah, we know
 		;;
 	--no-ff)
-		NEVER_FF=t
+		force_rebase=t
 		;;
 	--root)
-		REBASE_ROOT=t
+		rebase_root=t
 		;;
 	--autosquash)
-		AUTOSQUASH=t
+		autosquash=t
 		;;
 	--no-autosquash)
-		AUTOSQUASH=
+		autosquash=
 		;;
 	--onto)
 		shift
-		ONTO=$(parse_onto "$1") ||
+		onto=$(parse_onto "$1") ||
 			die "Does not point to a valid commit: $1"
 		;;
 	--)
@@ -872,27 +872,27 @@ first and then run 'git rebase --continue' again."
 	shift
 done
 
-test -z "$REBASE_ROOT" -a $# -ge 1 -a $# -le 2 ||
-test ! -z "$REBASE_ROOT" -a $# -le 1 || usage
+test -z "$rebase_root" -a $# -ge 1 -a $# -le 2 ||
+test ! -z "$rebase_root" -a $# -le 1 || usage
 test -d "$DOTEST" &&
 	die "Interactive rebase already started"
 
 git var GIT_COMMITTER_IDENT >/dev/null ||
 	die "You need to set your committer info first"
 
-if test -z "$REBASE_ROOT"
+if test -z "$rebase_root"
 then
-	UPSTREAM_ARG="$1"
-	UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base"
-	test -z "$ONTO" && ONTO=$UPSTREAM
+	upstream_arg="$1"
+	upstream=$(git rev-parse --verify "$1") || die "Invalid base"
+	test -z "$onto" && onto=$upstream
 	shift
 else
-	UPSTREAM=
-	UPSTREAM_ARG=--root
-	test -z "$ONTO" &&
-	die "You must specify --onto when using --root"
+	upstream=
+	upstream_arg=--root
+	test -z "$onto" &&
+		die "You must specify --onto when using --root"
 fi
-run_pre_rebase_hook "$UPSTREAM_ARG" "$@"
+run_pre_rebase_hook "$upstream_arg" "$@"
 
 comment_for_reflog start
 
@@ -912,49 +912,49 @@ git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
 	echo "detached HEAD" > "$DOTEST"/head-name
 
 echo $HEAD > "$DOTEST"/head
-case "$REBASE_ROOT" in
+case "$rebase_root" in
 '')
 	rm -f "$DOTEST"/rebase-root ;;
 *)
 	: >"$DOTEST"/rebase-root ;;
 esac
-echo $ONTO > "$DOTEST"/onto
-test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy
-test t = "$VERBOSE" && : > "$DOTEST"/verbose
-if test t = "$PRESERVE_MERGES"
+echo $onto > "$DOTEST"/onto
+test -z "$strategy" || echo "$strategy" > "$DOTEST"/strategy
+test t = "$verbose" && : > "$DOTEST"/verbose
+if test t = "$preserve_merges"
 then
-	if test -z "$REBASE_ROOT"
+	if test -z "$rebase_root"
 	then
 		mkdir "$REWRITTEN" &&
-		for c in $(git merge-base --all $HEAD $UPSTREAM)
+		for c in $(git merge-base --all $HEAD $upstream)
 		do
-			echo $ONTO > "$REWRITTEN"/$c ||
+			echo $onto > "$REWRITTEN"/$c ||
 				die "Could not init rewritten commits"
 		done
 	else
 		mkdir "$REWRITTEN" &&
-		echo $ONTO > "$REWRITTEN"/root ||
+		echo $onto > "$REWRITTEN"/root ||
 			die "Could not init rewritten commits"
 	fi
 	# No cherry-pick because our first pass is to determine
 	# parents to rewrite and skipping dropped commits would
 	# prematurely end our probe
 	MERGES_OPTION=
-	first_after_upstream="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)"
+	first_after_upstream="$(git rev-list --reverse --first-parent $upstream..$HEAD | head -n 1)"
 else
 	MERGES_OPTION="--no-merges --cherry-pick"
 fi
 
 SHORTHEAD=$(git rev-parse --short $HEAD)
-SHORTONTO=$(git rev-parse --short $ONTO)
-if test -z "$REBASE_ROOT"
-	# this is now equivalent to ! -z "$UPSTREAM"
+SHORTONTO=$(git rev-parse --short $onto)
+if test -z "$rebase_root"
+	# this is now equivalent to ! -z "$upstream"
 then
-	SHORTUPSTREAM=$(git rev-parse --short $UPSTREAM)
-	REVISIONS=$UPSTREAM...$HEAD
+	SHORTUPSTREAM=$(git rev-parse --short $upstream)
+	REVISIONS=$upstream...$HEAD
 	SHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD
 else
-	REVISIONS=$ONTO...$HEAD
+	REVISIONS=$onto...$HEAD
 	SHORTREVISIONS=$SHORTHEAD
 fi
 git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
@@ -963,17 +963,17 @@ git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
 	sed -n "s/^>//p" |
 while read -r shortsha1 rest
 do
-	if test t != "$PRESERVE_MERGES"
+	if test t != "$preserve_merges"
 	then
 		printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
 	else
 		sha1=$(git rev-parse $shortsha1)
-		if test -z "$REBASE_ROOT"
+		if test -z "$rebase_root"
 		then
 			preserve=t
 			for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
 			do
-				if test -f "$REWRITTEN"/$p -a \( $p != $ONTO -o $sha1 = $first_after_upstream \)
+				if test -f "$REWRITTEN"/$p -a \( $p != $onto -o $sha1 = $first_after_upstream \)
 				then
 					preserve=f
 				fi
@@ -990,7 +990,7 @@ do
 done
 
 # Watch for commits that been dropped by --cherry-pick
-if test t = "$PRESERVE_MERGES"
+if test t = "$preserve_merges"
 then
 	mkdir "$DROPPED"
 	# Save all non-cherry-picked changes
@@ -1016,7 +1016,7 @@ then
 fi
 
 test -s "$TODO" || echo noop >> "$TODO"
-test -n "$AUTOSQUASH" && rearrange_squash "$TODO"
+test -n "$autosquash" && rearrange_squash "$TODO"
 cat >> "$TODO" << EOF
 
 # Rebase $SHORTREVISIONS onto $SHORTONTO
@@ -1044,8 +1044,8 @@ git_editor "$TODO" ||
 has_action "$TODO" ||
 	die_abort "Nothing to do"
 
-test -d "$REWRITTEN" || test -n "$NEVER_FF" || skip_unnecessary_picks
+test -d "$REWRITTEN" || test -n "$force_rebase" || skip_unnecessary_picks
 
-output git checkout $ONTO || die_abort "could not detach HEAD"
+output git checkout $onto || die_abort "could not detach HEAD"
 git update-ref ORIG_HEAD $HEAD
 do_rest
diff --git a/git-rebase.sh b/git-rebase.sh
index 1cb0564..dc133e3 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -42,7 +42,7 @@ When you have resolved this problem run \"git rebase --continue\".
 If you would prefer to skip this patch, instead run \"git rebase --skip\".
 To restore the original branch and stop rebasing run \"git rebase --abort\".
 "
-unset newbase
+unset onto
 strategy=recursive
 strategy_opts=
 do_merge=
@@ -245,7 +245,7 @@ do
 		;;
 	--onto)
 		test 2 -le "$#" || usage
-		newbase="$2"
+		onto="$2"
 		shift
 		;;
 	-M|-m|--m|--me|--mer|--merg|--merge)
@@ -425,7 +425,7 @@ then
 	unset root_flag
 	upstream_arg="$upstream_name"
 else
-	test -z "$newbase" && die "--root must be used with --onto"
+	test -z "$onto" && die "--root must be used with --onto"
 	unset upstream_name
 	unset upstream
 	root_flag="--root"
@@ -433,7 +433,7 @@ else
 fi
 
 # Make sure the branch to rebase onto is valid.
-onto_name=${newbase-"$upstream_name"}
+onto_name=${onto-"$upstream_name"}
 case "$onto_name" in
 *...*)
 	if	left=${onto_name%...*} right=${onto_name#*...} &&
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 09/31] rebase: align variable content
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (7 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 08/31] rebase: align variable names Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 10/31] rebase: factor out command line option processing Martin von Zweigbergk
                   ` (23 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Make sure to interpret variables with the same name in the same way in
git-rebase.sh and git-rebase--interactive.sh. This will make it easier
to factor out code from git-rebase.sh to git-rebase--interactive and
export the variables.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |   16 +++++++++++-----
 git-rebase.sh              |    4 +++-
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 310d80e..1af739a 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -339,7 +339,8 @@ pick_one_preserving_merges () {
 			# No point in merging the first parent, that's HEAD
 			new_parents=${new_parents# $first_parent}
 			if ! do_with_author output \
-				git merge $strategy -m "$msg" $new_parents
+				git merge ${strategy:+-s $strategy} -m "$msg" \
+					$new_parents
 			then
 				printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
 				die_with_patch $sha1 "Error redoing merge $sha1"
@@ -827,11 +828,11 @@ first and then run 'git rebase --continue' again."
 	-s)
 		case "$#,$1" in
 		*,*=*)
-			strategy="-s "$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
+			strategy=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
 		1,*)
 			usage ;;
 		*)
-			strategy="-s $2"
+			strategy="$2"
 			shift ;;
 		esac
 		;;
@@ -860,9 +861,9 @@ first and then run 'git rebase --continue' again."
 		autosquash=
 		;;
 	--onto)
+		test 2 -le "$#" || usage
+		onto="$2"
 		shift
-		onto=$(parse_onto "$1") ||
-			die "Does not point to a valid commit: $1"
 		;;
 	--)
 		shift
@@ -872,6 +873,11 @@ first and then run 'git rebase --continue' again."
 	shift
 done
 
+if test -n "$onto"
+then
+	onto=$(parse_onto "$onto") || die "Does not point to a valid commit: $1"
+fi
+
 test -z "$rebase_root" -a $# -ge 1 -a $# -le 2 ||
 test ! -z "$rebase_root" -a $# -le 1 || usage
 test -d "$DOTEST" &&
diff --git a/git-rebase.sh b/git-rebase.sh
index dc133e3..21366ba 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -43,7 +43,7 @@ If you would prefer to skip this patch, instead run \"git rebase --skip\".
 To restore the original branch and stop rebasing run \"git rebase --abort\".
 "
 unset onto
-strategy=recursive
+strategy=
 strategy_opts=
 do_merge=
 merge_dir="$GIT_DIR"/rebase-merge
@@ -130,6 +130,7 @@ call_merge () {
 	then
 		GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
 	fi
+	test -z "$strategy" && strategy=recursive
 	eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
 	rv=$?
 	case "$rv" in
@@ -267,6 +268,7 @@ do
 		esac
 		strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$newopt")"
 		do_merge=t
+		test -z "$strategy" && strategy=recursive
 		;;
 	-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
 		--strateg=*|--strategy=*|\
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 10/31] rebase: factor out command line option processing
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (8 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 09/31] rebase: align variable content Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 11/31] rebase -i: remove now unnecessary directory checks Martin von Zweigbergk
                   ` (22 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Factor out the command line processing in git-rebase--interactive.sh
to git-rebase.sh. Store the options in variables in git-rebase.sh and
export them before calling git-rebase--interactive.sh.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

Since this removes the command line processing from
git-rebase--interactive.sh, it completely changes its command line
interface. Since it is not listed as even a plumbing command, I hope
this is fine.

 git-rebase--interactive.sh |  224 ++++++++++++--------------------------------
 git-rebase.sh              |   60 ++++++++----
 2 files changed, 102 insertions(+), 182 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 1af739a..4d3dc63 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -10,31 +10,7 @@
 # The original idea comes from Eric W. Biederman, in
 # http://article.gmane.org/gmane.comp.version-control.git/22407
 
-OPTIONS_KEEPDASHDASH=
-OPTIONS_SPEC="\
-git-rebase [-i] [options] [--] <upstream> [<branch>]
-git-rebase [-i] (--continue | --abort | --skip)
---
- Available options are
-v,verbose          display a diffstat of what changed upstream
-onto=              rebase onto given branch instead of upstream
-p,preserve-merges  try to recreate merges instead of ignoring them
-s,strategy=        use the given merge strategy
-no-ff              cherry-pick all commits, even if unchanged
-m,merge            always used (no-op)
-i,interactive      always used (no-op)
- Actions:
-continue           continue rebasing process
-abort              abort rebasing process and restore original branch
-skip               skip current patch and continue rebasing process
-no-verify          override pre-rebase hook from stopping the operation
-verify             allow pre-rebase hook to run
-root               rebase all reachable commmits up to the root(s)
-autosquash         move commits that begin with squash!/fixup! under -i
-"
-
 . git-sh-setup
-require_work_tree
 
 DOTEST="$GIT_DIR/rebase-merge"
 
@@ -105,16 +81,6 @@ AMEND="$DOTEST"/amend
 REWRITTEN_LIST="$DOTEST"/rewritten-list
 REWRITTEN_PENDING="$DOTEST"/rewritten-pending
 
-preserve_merges=
-strategy=
-onto=
-verbose=
-OK_TO_SKIP_PRE_REBASE=
-rebase_root=
-autosquash=
-test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
-force_rebase=
-
 GIT_CHERRY_PICK_HELP="\
 hint: after resolving the conflicts, mark the corrected paths
 hint: with 'git add <paths>' and run 'git rebase --continue'"
@@ -648,15 +614,6 @@ skip_unnecessary_picks () {
 	die "Could not skip unnecessary pick commands"
 }
 
-# check if no other options are set
-is_standalone () {
-	test $# -eq 2 -a "$2" = '--' &&
-	test -z "$onto" &&
-	test -z "$preserve_merges" &&
-	test -z "$strategy" &&
-	test -z "$verbose"
-}
-
 get_saved_options () {
 	test -d "$REWRITTEN" && preserve_merges=t
 	test -f "$DOTEST"/strategy && strategy="$(cat "$DOTEST"/strategy)"
@@ -744,134 +701,77 @@ parse_onto () {
 	git rev-parse --verify "$1^0"
 }
 
-while test $# != 0
-do
-	case "$1" in
-	--no-verify)
-		OK_TO_SKIP_PRE_REBASE=yes
-		;;
-	--verify)
-		OK_TO_SKIP_PRE_REBASE=
-		;;
-	--continue)
-		is_standalone "$@" || usage
-		get_saved_options
-		comment_for_reflog continue
-
-		test -d "$DOTEST" || die "No interactive rebase running"
-
-		# Sanity check
-		git rev-parse --verify HEAD >/dev/null ||
-			die "Cannot read HEAD"
-		git update-index --ignore-submodules --refresh &&
-			git diff-files --quiet --ignore-submodules ||
-			die "Working tree is dirty"
-
-		# do we have anything to commit?
-		if git diff-index --cached --quiet --ignore-submodules HEAD --
+case "$action" in
+continue)
+	get_saved_options
+	comment_for_reflog continue
+
+	test -d "$DOTEST" || die "No interactive rebase running"
+
+	# Sanity check
+	git rev-parse --verify HEAD >/dev/null ||
+		die "Cannot read HEAD"
+	git update-index --ignore-submodules --refresh &&
+		git diff-files --quiet --ignore-submodules ||
+		die "Working tree is dirty"
+
+	# do we have anything to commit?
+	if git diff-index --cached --quiet --ignore-submodules HEAD --
+	then
+		: Nothing to commit -- skip this
+	else
+		. "$AUTHOR_SCRIPT" ||
+			die "Cannot find the author identity"
+		amend=
+		if test -f "$AMEND"
 		then
-			: Nothing to commit -- skip this
-		else
-			. "$AUTHOR_SCRIPT" ||
-				die "Cannot find the author identity"
-			amend=
-			if test -f "$AMEND"
-			then
-				amend=$(git rev-parse --verify HEAD)
-				test "$amend" = $(cat "$AMEND") ||
-				die "\
+			amend=$(git rev-parse --verify HEAD)
+			test "$amend" = $(cat "$AMEND") ||
+			die "\
 You have uncommitted changes in your working tree. Please, commit them
 first and then run 'git rebase --continue' again."
-				git reset --soft HEAD^ ||
-				die "Cannot rewind the HEAD"
-			fi
-			do_with_author git commit --no-verify -F "$MSG" -e || {
-				test -n "$amend" && git reset --soft $amend
-				die "Could not commit staged changes."
-			}
+			git reset --soft HEAD^ ||
+			die "Cannot rewind the HEAD"
 		fi
+		do_with_author git commit --no-verify -F "$MSG" -e || {
+			test -n "$amend" && git reset --soft $amend
+			die "Could not commit staged changes."
+		}
+	fi
 
-		record_in_rewritten "$(cat "$DOTEST"/stopped-sha)"
+	record_in_rewritten "$(cat "$DOTEST"/stopped-sha)"
 
-		require_clean_work_tree "rebase"
-		do_rest
-		;;
-	--abort)
-		is_standalone "$@" || usage
-		get_saved_options
-		comment_for_reflog abort
-
-		git rerere clear
-		test -d "$DOTEST" || die "No interactive rebase running"
-
-		HEADNAME=$(cat "$DOTEST"/head-name)
-		HEAD=$(cat "$DOTEST"/head)
-		case $HEADNAME in
-		refs/*)
-			git symbolic-ref HEAD $HEADNAME
-			;;
-		esac &&
-		output git reset --hard $HEAD &&
-		rm -rf "$DOTEST"
-		exit
-		;;
-	--skip)
-		is_standalone "$@" || usage
-		get_saved_options
-		comment_for_reflog skip
+	require_clean_work_tree "rebase"
+	do_rest
+	;;
+abort)
+	get_saved_options
+	comment_for_reflog abort
 
-		git rerere clear
-		test -d "$DOTEST" || die "No interactive rebase running"
+	git rerere clear
+	test -d "$DOTEST" || die "No interactive rebase running"
 
-		output git reset --hard && do_rest
-		;;
-	-s)
-		case "$#,$1" in
-		*,*=*)
-			strategy=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
-		1,*)
-			usage ;;
-		*)
-			strategy="$2"
-			shift ;;
-		esac
-		;;
-	-m)
-		# we use merge anyway
-		;;
-	-v)
-		verbose=t
-		;;
-	-p)
-		preserve_merges=t
-		;;
-	-i)
-		# yeah, we know
-		;;
-	--no-ff)
-		force_rebase=t
-		;;
-	--root)
-		rebase_root=t
-		;;
-	--autosquash)
-		autosquash=t
-		;;
-	--no-autosquash)
-		autosquash=
-		;;
-	--onto)
-		test 2 -le "$#" || usage
-		onto="$2"
-		shift
-		;;
-	--)
-		shift
-		break
+	HEADNAME=$(cat "$DOTEST"/head-name)
+	HEAD=$(cat "$DOTEST"/head)
+	case $HEADNAME in
+	refs/*)
+		git symbolic-ref HEAD $HEADNAME
 		;;
-	esac
-	shift
-done
+	esac &&
+	output git reset --hard $HEAD &&
+	rm -rf "$DOTEST"
+	exit
+	;;
+skip)
+	get_saved_options
+	comment_for_reflog skip
+
+	git rerere clear
+	test -d "$DOTEST" || die "No interactive rebase running"
+
+	output git reset --hard && do_rest
+	;;
+esac
 
 if test -n "$onto"
 then
diff --git a/git-rebase.sh b/git-rebase.sh
index 21366ba..e646b8f 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -64,6 +64,9 @@ type=
 state_dir=
 # One of {'', continue, skip, abort}, as parsed from command line
 action=
+preserve_merges=
+autosquash=
+test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
 
 read_state () {
 	if test "$type" = merge
@@ -176,27 +179,14 @@ finish_rb_merge () {
 	say All done.
 }
 
-is_interactive () {
-	while test $# != 0
-	do
-		case "$1" in
-			-i|--interactive)
-				interactive_rebase=explicit
-				break
-			;;
-			-p|--preserve-merges)
-				interactive_rebase=implied
-			;;
-		esac
-		shift
-	done
-
+run_interactive_rebase () {
 	if [ "$interactive_rebase" = implied ]; then
 		GIT_EDITOR=:
 		export GIT_EDITOR
 	fi
-
-	test -n "$interactive_rebase" || test -f "$merge_dir"/interactive
+	export onto autosquash strategy strategy_opts verbose rebase_root \
+	force_rebase action preserve_merges OK_TO_SKIP_PRE_REBASE
+	exec git-rebase--interactive "$@"
 }
 
 run_pre_rebase_hook () {
@@ -211,8 +201,6 @@ run_pre_rebase_hook () {
 test -f "$apply_dir"/applying &&
 	die 'It looks like git-am is in progress. Cannot rebase.'
 
-is_interactive "$@" && exec git-rebase--interactive "$@"
-
 if test -d "$apply_dir"
 then
 	type=am
@@ -249,6 +237,19 @@ do
 		onto="$2"
 		shift
 		;;
+	-i|--interactive)
+		interactive_rebase=explicit
+		;;
+	-p|--preserve-merges)
+		preserve_merges=t
+		test -z "$interactive_rebase" && interactive_rebase=implied
+		;;
+	--autosquash)
+		autosquash=t
+		;;
+	--no-autosquash)
+		autosquash=
+		;;
 	-M|-m|--m|--me|--mer|--merg|--merge)
 		do_merge=t
 		;;
@@ -339,7 +340,11 @@ do
 done
 test $# -gt 2 && usage
 
-test -n "$action" && test -z "$in_progress" && die "No rebase in progress?"
+if test -n "$action"
+then
+	test -z "$in_progress" && die "No rebase in progress?"
+	test "$type" = interactive && run_interactive_rebase
+fi
 
 case "$action" in
 continue)
@@ -415,6 +420,21 @@ fi
 
 test $# -eq 0 && test -z "$rebase_root" && usage
 
+if test -n "$interactive_rebase"
+then
+	type=interactive
+	state_dir="$merge_dir"
+elif test -n "$do_merge"
+then
+	type=merge
+	state_dir="$merge_dir"
+else
+	type=am
+	state_dir="$apply_dir"
+fi
+
+test "$type" = interactive && run_interactive_rebase "$@"
+
 require_clean_work_tree "rebase" "Please commit or stash them."
 
 if test -z "$rebase_root"
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 11/31] rebase -i: remove now unnecessary directory checks
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (9 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 10/31] rebase: factor out command line option processing Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 12/31] rebase: reorder validation steps Martin von Zweigbergk
                   ` (21 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Remove directory checks from git-rebase--interactive.sh that are done in
git-rebase.sh.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

Squash with previous?

 git-rebase--interactive.sh |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 4d3dc63..21a9774 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -706,8 +706,6 @@ continue)
 	get_saved_options
 	comment_for_reflog continue
 
-	test -d "$DOTEST" || die "No interactive rebase running"
-
 	# Sanity check
 	git rev-parse --verify HEAD >/dev/null ||
 		die "Cannot read HEAD"
@@ -749,7 +747,6 @@ abort)
 	comment_for_reflog abort
 
 	git rerere clear
-	test -d "$DOTEST" || die "No interactive rebase running"
 
 	HEADNAME=$(cat "$DOTEST"/head-name)
 	HEAD=$(cat "$DOTEST"/head)
@@ -767,7 +764,6 @@ skip)
 	comment_for_reflog skip
 
 	git rerere clear
-	test -d "$DOTEST" || die "No interactive rebase running"
 
 	output git reset --hard && do_rest
 	;;
@@ -780,8 +776,6 @@ fi
 
 test -z "$rebase_root" -a $# -ge 1 -a $# -le 2 ||
 test ! -z "$rebase_root" -a $# -le 1 || usage
-test -d "$DOTEST" &&
-	die "Interactive rebase already started"
 
 git var GIT_COMMITTER_IDENT >/dev/null ||
 	die "You need to set your committer info first"
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 12/31] rebase: reorder validation steps
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (10 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 11/31] rebase -i: remove now unnecessary directory checks Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 13/31] rebase: factor out reference parsing Martin von Zweigbergk
                   ` (20 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Reorder validation steps in preparation for the validation to be factored
out from git-rebase--interactive.sh into git-rebase.sh.

The main functional difference is that the pre-rebase hook will no longer
be run if the work tree is dirty.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |    4 ++--
 git-rebase.sh              |   10 +++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 21a9774..5a8f582 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -792,12 +792,12 @@ else
 	test -z "$onto" &&
 		die "You must specify --onto when using --root"
 fi
+require_clean_work_tree "rebase" "Please commit or stash them."
+
 run_pre_rebase_hook "$upstream_arg" "$@"
 
 comment_for_reflog start
 
-require_clean_work_tree "rebase" "Please commit or stash them."
-
 if test ! -z "$1"
 then
 	output git checkout "$1" ||
diff --git a/git-rebase.sh b/git-rebase.sh
index e646b8f..26e4218 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -435,8 +435,6 @@ fi
 
 test "$type" = interactive && run_interactive_rebase "$@"
 
-require_clean_work_tree "rebase" "Please commit or stash them."
-
 if test -z "$rebase_root"
 then
 	# The upstream head must be given.  Make sure it is valid.
@@ -478,9 +476,6 @@ case "$onto_name" in
 	;;
 esac
 
-# If a hook exists, give it a chance to interrupt
-run_pre_rebase_hook "$upstream_arg" "$@"
-
 # If the branch to rebase is given, that is the branch we will rebase
 # $branch_name -- branch being rebased, or HEAD (already detached)
 # $orig_head -- commit object name of tip of the branch before rebasing
@@ -518,6 +513,8 @@ case "$#" in
 esac
 orig_head=$branch
 
+require_clean_work_tree "rebase" "Please commit or stash them."
+
 # Now we are rebasing commits $upstream..$branch (or with --root,
 # everything leading up to $branch) on top of $onto
 
@@ -539,6 +536,9 @@ then
 	fi
 fi
 
+# If a hook exists, give it a chance to interrupt
+run_pre_rebase_hook "$upstream_arg" "$@"
+
 # Detach HEAD and reset the tree
 say "First, rewinding head to replay your work on top of it..."
 git checkout -q "$onto^0" || die "could not detach HEAD"
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 13/31] rebase: factor out reference parsing
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (11 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 12/31] rebase: reorder validation steps Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 14/31] rebase: factor out clean work tree check Martin von Zweigbergk
                   ` (19 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Remove the parsing and validation of references (onto, upstream, branch)
from git-rebase--interactive.sh and rely on the information exported from
git-rebase.sh.

By using the parsing of the --onto parameter in git-rebase.sh, this
improves the error message when the parameter is invalid.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

Should the check for set GIT_COMMITTER_IDENT be done for
non-interactive rebase as well or does it only make sense for
interactive rebase?

 git-rebase--interactive.sh |   48 +++----------------------------------------
 git-rebase.sh              |   12 ++++++----
 2 files changed, 11 insertions(+), 49 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 5a8f582..c055fc4 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -682,25 +682,6 @@ rearrange_squash () {
 	rm -f "$1.sq" "$1.rearranged"
 }
 
-LF='
-'
-parse_onto () {
-	case "$1" in
-	*...*)
-		if	left=${1%...*} right=${1#*...} &&
-			onto=$(git merge-base --all ${left:-HEAD} ${right:-HEAD})
-		then
-			case "$onto" in
-			?*"$LF"?* | '')
-				exit 1 ;;
-			esac
-			echo "$onto"
-			exit 0
-		fi
-	esac
-	git rev-parse --verify "$1^0"
-}
-
 case "$action" in
 continue)
 	get_saved_options
@@ -769,47 +750,26 @@ skip)
 	;;
 esac
 
-if test -n "$onto"
-then
-	onto=$(parse_onto "$onto") || die "Does not point to a valid commit: $1"
-fi
-
-test -z "$rebase_root" -a $# -ge 1 -a $# -le 2 ||
-test ! -z "$rebase_root" -a $# -le 1 || usage
-
 git var GIT_COMMITTER_IDENT >/dev/null ||
 	die "You need to set your committer info first"
 
-if test -z "$rebase_root"
-then
-	upstream_arg="$1"
-	upstream=$(git rev-parse --verify "$1") || die "Invalid base"
-	test -z "$onto" && onto=$upstream
-	shift
-else
-	upstream=
-	upstream_arg=--root
-	test -z "$onto" &&
-		die "You must specify --onto when using --root"
-fi
 require_clean_work_tree "rebase" "Please commit or stash them."
 
 run_pre_rebase_hook "$upstream_arg" "$@"
 
 comment_for_reflog start
 
-if test ! -z "$1"
+if test ! -z "$switch_to"
 then
-	output git checkout "$1" ||
-		die "Could not checkout $1"
+	output git checkout "$switch_to" ||
+		die "Could not checkout $switch_to"
 fi
 
 HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?"
 mkdir "$DOTEST" || die "Could not create temporary $DOTEST"
 
 : > "$DOTEST"/interactive || die "Could not mark as interactive"
-git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
-	echo "detached HEAD" > "$DOTEST"/head-name
+echo "$head_name" > "$DOTEST"/head-name
 
 echo $HEAD > "$DOTEST"/head
 case "$rebase_root" in
diff --git a/git-rebase.sh b/git-rebase.sh
index 26e4218..d8c7c8d 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -185,7 +185,8 @@ run_interactive_rebase () {
 		export GIT_EDITOR
 	fi
 	export onto autosquash strategy strategy_opts verbose rebase_root \
-	force_rebase action preserve_merges OK_TO_SKIP_PRE_REBASE
+	force_rebase action preserve_merges OK_TO_SKIP_PRE_REBASE upstream \
+	upstream_arg switch_to head_name
 	exec git-rebase--interactive "$@"
 }
 
@@ -433,8 +434,6 @@ else
 	state_dir="$apply_dir"
 fi
 
-test "$type" = interactive && run_interactive_rebase "$@"
-
 if test -z "$rebase_root"
 then
 	# The upstream head must be given.  Make sure it is valid.
@@ -445,7 +444,7 @@ then
 	unset root_flag
 	upstream_arg="$upstream_name"
 else
-	test -z "$onto" && die "--root must be used with --onto"
+	test -z "$onto" && die "You must specify --onto when using --root"
 	unset upstream_name
 	unset upstream
 	root_flag="--root"
@@ -472,7 +471,8 @@ case "$onto_name" in
 	fi
 	;;
 *)
-	onto=$(git rev-parse --verify "${onto_name}^0") || exit
+	onto=$(git rev-parse --verify "${onto_name}^0") ||
+	die "Does not point to a valid commit: $1"
 	;;
 esac
 
@@ -513,6 +513,8 @@ case "$#" in
 esac
 orig_head=$branch
 
+test "$type" = interactive && run_interactive_rebase "$@"
+
 require_clean_work_tree "rebase" "Please commit or stash them."
 
 # Now we are rebasing commits $upstream..$branch (or with --root,
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 14/31] rebase: factor out clean work tree check
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (12 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 13/31] rebase: factor out reference parsing Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 15/31] rebase: factor out call to pre-rebase hook Martin von Zweigbergk
                   ` (18 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Remove the check for clean work tree from git-rebase--interactive.sh and
rely on the check in git-rebase.sh.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |    2 --
 git-rebase.sh              |    4 ++--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index c055fc4..edde1e5 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -753,8 +753,6 @@ esac
 git var GIT_COMMITTER_IDENT >/dev/null ||
 	die "You need to set your committer info first"
 
-require_clean_work_tree "rebase" "Please commit or stash them."
-
 run_pre_rebase_hook "$upstream_arg" "$@"
 
 comment_for_reflog start
diff --git a/git-rebase.sh b/git-rebase.sh
index d8c7c8d..e1e5263 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -513,10 +513,10 @@ case "$#" in
 esac
 orig_head=$branch
 
-test "$type" = interactive && run_interactive_rebase "$@"
-
 require_clean_work_tree "rebase" "Please commit or stash them."
 
+test "$type" = interactive && run_interactive_rebase "$@"
+
 # Now we are rebasing commits $upstream..$branch (or with --root,
 # everything leading up to $branch) on top of $onto
 
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 15/31] rebase: factor out call to pre-rebase hook
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (13 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 14/31] rebase: factor out clean work tree check Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 16/31] rebase -i: support --stat Martin von Zweigbergk
                   ` (17 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Remove the call to the pre-rebase hook from
git-rebase--interactive.sh and rely on the call in
git-rebase.sh.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |   14 --------------
 git-rebase.sh              |   15 ++++++++-------
 2 files changed, 8 insertions(+), 21 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index edde1e5..0beeb8b 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -109,18 +109,6 @@ commit_message () {
 	git cat-file commit "$1" | sed "1,/^$/d"
 }
 
-run_pre_rebase_hook () {
-	if test -z "$OK_TO_SKIP_PRE_REBASE" &&
-	   test -x "$GIT_DIR/hooks/pre-rebase"
-	then
-		"$GIT_DIR/hooks/pre-rebase" ${1+"$@"} || {
-			echo >&2 "The pre-rebase hook refused to rebase."
-			exit 1
-		}
-	fi
-}
-
-
 ORIG_REFLOG_ACTION="$GIT_REFLOG_ACTION"
 
 comment_for_reflog () {
@@ -753,8 +741,6 @@ esac
 git var GIT_COMMITTER_IDENT >/dev/null ||
 	die "You need to set your committer info first"
 
-run_pre_rebase_hook "$upstream_arg" "$@"
-
 comment_for_reflog start
 
 if test ! -z "$switch_to"
diff --git a/git-rebase.sh b/git-rebase.sh
index e1e5263..229e8d2 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -185,9 +185,8 @@ run_interactive_rebase () {
 		export GIT_EDITOR
 	fi
 	export onto autosquash strategy strategy_opts verbose rebase_root \
-	force_rebase action preserve_merges OK_TO_SKIP_PRE_REBASE upstream \
-	upstream_arg switch_to head_name
-	exec git-rebase--interactive "$@"
+	force_rebase action preserve_merges upstream switch_to head_name
+	exec git-rebase--interactive
 }
 
 run_pre_rebase_hook () {
@@ -515,15 +514,15 @@ orig_head=$branch
 
 require_clean_work_tree "rebase" "Please commit or stash them."
 
-test "$type" = interactive && run_interactive_rebase "$@"
-
 # Now we are rebasing commits $upstream..$branch (or with --root,
 # everything leading up to $branch) on top of $onto
 
 # Check if we are already based on $onto with linear history,
-# but this should be done only when upstream and onto are the same.
+# but this should be done only when upstream and onto are the same
+# and if this is not an interactive rebase.
 mb=$(git merge-base "$onto" "$branch")
-if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
+if test "$type" != interactive && test "$upstream" = "$onto" &&
+	test "$mb" = "$onto" &&
 	# linear history?
 	! (git rev-list --parents "$onto".."$branch" | sane_grep " .* ") > /dev/null
 then
@@ -541,6 +540,8 @@ fi
 # If a hook exists, give it a chance to interrupt
 run_pre_rebase_hook "$upstream_arg" "$@"
 
+test "$type" = interactive && run_interactive_rebase
+
 # Detach HEAD and reset the tree
 say "First, rewinding head to replay your work on top of it..."
 git checkout -q "$onto^0" || die "could not detach HEAD"
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 16/31] rebase -i: support --stat
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (14 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 15/31] rebase: factor out call to pre-rebase hook Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28 17:59   ` Johannes Schindelin
  2010-12-28  9:30 ` [PATCH 17/31] rebase: remove $branch as synonym for $orig_head Martin von Zweigbergk
                   ` (16 subsequent siblings)
  32 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Move up the code that displays the diffstat if '--stat' is passed, so
that it will be executed before calling git-rebase--interactive.sh.

A side effect is that the diffstat is now displayed before "First,
rewinding head to replay your work on top of it...".

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase.sh |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index 229e8d2..0fc580a 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -540,13 +540,6 @@ fi
 # If a hook exists, give it a chance to interrupt
 run_pre_rebase_hook "$upstream_arg" "$@"
 
-test "$type" = interactive && run_interactive_rebase
-
-# Detach HEAD and reset the tree
-say "First, rewinding head to replay your work on top of it..."
-git checkout -q "$onto^0" || die "could not detach HEAD"
-git update-ref ORIG_HEAD $branch
-
 if test -n "$diffstat"
 then
 	if test -n "$verbose"
@@ -557,6 +550,13 @@ then
 	GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
 fi
 
+test "$type" = interactive && run_interactive_rebase
+
+# Detach HEAD and reset the tree
+say "First, rewinding head to replay your work on top of it..."
+git checkout -q "$onto^0" || die "could not detach HEAD"
+git update-ref ORIG_HEAD $branch
+
 # If the $onto is a proper descendant of the tip of the branch, then
 # we just fast-forwarded.
 if test "$mb" = "$branch"
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 17/31] rebase: remove $branch as synonym for $orig_head
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (15 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 16/31] rebase -i: support --stat Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 18/31] rebase: extract merge code to new source file Martin von Zweigbergk
                   ` (15 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

The variables $branch and $orig_head were used as synonyms. To avoid
confusion, remove $branch. The name 'orig_head' seems more suitable,
since that is the name used when the variable is persisted.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase.sh |   19 +++++++++----------
 1 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index 0fc580a..eae2f7a 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -487,10 +487,10 @@ case "$#" in
 	switch_to="$1"
 
 	if git show-ref --verify --quiet -- "refs/heads/$1" &&
-	   branch=$(git rev-parse -q --verify "refs/heads/$1")
+	   orig_head=$(git rev-parse -q --verify "refs/heads/$1")
 	then
 		head_name="refs/heads/$1"
-	elif branch=$(git rev-parse -q --verify "$1")
+	elif orig_head=$(git rev-parse -q --verify "$1")
 	then
 		head_name="detached HEAD"
 	else
@@ -507,24 +507,23 @@ case "$#" in
 		head_name="detached HEAD"
 		branch_name=HEAD ;# detached
 	fi
-	branch=$(git rev-parse --verify "${branch_name}^0") || exit
+	orig_head=$(git rev-parse --verify "${branch_name}^0") || exit
 	;;
 esac
-orig_head=$branch
 
 require_clean_work_tree "rebase" "Please commit or stash them."
 
-# Now we are rebasing commits $upstream..$branch (or with --root,
-# everything leading up to $branch) on top of $onto
+# Now we are rebasing commits $upstream..$orig_head (or with --root,
+# everything leading up to $orig_head) on top of $onto
 
 # Check if we are already based on $onto with linear history,
 # but this should be done only when upstream and onto are the same
 # and if this is not an interactive rebase.
-mb=$(git merge-base "$onto" "$branch")
+mb=$(git merge-base "$onto" "$orig_head")
 if test "$type" != interactive && test "$upstream" = "$onto" &&
 	test "$mb" = "$onto" &&
 	# linear history?
-	! (git rev-list --parents "$onto".."$branch" | sane_grep " .* ") > /dev/null
+	! (git rev-list --parents "$onto".."$orig_head" | sane_grep " .* ") > /dev/null
 then
 	if test -z "$force_rebase"
 	then
@@ -555,11 +554,11 @@ test "$type" = interactive && run_interactive_rebase
 # Detach HEAD and reset the tree
 say "First, rewinding head to replay your work on top of it..."
 git checkout -q "$onto^0" || die "could not detach HEAD"
-git update-ref ORIG_HEAD $branch
+git update-ref ORIG_HEAD $orig_head
 
 # If the $onto is a proper descendant of the tip of the branch, then
 # we just fast-forwarded.
-if test "$mb" = "$branch"
+if test "$mb" = "$orig_head"
 then
 	say "Fast-forwarded $branch_name to $onto_name."
 	move_to_original_branch
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 18/31] rebase: extract merge code to new source file
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (16 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 17/31] rebase: remove $branch as synonym for $orig_head Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-29 21:31   ` Johannes Sixt
  2010-12-28  9:30 ` [PATCH 19/31] rebase: extract am " Martin von Zweigbergk
                   ` (14 subsequent siblings)
  32 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Extract the code for merge-based rebase to git-rebase--merge.sh.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

What copyright year? Most of the code is just extracted from
git-rebase.sh, which has copyright year 2005. Does that matter?

Would read_initial_state be a better name than read_basic_state?

 .gitignore           |    1 +
 Makefile             |    1 +
 git-rebase--merge.sh |  154 ++++++++++++++++++++++++++++++++++++++++++++++
 git-rebase.sh        |  167 +++++---------------------------------------------
 4 files changed, 171 insertions(+), 152 deletions(-)
 create mode 100644 git-rebase--merge.sh

diff --git a/.gitignore b/.gitignore
index 87b833c..40506ff 100644
--- a/.gitignore
+++ b/.gitignore
@@ -103,6 +103,7 @@
 /git-read-tree
 /git-rebase
 /git-rebase--interactive
+/git-rebase--merge
 /git-receive-pack
 /git-reflog
 /git-relink
diff --git a/Makefile b/Makefile
index ff35154..ffc3a5d 100644
--- a/Makefile
+++ b/Makefile
@@ -370,6 +370,7 @@ SCRIPT_SH += git-mergetool.sh
 SCRIPT_SH += git-pull.sh
 SCRIPT_SH += git-quiltimport.sh
 SCRIPT_SH += git-rebase--interactive.sh
+SCRIPT_SH += git-rebase--merge.sh
 SCRIPT_SH += git-rebase.sh
 SCRIPT_SH += git-repack.sh
 SCRIPT_SH += git-request-pull.sh
diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
new file mode 100644
index 0000000..8cfdcf1
--- /dev/null
+++ b/git-rebase--merge.sh
@@ -0,0 +1,154 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Junio C Hamano.
+#
+
+. git-sh-setup
+
+prec=4
+
+read_state () {
+	onto_name=$(cat "$state_dir"/onto_name) &&
+	end=$(cat "$state_dir"/end) &&
+	msgnum=$(cat "$state_dir"/msgnum)
+}
+
+continue_merge () {
+	test -d "$state_dir" || die "$state_dir directory does not exist"
+
+	unmerged=$(git ls-files -u)
+	if test -n "$unmerged"
+	then
+		echo "You still have unmerged paths in your index"
+		echo "did you forget to use git add?"
+		die "$RESOLVEMSG"
+	fi
+
+	cmt=`cat "$state_dir/current"`
+	if ! git diff-index --quiet --ignore-submodules HEAD --
+	then
+		if ! git commit --no-verify -C "$cmt"
+		then
+			echo "Commit failed, please do not call \"git commit\""
+			echo "directly, but instead do one of the following: "
+			die "$RESOLVEMSG"
+		fi
+		if test -z "$GIT_QUIET"
+		then
+			printf "Committed: %0${prec}d " $msgnum
+		fi
+		echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten"
+	else
+		if test -z "$GIT_QUIET"
+		then
+			printf "Already applied: %0${prec}d " $msgnum
+		fi
+	fi
+	test -z "$GIT_QUIET" &&
+	GIT_PAGER='' git log --format=%s -1 "$cmt"
+
+	# onto the next patch:
+	msgnum=$(($msgnum + 1))
+	echo "$msgnum" >"$state_dir/msgnum"
+}
+
+call_merge () {
+	cmt="$(cat "$state_dir/cmt.$1")"
+	echo "$cmt" > "$state_dir/current"
+	hd=$(git rev-parse --verify HEAD)
+	cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
+	msgnum=$(cat "$state_dir/msgnum")
+	eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
+	eval GITHEAD_$hd='$onto_name'
+	export GITHEAD_$cmt GITHEAD_$hd
+	if test -n "$GIT_QUIET"
+	then
+		GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
+	fi
+	test -z "$strategy" && strategy=recursive
+	eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
+	rv=$?
+	case "$rv" in
+	0)
+		unset GITHEAD_$cmt GITHEAD_$hd
+		return
+		;;
+	1)
+		git rerere $allow_rerere_autoupdate
+		die "$RESOLVEMSG"
+		;;
+	2)
+		echo "Strategy: $rv $strategy failed, try another" 1>&2
+		die "$RESOLVEMSG"
+		;;
+	*)
+		die "Unknown exit code ($rv) from command:" \
+			"git-merge-$strategy $cmt^ -- HEAD $cmt"
+		;;
+	esac
+}
+
+finish_rb_merge () {
+	move_to_original_branch
+	git notes copy --for-rewrite=rebase < "$state_dir"/rewritten
+	if test -x "$GIT_DIR"/hooks/post-rewrite &&
+		test -s "$state_dir"/rewritten; then
+		"$GIT_DIR"/hooks/post-rewrite rebase < "$state_dir"/rewritten
+	fi
+	rm -r "$state_dir"
+	say All done.
+}
+
+case "$action" in
+continue)
+	read_state
+	continue_merge
+	while test "$msgnum" -le "$end"
+	do
+		call_merge "$msgnum"
+		continue_merge
+	done
+	finish_rb_merge
+	exit
+	;;
+skip)
+	read_state
+	git rerere clear
+	msgnum=$(($msgnum + 1))
+	while test "$msgnum" -le "$end"
+	do
+		call_merge "$msgnum"
+		continue_merge
+	done
+	finish_rb_merge
+	exit
+	;;
+esac
+
+mkdir -p "$state_dir"
+echo "$onto_name" > "$state_dir/onto_name"
+echo "$head_name" > "$state_dir/head-name"
+echo "$onto" > "$state_dir/onto"
+echo "$orig_head" > "$state_dir/orig-head"
+echo "$GIT_QUIET" > "$state_dir/quiet"
+
+msgnum=0
+for cmt in `git rev-list --reverse --no-merges "$revisions"`
+do
+	msgnum=$(($msgnum + 1))
+	echo "$cmt" > "$state_dir/cmt.$msgnum"
+done
+
+echo 1 >"$state_dir/msgnum"
+echo $msgnum >"$state_dir/end"
+
+end=$msgnum
+msgnum=1
+
+while test "$msgnum" -le "$end"
+do
+	call_merge "$msgnum"
+	continue_merge
+done
+
+finish_rb_merge
diff --git a/git-rebase.sh b/git-rebase.sh
index eae2f7a..ee586e8 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -48,7 +48,6 @@ strategy_opts=
 do_merge=
 merge_dir="$GIT_DIR"/rebase-merge
 apply_dir="$GIT_DIR"/rebase-apply
-prec=4
 verbose=
 diffstat=
 test "$(git config --bool rebase.stat)" = true && diffstat=t
@@ -68,94 +67,13 @@ preserve_merges=
 autosquash=
 test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
 
-read_state () {
-	if test "$type" = merge
-	then
-		onto_name=$(cat "$state_dir"/onto_name) &&
-		end=$(cat "$state_dir"/end) &&
-		msgnum=$(cat "$state_dir"/msgnum)
-	fi &&
+read_basic_state () {
 	head_name=$(cat "$state_dir"/head-name) &&
 	onto=$(cat "$state_dir"/onto) &&
 	orig_head=$(cat "$state_dir"/orig-head) &&
 	GIT_QUIET=$(cat "$state_dir"/quiet)
 }
 
-continue_merge () {
-	test -d "$merge_dir" || die "$merge_dir directory does not exist"
-
-	unmerged=$(git ls-files -u)
-	if test -n "$unmerged"
-	then
-		echo "You still have unmerged paths in your index"
-		echo "did you forget to use git add?"
-		die "$RESOLVEMSG"
-	fi
-
-	cmt=`cat "$merge_dir/current"`
-	if ! git diff-index --quiet --ignore-submodules HEAD --
-	then
-		if ! git commit --no-verify -C "$cmt"
-		then
-			echo "Commit failed, please do not call \"git commit\""
-			echo "directly, but instead do one of the following: "
-			die "$RESOLVEMSG"
-		fi
-		if test -z "$GIT_QUIET"
-		then
-			printf "Committed: %0${prec}d " $msgnum
-		fi
-		echo "$cmt $(git rev-parse HEAD^0)" >> "$merge_dir/rewritten"
-	else
-		if test -z "$GIT_QUIET"
-		then
-			printf "Already applied: %0${prec}d " $msgnum
-		fi
-	fi
-	test -z "$GIT_QUIET" &&
-	GIT_PAGER='' git log --format=%s -1 "$cmt"
-
-	# onto the next patch:
-	msgnum=$(($msgnum + 1))
-	echo "$msgnum" >"$merge_dir/msgnum"
-}
-
-call_merge () {
-	cmt="$(cat "$merge_dir/cmt.$1")"
-	echo "$cmt" > "$merge_dir/current"
-	hd=$(git rev-parse --verify HEAD)
-	cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
-	msgnum=$(cat "$merge_dir/msgnum")
-	eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
-	eval GITHEAD_$hd='$onto_name'
-	export GITHEAD_$cmt GITHEAD_$hd
-	if test -n "$GIT_QUIET"
-	then
-		GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
-	fi
-	test -z "$strategy" && strategy=recursive
-	eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
-	rv=$?
-	case "$rv" in
-	0)
-		unset GITHEAD_$cmt GITHEAD_$hd
-		return
-		;;
-	1)
-		git rerere $allow_rerere_autoupdate
-		die "$RESOLVEMSG"
-		;;
-	2)
-		echo "Strategy: $rv $strategy failed, try another" 1>&2
-		die "$RESOLVEMSG"
-		;;
-	*)
-		die "Unknown exit code ($rv) from command:" \
-			"git-merge-$strategy $cmt^ -- HEAD $cmt"
-		;;
-	esac
-}
-
 move_to_original_branch () {
 	case "$head_name" in
 	refs/*)
@@ -168,25 +86,17 @@ move_to_original_branch () {
 	esac
 }
 
-finish_rb_merge () {
-	move_to_original_branch
-	git notes copy --for-rewrite=rebase < "$merge_dir"/rewritten
-	if test -x "$GIT_DIR"/hooks/post-rewrite &&
-		test -s "$merge_dir"/rewritten; then
-		"$GIT_DIR"/hooks/post-rewrite rebase < "$merge_dir"/rewritten
-	fi
-	rm -r "$merge_dir"
-	say All done.
-}
-
-run_interactive_rebase () {
+run_specific_rebase () {
 	if [ "$interactive_rebase" = implied ]; then
 		GIT_EDITOR=:
 		export GIT_EDITOR
 	fi
 	export onto autosquash strategy strategy_opts verbose rebase_root \
-	force_rebase action preserve_merges upstream switch_to head_name
-	exec git-rebase--interactive
+	force_rebase action preserve_merges upstream switch_to head_name \
+	state_dir orig_head onto_name GIT_QUIET revisions RESOLVEMSG \
+	allow_rerere_autoupdate
+	export -f move_to_original_branch
+	test "$type" != am && exec git-rebase--$type
 }
 
 run_pre_rebase_hook () {
@@ -343,7 +253,7 @@ test $# -gt 2 && usage
 if test -n "$action"
 then
 	test -z "$in_progress" && die "No rebase in progress?"
-	test "$type" = interactive && run_interactive_rebase
+	test "$type" = interactive && run_specific_rebase
 fi
 
 case "$action" in
@@ -354,44 +264,23 @@ continue)
 		echo "mark them as resolved using git add"
 		exit 1
 	}
-	read_state
-	if test -d "$merge_dir"
-	then
-		continue_merge
-		while test "$msgnum" -le "$end"
-		do
-			call_merge "$msgnum"
-			continue_merge
-		done
-		finish_rb_merge
-		exit
-	fi
+	read_basic_state
+	run_specific_rebase
 	git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
 	move_to_original_branch
 	exit
 	;;
 skip)
 	git reset --hard HEAD || exit $?
-	read_state
-	if test -d "$merge_dir"
-	then
-		git rerere clear
-		msgnum=$(($msgnum + 1))
-		while test "$msgnum" -le "$end"
-		do
-			call_merge "$msgnum"
-			continue_merge
-		done
-		finish_rb_merge
-		exit
-	fi
+	read_basic_state
+	run_specific_rebase
 	git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
 	move_to_original_branch
 	exit
 	;;
 abort)
 	git rerere clear
-	read_state
+	read_basic_state
 	case "$head_name" in
 	refs/*)
 		git symbolic-ref HEAD $head_name ||
@@ -549,7 +438,7 @@ then
 	GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
 fi
 
-test "$type" = interactive && run_interactive_rebase
+test "$type" = interactive && run_specific_rebase
 
 # Detach HEAD and reset the tree
 say "First, rewinding head to replay your work on top of it..."
@@ -591,30 +480,4 @@ fi
 # start doing a rebase with git-merge
 # this is rename-aware if the recursive (default) strategy is used
 
-mkdir -p "$merge_dir"
-echo "$onto_name" > "$merge_dir/onto_name"
-echo "$head_name" > "$merge_dir/head-name"
-echo "$onto" > "$merge_dir/onto"
-echo "$orig_head" > "$merge_dir/orig-head"
-echo "$GIT_QUIET" > "$merge_dir/quiet"
-
-msgnum=0
-for cmt in `git rev-list --reverse --no-merges "$revisions"`
-do
-	msgnum=$(($msgnum + 1))
-	echo "$cmt" > "$merge_dir/cmt.$msgnum"
-done
-
-echo 1 >"$merge_dir/msgnum"
-echo $msgnum >"$merge_dir/end"
-
-end=$msgnum
-msgnum=1
-
-while test "$msgnum" -le "$end"
-do
-	call_merge "$msgnum"
-	continue_merge
-done
-
-finish_rb_merge
+run_specific_rebase
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 19/31] rebase: extract am code to new source file
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (17 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 18/31] rebase: extract merge code to new source file Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 20/31] rebase: show consistent conflict resolution hint Martin von Zweigbergk
                   ` (13 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Extract the code for am-based rebase to git-rebase--am.sh.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 .gitignore        |    1 +
 Makefile          |    1 +
 git-rebase--am.sh |   34 ++++++++++++++++++++++++++++++++++
 git-rebase.sh     |   33 +++------------------------------
 4 files changed, 39 insertions(+), 30 deletions(-)
 create mode 100644 git-rebase--am.sh

diff --git a/.gitignore b/.gitignore
index 40506ff..ef04058 100644
--- a/.gitignore
+++ b/.gitignore
@@ -102,6 +102,7 @@
 /git-quiltimport
 /git-read-tree
 /git-rebase
+/git-rebase--am
 /git-rebase--interactive
 /git-rebase--merge
 /git-receive-pack
diff --git a/Makefile b/Makefile
index ffc3a5d..459df3a 100644
--- a/Makefile
+++ b/Makefile
@@ -369,6 +369,7 @@ SCRIPT_SH += git-merge-resolve.sh
 SCRIPT_SH += git-mergetool.sh
 SCRIPT_SH += git-pull.sh
 SCRIPT_SH += git-quiltimport.sh
+SCRIPT_SH += git-rebase--am.sh
 SCRIPT_SH += git-rebase--interactive.sh
 SCRIPT_SH += git-rebase--merge.sh
 SCRIPT_SH += git-rebase.sh
diff --git a/git-rebase--am.sh b/git-rebase--am.sh
new file mode 100644
index 0000000..9316761
--- /dev/null
+++ b/git-rebase--am.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Junio C Hamano.
+#
+
+. git-sh-setup
+
+case "$action" in
+continue)
+	git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
+	move_to_original_branch
+	exit
+	;;
+skip)
+	git am --skip -3 --resolvemsg="$RESOLVEMSG" &&
+	move_to_original_branch
+	exit
+	;;
+esac
+
+test -n "$rebase_root" && root_flag=--root
+
+git format-patch -k --stdout --full-index --ignore-if-in-upstream \
+	--src-prefix=a/ --dst-prefix=b/ \
+	--no-renames $root_flag "$revisions" |
+git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
+move_to_original_branch
+ret=$?
+test 0 != $ret -a -d "$state_dir" &&
+	echo $head_name > "$state_dir/head-name" &&
+	echo $onto > "$state_dir/onto" &&
+	echo $orig_head > "$state_dir/orig-head" &&
+	echo "$GIT_QUIET" > "$state_dir/quiet"
+exit $ret
diff --git a/git-rebase.sh b/git-rebase.sh
index ee586e8..615d9dd 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -94,9 +94,9 @@ run_specific_rebase () {
 	export onto autosquash strategy strategy_opts verbose rebase_root \
 	force_rebase action preserve_merges upstream switch_to head_name \
 	state_dir orig_head onto_name GIT_QUIET revisions RESOLVEMSG \
-	allow_rerere_autoupdate
+	allow_rerere_autoupdate git_am_opt
 	export -f move_to_original_branch
-	test "$type" != am && exec git-rebase--$type
+	exec git-rebase--$type
 }
 
 run_pre_rebase_hook () {
@@ -266,17 +266,11 @@ continue)
 	}
 	read_basic_state
 	run_specific_rebase
-	git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
-	move_to_original_branch
-	exit
 	;;
 skip)
 	git reset --hard HEAD || exit $?
 	read_basic_state
 	run_specific_rebase
-	git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
-	move_to_original_branch
-	exit
 	;;
 abort)
 	git rerere clear
@@ -329,14 +323,12 @@ then
 	shift
 	upstream=`git rev-parse --verify "${upstream_name}^0"` ||
 	die "invalid upstream $upstream_name"
-	unset root_flag
 	upstream_arg="$upstream_name"
 else
 	test -z "$onto" && die "You must specify --onto when using --root"
 	unset upstream_name
 	unset upstream
-	root_flag="--root"
-	upstream_arg="$root_flag"
+	upstream_arg=--root
 fi
 
 # Make sure the branch to rebase onto is valid.
@@ -461,23 +453,4 @@ else
 	revisions="$upstream..$orig_head"
 fi
 
-if test -z "$do_merge"
-then
-	git format-patch -k --stdout --full-index --ignore-if-in-upstream \
-		--src-prefix=a/ --dst-prefix=b/ \
-		--no-renames $root_flag "$revisions" |
-	git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
-	move_to_original_branch
-	ret=$?
-	test 0 != $ret -a -d "$apply_dir" &&
-		echo $head_name > "$apply_dir/head-name" &&
-		echo $onto > "$apply_dir/onto" &&
-		echo $orig_head > "$apply_dir/orig-head" &&
-		echo "$GIT_QUIET" > "$apply_dir/quiet"
-	exit $ret
-fi
-
-# start doing a rebase with git-merge
-# this is rename-aware if the recursive (default) strategy is used
-
 run_specific_rebase
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 20/31] rebase: show consistent conflict resolution hint
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (18 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 19/31] rebase: extract am " Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 21/31] rebase -i: align variable names Martin von Zweigbergk
                   ` (12 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

When rebase stops due to conflict, interactive rebase currently
displays a different hint to the user than non-interactive rebase
does. Use the same message for both types of rebase.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

Should we include the "mark the corrected paths with 'git add
<paths>'" part?

 git-rebase--interactive.sh |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 0beeb8b..e848ea2 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -81,9 +81,7 @@ AMEND="$DOTEST"/amend
 REWRITTEN_LIST="$DOTEST"/rewritten-list
 REWRITTEN_PENDING="$DOTEST"/rewritten-pending
 
-GIT_CHERRY_PICK_HELP="\
-hint: after resolving the conflicts, mark the corrected paths
-hint: with 'git add <paths>' and run 'git rebase --continue'"
+GIT_CHERRY_PICK_HELP="$RESOLVEMSG"
 export GIT_CHERRY_PICK_HELP
 
 warn () {
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 21/31] rebase -i: align variable names
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (19 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 20/31] rebase: show consistent conflict resolution hint Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 22/31] rebase: make -v a tiny bit more verbose Martin von Zweigbergk
                   ` (11 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Rename variables HEAD and OLDHEAD to orig_head and HEADNAME to
head_name, which are the names used in git-rebase.sh. This prepares
for factoring out of the code that persists these variables during the
entire rebase process. Using the same variable names to mean the same
thing in both files also makes the code easier to read.

While at it, also remove the DOTEST variable and use the state_dir
variable that was inherited from git-rebase.sh instead.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

Squash this commit with earlier commit that also renamed variables in
git-rebase--interactive.sh?

 git-rebase--interactive.sh |  120 +++++++++++++++++++++----------------------
 1 files changed, 59 insertions(+), 61 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index e848ea2..eace4e5 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -12,22 +12,20 @@
 
 . git-sh-setup
 
-DOTEST="$GIT_DIR/rebase-merge"
-
 # The file containing rebase commands, comments, and empty lines.
 # This file is created by "git rebase -i" then edited by the user.  As
 # the lines are processed, they are removed from the front of this
 # file and written to the tail of $DONE.
-TODO="$DOTEST"/git-rebase-todo
+TODO="$state_dir"/git-rebase-todo
 
 # The rebase command lines that have already been processed.  A line
 # is moved here when it is first handled, before any associated user
 # actions.
-DONE="$DOTEST"/done
+DONE="$state_dir"/done
 
 # The commit message that is planned to be used for any changes that
 # need to be committed following a user interaction.
-MSG="$DOTEST"/message
+MSG="$state_dir"/message
 
 # The file into which is accumulated the suggested commit message for
 # squash/fixup commands.  When the first of a series of squash/fixups
@@ -42,14 +40,14 @@ MSG="$DOTEST"/message
 # written to the file so far (including the initial "pick" commit).
 # Each time that a commit message is processed, this line is read and
 # updated.  It is deleted just before the combined commit is made.
-SQUASH_MSG="$DOTEST"/message-squash
+SQUASH_MSG="$state_dir"/message-squash
 
 # If the current series of squash/fixups has not yet included a squash
 # command, then this file exists and holds the commit message of the
 # original "pick" commit.  (If the series ends without a "squash"
 # command, then this can be used as the commit message of the combined
 # commit without opening the editor.)
-FIXUP_MSG="$DOTEST"/message-fixup
+FIXUP_MSG="$state_dir"/message-fixup
 
 # $REWRITTEN is the name of a directory containing files for each
 # commit that is reachable by at least one merge base of $HEAD and
@@ -57,14 +55,14 @@ FIXUP_MSG="$DOTEST"/message-fixup
 # might be.  This ensures that commits on merged, but otherwise
 # unrelated side branches are left alone. (Think "X" in the man page's
 # example.)
-REWRITTEN="$DOTEST"/rewritten
+REWRITTEN="$state_dir"/rewritten
 
-DROPPED="$DOTEST"/dropped
+DROPPED="$state_dir"/dropped
 
 # A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
 # GIT_AUTHOR_DATE that will be used for the commit that is currently
 # being rebased.
-AUTHOR_SCRIPT="$DOTEST"/author-script
+AUTHOR_SCRIPT="$state_dir"/author-script
 
 # When an "edit" rebase command is being processed, the SHA1 of the
 # commit to be edited is recorded in this file.  When "git rebase
@@ -72,14 +70,14 @@ AUTHOR_SCRIPT="$DOTEST"/author-script
 # will be amended to the HEAD commit, but only provided the HEAD
 # commit is still the commit to be edited.  When any other rebase
 # command is processed, this file is deleted.
-AMEND="$DOTEST"/amend
+AMEND="$state_dir"/amend
 
 # For the post-rewrite hook, we make a list of rewritten commits and
 # their new sha1s.  The rewritten-pending list keeps the sha1s of
 # commits that have been processed, but not committed yet,
 # e.g. because they are waiting for a 'squash' command.
-REWRITTEN_LIST="$DOTEST"/rewritten-list
-REWRITTEN_PENDING="$DOTEST"/rewritten-pending
+REWRITTEN_LIST="$state_dir"/rewritten-list
+REWRITTEN_PENDING="$state_dir"/rewritten-pending
 
 GIT_CHERRY_PICK_HELP="$RESOLVEMSG"
 export GIT_CHERRY_PICK_HELP
@@ -145,7 +143,7 @@ make_patch () {
 	*)
 		echo "Root commit"
 		;;
-	esac > "$DOTEST"/patch
+	esac > "$state_dir"/patch
 	test -f "$MSG" ||
 		commit_message "$1" > "$MSG"
 	test -f "$AUTHOR_SCRIPT" ||
@@ -153,14 +151,14 @@ make_patch () {
 }
 
 die_with_patch () {
-	echo "$1" > "$DOTEST"/stopped-sha
+	echo "$1" > "$state_dir"/stopped-sha
 	make_patch "$1"
 	git rerere
 	die "$2"
 }
 
 die_abort () {
-	rm -rf "$DOTEST"
+	rm -rf "$state_dir"
 	die "$1"
 }
 
@@ -205,20 +203,20 @@ pick_one_preserving_merges () {
 	esac
 	sha1=$(git rev-parse $sha1)
 
-	if test -f "$DOTEST"/current-commit
+	if test -f "$state_dir"/current-commit
 	then
 		if test "$fast_forward" = t
 		then
 			while read current_commit
 			do
 				git rev-parse HEAD > "$REWRITTEN"/$current_commit
-			done <"$DOTEST"/current-commit
-			rm "$DOTEST"/current-commit ||
+			done <"$state_dir"/current-commit
+			rm "$state_dir"/current-commit ||
 			die "Cannot write current commit's replacement sha1"
 		fi
 	fi
 
-	echo $sha1 >> "$DOTEST"/current-commit
+	echo $sha1 >> "$state_dir"/current-commit
 
 	# rewrite parents; if none were rewritten, we can fast-forward.
 	new_parents=
@@ -425,7 +423,7 @@ do_next () {
 		mark_action_done
 		pick_one $sha1 ||
 			die_with_patch $sha1 "Could not apply $sha1... $rest"
-		echo "$sha1" > "$DOTEST"/stopped-sha
+		echo "$sha1" > "$state_dir"/stopped-sha
 		make_patch $sha1
 		git rev-parse --verify HEAD > "$AMEND"
 		warn "Stopped at $sha1... $rest"
@@ -490,7 +488,7 @@ do_next () {
 		printf 'Executing: %s\n' "$rest"
 		# "exec" command doesn't take a sha1 in the todo-list.
 		# => can't just use $sha1 here.
-		git rev-parse --verify HEAD > "$DOTEST"/stopped-sha
+		git rev-parse --verify HEAD > "$state_dir"/stopped-sha
 		${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
 		status=$?
 		if test "$status" -ne 0
@@ -525,19 +523,19 @@ do_next () {
 	test -s "$TODO" && return
 
 	comment_for_reflog finish &&
-	HEADNAME=$(cat "$DOTEST"/head-name) &&
-	OLDHEAD=$(cat "$DOTEST"/head) &&
-	SHORTONTO=$(git rev-parse --short $(cat "$DOTEST"/onto)) &&
+	head_name=$(cat "$state_dir"/head-name) &&
+	orig_head=$(cat "$state_dir"/head) &&
+	SHORTONTO=$(git rev-parse --short $(cat "$state_dir"/onto)) &&
 	NEWHEAD=$(git rev-parse HEAD) &&
-	case $HEADNAME in
+	case $head_name in
 	refs/*)
-		message="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO" &&
-		git update-ref -m "$message" $HEADNAME $NEWHEAD $OLDHEAD &&
-		git symbolic-ref HEAD $HEADNAME
+		message="$GIT_REFLOG_ACTION: $head_name onto $SHORTONTO" &&
+		git update-ref -m "$message" $head_name $NEWHEAD $orig_head &&
+		git symbolic-ref HEAD $head_name
 		;;
 	esac && {
-		test ! -f "$DOTEST"/verbose ||
-			git diff-tree --stat $(cat "$DOTEST"/head)..HEAD
+		test ! -f "$state_dir"/verbose ||
+			git diff-tree --stat $(cat "$state_dir"/head)..HEAD
 	} &&
 	{
 		test -s "$REWRITTEN_LIST" &&
@@ -549,9 +547,9 @@ do_next () {
 		"$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST"
 		true # we don't care if this hook failed
 	fi &&
-	rm -rf "$DOTEST" &&
+	rm -rf "$state_dir" &&
 	git gc --auto &&
-	warn "Successfully rebased and updated $HEADNAME."
+	warn "Successfully rebased and updated $head_name."
 
 	exit
 }
@@ -602,9 +600,9 @@ skip_unnecessary_picks () {
 
 get_saved_options () {
 	test -d "$REWRITTEN" && preserve_merges=t
-	test -f "$DOTEST"/strategy && strategy="$(cat "$DOTEST"/strategy)"
-	test -f "$DOTEST"/verbose && verbose=t
-	test -f "$DOTEST"/rebase-root && rebase_root=t
+	test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
+	test -f "$state_dir"/verbose && verbose=t
+	test -f "$state_dir"/rebase-root && rebase_root=t
 }
 
 # Rearrange the todo list that has both "pick sha1 msg" and
@@ -704,7 +702,7 @@ first and then run 'git rebase --continue' again."
 		}
 	fi
 
-	record_in_rewritten "$(cat "$DOTEST"/stopped-sha)"
+	record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
 
 	require_clean_work_tree "rebase"
 	do_rest
@@ -715,15 +713,15 @@ abort)
 
 	git rerere clear
 
-	HEADNAME=$(cat "$DOTEST"/head-name)
-	HEAD=$(cat "$DOTEST"/head)
-	case $HEADNAME in
+	head_name=$(cat "$state_dir"/head-name)
+	orig_head=$(cat "$state_dir"/head)
+	case $head_name in
 	refs/*)
-		git symbolic-ref HEAD $HEADNAME
+		git symbolic-ref HEAD $head_name
 		;;
 	esac &&
-	output git reset --hard $HEAD &&
-	rm -rf "$DOTEST"
+	output git reset --hard $orig_head &&
+	rm -rf "$state_dir"
 	exit
 	;;
 skip)
@@ -747,28 +745,28 @@ then
 		die "Could not checkout $switch_to"
 fi
 
-HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?"
-mkdir "$DOTEST" || die "Could not create temporary $DOTEST"
+orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
+mkdir "$state_dir" || die "Could not create temporary $state_dir"
 
-: > "$DOTEST"/interactive || die "Could not mark as interactive"
-echo "$head_name" > "$DOTEST"/head-name
+: > "$state_dir"/interactive || die "Could not mark as interactive"
+echo "$head_name" > "$state_dir"/head-name
 
-echo $HEAD > "$DOTEST"/head
+echo $orig_head > "$state_dir"/head
 case "$rebase_root" in
 '')
-	rm -f "$DOTEST"/rebase-root ;;
+	rm -f "$state_dir"/rebase-root ;;
 *)
-	: >"$DOTEST"/rebase-root ;;
+	: >"$state_dir"/rebase-root ;;
 esac
-echo $onto > "$DOTEST"/onto
-test -z "$strategy" || echo "$strategy" > "$DOTEST"/strategy
-test t = "$verbose" && : > "$DOTEST"/verbose
+echo $onto > "$state_dir"/onto
+test -z "$strategy" || echo "$strategy" > "$state_dir"/strategy
+test t = "$verbose" && : > "$state_dir"/verbose
 if test t = "$preserve_merges"
 then
 	if test -z "$rebase_root"
 	then
 		mkdir "$REWRITTEN" &&
-		for c in $(git merge-base --all $HEAD $upstream)
+		for c in $(git merge-base --all $orig_head $upstream)
 		do
 			echo $onto > "$REWRITTEN"/$c ||
 				die "Could not init rewritten commits"
@@ -782,21 +780,21 @@ then
 	# parents to rewrite and skipping dropped commits would
 	# prematurely end our probe
 	MERGES_OPTION=
-	first_after_upstream="$(git rev-list --reverse --first-parent $upstream..$HEAD | head -n 1)"
+	first_after_upstream="$(git rev-list --reverse --first-parent $upstream..$orig_head | head -n 1)"
 else
 	MERGES_OPTION="--no-merges --cherry-pick"
 fi
 
-SHORTHEAD=$(git rev-parse --short $HEAD)
+SHORTHEAD=$(git rev-parse --short $orig_head)
 SHORTONTO=$(git rev-parse --short $onto)
 if test -z "$rebase_root"
 	# this is now equivalent to ! -z "$upstream"
 then
 	SHORTUPSTREAM=$(git rev-parse --short $upstream)
-	REVISIONS=$upstream...$HEAD
+	REVISIONS=$upstream...$orig_head
 	SHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD
 else
-	REVISIONS=$onto...$HEAD
+	REVISIONS=$onto...$orig_head
 	SHORTREVISIONS=$SHORTHEAD
 fi
 git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
@@ -837,13 +835,13 @@ then
 	mkdir "$DROPPED"
 	# Save all non-cherry-picked changes
 	git rev-list $REVISIONS --left-right --cherry-pick | \
-		sed -n "s/^>//p" > "$DOTEST"/not-cherry-picks
+		sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
 	# Now all commits and note which ones are missing in
 	# not-cherry-picks and hence being dropped
 	git rev-list $REVISIONS |
 	while read rev
 	do
-		if test -f "$REWRITTEN"/$rev -a "$(sane_grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
+		if test -f "$REWRITTEN"/$rev -a "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = ""
 		then
 			# Use -f2 because if rev-list is telling us this commit is
 			# not worthwhile, we don't want to track its multiple heads,
@@ -889,5 +887,5 @@ has_action "$TODO" ||
 test -d "$REWRITTEN" || test -n "$force_rebase" || skip_unnecessary_picks
 
 output git checkout $onto || die_abort "could not detach HEAD"
-git update-ref ORIG_HEAD $HEAD
+git update-ref ORIG_HEAD $orig_head
 do_rest
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 22/31] rebase: make -v a tiny bit more verbose
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (20 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 21/31] rebase -i: align variable names Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 23/31] rebase: factor out sub command handling Martin von Zweigbergk
                   ` (10 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

To make it possible to later remove the handling of --abort from
git-rebase--interactive.sh, align the implementation in git-rebase.sh
with the former by making it a bit more verbose.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

What do we really want to print when -v is passed? Interactive rebase
is currently quite a bit more verbose than non-interactive rebase.

 git-rebase--interactive.sh |   14 --------------
 git-rebase.sh              |   20 +++++++++++++++++---
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index eace4e5..acd0258 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -86,20 +86,6 @@ warn () {
 	printf '%s\n' "$*" >&2
 }
 
-output () {
-	case "$verbose" in
-	'')
-		output=$("$@" 2>&1 )
-		status=$?
-		test $status != 0 && printf "%s\n" "$output"
-		return $status
-		;;
-	*)
-		"$@"
-		;;
-	esac
-}
-
 # Output the commit message for the specified commit.
 commit_message () {
 	git cat-file commit "$1" | sed "1,/^$/d"
diff --git a/git-rebase.sh b/git-rebase.sh
index 615d9dd..0322f27 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -74,6 +74,20 @@ read_basic_state () {
 	GIT_QUIET=$(cat "$state_dir"/quiet)
 }
 
+output () {
+	case "$verbose" in
+	'')
+		output=$("$@" 2>&1 )
+		status=$?
+		test $status != 0 && printf "%s\n" "$output"
+		return $status
+		;;
+	*)
+		"$@"
+		;;
+	esac
+}
+
 move_to_original_branch () {
 	case "$head_name" in
 	refs/*)
@@ -95,7 +109,7 @@ run_specific_rebase () {
 	force_rebase action preserve_merges upstream switch_to head_name \
 	state_dir orig_head onto_name GIT_QUIET revisions RESOLVEMSG \
 	allow_rerere_autoupdate git_am_opt
-	export -f move_to_original_branch
+	export -f move_to_original_branch output
 	exec git-rebase--$type
 }
 
@@ -268,7 +282,7 @@ continue)
 	run_specific_rebase
 	;;
 skip)
-	git reset --hard HEAD || exit $?
+	output git reset --hard HEAD || exit $?
 	read_basic_state
 	run_specific_rebase
 	;;
@@ -281,7 +295,7 @@ abort)
 		die "Could not move back to $head_name"
 		;;
 	esac
-	git reset --hard $orig_head
+	output git reset --hard $orig_head
 	rm -r "$state_dir"
 	exit
 	;;
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 23/31] rebase: factor out sub command handling
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (21 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 22/31] rebase: make -v a tiny bit more verbose Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 24/31] rebase: extract code for writing basic state Martin von Zweigbergk
                   ` (9 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Factor out the common parts of the handling of the sub commands
'--continue', '--skip' and '--abort'. The '--abort' handling can
handled completely in git-rebase.sh.

After this refactoring, the calls to git-rebase--am.sh,
git-rebase--merge.sh and git-rebase--interactive.sh will be better
aligned. There will only be one call to interactive rebase that will
shortcut the very last part of git-rebase.sh.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |   34 +++-------------------------------
 git-rebase.sh              |   17 +++++++++++++++--
 2 files changed, 18 insertions(+), 33 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index acd0258..1079994 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -509,9 +509,7 @@ do_next () {
 	test -s "$TODO" && return
 
 	comment_for_reflog finish &&
-	head_name=$(cat "$state_dir"/head-name) &&
-	orig_head=$(cat "$state_dir"/head) &&
-	SHORTONTO=$(git rev-parse --short $(cat "$state_dir"/onto)) &&
+	SHORTONTO=$(git rev-parse --short $onto) &&
 	NEWHEAD=$(git rev-parse HEAD) &&
 	case $head_name in
 	refs/*)
@@ -521,7 +519,7 @@ do_next () {
 		;;
 	esac && {
 		test ! -f "$state_dir"/verbose ||
-			git diff-tree --stat $(cat "$state_dir"/head)..HEAD
+			git diff-tree --stat $orig_head..HEAD
 	} &&
 	{
 		test -s "$REWRITTEN_LIST" &&
@@ -655,14 +653,6 @@ rearrange_squash () {
 case "$action" in
 continue)
 	get_saved_options
-	comment_for_reflog continue
-
-	# Sanity check
-	git rev-parse --verify HEAD >/dev/null ||
-		die "Cannot read HEAD"
-	git update-index --ignore-submodules --refresh &&
-		git diff-files --quiet --ignore-submodules ||
-		die "Working tree is dirty"
 
 	# do we have anything to commit?
 	if git diff-index --cached --quiet --ignore-submodules HEAD --
@@ -693,30 +683,12 @@ first and then run 'git rebase --continue' again."
 	require_clean_work_tree "rebase"
 	do_rest
 	;;
-abort)
-	get_saved_options
-	comment_for_reflog abort
-
-	git rerere clear
-
-	head_name=$(cat "$state_dir"/head-name)
-	orig_head=$(cat "$state_dir"/head)
-	case $head_name in
-	refs/*)
-		git symbolic-ref HEAD $head_name
-		;;
-	esac &&
-	output git reset --hard $orig_head &&
-	rm -rf "$state_dir"
-	exit
-	;;
 skip)
 	get_saved_options
-	comment_for_reflog skip
 
 	git rerere clear
 
-	output git reset --hard && do_rest
+	do_rest
 	;;
 esac
 
diff --git a/git-rebase.sh b/git-rebase.sh
index 0322f27..7e2e978 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -70,7 +70,12 @@ test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
 read_basic_state () {
 	head_name=$(cat "$state_dir"/head-name) &&
 	onto=$(cat "$state_dir"/onto) &&
-	orig_head=$(cat "$state_dir"/orig-head) &&
+	if test "$type" = interactive
+	then
+		orig_head=$(cat "$state_dir"/head)
+	else
+		orig_head=$(cat "$state_dir"/orig-head)
+	fi &&
 	GIT_QUIET=$(cat "$state_dir"/quiet)
 }
 
@@ -267,11 +272,19 @@ test $# -gt 2 && usage
 if test -n "$action"
 then
 	test -z "$in_progress" && die "No rebase in progress?"
-	test "$type" = interactive && run_specific_rebase
+	# Only interactive rebase uses detailed reflog messages
+	if test "$type" = interactive && test "$GIT_REFLOG_ACTION" = rebase
+	then
+		GIT_REFLOG_ACTION="rebase -i ($action)"
+		export GIT_REFLOG_ACTION
+	fi
 fi
 
 case "$action" in
 continue)
+	# Sanity check
+	git rev-parse --verify HEAD >/dev/null ||
+		die "Cannot read HEAD"
 	git update-index --ignore-submodules --refresh &&
 	git diff-files --quiet --ignore-submodules || {
 		echo "You must edit all merge conflicts and then"
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 24/31] rebase: extract code for writing basic state
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (22 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 23/31] rebase: factor out sub command handling Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2011-01-04 19:19   ` Thomas Rast
  2010-12-28  9:30 ` [PATCH 25/31] rebase: remember verbose option Martin von Zweigbergk
                   ` (8 subsequent siblings)
  32 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Extrace the code for writing the state to rebase-apply/ or
rebase-merge/ when a rebase is initiated. This will make it easier to
later make both interactive and non-interactive rebase remember the
options used.

Note that non-interactive rebase stores the sha1 of the original head
in a file called orig-head, while interactive rebase stores it in a
file called head.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--am.sh          |    6 +-----
 git-rebase--interactive.sh |    5 +----
 git-rebase--merge.sh       |    5 +----
 git-rebase.sh              |   16 ++++++++++++++--
 4 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/git-rebase--am.sh b/git-rebase--am.sh
index 9316761..5acfa00 100644
--- a/git-rebase--am.sh
+++ b/git-rebase--am.sh
@@ -26,9 +26,5 @@ git format-patch -k --stdout --full-index --ignore-if-in-upstream \
 git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
 move_to_original_branch
 ret=$?
-test 0 != $ret -a -d "$state_dir" &&
-	echo $head_name > "$state_dir/head-name" &&
-	echo $onto > "$state_dir/onto" &&
-	echo $orig_head > "$state_dir/orig-head" &&
-	echo "$GIT_QUIET" > "$state_dir/quiet"
+test 0 != $ret -a -d "$state_dir" && write_basic_state
 exit $ret
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 1079994..a33b246 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -707,16 +707,13 @@ orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
 mkdir "$state_dir" || die "Could not create temporary $state_dir"
 
 : > "$state_dir"/interactive || die "Could not mark as interactive"
-echo "$head_name" > "$state_dir"/head-name
-
-echo $orig_head > "$state_dir"/head
+write_basic_state
 case "$rebase_root" in
 '')
 	rm -f "$state_dir"/rebase-root ;;
 *)
 	: >"$state_dir"/rebase-root ;;
 esac
-echo $onto > "$state_dir"/onto
 test -z "$strategy" || echo "$strategy" > "$state_dir"/strategy
 test t = "$verbose" && : > "$state_dir"/verbose
 if test t = "$preserve_merges"
diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
index 8cfdcf1..705d2f5 100644
--- a/git-rebase--merge.sh
+++ b/git-rebase--merge.sh
@@ -127,10 +127,7 @@ esac
 
 mkdir -p "$state_dir"
 echo "$onto_name" > "$state_dir/onto_name"
-echo "$head_name" > "$state_dir/head-name"
-echo "$onto" > "$state_dir/onto"
-echo "$orig_head" > "$state_dir/orig-head"
-echo "$GIT_QUIET" > "$state_dir/quiet"
+write_basic_state
 
 msgnum=0
 for cmt in `git rev-list --reverse --no-merges "$revisions"`
diff --git a/git-rebase.sh b/git-rebase.sh
index 7e2e978..95c0d05 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -79,6 +79,18 @@ read_basic_state () {
 	GIT_QUIET=$(cat "$state_dir"/quiet)
 }
 
+write_basic_state () {
+	echo "$head_name" > "$state_dir"/head-name &&
+	echo "$onto" > "$state_dir"/onto &&
+	if test "$type" = interactive
+	then
+		echo "$orig_head" > "$state_dir"/head
+	else
+		echo "$orig_head" > "$state_dir"/orig-head
+	fi &&
+	echo "$GIT_QUIET" > "$state_dir"/quiet
+}
+
 output () {
 	case "$verbose" in
 	'')
@@ -113,8 +125,8 @@ run_specific_rebase () {
 	export onto autosquash strategy strategy_opts verbose rebase_root \
 	force_rebase action preserve_merges upstream switch_to head_name \
 	state_dir orig_head onto_name GIT_QUIET revisions RESOLVEMSG \
-	allow_rerere_autoupdate git_am_opt
-	export -f move_to_original_branch output
+	allow_rerere_autoupdate git_am_opt type
+	export -f move_to_original_branch output write_basic_state
 	exec git-rebase--$type
 }
 
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 25/31] rebase: remember verbose option
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (23 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 24/31] rebase: extract code for writing basic state Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 26/31] rebase: remember strategy and strategy options Martin von Zweigbergk
                   ` (7 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Currently, only interactive rebase remembers the value of the '-v'
flag from the initial invocation. Make non-interactive rebase also
remember it.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |    2 --
 git-rebase.sh              |    6 ++++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index a33b246..7809932 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -585,7 +585,6 @@ skip_unnecessary_picks () {
 get_saved_options () {
 	test -d "$REWRITTEN" && preserve_merges=t
 	test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
-	test -f "$state_dir"/verbose && verbose=t
 	test -f "$state_dir"/rebase-root && rebase_root=t
 }
 
@@ -715,7 +714,6 @@ case "$rebase_root" in
 	: >"$state_dir"/rebase-root ;;
 esac
 test -z "$strategy" || echo "$strategy" > "$state_dir"/strategy
-test t = "$verbose" && : > "$state_dir"/verbose
 if test t = "$preserve_merges"
 then
 	if test -z "$rebase_root"
diff --git a/git-rebase.sh b/git-rebase.sh
index 95c0d05..e5be7e5 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -76,7 +76,8 @@ read_basic_state () {
 	else
 		orig_head=$(cat "$state_dir"/orig-head)
 	fi &&
-	GIT_QUIET=$(cat "$state_dir"/quiet)
+	GIT_QUIET=$(cat "$state_dir"/quiet) &&
+	test -f "$state_dir"/verbose && verbose=t
 }
 
 write_basic_state () {
@@ -88,7 +89,8 @@ write_basic_state () {
 	else
 		echo "$orig_head" > "$state_dir"/orig-head
 	fi &&
-	echo "$GIT_QUIET" > "$state_dir"/quiet
+	echo "$GIT_QUIET" > "$state_dir"/quiet &&
+	test t = "$verbose" && : > "$state_dir"/verbose
 }
 
 output () {
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 26/31] rebase: remember strategy and strategy options
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (24 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 25/31] rebase: remember verbose option Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2011-01-04 19:27   ` Thomas Rast
  2010-12-28  9:30 ` [PATCH 27/31] rebase -m: remember allow_rerere_autoupdate option Martin von Zweigbergk
                   ` (6 subsequent siblings)
  32 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

When a rebase is resumed, interactive rebase remembers any merge
strategy passed when the rebase was initated. Make non-interactive
rebase remember any merge strategy as well. Also make non-interactive
rebase remember any merge strategy options.

To be able to resume a rebase that was initiated with an older version
of git (older than this commit), make sure not to expect the saved
option files to exist.

Test case idea taken from Junio's 71fc224 (t3402: test "rebase
-s<strategy> -X<opt>", 2010-11-11).

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

How to add support for strategy options to interactive rebase?

 git-rebase--interactive.sh |    2 --
 git-rebase.sh              |    6 ++++++
 t/t3418-rebase-continue.sh |   29 +++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 7809932..0763ef5 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -584,7 +584,6 @@ skip_unnecessary_picks () {
 
 get_saved_options () {
 	test -d "$REWRITTEN" && preserve_merges=t
-	test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
 	test -f "$state_dir"/rebase-root && rebase_root=t
 }
 
@@ -713,7 +712,6 @@ case "$rebase_root" in
 *)
 	: >"$state_dir"/rebase-root ;;
 esac
-test -z "$strategy" || echo "$strategy" > "$state_dir"/strategy
 if test t = "$preserve_merges"
 then
 	if test -z "$rebase_root"
diff --git a/git-rebase.sh b/git-rebase.sh
index e5be7e5..d192038 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -78,6 +78,9 @@ read_basic_state () {
 	fi &&
 	GIT_QUIET=$(cat "$state_dir"/quiet) &&
 	test -f "$state_dir"/verbose && verbose=t
+	test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
+	test -f "$state_dir"/strategy_opts &&
+		strategy_opts="$(cat "$state_dir"/strategy_opts)"
 }
 
 write_basic_state () {
@@ -91,6 +94,9 @@ write_basic_state () {
 	fi &&
 	echo "$GIT_QUIET" > "$state_dir"/quiet &&
 	test t = "$verbose" && : > "$state_dir"/verbose
+	test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
+	test -n "$strategy_opts" && echo "$strategy_opts" > \
+		"$state_dir"/strategy_opts
 }
 
 output () {
diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh
index 1d90191..5469546 100755
--- a/t/t3418-rebase-continue.sh
+++ b/t/t3418-rebase-continue.sh
@@ -45,4 +45,33 @@ test_expect_success 'rebase --continue can not be used with other options' '
 	test_must_fail git rebase --continue -v
 '
 
+test_expect_success 'rebase --continue remembers merge strategy and options' '
+	rm -fr .git/rebase-* &&
+	git reset --hard commit-new-file-F2-on-topic-branch &&
+	test_commit "commit-new-file-F3-on-topic-branch" F3 32 &&
+	test_when_finished "rm -fr test-bin funny.was.run" &&
+	mkdir test-bin &&
+	cat >test-bin/git-merge-funny <<-EOF
+	#!$SHELL_PATH
+	case "\$1" in --opt) ;; *) exit 2 ;; esac
+	shift &&
+	>funny.was.run &&
+	exec git merge-recursive "\$@"
+	EOF
+	chmod +x test-bin/git-merge-funny &&
+	(
+		PATH=./test-bin:$PATH
+		test_must_fail git rebase -s funny -Xopt master topic
+	) &&
+	test -f funny.was.run &&
+	rm funny.was.run &&
+	echo "Resolved" >F2 &&
+	git add F2 &&
+	(
+		PATH=./test-bin:$PATH
+		git rebase --continue
+	) &&
+	test -f funny.was.run
+'
+
 test_done
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 27/31] rebase -m: remember allow_rerere_autoupdate option
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (25 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 26/31] rebase: remember strategy and strategy options Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 28/31] rebase -m: don't print exit code 2 when merge fails Martin von Zweigbergk
                   ` (5 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

If '--[no-]allow_rerere_autoupdate' is passed when 'git rebase -m' is
called and a merge conflict occurs, the flag will be forgotten for the
rest of the rebase process. Make rebase remember it by saving the
value.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

allow_rerere_autoupdate is only used by git-rebase--merge. Still ok to
write and read it here?

Should allow_rerere_autoupdate also be added to git_am_opt?

 git-rebase.sh              |    4 ++++
 t/t3418-rebase-continue.sh |   21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index d192038..05b4fe1 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -81,6 +81,8 @@ read_basic_state () {
 	test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
 	test -f "$state_dir"/strategy_opts &&
 		strategy_opts="$(cat "$state_dir"/strategy_opts)"
+	test -f "$state_dir"/allow_rerere_autoupdate &&
+		allow_rerere_autoupdate="$(cat "$state_dir"/allow_rerere_autoupdate)"
 }
 
 write_basic_state () {
@@ -97,6 +99,8 @@ write_basic_state () {
 	test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
 	test -n "$strategy_opts" && echo "$strategy_opts" > \
 		"$state_dir"/strategy_opts
+	test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \
+		"$state_dir"/allow_rerere_autoupdate
 }
 
 output () {
diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh
index 5469546..1e855cd 100755
--- a/t/t3418-rebase-continue.sh
+++ b/t/t3418-rebase-continue.sh
@@ -74,4 +74,25 @@ test_expect_success 'rebase --continue remembers merge strategy and options' '
 	test -f funny.was.run
 '
 
+test_expect_success 'rebase --continue remembers --rerere-autoupdate' '
+	rm -fr .git/rebase-* &&
+	git reset --hard commit-new-file-F3-on-topic-branch &&
+	git checkout master
+	test_commit "commit-new-file-F3" F3 3 &&
+	git config rerere.enabled true &&
+	test_must_fail git rebase -m master topic &&
+	echo "Resolved" >F2 &&
+	git add F2 &&
+	test_must_fail git rebase --continue &&
+	echo "Resolved" >F3 &&
+	git add F3 &&
+	git rebase --continue &&
+	git reset --hard topic@{1} &&
+	test_must_fail git rebase -m --rerere-autoupdate master &&
+	test "$(cat F2)" = "Resolved" &&
+	test_must_fail git rebase --continue &&
+	test "$(cat F3)" = "Resolved" &&
+	git rebase --continue
+'
+
 test_done
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 28/31] rebase -m: don't print exit code 2 when merge fails
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (26 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 27/31] rebase -m: remember allow_rerere_autoupdate option Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 29/31] git-rebase--am: remove unnecessary --3way option Martin von Zweigbergk
                   ` (4 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

When the merge strategy fails, a message suggesting the user to try
another strategy is displayed. Remove the "$rv" (which is always equal
to "2" in this case) from that message.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--merge.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
index 705d2f5..4ea3ca7 100644
--- a/git-rebase--merge.sh
+++ b/git-rebase--merge.sh
@@ -78,7 +78,7 @@ call_merge () {
 		die "$RESOLVEMSG"
 		;;
 	2)
-		echo "Strategy: $rv $strategy failed, try another" 1>&2
+		echo "Strategy: $strategy failed, try another" 1>&2
 		die "$RESOLVEMSG"
 		;;
 	*)
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 29/31] git-rebase--am: remove unnecessary --3way option
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (27 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 28/31] rebase -m: don't print exit code 2 when merge fails Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 30/31] rebase -i: don't read unused variable preserve_merges Martin von Zweigbergk
                   ` (3 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Since 22db240 (git-am: propagate --3way options as well, 2008-12-04),
the --3way has been propageted across failure, so it is since
pointless to pass it to git-am when resuming.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--am.sh |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/git-rebase--am.sh b/git-rebase--am.sh
index 5acfa00..95608c6 100644
--- a/git-rebase--am.sh
+++ b/git-rebase--am.sh
@@ -7,12 +7,12 @@
 
 case "$action" in
 continue)
-	git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
+	git am --resolved --resolvemsg="$RESOLVEMSG" &&
 	move_to_original_branch
 	exit
 	;;
 skip)
-	git am --skip -3 --resolvemsg="$RESOLVEMSG" &&
+	git am --skip --resolvemsg="$RESOLVEMSG" &&
 	move_to_original_branch
 	exit
 	;;
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 30/31] rebase -i: don't read unused variable preserve_merges
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (28 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 29/31] git-rebase--am: remove unnecessary --3way option Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28  9:30 ` [PATCH 31/31] rebase -i: remove unnecessary state rebase-root Martin von Zweigbergk
                   ` (2 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk

Since 8e4a91b (rebase -i: remember the settings of -v, -s and -p when
interrupted, 2007-07-08), the variable preserve_merges (then called
PRESERVE_MERGES) was detected from the state saved in
$GIT_DIR/rebase-merge in order to be used when the rebase resumed, but
its value was never actually used. The variable's value was only used
when the rebase was initated.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 0763ef5..d20a9b2 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -583,7 +583,6 @@ skip_unnecessary_picks () {
 }
 
 get_saved_options () {
-	test -d "$REWRITTEN" && preserve_merges=t
 	test -f "$state_dir"/rebase-root && rebase_root=t
 }
 
@@ -650,8 +649,6 @@ rearrange_squash () {
 
 case "$action" in
 continue)
-	get_saved_options
-
 	# do we have anything to commit?
 	if git diff-index --cached --quiet --ignore-submodules HEAD --
 	then
@@ -682,8 +679,6 @@ first and then run 'git rebase --continue' again."
 	do_rest
 	;;
 skip)
-	get_saved_options
-
 	git rerere clear
 
 	do_rest
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH 31/31] rebase -i: remove unnecessary state rebase-root
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (29 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 30/31] rebase -i: don't read unused variable preserve_merges Martin von Zweigbergk
@ 2010-12-28  9:30 ` Martin von Zweigbergk
  2010-12-28 16:40   ` Thomas Rast
  2011-01-04 19:57 ` [PATCH 00/31] Refactor rebase Thomas Rast
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
  32 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28  9:30 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Martin von Zweigbergk, Thomas Rast

Before calling 'git cherry-pick', interactive rebase currently checks
if we are rebasing from root (if --root was passed). If we are, the
'--ff' flag to 'git cherry-pick' is omitted. However, according to the
documentation for 'git cherry-pick --ff', "If the current HEAD is the
same as the parent of the cherry-picked commit, then a fast forward to
this commit will be performed.". This should never be the case when
rebasing from root, so it should not matter whether --ff is passed, so
simplify the code by removing the condition.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

While factoring out the state writing code a few patches back, I went
through each of the pieces of state that was written. I was a bit
hesitant to include this patch since I'm not quite sure why the code
was introduced, but I thought I would include it anyway to hear what
you have to say.

There used to be bug when using --ff when rebasing a root commit. This
was fixed in 6355e50 (builtin/revert.c: don't dereference a NULL
pointer, 2010-09-27). Could this have been the reason for the check?
Thomas, do you remember?

 git-rebase--interactive.sh |   15 ---------------
 1 files changed, 0 insertions(+), 15 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index d20a9b2..a9f44d8 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -168,11 +168,6 @@ pick_one () {
 	output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
 	test -d "$REWRITTEN" &&
 		pick_one_preserving_merges "$@" && return
-	if test -n "$rebase_root"
-	then
-		output git cherry-pick "$@"
-		return
-	fi
 	output git cherry-pick $ff "$@"
 }
 
@@ -582,10 +577,6 @@ skip_unnecessary_picks () {
 	die "Could not skip unnecessary pick commands"
 }
 
-get_saved_options () {
-	test -f "$state_dir"/rebase-root && rebase_root=t
-}
-
 # Rearrange the todo list that has both "pick sha1 msg" and
 # "pick sha1 fixup!/squash! msg" appears in it so that the latter
 # comes immediately after the former, and change "pick" to
@@ -701,12 +692,6 @@ mkdir "$state_dir" || die "Could not create temporary $state_dir"
 
 : > "$state_dir"/interactive || die "Could not mark as interactive"
 write_basic_state
-case "$rebase_root" in
-'')
-	rm -f "$state_dir"/rebase-root ;;
-*)
-	: >"$state_dir"/rebase-root ;;
-esac
 if test t = "$preserve_merges"
 then
 	if test -z "$rebase_root"
-- 
1.7.3.2.864.gbbb96

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* Re: [PATCH 16/31] rebase -i: support --stat
  2010-12-28 17:59   ` Johannes Schindelin
@ 2010-12-28 13:24     ` Martin von Zweigbergk
  2010-12-28 23:36     ` Junio C Hamano
  1 sibling, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28 13:24 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Martin von Zweigbergk, git, Junio C Hamano, Johannes Sixt,
	Christian Couder

On Tue, 28 Dec 2010, Johannes Schindelin wrote:

> Hi,
> 
> On Tue, 28 Dec 2010, Martin von Zweigbergk wrote:
> 
> > diff --git a/git-rebase.sh b/git-rebase.sh
> > index 229e8d2..0fc580a 100755
> 
> Hmpf... After a rebasing merge to junio/next:
> 
> -- snip --
> [...]
> Applying: rebase -i: support --stat
> fatal: sha1 information is lacking or useless (git-rebase.sh).
> Repository lacks necessary blobs to fall back on 3-way merge.
> Cannot fall back to three-way merge.
> [...]
> -- snap --
> 
> Is this supposed to apply on top of junio/master, junio/next, junio/maint?

It is supposed to apply on top of junio/master. I tried exporting the
recevied emails using Alpine. This is the first time I do this, but I
managed to export them to one big file. I then applied it using 'git
am' onto a new branch created from junio/master and it was
successful. I'm very surprised that patch 16 failed for you if the
first 15 patches applied correctly.

I'm not sure what to use the hashes in the beginning of your mail for,
but I have verified that they match the hashes of git-rebase.sh before
and after patch 16 (in both my original branch and in the temporary
branch where I ran 'git am' on my own emails).


Regards,
Martin

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 31/31] rebase -i: remove unnecessary state rebase-root
  2010-12-28  9:30 ` [PATCH 31/31] rebase -i: remove unnecessary state rebase-root Martin von Zweigbergk
@ 2010-12-28 16:40   ` Thomas Rast
  2010-12-29 22:31     ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Thomas Rast @ 2010-12-28 16:40 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder

Martin von Zweigbergk wrote:
> @@ -168,11 +168,6 @@ pick_one () {
>  	output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
>  	test -d "$REWRITTEN" &&
>  		pick_one_preserving_merges "$@" && return
> -	if test -n "$rebase_root"
> -	then
> -		output git cherry-pick "$@"
> -		return
> -	fi
>  	output git cherry-pick $ff "$@"
>  }
[...]
> While factoring out the state writing code a few patches back, I went
> through each of the pieces of state that was written. I was a bit
> hesitant to include this patch since I'm not quite sure why the code
> was introduced, but I thought I would include it anyway to hear what
> you have to say.
> 
> There used to be bug when using --ff when rebasing a root commit. This
> was fixed in 6355e50 (builtin/revert.c: don't dereference a NULL
> pointer, 2010-09-27). Could this have been the reason for the check?
> Thomas, do you remember?

I think this just ended up being such a strange test because of the
following hunk in 8e75abf (rebase -i: use new --ff cherry-pick option,
2010-03-06):

@@ -232,16 +232,7 @@ pick_one () {
                output git cherry-pick "$@"
                return
        fi
-       parent_sha1=$(git rev-parse --verify $sha1^) ||
-               die "Could not get the parent of $sha1"
-       current_sha1=$(git rev-parse --verify HEAD)
-       if test -z "$no_ff" && test "$current_sha1" = "$parent_sha1"
-       then
-               output git reset --hard $sha1
-               output warn Fast-forward to $(git rev-parse --short $sha1)
-       else
-               output git cherry-pick "$@"
-       fi
+       output git cherry-pick $ff "$@"
 }
-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 16/31] rebase -i: support --stat
  2010-12-28  9:30 ` [PATCH 16/31] rebase -i: support --stat Martin von Zweigbergk
@ 2010-12-28 17:59   ` Johannes Schindelin
  2010-12-28 13:24     ` Martin von Zweigbergk
  2010-12-28 23:36     ` Junio C Hamano
  0 siblings, 2 replies; 118+ messages in thread
From: Johannes Schindelin @ 2010-12-28 17:59 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Junio C Hamano, Johannes Sixt, Christian Couder

Hi,

On Tue, 28 Dec 2010, Martin von Zweigbergk wrote:

> diff --git a/git-rebase.sh b/git-rebase.sh
> index 229e8d2..0fc580a 100755

Hmpf... After a rebasing merge to junio/next:

-- snip --
[...]
Applying: rebase -i: support --stat
fatal: sha1 information is lacking or useless (git-rebase.sh).
Repository lacks necessary blobs to fall back on 3-way merge.
Cannot fall back to three-way merge.
[...]
-- snap --

Is this supposed to apply on top of junio/master, junio/next, junio/maint?

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 05/31] rebase: improve detection of rebase in progress
  2010-12-28 23:08   ` Junio C Hamano
@ 2010-12-28 20:35     ` Martin von Zweigbergk
  2011-01-12 10:20       ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28 20:35 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Martin von Zweigbergk, git, Johannes Schindelin, Johannes Sixt,
	Christian Couder


On Tue, 28 Dec 2010, Junio C Hamano wrote:

> Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:
> 
> > Currently, the existence of rebase-merge/ is tested with 'test -d',
> > while the existence of rebase-apply/ is tested by creating the
> > directory and then deleting it again. Any good reason for this?
> 
> I don't recall how the merge side reached the current shape of the code,
> but I think the rebase-apply one was that we wanted to make sure not only
> we don't have a directory but also we actually _can_ create one.  If
> somebody had a bad permission set, "test -d" wouldn't help us much.  We
> would fail later and error diagnosis codepath should do the right thing
> anyway, so it is not a correctness issue, but is more about attempting to
> notice an error early rather than late.

Yeah, I was wondering if that might have been the reason. Why would
anyone set such permissions on .git (keep in mind that I am no
Linux/Unix expert)?

I saw that the code was introduced [1] when the directory was called
.dotest and I believe this directory was created at the top level
(i.e. a sibling to .git). Could it be that it was reasonable for the
user to set such permissions back then (on the top level dir), but not
any longer (on the .git dir)?


Either way, if it is good to have the that check for rebase-apply/,
wouldn't it be good to have for rebase-merge/ as well?

/Martin


[1] 7f4bd5d (rebase: one safety net, one bugfix and one optimization.,
2005-11-28)

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 01/31] rebase: clearer names for directory variables
  2010-12-28 23:08   ` Junio C Hamano
@ 2010-12-28 20:53     ` Martin von Zweigbergk
  0 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-28 20:53 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Martin von Zweigbergk, git, Johannes Schindelin, Johannes Sixt,
	Christian Couder


On Tue, 28 Dec 2010, Junio C Hamano wrote:

> If this were just "s/dotest/merge_dir/g" and the same for rebase-apply, I
> would have to say it is long overdue ;-)


Yes, that should be all!

Well, to be precise, in the "@@ -560,35 +561,35 @@ then" hunk, I also
moved the quotes to contain the file name as was done for
rebase-merge. I redid the search/replace just to double check.

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 05/31] rebase: improve detection of rebase in progress
  2010-12-28  9:30 ` [PATCH 05/31] rebase: improve detection of rebase in progress Martin von Zweigbergk
@ 2010-12-28 23:08   ` Junio C Hamano
  2010-12-28 20:35     ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Junio C Hamano @ 2010-12-28 23:08 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Johannes Schindelin, Johannes Sixt, Christian Couder

Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:

> Currently, the existence of rebase-merge/ is tested with 'test -d',
> while the existence of rebase-apply/ is tested by creating the
> directory and then deleting it again. Any good reason for this?

I don't recall how the merge side reached the current shape of the code,
but I think the rebase-apply one was that we wanted to make sure not only
we don't have a directory but also we actually _can_ create one.  If
somebody had a bad permission set, "test -d" wouldn't help us much.  We
would fail later and error diagnosis codepath should do the right thing
anyway, so it is not a correctness issue, but is more about attempting to
notice an error early rather than late.

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 02/31] rebase: refactor reading of state
  2010-12-28  9:30 ` [PATCH 02/31] rebase: refactor reading of state Martin von Zweigbergk
@ 2010-12-28 23:08   ` Junio C Hamano
  2010-12-29  8:09     ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Junio C Hamano @ 2010-12-28 23:08 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Johannes Schindelin, Johannes Sixt, Christian Couder

Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:

> +read_state () {
> +	if test -d "$merge_dir"
> +	then
> +		state_dir="$merge_dir"
> +		prev_head=$(cat "$merge_dir"/prev_head) &&
> +		end=$(cat "$merge_dir"/end) &&
> +		msgnum=$(cat "$merge_dir"/msgnum)
> +	else
> +		state_dir="$apply_dir"
> +	fi &&
> +	head_name=$(cat "$state_dir"/head-name) &&
> +	onto=$(cat "$state_dir"/onto) &&
> +	orig_head=$(cat "$state_dir"/orig-head) &&
> +	GIT_QUIET=$(cat "$state_dir"/quiet)
> +}
> +
>  continue_merge () {
>  	test -n "$prev_head" || die "prev_head must be defined"
>  	test -d "$merge_dir" || die "$merge_dir directory does not exist"
> @@ -138,10 +154,6 @@ call_merge () {
>  }
>  
>  move_to_original_branch () {
> -	test -z "$head_name" &&
> -		head_name="$(cat "$merge_dir"/head-name)" &&
> -		onto="$(cat "$merge_dir"/onto)" &&
> -		orig_head="$(cat "$merge_dir"/orig-head)"

It used to be safe to call this without head_name and friends set, because
the function took care of reading these itself.  Nobody calls this without
head_name set anymore?

I am not complaining nor suggesting to add an unnecessary "read_state"
here only to slow things down---I am making sure that you removed this
because you know it is unnecessary.

> @@ -220,13 +232,9 @@ do
>  			echo "mark them as resolved using git add"
>  			exit 1
>  		}
> +		read_state
>  		if test -d "$merge_dir"
>  		then
> -			prev_head=$(cat "$merge_dir/prev_head")
> -			end=$(cat "$merge_dir/end")
> -			msgnum=$(cat "$merge_dir/msgnum")
> -			onto=$(cat "$merge_dir/onto")
> -			GIT_QUIET=$(cat "$merge_dir/quiet")

Even though this patch may make the code shorter, it starts to read
head_name and orig_head that we previously did not open and change the
values of variables with what are read from them.  Does this change affect
the behaviour in any way (either in performance or in correctness)?

> @@ -236,10 +244,6 @@ do
>  			finish_rb_merge
>  			exit
>  		fi
> -		head_name=$(cat "$apply_dir"/head-name) &&
> -		onto=$(cat "$apply_dir"/onto) &&
> -		orig_head=$(cat "$apply_dir"/orig-head) &&
> -		GIT_QUIET=$(cat "$apply_dir"/quiet)
>  		git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
>  		move_to_original_branch

Earlier move-to-original-branch was Ok to be called without head_name, and
the old code here read from the file anyway, so it didn't matter, but now
it seems that the first check and assignment you removed from the function
may matter because this caller does not even read from head_name.  Are you
sure about this change?

> @@ -279,18 +275,15 @@ do
>  			die "No rebase in progress?"
>  
>  		git rerere clear
> -
> -		test -d "$merge_dir" || merge_dir="$apply_dir"

My heartbeat skipped when I first saw this.  Thanks to the previous
commit, it was exposed that somebody reused $dotest that was only to be
used when using merge machinery because the things left to be done in this
codepath are common between the merge and apply, which is kind of sloppy,
but that sloppiness is now gone ;-).

Are there places that read from individual files for states left after
this patch, or read_state is the only interface to get to the states?  If
the latter that would be a great news, and also would suggest that we may
want to have a corresponding write_state function (and we may even want to
make the state into a single file to reduce I/O---but that is a separate
issue that can be done at the very end of the series if it turns out to be
beneficial).

Of course it is fine if introduction of read_state is an attempt to catch
most common cases, but it would reduce chances of mistake if the coverage
were 100% (as opposed to 99.9%) hence this question.

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 01/31] rebase: clearer names for directory variables
  2010-12-28  9:30 ` [PATCH 01/31] rebase: clearer names for directory variables Martin von Zweigbergk
@ 2010-12-28 23:08   ` Junio C Hamano
  2010-12-28 20:53     ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Junio C Hamano @ 2010-12-28 23:08 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Johannes Schindelin, Johannes Sixt, Christian Couder

If this were just "s/dotest/merge_dir/g" and the same for rebase-apply, I
would have to say it is long overdue ;-)

I read the patch and didn't spot any glaring mistake, but I wasn't being
as careful as I usually am.

Thanks.

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 16/31] rebase -i: support --stat
  2010-12-28 17:59   ` Johannes Schindelin
  2010-12-28 13:24     ` Martin von Zweigbergk
@ 2010-12-28 23:36     ` Junio C Hamano
  2010-12-28 23:44       ` Johannes Schindelin
  1 sibling, 1 reply; 118+ messages in thread
From: Junio C Hamano @ 2010-12-28 23:36 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Martin von Zweigbergk, git, Johannes Sixt, Christian Couder

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> On Tue, 28 Dec 2010, Martin von Zweigbergk wrote:
>
>> diff --git a/git-rebase.sh b/git-rebase.sh
>> index 229e8d2..0fc580a 100755
>
> Hmpf... After a rebasing merge to junio/next:

The series applied cleanly near the tip of my 'master'.  I've been
preparing to push out 1.7.4-rc0 so the commit I applied the series was
probably a few commits ahead of the public 'master', but I don't think
there is anything that may conflict with or may be required for this
series to make any difference.

Please check tonight's 'pu' where the series is parked.

Thanks.

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 16/31] rebase -i: support --stat
  2010-12-28 23:36     ` Junio C Hamano
@ 2010-12-28 23:44       ` Johannes Schindelin
  0 siblings, 0 replies; 118+ messages in thread
From: Johannes Schindelin @ 2010-12-28 23:44 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Martin von Zweigbergk, git, Johannes Sixt, Christian Couder

Hi,

On Tue, 28 Dec 2010, Junio C Hamano wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > On Tue, 28 Dec 2010, Martin von Zweigbergk wrote:
> >
> >> diff --git a/git-rebase.sh b/git-rebase.sh
> >> index 229e8d2..0fc580a 100755
> >
> > Hmpf... After a rebasing merge to junio/next:
> 
> The series applied cleanly near the tip of my 'master'.

Sorry, I should have been more specific. I updated to current 'next' 
(a2bc419) of git://repo.or.cz/git.git/.

> Please check tonight's 'pu' where the series is parked.

Thanks, but unfortunately I have to tend to other things now.

Ciao,
Johannes

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 02/31] rebase: refactor reading of state
  2010-12-28 23:08   ` Junio C Hamano
@ 2010-12-29  8:09     ` Martin von Zweigbergk
  0 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-29  8:09 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Martin von Zweigbergk, git, Johannes Schindelin, Johannes Sixt,
	Christian Couder

On Tue, 28 Dec 2010, Junio C Hamano wrote:

> Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:
> 
> > +read_state () {
> > +	if test -d "$merge_dir"
> > +	then
> > +		state_dir="$merge_dir"
> > +		prev_head=$(cat "$merge_dir"/prev_head) &&
> > +		end=$(cat "$merge_dir"/end) &&
> > +		msgnum=$(cat "$merge_dir"/msgnum)
> > +	else
> > +		state_dir="$apply_dir"
> > +	fi &&
> > +	head_name=$(cat "$state_dir"/head-name) &&
> > +	onto=$(cat "$state_dir"/onto) &&
> > +	orig_head=$(cat "$state_dir"/orig-head) &&
> > +	GIT_QUIET=$(cat "$state_dir"/quiet)
> > +}
> > +
> >  continue_merge () {
> >  	test -n "$prev_head" || die "prev_head must be defined"
> >  	test -d "$merge_dir" || die "$merge_dir directory does not exist"
> > @@ -138,10 +154,6 @@ call_merge () {
> >  }
> >  
> >  move_to_original_branch () {
> > -	test -z "$head_name" &&
> > -		head_name="$(cat "$merge_dir"/head-name)" &&
> > -		onto="$(cat "$merge_dir"/onto)" &&
> > -		orig_head="$(cat "$merge_dir"/orig-head)"
> 
> It used to be safe to call this without head_name and friends set, because
> the function took care of reading these itself.  Nobody calls this without
> head_name set anymore?
> 
> I am not complaining nor suggesting to add an unnecessary "read_state"
> here only to slow things down---I am making sure that you removed this
> because you know it is unnecessary.

Correct. It used to be called without head_name set from
finish_rb_merge, which would in turn be called from the --continue and
--skip arms. onto would already have been set in these cases, but
would then be re-read.

> > @@ -220,13 +232,9 @@ do
> >  			echo "mark them as resolved using git add"
> >  			exit 1
> >  		}
> > +		read_state
> >  		if test -d "$merge_dir"
> >  		then
> > -			prev_head=$(cat "$merge_dir/prev_head")
> > -			end=$(cat "$merge_dir/end")
> > -			msgnum=$(cat "$merge_dir/msgnum")
> > -			onto=$(cat "$merge_dir/onto")
> > -			GIT_QUIET=$(cat "$merge_dir/quiet")
> 
> Even though this patch may make the code shorter, it starts to read
> head_name and orig_head that we previously did not open and change the
> values of variables with what are read from them.  Does this change affect
> the behaviour in any way (either in performance or in correctness)?

True. Previously, head_name and orig_head were lazily read only when
the rebase had been finished (in the finish_rb_merge, as I mentioned
above). Now these values are read unnecessarily when the rebase is
resumed, but a later patch fails. The am-based rebase is not affacted
by this patch as it already read head_name and orig_head eagerly.

Good point about the correctness. I looked into the correctness issue
arising if a file could not be found and I think I concluded that all
of the files would always be written (do we need to care about the
case where a user deletes e.g. .git/rebase-apply/onto?). However, I
did not think about the possibility of overwriting variables. It seems
fine, though, as neither continue_merge nor call_merge uses either of
these variables.

Regarding performance, I would say there is definitely a cost
associated with this patch. How big this cost is, though, I don't dare
to speculate. I will leave that up to the rest of you.

It should be noted that read_state is only called when a rebase is
resumed with --continue or --skip, or when it is aborted. There are no
changes to the code in the call_merge-continue_merge loop.

The performance hit is probably biggest in the --abort case, which
previously only read head_name and orig_head. It now ends up reading
_at least_ two more values.

> 
> > @@ -236,10 +244,6 @@ do
> >  			finish_rb_merge
> >  			exit
> >  		fi
> > -		head_name=$(cat "$apply_dir"/head-name) &&
> > -		onto=$(cat "$apply_dir"/onto) &&
> > -		orig_head=$(cat "$apply_dir"/orig-head) &&
> > -		GIT_QUIET=$(cat "$apply_dir"/quiet)
> >  		git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
> >  		move_to_original_branch
> 
> Earlier move-to-original-branch was Ok to be called without head_name, and
> the old code here read from the file anyway, so it didn't matter, but now
> it seems that the first check and assignment you removed from the function
> may matter because this caller does not even read from head_name.  Are you
> sure about this change?

If I understand your question correctly, then yes, it is ok, because
of the previous hunk that calls read_state. That call is made
before/outside the if block for merge-based rebase, so the variables
are already set when this code is reached.
 
> > @@ -279,18 +275,15 @@ do
> >  			die "No rebase in progress?"
> >  
> >  		git rerere clear
> > -
> > -		test -d "$merge_dir" || merge_dir="$apply_dir"
> 
> My heartbeat skipped when I first saw this.  Thanks to the previous
> commit, it was exposed that somebody reused $dotest that was only to be
> used when using merge machinery because the things left to be done in this
> codepath are common between the merge and apply, which is kind of sloppy,
> but that sloppiness is now gone ;-).
> 
> Are there places that read from individual files for states left after
> this patch, or read_state is the only interface to get to the states?  If
> the latter that would be a great news, and also would suggest that we may
> want to have a corresponding write_state function (and we may even want to
> make the state into a single file to reduce I/O---but that is a separate
> issue that can be done at the very end of the series if it turns out to be
> beneficial).

There are still a few other places where state is read, mainly in
call_merge. It reads things that vary from iteration to iteration,
such as a counter. I forgot to say in the commit message, but I tried
to extract only the code that reads the initial state.

The write_state function actually is there, but it comes pretty late,
in patch 24. I don't remember why I added it so much later. I could
possibly move it closer to the beginning of this series.
 
> Of course it is fine if introduction of read_state is an attempt to catch
> most common cases, but it would reduce chances of mistake if the coverage
> were 100% (as opposed to 99.9%) hence this question.

Do you mean if all the state was read in the read_state function? I
should say that the pieces of state that are read in read_state are
not read anywhere else. But overall, the coverage is more like 60% or
so.


Thanks for a thorough review. Many of these things should have been in
the commit message. I need to get better at writing those...


Thanks,
Martin

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 18/31] rebase: extract merge code to new source file
  2010-12-28  9:30 ` [PATCH 18/31] rebase: extract merge code to new source file Martin von Zweigbergk
@ 2010-12-29 21:31   ` Johannes Sixt
  2010-12-29 22:24     ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Johannes Sixt @ 2010-12-29 21:31 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Junio C Hamano, Johannes Schindelin, Christian Couder

On Dienstag, 28. Dezember 2010, Martin von Zweigbergk wrote:
> -run_interactive_rebase () {
> +run_specific_rebase () {
>  	if [ "$interactive_rebase" = implied ]; then
>  		GIT_EDITOR=:
>  		export GIT_EDITOR
>  	fi
>  	export onto autosquash strategy strategy_opts verbose rebase_root \
> -	force_rebase action preserve_merges upstream switch_to head_name
> -	exec git-rebase--interactive
> +	force_rebase action preserve_merges upstream switch_to head_name \
> +	state_dir orig_head onto_name GIT_QUIET revisions RESOLVEMSG \
> +	allow_rerere_autoupdate
> +	export -f move_to_original_branch

Is export -f portable?

> +	test "$type" != am && exec git-rebase--$type

I'd prefer to dispatch to the final rebase type using

	. git-rebase--$type

This way, you can avoid to export the huge list of helper variables and the 
function. (And it might be faster by a millisecond - or a few dozens on 
Windows.)

-- Hannes

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 18/31] rebase: extract merge code to new source file
  2010-12-29 21:31   ` Johannes Sixt
@ 2010-12-29 22:24     ` Martin von Zweigbergk
  2010-12-31 12:23       ` Thomas Rast
  0 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-29 22:24 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: Martin von Zweigbergk, git, Junio C Hamano, Johannes Schindelin,
	Christian Couder

On Wed, 29 Dec 2010, Johannes Sixt wrote:

> On Dienstag, 28. Dezember 2010, Martin von Zweigbergk wrote:
> > -run_interactive_rebase () {
> > +run_specific_rebase () {
> >  	if [ "$interactive_rebase" = implied ]; then
> >  		GIT_EDITOR=:
> >  		export GIT_EDITOR
> >  	fi
> >  	export onto autosquash strategy strategy_opts verbose rebase_root \
> > -	force_rebase action preserve_merges upstream switch_to head_name
> > -	exec git-rebase--interactive
> > +	force_rebase action preserve_merges upstream switch_to head_name \
> > +	state_dir orig_head onto_name GIT_QUIET revisions RESOLVEMSG \
> > +	allow_rerere_autoupdate
> > +	export -f move_to_original_branch
> 
> Is export -f portable?

It seems like it isn't. What is a good way to check?
 
> > +	test "$type" != am && exec git-rebase--$type
> 
> I'd prefer to dispatch to the final rebase type using
> 
> 	. git-rebase--$type
> 
> This way, you can avoid to export the huge list of helper variables and the 
> function. (And it might be faster by a millisecond - or a few dozens on 
> Windows.)

Makes a lot of sense. Will change. Why didn't I do that from the
beginning?


Thanks,
Martin

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 31/31] rebase -i: remove unnecessary state rebase-root
  2010-12-28 16:40   ` Thomas Rast
@ 2010-12-29 22:31     ` Martin von Zweigbergk
  2010-12-31  5:41       ` Christian Couder
  0 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-29 22:31 UTC (permalink / raw)
  To: Thomas Rast
  Cc: Martin von Zweigbergk, git, Junio C Hamano, Johannes Schindelin,
	Johannes Sixt, Christian Couder

On Tue, 28 Dec 2010, Thomas Rast wrote:

> Martin von Zweigbergk wrote:
> > @@ -168,11 +168,6 @@ pick_one () {
> >  	output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
> >  	test -d "$REWRITTEN" &&
> >  		pick_one_preserving_merges "$@" && return
> > -	if test -n "$rebase_root"
> > -	then
> > -		output git cherry-pick "$@"
> > -		return
> > -	fi
> >  	output git cherry-pick $ff "$@"
> >  }
> [...]
> > While factoring out the state writing code a few patches back, I went
> > through each of the pieces of state that was written. I was a bit
> > hesitant to include this patch since I'm not quite sure why the code
> > was introduced, but I thought I would include it anyway to hear what
> > you have to say.
> > 
> > There used to be bug when using --ff when rebasing a root commit. This
> > was fixed in 6355e50 (builtin/revert.c: don't dereference a NULL
> > pointer, 2010-09-27). Could this have been the reason for the check?
> > Thomas, do you remember?
> 
> I think this just ended up being such a strange test because of the
> following hunk in 8e75abf (rebase -i: use new --ff cherry-pick option,
> 2010-03-06):
> 
> @@ -232,16 +232,7 @@ pick_one () {
>                 output git cherry-pick "$@"
>                 return
>         fi
> -       parent_sha1=$(git rev-parse --verify $sha1^) ||
> -               die "Could not get the parent of $sha1"
> -       current_sha1=$(git rev-parse --verify HEAD)
> -       if test -z "$no_ff" && test "$current_sha1" = "$parent_sha1"
> -       then
> -               output git reset --hard $sha1
> -               output warn Fast-forward to $(git rev-parse --short $sha1)
> -       else
> -               output git cherry-pick "$@"
> -       fi
> +       output git cherry-pick $ff "$@"
>  }
> -- 

Yes, I saw that one as well, so it would probably have made more sense
to ask Christian instead (the author of 8e75abf). So do you remember,
Christian?

Anyway, thanks for your input, Thomas. That makes me feel a little
less worried about this patch.


/Martin

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 31/31] rebase -i: remove unnecessary state rebase-root
  2010-12-29 22:31     ` Martin von Zweigbergk
@ 2010-12-31  5:41       ` Christian Couder
  0 siblings, 0 replies; 118+ messages in thread
From: Christian Couder @ 2010-12-31  5:41 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: Thomas Rast, git, Junio C Hamano, Johannes Schindelin,
	Johannes Sixt, Christian Couder

Hi,

On Wed, Dec 29, 2010 at 11:31 PM, Martin von Zweigbergk
<martin.von.zweigbergk@gmail.com> wrote:
> On Tue, 28 Dec 2010, Thomas Rast wrote:
>
>> Martin von Zweigbergk wrote:
>> > @@ -168,11 +168,6 @@ pick_one () {
>> >     output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
>> >     test -d "$REWRITTEN" &&
>> >             pick_one_preserving_merges "$@" && return
>> > -   if test -n "$rebase_root"
>> > -   then
>> > -           output git cherry-pick "$@"
>> > -           return
>> > -   fi
>> >     output git cherry-pick $ff "$@"
>> >  }
>> [...]
>> > While factoring out the state writing code a few patches back, I went
>> > through each of the pieces of state that was written. I was a bit
>> > hesitant to include this patch since I'm not quite sure why the code
>> > was introduced, but I thought I would include it anyway to hear what
>> > you have to say.
>> >
>> > There used to be bug when using --ff when rebasing a root commit. This
>> > was fixed in 6355e50 (builtin/revert.c: don't dereference a NULL
>> > pointer, 2010-09-27). Could this have been the reason for the check?
>> > Thomas, do you remember?
>>
>> I think this just ended up being such a strange test because of the
>> following hunk in 8e75abf (rebase -i: use new --ff cherry-pick option,
>> 2010-03-06):
>>
>> @@ -232,16 +232,7 @@ pick_one () {
>>                 output git cherry-pick "$@"
>>                 return
>>         fi
>> -       parent_sha1=$(git rev-parse --verify $sha1^) ||
>> -               die "Could not get the parent of $sha1"
>> -       current_sha1=$(git rev-parse --verify HEAD)
>> -       if test -z "$no_ff" && test "$current_sha1" = "$parent_sha1"
>> -       then
>> -               output git reset --hard $sha1
>> -               output warn Fast-forward to $(git rev-parse --short $sha1)
>> -       else
>> -               output git cherry-pick "$@"
>> -       fi
>> +       output git cherry-pick $ff "$@"
>>  }
>> --
>
> Yes, I saw that one as well, so it would probably have made more sense
> to ask Christian instead (the author of 8e75abf). So do you remember,
> Christian?

Yeah, I must say that I did not try to understand why there was a
special case for $rebase_root above the code I was changing.
Perhaps I should have, and I would probably have sent a patch like yours...

> Anyway, thanks for your input, Thomas. That makes me feel a little
> less worried about this patch.

Yeah I think it's a good one.

Thanks,
Christian.

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 18/31] rebase: extract merge code to new source file
  2010-12-29 22:24     ` Martin von Zweigbergk
@ 2010-12-31 12:23       ` Thomas Rast
  2010-12-31 14:05         ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Thomas Rast @ 2010-12-31 12:23 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: Johannes Sixt, git, Junio C Hamano, Johannes Schindelin,
	Christian Couder

Martin von Zweigbergk wrote:
> On Wed, 29 Dec 2010, Johannes Sixt wrote:
> > 
> > Is export -f portable?
> 
> It seems like it isn't. What is a good way to check?

On my system I have POSIX docs for various commands, coming from the
'man-pages-posix' package.  Maybe your distribution has those too?
Then you can simply run 'man 1p export' for the documentation.
Anything that is documented there should be safe (except on Windows
maybe).

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 18/31] rebase: extract merge code to new source file
  2010-12-31 12:23       ` Thomas Rast
@ 2010-12-31 14:05         ` Martin von Zweigbergk
  0 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2010-12-31 14:05 UTC (permalink / raw)
  To: Thomas Rast
  Cc: Martin von Zweigbergk, Johannes Sixt, git, Junio C Hamano,
	Johannes Schindelin, Christian Couder

On Fri, 31 Dec 2010, Thomas Rast wrote:

> Martin von Zweigbergk wrote:
> > On Wed, 29 Dec 2010, Johannes Sixt wrote:
> > > 
> > > Is export -f portable?
> > 
> > It seems like it isn't. What is a good way to check?
> 
> On my system I have POSIX docs for various commands, coming from the
> 'man-pages-posix' package.  Maybe your distribution has those too?
> Then you can simply run 'man 1p export' for the documentation.
> Anything that is documented there should be safe (except on Windows
> maybe).

Thanks. I'm running Debian and I just installed the package from
non-free. Thanks for the hint on the '1p' syntax as well.


/Martin

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 08/31] rebase: align variable names
  2010-12-28  9:30 ` [PATCH 08/31] rebase: align variable names Martin von Zweigbergk
@ 2011-01-04 19:12   ` Thomas Rast
  2011-01-05  2:25     ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Thomas Rast @ 2011-01-04 19:12 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder

Martin von Zweigbergk wrote:
> Use the same names for variables that git-rebase--interactive.sh will
> soon inherit from git-rebase.sh.

AFAICS this is partly about spelling the variables in lowercase
instead of all-caps.

Wouldn't it be nicer to simply downcase *all* variables, so that the
end result has a consistent coding style?

> -# $UPSTREAM. They are not necessarily rewritten, but their children
> +# $upstream. They are not necessarily rewritten, but their children
[...]
-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 24/31] rebase: extract code for writing basic state
  2010-12-28  9:30 ` [PATCH 24/31] rebase: extract code for writing basic state Martin von Zweigbergk
@ 2011-01-04 19:19   ` Thomas Rast
  2011-01-05  2:40     ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Thomas Rast @ 2011-01-04 19:19 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder

Martin von Zweigbergk wrote:
> Note that non-interactive rebase stores the sha1 of the original head
> in a file called orig-head, while interactive rebase stores it in a
> file called head.
[...]
> +	if test "$type" = interactive
> +	then
> +		echo "$orig_head" > "$state_dir"/head
> +	else
> +		echo "$orig_head" > "$state_dir"/orig-head
> +	fi &&

Do we have to cater to the use-case where the user starts a rebase,
downgrades at a conflict, and then continues?

If not, you could read 'orig-head' first and fall back to 'head', only
writing 'orig-head' in the state saving independent of the mode.  That
would give us the chance of removing the redundancy at some point.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 26/31] rebase: remember strategy and strategy options
  2010-12-28  9:30 ` [PATCH 26/31] rebase: remember strategy and strategy options Martin von Zweigbergk
@ 2011-01-04 19:27   ` Thomas Rast
  2011-01-05  3:33     ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Thomas Rast @ 2011-01-04 19:27 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder

Martin von Zweigbergk wrote:
> How to add support for strategy options to interactive rebase?

AFAICS rebase -i currently only uses the strategy when dealing with
multiple parents, i.e., in --preserve-merges mode.  I think
git-cherry-pick needs to learn about the -s and -X options, and then
it'll be a simple matter of passing them along.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 00/31] Refactor rebase
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (30 preceding siblings ...)
  2010-12-28  9:30 ` [PATCH 31/31] rebase -i: remove unnecessary state rebase-root Martin von Zweigbergk
@ 2011-01-04 19:57 ` Thomas Rast
  2011-01-05  3:39   ` Martin von Zweigbergk
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
  32 siblings, 1 reply; 118+ messages in thread
From: Thomas Rast @ 2011-01-04 19:57 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder

Martin von Zweigbergk wrote:
> For the past two months, I have been working on refactoring the rebase
> code. See [1] for background information. I have been trying to polish
> the patch set for some time, but now I don't think I will get much
> further without your help.

Thanks a lot for undertaking this effort!  I just finished looking
through the entire series, and it all seems sane to me.  Apart from
j6t's reply I think we're mostly nit-picking or agreeing with you, and
this is the first iteration!

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 08/31] rebase: align variable names
  2011-01-04 19:12   ` Thomas Rast
@ 2011-01-05  2:25     ` Martin von Zweigbergk
  0 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-01-05  2:25 UTC (permalink / raw)
  To: Thomas Rast
  Cc: Martin von Zweigbergk, git, Junio C Hamano, Johannes Schindelin,
	Johannes Sixt, Christian Couder

On Tue, 4 Jan 2011, Thomas Rast wrote:

> Martin von Zweigbergk wrote:
> > Use the same names for variables that git-rebase--interactive.sh will
> > soon inherit from git-rebase.sh.
> 
> AFAICS this is partly about spelling the variables in lowercase
> instead of all-caps.
> 
> Wouldn't it be nicer to simply downcase *all* variables, so that the
> end result has a consistent coding style?

Yes, it would :-). I was just being conservative by trying not to
touch code that I didn't have to touch. I'll rename the remaining
variables in the next iteration.

Thanks,
Martin

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 24/31] rebase: extract code for writing basic state
  2011-01-04 19:19   ` Thomas Rast
@ 2011-01-05  2:40     ` Martin von Zweigbergk
  0 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-01-05  2:40 UTC (permalink / raw)
  To: Thomas Rast
  Cc: Martin von Zweigbergk, git, Junio C Hamano, Johannes Schindelin,
	Johannes Sixt, Christian Couder

On Tue, 4 Jan 2011, Thomas Rast wrote:

> Martin von Zweigbergk wrote:
> > Note that non-interactive rebase stores the sha1 of the original head
> > in a file called orig-head, while interactive rebase stores it in a
> > file called head.
> [...]
> > +	if test "$type" = interactive
> > +	then
> > +		echo "$orig_head" > "$state_dir"/head
> > +	else
> > +		echo "$orig_head" > "$state_dir"/orig-head
> > +	fi &&
> 
> Do we have to cater to the use-case where the user starts a rebase,
> downgrades at a conflict, and then continues?

I'll let Junio answer that.
 
> If not, you could read 'orig-head' first and fall back to 'head', only
> writing 'orig-head' in the state saving independent of the mode.  That
> would give us the chance of removing the redundancy at some point.

Makes sense. Given that the answer to the previous question is a "no",
I'll change this as well in the next iteration.


/Martin

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 26/31] rebase: remember strategy and strategy options
  2011-01-04 19:27   ` Thomas Rast
@ 2011-01-05  3:33     ` Martin von Zweigbergk
  0 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-01-05  3:33 UTC (permalink / raw)
  To: Thomas Rast
  Cc: Martin von Zweigbergk, git, Junio C Hamano, Johannes Schindelin,
	Johannes Sixt, Christian Couder

On Tue, 4 Jan 2011, Thomas Rast wrote:

> Martin von Zweigbergk wrote:
> > How to add support for strategy options to interactive rebase?
> 
> AFAICS rebase -i currently only uses the strategy when dealing with
> multiple parents, i.e., in --preserve-merges mode.  I think
> git-cherry-pick needs to learn about the -s and -X options, and then
> it'll be a simple matter of passing them along.

I just saw that Jonathan has actually implemented that support in
git-cherry-pick. It is currently in pu.

I asked just because the merge strategy is currently passed to the
call to 'git merge' in git-rebase--interactive.sh (when dealing with
multiple parents, as you said), so it seems like it would make sense
to pass any merge options there as well.

Come to think of it, doesn't the merge option when passed to 'git
rebase -i' mean something quite different compared to when it is
passed to 'git rebase -m'? For interactive rebase, the 'ours' side
refers to the upstream, but in the case of merge-based rebase, it
refers to one branch in the branch-to-be-rebased, no? In that case,
should the merge strategy even be passed to 'git merge' when dealing
with multiple parents? Is it likely that one would want to use the
same strategy for both things? Am I just not thinking straight?

Some history:

The command line option '-s' was there from the inception of
interactive rebase in 1b1dce4 (Teach rebase an interactive mode,
2007-06-25) and back then it was passed to git-cherry-pick, which just
ignored it.

Since f09c9b8 (Teach rebase -i about --preserve-merges, 2007-06-25),
the strategy has been passed to git-merge as well.

Since 2a9c53e (git-rebase--interactive.sh: Don't pass a strategy to
git-cherry-pick., 2007-10-31), the strategy has only been passed to
git-merge, because it was ignored by git-cherry-pick.


Anyway, I'll leave any changes related to this outside of the current
series.


/Martin

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 00/31] Refactor rebase
  2011-01-04 19:57 ` [PATCH 00/31] Refactor rebase Thomas Rast
@ 2011-01-05  3:39   ` Martin von Zweigbergk
  0 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-01-05  3:39 UTC (permalink / raw)
  To: Thomas Rast
  Cc: Martin von Zweigbergk, git, Junio C Hamano, Johannes Schindelin,
	Johannes Sixt, Christian Couder

On Tue, 4 Jan 2011, Thomas Rast wrote:

> Martin von Zweigbergk wrote:
> > For the past two months, I have been working on refactoring the rebase
> > code. See [1] for background information. I have been trying to polish
> > the patch set for some time, but now I don't think I will get much
> > further without your help.
> 
> Thanks a lot for undertaking this effort!  I just finished looking
> through the entire series, and it all seems sane to me.  Apart from
> j6t's reply I think we're mostly nit-picking or agreeing with you, and
> this is the first iteration!

Thanks. And thanks a lot for taking the time to review it!


/Martin

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH 05/31] rebase: improve detection of rebase in progress
  2010-12-28 20:35     ` Martin von Zweigbergk
@ 2011-01-12 10:20       ` Martin von Zweigbergk
  0 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-01-12 10:20 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Martin von Zweigbergk, git, Johannes Schindelin, Johannes Sixt,
	Christian Couder

On Tue, 28 Dec 2010, Martin von Zweigbergk wrote:

> 
> On Tue, 28 Dec 2010, Junio C Hamano wrote:
> 
> > Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:
> > 
> > > Currently, the existence of rebase-merge/ is tested with 'test -d',
> > > while the existence of rebase-apply/ is tested by creating the
> > > directory and then deleting it again. Any good reason for this?
> > 
> > I don't recall how the merge side reached the current shape of the code,
> > but I think the rebase-apply one was that we wanted to make sure not only
> > we don't have a directory but also we actually _can_ create one.  If
> > somebody had a bad permission set, "test -d" wouldn't help us much.  We
> > would fail later and error diagnosis codepath should do the right thing
> > anyway, so it is not a correctness issue, but is more about attempting to
> > notice an error early rather than late.
> 
> Yeah, I was wondering if that might have been the reason. Why would
> anyone set such permissions on .git (keep in mind that I am no
> Linux/Unix expert)?
> 
> I saw that the code was introduced [1] when the directory was called
> .dotest and I believe this directory was created at the top level
> (i.e. a sibling to .git). Could it be that it was reasonable for the
> user to set such permissions back then (on the top level dir), but not
> any longer (on the .git dir)?
> 
> 
> Either way, if it is good to have the that check for rebase-apply/,
> wouldn't it be good to have for rebase-merge/ as well?
> 
> /Martin
> 
> 
> [1] 7f4bd5d (rebase: one safety net, one bugfix and one optimization.,
> 2005-11-28)
> 

I'm working on a re-roll. Any input on this?

^ permalink raw reply	[flat|nested] 118+ messages in thread

* [PATCH v2 00/31] refactor rebase
  2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
                   ` (31 preceding siblings ...)
  2011-01-04 19:57 ` [PATCH 00/31] Refactor rebase Thomas Rast
@ 2011-02-06 18:43 ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 01/31] rebase: clearer names for directory variables Martin von Zweigbergk
                     ` (32 more replies)
  32 siblings, 33 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Changes since the first round:

As suggested by Johannes Sixt, source git-rebase--interactive.sh and
friends instead of executing them.

As suggested by Thomas Rast, downcase all variables for consitency.

Based on current master, including Jeff's two patches to rebase.

There are also a few other minor changes, but see the notes in each
patch for more information.


Martin von Zweigbergk (31):
  rebase: clearer names for directory variables
  rebase: refactor reading of state
  rebase: read state outside loop
  rebase: remove unused rebase state 'prev_head'
  rebase: improve detection of rebase in progress
  rebase: act on command line outside parsing loop
  rebase: stricter check of standalone sub command
  rebase: align variable names
  rebase: align variable content
  rebase: factor out command line option processing
  rebase -i: remove now unnecessary directory checks
  rebase: reorder validation steps
  rebase: factor out reference parsing
  rebase: factor out clean work tree check
  rebase: factor out call to pre-rebase hook
  rebase -i: support --stat
  rebase: remove $branch as synonym for $orig_head
  rebase: extract merge code to new source file
  rebase: extract am code to new source file
  rebase: show consistent conflict resolution hint
  rebase -i: align variable names
  rebase: make -v a tiny bit more verbose
  rebase: factor out sub command handling
  rebase: extract code for writing basic state
  rebase: remember verbose option
  rebase: remember strategy and strategy options
  rebase -m: remember allow_rerere_autoupdate option
  rebase -m: don't print exit code 2 when merge fails
  git-rebase--am: remove unnecessary --3way option
  rebase -i: don't read unused variable preserve_merges
  rebase -i: remove unnecessary state rebase-root

 .gitignore                 |    2 +
 Makefile                   |    2 +
 git-rebase--am.sh          |   30 ++
 git-rebase--interactive.sh |  751 +++++++++++++++----------------------------
 git-rebase--merge.sh       |  151 +++++++++
 git-rebase.sh              |  482 +++++++++++-----------------
 t/t3403-rebase-skip.sh     |    5 +
 t/t3407-rebase-abort.sh    |   10 +
 t/t3418-rebase-continue.sh |   55 ++++
 9 files changed, 707 insertions(+), 781 deletions(-)
 create mode 100644 git-rebase--am.sh
 create mode 100644 git-rebase--merge.sh

-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply	[flat|nested] 118+ messages in thread

* [PATCH v2 01/31] rebase: clearer names for directory variables
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 02/31] rebase: refactor reading of state Martin von Zweigbergk
                     ` (31 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Instead of using the old variable name 'dotest' for
"$GIT_DIR"/rebase-merge and no variable for "$GIT_DIR"/rebase-apply,
introduce two variables 'merge_dir' and 'apply_dir' for these paths.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase.sh |  141 +++++++++++++++++++++++++++++----------------------------
 1 files changed, 71 insertions(+), 70 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index cbb0ea9..72696bf 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -46,7 +46,8 @@ unset newbase
 strategy=recursive
 strategy_opts=
 do_merge=
-dotest="$GIT_DIR"/rebase-merge
+merge_dir="$GIT_DIR"/rebase-merge
+apply_dir="$GIT_DIR"/rebase-apply
 prec=4
 verbose=
 diffstat=
@@ -58,7 +59,7 @@ allow_rerere_autoupdate=
 
 continue_merge () {
 	test -n "$prev_head" || die "prev_head must be defined"
-	test -d "$dotest" || die "$dotest directory does not exist"
+	test -d "$merge_dir" || die "$merge_dir directory does not exist"
 
 	unmerged=$(git ls-files -u)
 	if test -n "$unmerged"
@@ -68,7 +69,7 @@ continue_merge () {
 		die "$RESOLVEMSG"
 	fi
 
-	cmt=`cat "$dotest/current"`
+	cmt=`cat "$merge_dir/current"`
 	if ! git diff-index --quiet --ignore-submodules HEAD --
 	then
 		if ! git commit --no-verify -C "$cmt"
@@ -81,7 +82,7 @@ continue_merge () {
 		then
 			printf "Committed: %0${prec}d " $msgnum
 		fi
-		echo "$cmt $(git rev-parse HEAD^0)" >> "$dotest/rewritten"
+		echo "$cmt $(git rev-parse HEAD^0)" >> "$merge_dir/rewritten"
 	else
 		if test -z "$GIT_QUIET"
 		then
@@ -93,22 +94,22 @@ continue_merge () {
 
 	prev_head=`git rev-parse HEAD^0`
 	# save the resulting commit so we can read-tree on it later
-	echo "$prev_head" > "$dotest/prev_head"
+	echo "$prev_head" > "$merge_dir/prev_head"
 
 	# onto the next patch:
 	msgnum=$(($msgnum + 1))
-	echo "$msgnum" >"$dotest/msgnum"
+	echo "$msgnum" >"$merge_dir/msgnum"
 }
 
 call_merge () {
-	cmt="$(cat "$dotest/cmt.$1")"
-	echo "$cmt" > "$dotest/current"
+	cmt="$(cat "$merge_dir/cmt.$1")"
+	echo "$cmt" > "$merge_dir/current"
 	hd=$(git rev-parse --verify HEAD)
 	cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
-	msgnum=$(cat "$dotest/msgnum")
-	end=$(cat "$dotest/end")
+	msgnum=$(cat "$merge_dir/msgnum")
+	end=$(cat "$merge_dir/end")
 	eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
-	eval GITHEAD_$hd='$(cat "$dotest/onto_name")'
+	eval GITHEAD_$hd='$(cat "$merge_dir/onto_name")'
 	export GITHEAD_$cmt GITHEAD_$hd
 	if test -n "$GIT_QUIET"
 	then
@@ -138,9 +139,9 @@ call_merge () {
 
 move_to_original_branch () {
 	test -z "$head_name" &&
-		head_name="$(cat "$dotest"/head-name)" &&
-		onto="$(cat "$dotest"/onto)" &&
-		orig_head="$(cat "$dotest"/orig-head)"
+		head_name="$(cat "$merge_dir"/head-name)" &&
+		onto="$(cat "$merge_dir"/onto)" &&
+		orig_head="$(cat "$merge_dir"/orig-head)"
 	case "$head_name" in
 	refs/*)
 		message="rebase finished: $head_name onto $onto"
@@ -154,12 +155,12 @@ move_to_original_branch () {
 
 finish_rb_merge () {
 	move_to_original_branch
-	git notes copy --for-rewrite=rebase < "$dotest"/rewritten
+	git notes copy --for-rewrite=rebase < "$merge_dir"/rewritten
 	if test -x "$GIT_DIR"/hooks/post-rewrite &&
-		test -s "$dotest"/rewritten; then
-		"$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
+		test -s "$merge_dir"/rewritten; then
+		"$GIT_DIR"/hooks/post-rewrite rebase < "$merge_dir"/rewritten
 	fi
-	rm -r "$dotest"
+	rm -r "$merge_dir"
 	say All done.
 }
 
@@ -183,7 +184,7 @@ is_interactive () {
 		export GIT_EDITOR
 	fi
 
-	test -n "$interactive_rebase" || test -f "$dotest"/interactive
+	test -n "$interactive_rebase" || test -f "$merge_dir"/interactive
 }
 
 run_pre_rebase_hook () {
@@ -195,7 +196,7 @@ run_pre_rebase_hook () {
 	fi
 }
 
-test -f "$GIT_DIR"/rebase-apply/applying &&
+test -f "$apply_dir"/applying &&
 	die 'It looks like git-am is in progress. Cannot rebase.'
 
 is_interactive "$@" && exec git-rebase--interactive "$@"
@@ -210,7 +211,7 @@ do
 		OK_TO_SKIP_PRE_REBASE=
 		;;
 	--continue)
-		test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply ||
+		test -d "$merge_dir" -o -d "$apply_dir" ||
 			die "No rebase in progress?"
 
 		git update-index --ignore-submodules --refresh &&
@@ -219,13 +220,13 @@ do
 			echo "mark them as resolved using git add"
 			exit 1
 		}
-		if test -d "$dotest"
+		if test -d "$merge_dir"
 		then
-			prev_head=$(cat "$dotest/prev_head")
-			end=$(cat "$dotest/end")
-			msgnum=$(cat "$dotest/msgnum")
-			onto=$(cat "$dotest/onto")
-			GIT_QUIET=$(cat "$dotest/quiet")
+			prev_head=$(cat "$merge_dir/prev_head")
+			end=$(cat "$merge_dir/end")
+			msgnum=$(cat "$merge_dir/msgnum")
+			onto=$(cat "$merge_dir/onto")
+			GIT_QUIET=$(cat "$merge_dir/quiet")
 			continue_merge
 			while test "$msgnum" -le "$end"
 			do
@@ -235,28 +236,28 @@ do
 			finish_rb_merge
 			exit
 		fi
-		head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) &&
-		onto=$(cat "$GIT_DIR"/rebase-apply/onto) &&
-		orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) &&
-		GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet)
+		head_name=$(cat "$apply_dir"/head-name) &&
+		onto=$(cat "$apply_dir"/onto) &&
+		orig_head=$(cat "$apply_dir"/orig-head) &&
+		GIT_QUIET=$(cat "$apply_dir"/quiet)
 		git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
 		move_to_original_branch
 		exit
 		;;
 	--skip)
-		test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply ||
+		test -d "$merge_dir" -o -d "$apply_dir" ||
 			die "No rebase in progress?"
 
 		git reset --hard HEAD || exit $?
-		if test -d "$dotest"
+		if test -d "$merge_dir"
 		then
 			git rerere clear
-			prev_head=$(cat "$dotest/prev_head")
-			end=$(cat "$dotest/end")
-			msgnum=$(cat "$dotest/msgnum")
+			prev_head=$(cat "$merge_dir/prev_head")
+			end=$(cat "$merge_dir/end")
+			msgnum=$(cat "$merge_dir/msgnum")
 			msgnum=$(($msgnum + 1))
-			onto=$(cat "$dotest/onto")
-			GIT_QUIET=$(cat "$dotest/quiet")
+			onto=$(cat "$merge_dir/onto")
+			GIT_QUIET=$(cat "$merge_dir/quiet")
 			while test "$msgnum" -le "$end"
 			do
 				call_merge "$msgnum"
@@ -265,31 +266,31 @@ do
 			finish_rb_merge
 			exit
 		fi
-		head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) &&
-		onto=$(cat "$GIT_DIR"/rebase-apply/onto) &&
-		orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) &&
-		GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet)
+		head_name=$(cat "$apply_dir"/head-name) &&
+		onto=$(cat "$apply_dir"/onto) &&
+		orig_head=$(cat "$apply_dir"/orig-head) &&
+		GIT_QUIET=$(cat "$apply_dir"/quiet)
 		git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
 		move_to_original_branch
 		exit
 		;;
 	--abort)
-		test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply ||
+		test -d "$merge_dir" -o -d "$apply_dir" ||
 			die "No rebase in progress?"
 
 		git rerere clear
 
-		test -d "$dotest" || dotest="$GIT_DIR"/rebase-apply
+		test -d "$merge_dir" || merge_dir="$apply_dir"
 
-		head_name="$(cat "$dotest"/head-name)" &&
+		head_name="$(cat "$merge_dir"/head-name)" &&
 		case "$head_name" in
 		refs/*)
 			git symbolic-ref HEAD $head_name ||
 			die "Could not move back to $head_name"
 			;;
 		esac
-		git reset --hard $(cat "$dotest/orig-head")
-		rm -r "$dotest"
+		git reset --hard $(cat "$merge_dir/orig-head")
+		rm -r "$merge_dir"
 		exit
 		;;
 	--onto)
@@ -388,31 +389,31 @@ test $# -gt 2 && usage
 
 if test $# -eq 0 && test -z "$rebase_root"
 then
-	test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || usage
-	test -d "$dotest" -o -f "$GIT_DIR"/rebase-apply/rebasing &&
+	test -d "$merge_dir" -o -d "$apply_dir" || usage
+	test -d "$merge_dir" -o -f "$apply_dir"/rebasing &&
 		die 'A rebase is in progress, try --continue, --skip or --abort.'
 fi
 
-# Make sure we do not have $GIT_DIR/rebase-apply
+# Make sure we do not have $apply_dir or $merge_dir
 if test -z "$do_merge"
 then
-	if mkdir "$GIT_DIR"/rebase-apply 2>/dev/null
+	if mkdir "$apply_dir" 2>/dev/null
 	then
-		rmdir "$GIT_DIR"/rebase-apply
+		rmdir "$apply_dir"
 	else
 		echo >&2 '
 It seems that I cannot create a rebase-apply directory, and
 I wonder if you are in the middle of patch application or another
 rebase.  If that is not the case, please
-	rm -fr '"$GIT_DIR"'/rebase-apply
+	rm -fr '"$apply_dir"'
 and run me again.  I am stopping in case you still have something
 valuable there.'
 		exit 1
 	fi
 else
-	if test -d "$dotest"
+	if test -d "$merge_dir"
 	then
-		die "previous rebase directory $dotest still exists." \
+		die "previous rebase directory $merge_dir still exists." \
 			'Try git rebase (--continue | --abort | --skip)'
 	fi
 fi
@@ -561,35 +562,35 @@ then
 	git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
 	move_to_original_branch
 	ret=$?
-	test 0 != $ret -a -d "$GIT_DIR"/rebase-apply &&
-		echo $head_name > "$GIT_DIR"/rebase-apply/head-name &&
-		echo $onto > "$GIT_DIR"/rebase-apply/onto &&
-		echo $orig_head > "$GIT_DIR"/rebase-apply/orig-head &&
-		echo "$GIT_QUIET" > "$GIT_DIR"/rebase-apply/quiet
+	test 0 != $ret -a -d "$apply_dir" &&
+		echo $head_name > "$apply_dir/head-name" &&
+		echo $onto > "$apply_dir/onto" &&
+		echo $orig_head > "$apply_dir/orig-head" &&
+		echo "$GIT_QUIET" > "$apply_dir/quiet"
 	exit $ret
 fi
 
 # start doing a rebase with git-merge
 # this is rename-aware if the recursive (default) strategy is used
 
-mkdir -p "$dotest"
-echo "$onto" > "$dotest/onto"
-echo "$onto_name" > "$dotest/onto_name"
+mkdir -p "$merge_dir"
+echo "$onto" > "$merge_dir/onto"
+echo "$onto_name" > "$merge_dir/onto_name"
 prev_head=$orig_head
-echo "$prev_head" > "$dotest/prev_head"
-echo "$orig_head" > "$dotest/orig-head"
-echo "$head_name" > "$dotest/head-name"
-echo "$GIT_QUIET" > "$dotest/quiet"
+echo "$prev_head" > "$merge_dir/prev_head"
+echo "$orig_head" > "$merge_dir/orig-head"
+echo "$head_name" > "$merge_dir/head-name"
+echo "$GIT_QUIET" > "$merge_dir/quiet"
 
 msgnum=0
 for cmt in `git rev-list --reverse --no-merges "$revisions"`
 do
 	msgnum=$(($msgnum + 1))
-	echo "$cmt" > "$dotest/cmt.$msgnum"
+	echo "$cmt" > "$merge_dir/cmt.$msgnum"
 done
 
-echo 1 >"$dotest/msgnum"
-echo $msgnum >"$dotest/end"
+echo 1 >"$merge_dir/msgnum"
+echo $msgnum >"$merge_dir/end"
 
 end=$msgnum
 msgnum=1
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 02/31] rebase: refactor reading of state
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 01/31] rebase: clearer names for directory variables Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 03/31] rebase: read state outside loop Martin von Zweigbergk
                     ` (30 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

The code reading the state saved in $merge_dir or $rebase_dir is
currently spread out in many places, making it harder to read and to
introduce additional state. Extract this code into one method that
reads the state. Only extract the code associated with the state that
is written when the rebase is initiated. Leave the state that changes
for each commmit, at least for now.

Currently, when resuming a merge-based rebase using --continue or
--skip, move_to_original_branch (via finish_rb_merge) will be called
without head_name and orig_head set. These variables are then lazily
read in move_to_original_branch if head_name is not set (together with
onto, which is unnecessarily read again). Change this by always
eagerly reading the state, for both am-based and merge-based rebase,
in the --continue and --skip cases. Note that this does not change the
behavior for am-based rebase, which read the state eagerly even before
this commit.

Reading the state eagerly means that part of the state will sometimes
be read unnecessarily. One example is when the rebase is continued,
but stops again at another merge conflict. Another example is when the
rebase is aborted. However, since both of these cases involve user
interaction, the delay is hopefully not noticeable. The
call_merge/continue_merge loop is not affected.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase.sh |   53 +++++++++++++++++++++++------------------------------
 1 files changed, 23 insertions(+), 30 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index 72696bf..63b5683 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -57,6 +57,22 @@ rebase_root=
 force_rebase=
 allow_rerere_autoupdate=
 
+read_state () {
+	if test -d "$merge_dir"
+	then
+		state_dir="$merge_dir"
+		prev_head=$(cat "$merge_dir"/prev_head) &&
+		end=$(cat "$merge_dir"/end) &&
+		msgnum=$(cat "$merge_dir"/msgnum)
+	else
+		state_dir="$apply_dir"
+	fi &&
+	head_name=$(cat "$state_dir"/head-name) &&
+	onto=$(cat "$state_dir"/onto) &&
+	orig_head=$(cat "$state_dir"/orig-head) &&
+	GIT_QUIET=$(cat "$state_dir"/quiet)
+}
+
 continue_merge () {
 	test -n "$prev_head" || die "prev_head must be defined"
 	test -d "$merge_dir" || die "$merge_dir directory does not exist"
@@ -138,10 +154,6 @@ call_merge () {
 }
 
 move_to_original_branch () {
-	test -z "$head_name" &&
-		head_name="$(cat "$merge_dir"/head-name)" &&
-		onto="$(cat "$merge_dir"/onto)" &&
-		orig_head="$(cat "$merge_dir"/orig-head)"
 	case "$head_name" in
 	refs/*)
 		message="rebase finished: $head_name onto $onto"
@@ -220,13 +232,9 @@ do
 			echo "mark them as resolved using git add"
 			exit 1
 		}
+		read_state
 		if test -d "$merge_dir"
 		then
-			prev_head=$(cat "$merge_dir/prev_head")
-			end=$(cat "$merge_dir/end")
-			msgnum=$(cat "$merge_dir/msgnum")
-			onto=$(cat "$merge_dir/onto")
-			GIT_QUIET=$(cat "$merge_dir/quiet")
 			continue_merge
 			while test "$msgnum" -le "$end"
 			do
@@ -236,10 +244,6 @@ do
 			finish_rb_merge
 			exit
 		fi
-		head_name=$(cat "$apply_dir"/head-name) &&
-		onto=$(cat "$apply_dir"/onto) &&
-		orig_head=$(cat "$apply_dir"/orig-head) &&
-		GIT_QUIET=$(cat "$apply_dir"/quiet)
 		git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
 		move_to_original_branch
 		exit
@@ -249,15 +253,11 @@ do
 			die "No rebase in progress?"
 
 		git reset --hard HEAD || exit $?
+		read_state
 		if test -d "$merge_dir"
 		then
 			git rerere clear
-			prev_head=$(cat "$merge_dir/prev_head")
-			end=$(cat "$merge_dir/end")
-			msgnum=$(cat "$merge_dir/msgnum")
 			msgnum=$(($msgnum + 1))
-			onto=$(cat "$merge_dir/onto")
-			GIT_QUIET=$(cat "$merge_dir/quiet")
 			while test "$msgnum" -le "$end"
 			do
 				call_merge "$msgnum"
@@ -266,10 +266,6 @@ do
 			finish_rb_merge
 			exit
 		fi
-		head_name=$(cat "$apply_dir"/head-name) &&
-		onto=$(cat "$apply_dir"/onto) &&
-		orig_head=$(cat "$apply_dir"/orig-head) &&
-		GIT_QUIET=$(cat "$apply_dir"/quiet)
 		git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
 		move_to_original_branch
 		exit
@@ -279,18 +275,15 @@ do
 			die "No rebase in progress?"
 
 		git rerere clear
-
-		test -d "$merge_dir" || merge_dir="$apply_dir"
-
-		head_name="$(cat "$merge_dir"/head-name)" &&
+		read_state
 		case "$head_name" in
 		refs/*)
 			git symbolic-ref HEAD $head_name ||
 			die "Could not move back to $head_name"
 			;;
 		esac
-		git reset --hard $(cat "$merge_dir/orig-head")
-		rm -r "$merge_dir"
+		git reset --hard $orig_head
+		rm -r "$state_dir"
 		exit
 		;;
 	--onto)
@@ -574,12 +567,12 @@ fi
 # this is rename-aware if the recursive (default) strategy is used
 
 mkdir -p "$merge_dir"
-echo "$onto" > "$merge_dir/onto"
 echo "$onto_name" > "$merge_dir/onto_name"
 prev_head=$orig_head
 echo "$prev_head" > "$merge_dir/prev_head"
-echo "$orig_head" > "$merge_dir/orig-head"
 echo "$head_name" > "$merge_dir/head-name"
+echo "$onto" > "$merge_dir/onto"
+echo "$orig_head" > "$merge_dir/orig-head"
 echo "$GIT_QUIET" > "$merge_dir/quiet"
 
 msgnum=0
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 03/31] rebase: read state outside loop
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 01/31] rebase: clearer names for directory variables Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 02/31] rebase: refactor reading of state Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 04/31] rebase: remove unused rebase state 'prev_head' Martin von Zweigbergk
                     ` (29 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

The 'onto_name' state used in 'git rebase --merge' is currently read
once for each commit that need to be applied. It doesn't change
between each iteration, however, so it should be moved out of the
loop. This also makes the code more readable. Also remove the unused
variable 'end'.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase.sh |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index 63b5683..70948bc 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -62,6 +62,7 @@ read_state () {
 	then
 		state_dir="$merge_dir"
 		prev_head=$(cat "$merge_dir"/prev_head) &&
+		onto_name=$(cat "$merge_dir"/onto_name) &&
 		end=$(cat "$merge_dir"/end) &&
 		msgnum=$(cat "$merge_dir"/msgnum)
 	else
@@ -123,9 +124,8 @@ call_merge () {
 	hd=$(git rev-parse --verify HEAD)
 	cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
 	msgnum=$(cat "$merge_dir/msgnum")
-	end=$(cat "$merge_dir/end")
 	eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
-	eval GITHEAD_$hd='$(cat "$merge_dir/onto_name")'
+	eval GITHEAD_$hd='$onto_name'
 	export GITHEAD_$cmt GITHEAD_$hd
 	if test -n "$GIT_QUIET"
 	then
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 04/31] rebase: remove unused rebase state 'prev_head'
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (2 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 03/31] rebase: read state outside loop Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 05/31] rebase: improve detection of rebase in progress Martin von Zweigbergk
                     ` (28 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

The state stored in $GIT_DIR/rebase-merge/prev_head was introduced in
58634db (rebase: Allow merge strategies to be used when rebasing,
2006-06-21), but it was never used and should therefore be removed.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase.sh |    8 --------
 1 files changed, 0 insertions(+), 8 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index 70948bc..8c1c4ed 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -61,7 +61,6 @@ read_state () {
 	if test -d "$merge_dir"
 	then
 		state_dir="$merge_dir"
-		prev_head=$(cat "$merge_dir"/prev_head) &&
 		onto_name=$(cat "$merge_dir"/onto_name) &&
 		end=$(cat "$merge_dir"/end) &&
 		msgnum=$(cat "$merge_dir"/msgnum)
@@ -75,7 +74,6 @@ read_state () {
 }
 
 continue_merge () {
-	test -n "$prev_head" || die "prev_head must be defined"
 	test -d "$merge_dir" || die "$merge_dir directory does not exist"
 
 	unmerged=$(git ls-files -u)
@@ -109,10 +107,6 @@ continue_merge () {
 	test -z "$GIT_QUIET" &&
 	GIT_PAGER='' git log --format=%s -1 "$cmt"
 
-	prev_head=`git rev-parse HEAD^0`
-	# save the resulting commit so we can read-tree on it later
-	echo "$prev_head" > "$merge_dir/prev_head"
-
 	# onto the next patch:
 	msgnum=$(($msgnum + 1))
 	echo "$msgnum" >"$merge_dir/msgnum"
@@ -568,8 +562,6 @@ fi
 
 mkdir -p "$merge_dir"
 echo "$onto_name" > "$merge_dir/onto_name"
-prev_head=$orig_head
-echo "$prev_head" > "$merge_dir/prev_head"
 echo "$head_name" > "$merge_dir/head-name"
 echo "$onto" > "$merge_dir/onto"
 echo "$orig_head" > "$merge_dir/orig-head"
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 05/31] rebase: improve detection of rebase in progress
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (3 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 04/31] rebase: remove unused rebase state 'prev_head' Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 06/31] rebase: act on command line outside parsing loop Martin von Zweigbergk
                     ` (27 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Detect early on if a rebase is in progress and what type of rebase it
is (interactive, merge-based or am-based). This prepares for further
refactoring where am-based rebase will be dispatched to
git-rebase--am.sh and merge-based rebase will be dispatched to
git-rebase--merge.sh.

The idea is to use the same variables whether the type of rebase was
detected from rebase-apply/ or rebase-merge/ directories or from the
command line options. This will make the code more readable and will
later also make it easier to dispatch to the type-specific scripts.

Also show a consistent error message independent of the type of rebase
that was in progress and remove the obsolete wording about being in
the middle of a 'patch application', since that (an existing
"$GIT_DIR"/rebase-apply/applying) aborts 'git rebase' at an earlier
stage.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Currently, the existence of rebase-merge/ is tested with 'test -d',
while the existence of rebase-apply/ is tested by creating the
directory and then deleting it again. Any good reason for this?

There were some discussions on the above subject in the first round,
but nothing conclusive, so I have left it the way it was for now.

 git-rebase.sh |   80 +++++++++++++++++++++++++++++---------------------------
 1 files changed, 41 insertions(+), 39 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index 8c1c4ed..1d34d43 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -56,16 +56,19 @@ git_am_opt=
 rebase_root=
 force_rebase=
 allow_rerere_autoupdate=
+# Non-empty if a rebase was in progress when 'git rebase' was invoked
+in_progress=
+# One of {am, merge, interactive}
+type=
+# One of {"$GIT_DIR"/rebase-apply, "$GIT_DIR"/rebase-merge}
+state_dir=
 
 read_state () {
-	if test -d "$merge_dir"
+	if test "$type" = merge
 	then
-		state_dir="$merge_dir"
-		onto_name=$(cat "$merge_dir"/onto_name) &&
-		end=$(cat "$merge_dir"/end) &&
-		msgnum=$(cat "$merge_dir"/msgnum)
-	else
-		state_dir="$apply_dir"
+		onto_name=$(cat "$state_dir"/onto_name) &&
+		end=$(cat "$state_dir"/end) &&
+		msgnum=$(cat "$state_dir"/msgnum)
 	fi &&
 	head_name=$(cat "$state_dir"/head-name) &&
 	onto=$(cat "$state_dir"/onto) &&
@@ -207,6 +210,23 @@ test -f "$apply_dir"/applying &&
 
 is_interactive "$@" && exec git-rebase--interactive "$@"
 
+if test -d "$apply_dir"
+then
+	type=am
+	state_dir="$apply_dir"
+elif test -d "$merge_dir"
+then
+	if test -f "$merge_dir"/interactive
+	then
+		type=interactive
+		interactive_rebase=explicit
+	else
+		type=merge
+	fi
+	state_dir="$merge_dir"
+fi
+test -n "$type" && in_progress=t
+
 while test $# != 0
 do
 	case "$1" in
@@ -217,8 +237,7 @@ do
 		OK_TO_SKIP_PRE_REBASE=
 		;;
 	--continue)
-		test -d "$merge_dir" -o -d "$apply_dir" ||
-			die "No rebase in progress?"
+		test -z "$in_progress" && die "No rebase in progress?"
 
 		git update-index --ignore-submodules --refresh &&
 		git diff-files --quiet --ignore-submodules || {
@@ -243,8 +262,7 @@ do
 		exit
 		;;
 	--skip)
-		test -d "$merge_dir" -o -d "$apply_dir" ||
-			die "No rebase in progress?"
+		test -z "$in_progress" && die "No rebase in progress?"
 
 		git reset --hard HEAD || exit $?
 		read_state
@@ -265,8 +283,7 @@ do
 		exit
 		;;
 	--abort)
-		test -d "$merge_dir" -o -d "$apply_dir" ||
-			die "No rebase in progress?"
+		test -z "$in_progress" && die "No rebase in progress?"
 
 		git rerere clear
 		read_state
@@ -374,37 +391,22 @@ do
 done
 test $# -gt 2 && usage
 
-if test $# -eq 0 && test -z "$rebase_root"
+# Make sure no rebase is in progress
+if test -n "$in_progress"
 then
-	test -d "$merge_dir" -o -d "$apply_dir" || usage
-	test -d "$merge_dir" -o -f "$apply_dir"/rebasing &&
-		die 'A rebase is in progress, try --continue, --skip or --abort.'
-fi
-
-# Make sure we do not have $apply_dir or $merge_dir
-if test -z "$do_merge"
-then
-	if mkdir "$apply_dir" 2>/dev/null
-	then
-		rmdir "$apply_dir"
-	else
-		echo >&2 '
-It seems that I cannot create a rebase-apply directory, and
-I wonder if you are in the middle of patch application or another
-rebase.  If that is not the case, please
-	rm -fr '"$apply_dir"'
+	die '
+It seems that there is already a '"${state_dir##*/}"' directory, and
+I wonder if you are in the middle of another rebase.  If that is the
+case, please try
+	git rebase (--continue | --abort | --skip)
+If that is not the case, please
+	rm -fr '"$state_dir"'
 and run me again.  I am stopping in case you still have something
 valuable there.'
-		exit 1
-	fi
-else
-	if test -d "$merge_dir"
-	then
-		die "previous rebase directory $merge_dir still exists." \
-			'Try git rebase (--continue | --abort | --skip)'
-	fi
 fi
 
+test $# -eq 0 && test -z "$rebase_root" && usage
+
 require_clean_work_tree "rebase" "Please commit or stash them."
 
 if test -z "$rebase_root"
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 06/31] rebase: act on command line outside parsing loop
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (4 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 05/31] rebase: improve detection of rebase in progress Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 07/31] rebase: stricter check of standalone sub command Martin von Zweigbergk
                     ` (26 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

To later be able to use the command line processing in git-rebase.sh
for both interactive and non-interactive rebases, move anything that
is specific to non-interactive rebase outside of the parsing
loop. Keep only parsing and validation of command line options in the
loop.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
May want to view this patch with --ignore-all-space.

 git-rebase--interactive.sh |  300 ++++++++++++++++++++++----------------------
 git-rebase.sh              |  126 ++++++++++---------
 2 files changed, 217 insertions(+), 209 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 5873ba4..824f4f3 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -866,152 +866,158 @@ first and then run 'git rebase --continue' again."
 		;;
 	--)
 		shift
-		test -z "$REBASE_ROOT" -a $# -ge 1 -a $# -le 2 ||
-		test ! -z "$REBASE_ROOT" -a $# -le 1 || usage
-		test -d "$DOTEST" &&
-			die "Interactive rebase already started"
-
-		git var GIT_COMMITTER_IDENT >/dev/null ||
-			die "You need to set your committer info first"
-
-		if test -z "$REBASE_ROOT"
-		then
-			UPSTREAM_ARG="$1"
-			UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base"
-			test -z "$ONTO" && ONTO=$UPSTREAM
-			shift
-		else
-			UPSTREAM=
-			UPSTREAM_ARG=--root
-			test -z "$ONTO" &&
-				die "You must specify --onto when using --root"
-		fi
-		run_pre_rebase_hook "$UPSTREAM_ARG" "$@"
-
-		comment_for_reflog start
-
-		require_clean_work_tree "rebase" "Please commit or stash them."
-
-		if test ! -z "$1"
-		then
-			output git checkout "$1" -- ||
-				die "Could not checkout $1"
-		fi
+		break
+		;;
+	esac
+	shift
+done
 
-		HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?"
-		mkdir "$DOTEST" || die "Could not create temporary $DOTEST"
+test -z "$REBASE_ROOT" -a $# -ge 1 -a $# -le 2 ||
+test ! -z "$REBASE_ROOT" -a $# -le 1 || usage
+test -d "$DOTEST" &&
+	die "Interactive rebase already started"
 
-		: > "$DOTEST"/interactive || die "Could not mark as interactive"
-		git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
-			echo "detached HEAD" > "$DOTEST"/head-name
+git var GIT_COMMITTER_IDENT >/dev/null ||
+	die "You need to set your committer info first"
 
-		echo $HEAD > "$DOTEST"/head
-		case "$REBASE_ROOT" in
-		'')
-			rm -f "$DOTEST"/rebase-root ;;
-		*)
-			: >"$DOTEST"/rebase-root ;;
-		esac
-		echo $ONTO > "$DOTEST"/onto
-		test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy
-		test t = "$VERBOSE" && : > "$DOTEST"/verbose
-		if test t = "$PRESERVE_MERGES"
-		then
-			if test -z "$REBASE_ROOT"
-			then
-				mkdir "$REWRITTEN" &&
-				for c in $(git merge-base --all $HEAD $UPSTREAM)
-				do
-					echo $ONTO > "$REWRITTEN"/$c ||
-						die "Could not init rewritten commits"
-				done
-			else
-				mkdir "$REWRITTEN" &&
-				echo $ONTO > "$REWRITTEN"/root ||
-					die "Could not init rewritten commits"
-			fi
-			# No cherry-pick because our first pass is to determine
-			# parents to rewrite and skipping dropped commits would
-			# prematurely end our probe
-			MERGES_OPTION=
-			first_after_upstream="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)"
-		else
-			MERGES_OPTION="--no-merges --cherry-pick"
-		fi
-
-		SHORTHEAD=$(git rev-parse --short $HEAD)
-		SHORTONTO=$(git rev-parse --short $ONTO)
-		if test -z "$REBASE_ROOT"
-			# this is now equivalent to ! -z "$UPSTREAM"
-		then
-			SHORTUPSTREAM=$(git rev-parse --short $UPSTREAM)
-			REVISIONS=$UPSTREAM...$HEAD
-			SHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD
-		else
-			REVISIONS=$ONTO...$HEAD
-			SHORTREVISIONS=$SHORTHEAD
-		fi
-		git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
-			--abbrev=7 --reverse --left-right --topo-order \
-			$REVISIONS | \
-			sed -n "s/^>//p" |
-		while read -r shortsha1 rest
+if test -z "$REBASE_ROOT"
+then
+	UPSTREAM_ARG="$1"
+	UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base"
+	test -z "$ONTO" && ONTO=$UPSTREAM
+	shift
+else
+	UPSTREAM=
+	UPSTREAM_ARG=--root
+	test -z "$ONTO" &&
+	die "You must specify --onto when using --root"
+fi
+run_pre_rebase_hook "$UPSTREAM_ARG" "$@"
+
+comment_for_reflog start
+
+require_clean_work_tree "rebase" "Please commit or stash them."
+
+if test ! -z "$1"
+then
+	output git checkout "$1" -- ||
+		die "Could not checkout $1"
+fi
+
+HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?"
+mkdir "$DOTEST" || die "Could not create temporary $DOTEST"
+
+: > "$DOTEST"/interactive || die "Could not mark as interactive"
+git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
+	echo "detached HEAD" > "$DOTEST"/head-name
+
+echo $HEAD > "$DOTEST"/head
+case "$REBASE_ROOT" in
+'')
+	rm -f "$DOTEST"/rebase-root ;;
+*)
+	: >"$DOTEST"/rebase-root ;;
+esac
+echo $ONTO > "$DOTEST"/onto
+test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy
+test t = "$VERBOSE" && : > "$DOTEST"/verbose
+if test t = "$PRESERVE_MERGES"
+then
+	if test -z "$REBASE_ROOT"
+	then
+		mkdir "$REWRITTEN" &&
+		for c in $(git merge-base --all $HEAD $UPSTREAM)
 		do
-			if test t != "$PRESERVE_MERGES"
-			then
-				printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
-			else
-				sha1=$(git rev-parse $shortsha1)
-				if test -z "$REBASE_ROOT"
-				then
-					preserve=t
-					for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
-					do
-						if test -f "$REWRITTEN"/$p -a \( $p != $ONTO -o $sha1 = $first_after_upstream \)
-						then
-							preserve=f
-						fi
-					done
-				else
-					preserve=f
-				fi
-				if test f = "$preserve"
-				then
-					touch "$REWRITTEN"/$sha1
-					printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
-				fi
-			fi
+			echo $ONTO > "$REWRITTEN"/$c ||
+				die "Could not init rewritten commits"
 		done
-
-		# Watch for commits that been dropped by --cherry-pick
-		if test t = "$PRESERVE_MERGES"
+	else
+		mkdir "$REWRITTEN" &&
+		echo $ONTO > "$REWRITTEN"/root ||
+			die "Could not init rewritten commits"
+	fi
+	# No cherry-pick because our first pass is to determine
+	# parents to rewrite and skipping dropped commits would
+	# prematurely end our probe
+	MERGES_OPTION=
+	first_after_upstream="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)"
+else
+	MERGES_OPTION="--no-merges --cherry-pick"
+fi
+
+SHORTHEAD=$(git rev-parse --short $HEAD)
+SHORTONTO=$(git rev-parse --short $ONTO)
+if test -z "$REBASE_ROOT"
+	# this is now equivalent to ! -z "$UPSTREAM"
+then
+	SHORTUPSTREAM=$(git rev-parse --short $UPSTREAM)
+	REVISIONS=$UPSTREAM...$HEAD
+	SHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD
+else
+	REVISIONS=$ONTO...$HEAD
+	SHORTREVISIONS=$SHORTHEAD
+fi
+git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
+	--abbrev=7 --reverse --left-right --topo-order \
+	$REVISIONS | \
+	sed -n "s/^>//p" |
+while read -r shortsha1 rest
+do
+	if test t != "$PRESERVE_MERGES"
+	then
+		printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
+	else
+		sha1=$(git rev-parse $shortsha1)
+		if test -z "$REBASE_ROOT"
 		then
-			mkdir "$DROPPED"
-			# Save all non-cherry-picked changes
-			git rev-list $REVISIONS --left-right --cherry-pick | \
-				sed -n "s/^>//p" > "$DOTEST"/not-cherry-picks
-			# Now all commits and note which ones are missing in
-			# not-cherry-picks and hence being dropped
-			git rev-list $REVISIONS |
-			while read rev
+			preserve=t
+			for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
 			do
-				if test -f "$REWRITTEN"/$rev -a "$(sane_grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
+				if test -f "$REWRITTEN"/$p -a \( $p != $ONTO -o $sha1 = $first_after_upstream \)
 				then
-					# Use -f2 because if rev-list is telling us this commit is
-					# not worthwhile, we don't want to track its multiple heads,
-					# just the history of its first-parent for others that will
-					# be rebasing on top of it
-					git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$DROPPED"/$rev
-					short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
-					sane_grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
-					rm "$REWRITTEN"/$rev
+					preserve=f
 				fi
 			done
+		else
+			preserve=f
+		fi
+		if test f = "$preserve"
+		then
+			touch "$REWRITTEN"/$sha1
+			printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
 		fi
+	fi
+done
 
-		test -s "$TODO" || echo noop >> "$TODO"
-		test -n "$AUTOSQUASH" && rearrange_squash "$TODO"
-		cat >> "$TODO" << EOF
+# Watch for commits that been dropped by --cherry-pick
+if test t = "$PRESERVE_MERGES"
+then
+	mkdir "$DROPPED"
+	# Save all non-cherry-picked changes
+	git rev-list $REVISIONS --left-right --cherry-pick | \
+		sed -n "s/^>//p" > "$DOTEST"/not-cherry-picks
+	# Now all commits and note which ones are missing in
+	# not-cherry-picks and hence being dropped
+	git rev-list $REVISIONS |
+	while read rev
+	do
+		if test -f "$REWRITTEN"/$rev -a "$(sane_grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
+		then
+			# Use -f2 because if rev-list is telling us this commit is
+			# not worthwhile, we don't want to track its multiple heads,
+			# just the history of its first-parent for others that will
+			# be rebasing on top of it
+			git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$DROPPED"/$rev
+			short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
+			sane_grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
+			rm "$REWRITTEN"/$rev
+		fi
+	done
+fi
+
+test -s "$TODO" || echo noop >> "$TODO"
+test -n "$AUTOSQUASH" && rearrange_squash "$TODO"
+cat >> "$TODO" << EOF
 
 # Rebase $SHORTREVISIONS onto $SHORTONTO
 #
@@ -1028,22 +1034,18 @@ first and then run 'git rebase --continue' again."
 #
 EOF
 
-		has_action "$TODO" ||
-			die_abort "Nothing to do"
+has_action "$TODO" ||
+	die_abort "Nothing to do"
 
-		cp "$TODO" "$TODO".backup
-		git_editor "$TODO" ||
-			die_abort "Could not execute editor"
+cp "$TODO" "$TODO".backup
+git_editor "$TODO" ||
+	die_abort "Could not execute editor"
 
-		has_action "$TODO" ||
-			die_abort "Nothing to do"
+has_action "$TODO" ||
+	die_abort "Nothing to do"
 
-		test -d "$REWRITTEN" || test -n "$NEVER_FF" || skip_unnecessary_picks
+test -d "$REWRITTEN" || test -n "$NEVER_FF" || skip_unnecessary_picks
 
-		output git checkout $ONTO || die_abort "could not detach HEAD"
-		git update-ref ORIG_HEAD $HEAD
-		do_rest
-		;;
-	esac
-	shift
-done
+output git checkout $ONTO || die_abort "could not detach HEAD"
+git update-ref ORIG_HEAD $HEAD
+do_rest
diff --git a/git-rebase.sh b/git-rebase.sh
index 1d34d43..e3fd001 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -62,6 +62,8 @@ in_progress=
 type=
 # One of {"$GIT_DIR"/rebase-apply, "$GIT_DIR"/rebase-merge}
 state_dir=
+# One of {'', continue, skip, abort}, as parsed from command line
+action=
 
 read_state () {
 	if test "$type" = merge
@@ -236,66 +238,10 @@ do
 	--verify)
 		OK_TO_SKIP_PRE_REBASE=
 		;;
-	--continue)
-		test -z "$in_progress" && die "No rebase in progress?"
-
-		git update-index --ignore-submodules --refresh &&
-		git diff-files --quiet --ignore-submodules || {
-			echo "You must edit all merge conflicts and then"
-			echo "mark them as resolved using git add"
-			exit 1
-		}
-		read_state
-		if test -d "$merge_dir"
-		then
-			continue_merge
-			while test "$msgnum" -le "$end"
-			do
-				call_merge "$msgnum"
-				continue_merge
-			done
-			finish_rb_merge
-			exit
-		fi
-		git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
-		move_to_original_branch
-		exit
-		;;
-	--skip)
-		test -z "$in_progress" && die "No rebase in progress?"
-
-		git reset --hard HEAD || exit $?
-		read_state
-		if test -d "$merge_dir"
-		then
-			git rerere clear
-			msgnum=$(($msgnum + 1))
-			while test "$msgnum" -le "$end"
-			do
-				call_merge "$msgnum"
-				continue_merge
-			done
-			finish_rb_merge
-			exit
-		fi
-		git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
-		move_to_original_branch
-		exit
-		;;
-	--abort)
-		test -z "$in_progress" && die "No rebase in progress?"
-
-		git rerere clear
-		read_state
-		case "$head_name" in
-		refs/*)
-			git symbolic-ref HEAD $head_name ||
-			die "Could not move back to $head_name"
-			;;
-		esac
-		git reset --hard $orig_head
-		rm -r "$state_dir"
-		exit
+	--continue|--skip|--abort)
+		action=${1##--}
+		shift
+		break
 		;;
 	--onto)
 		test 2 -le "$#" || usage
@@ -391,6 +337,66 @@ do
 done
 test $# -gt 2 && usage
 
+test -n "$action" && test -z "$in_progress" && die "No rebase in progress?"
+
+case "$action" in
+continue)
+	git update-index --ignore-submodules --refresh &&
+	git diff-files --quiet --ignore-submodules || {
+		echo "You must edit all merge conflicts and then"
+		echo "mark them as resolved using git add"
+		exit 1
+	}
+	read_state
+	if test -d "$merge_dir"
+	then
+		continue_merge
+		while test "$msgnum" -le "$end"
+		do
+			call_merge "$msgnum"
+			continue_merge
+		done
+		finish_rb_merge
+		exit
+	fi
+	git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
+	move_to_original_branch
+	exit
+	;;
+skip)
+	git reset --hard HEAD || exit $?
+	read_state
+	if test -d "$merge_dir"
+	then
+		git rerere clear
+		msgnum=$(($msgnum + 1))
+		while test "$msgnum" -le "$end"
+		do
+			call_merge "$msgnum"
+			continue_merge
+		done
+		finish_rb_merge
+		exit
+	fi
+	git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
+	move_to_original_branch
+	exit
+	;;
+abort)
+	git rerere clear
+	read_state
+	case "$head_name" in
+	refs/*)
+		git symbolic-ref HEAD $head_name ||
+		die "Could not move back to $head_name"
+		;;
+	esac
+	git reset --hard $orig_head
+	rm -r "$state_dir"
+	exit
+	;;
+esac
+
 # Make sure no rebase is in progress
 if test -n "$in_progress"
 then
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 07/31] rebase: stricter check of standalone sub command
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (5 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 06/31] rebase: act on command line outside parsing loop Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-07-01  3:55     ` Jonathan Nieder
  2011-02-06 18:43   ` [PATCH v2 08/31] rebase: align variable names Martin von Zweigbergk
                     ` (25 subsequent siblings)
  32 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

The sub commands '--continue', '--skip' or '--abort' may only be used
standalone according to the documentation. Other options following the
sub command are currently not accepted, but options preceeding them
are. For example, 'git rebase --continue -v' is not accepted, while
'git rebase -v --continue' is. Tighten up the check and allow no other
options when one of these sub commands are used.

Only check that it is standalone for non-interactive rebase for
now. Once the command line processing for interactive rebase has been
replaced by the command line processing in git-rebase.sh, this check
will also apply to interactive rebase.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Is this too simplistic? Do we forsee that we want to support passing
options when resuming a rebase? Is it better to check for each other
option that it is not passed (i.e. no '-v', no '-s' etc.)?

Might some users be depending on the current behavior, even though it
is undocumented?


 git-rebase.sh              |    4 ++--
 t/t3403-rebase-skip.sh     |    5 +++++
 t/t3407-rebase-abort.sh    |   10 ++++++++++
 t/t3418-rebase-continue.sh |    5 +++++
 4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index e3fd001..d689aad 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -229,6 +229,7 @@ then
 fi
 test -n "$type" && in_progress=t
 
+total_argc=$#
 while test $# != 0
 do
 	case "$1" in
@@ -239,9 +240,8 @@ do
 		OK_TO_SKIP_PRE_REBASE=
 		;;
 	--continue|--skip|--abort)
+		test $total_argc -eq 1 || usage
 		action=${1##--}
-		shift
-		break
 		;;
 	--onto)
 		test 2 -le "$#" || usage
diff --git a/t/t3403-rebase-skip.sh b/t/t3403-rebase-skip.sh
index 64446e3..826500b 100755
--- a/t/t3403-rebase-skip.sh
+++ b/t/t3403-rebase-skip.sh
@@ -35,6 +35,11 @@ test_expect_success 'rebase with git am -3 (default)' '
 	test_must_fail git rebase master
 '
 
+test_expect_success 'rebase --skip can not be used with other options' '
+	test_must_fail git rebase -v --skip &&
+	test_must_fail git rebase --skip -v
+'
+
 test_expect_success 'rebase --skip with am -3' '
 	git rebase --skip
 	'
diff --git a/t/t3407-rebase-abort.sh b/t/t3407-rebase-abort.sh
index e573dc8..a6a6c40 100755
--- a/t/t3407-rebase-abort.sh
+++ b/t/t3407-rebase-abort.sh
@@ -84,6 +84,16 @@ testrebase() {
 		test_cmp reflog_before reflog_after &&
 		rm reflog_before reflog_after
 	'
+
+	test_expect_success 'rebase --abort can not be used with other options' '
+		cd "$work_dir" &&
+		# Clean up the state from the previous one
+		git reset --hard pre-rebase &&
+		test_must_fail git rebase$type master &&
+		test_must_fail git rebase -v --abort &&
+		test_must_fail git rebase --abort -v &&
+		git rebase --abort
+	'
 }
 
 testrebase "" .git/rebase-apply
diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh
index 3b0d273..1d90191 100755
--- a/t/t3418-rebase-continue.sh
+++ b/t/t3418-rebase-continue.sh
@@ -40,4 +40,9 @@ test_expect_success 'non-interactive rebase --continue works with touched file'
 	git rebase --continue
 '
 
+test_expect_success 'rebase --continue can not be used with other options' '
+	test_must_fail git rebase -v --continue &&
+	test_must_fail git rebase --continue -v
+'
+
 test_done
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 08/31] rebase: align variable names
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (6 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 07/31] rebase: stricter check of standalone sub command Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 09/31] rebase: align variable content Martin von Zweigbergk
                     ` (24 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

git-rebase--interactive.sh will soon be sourced from
git-rebase.sh. Align the names of variables used in these scripts to
prepare for that.

Some names in git-rebase--interactive.sh, such as "author_script" and
"amend", are currently used in their upper case form to refer to a
file and in their lower case form to refer to something else. In these
cases, change the name of the existing lower case variable and
downcase the name of the variable that refers to the file.

Currently, git-rebase.sh uses mostly lower case variable names, while
git-rebase--interactive.sh uses mostly upper case variable names. For
consistency, downcase all variables, not just the ones that will be
shared between the two script files.

Helped-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Changes since v1:

 * As suggested by Thomas, downcase *all* variables, so that the end
   result looks consistent.

 git-rebase--interactive.sh |  480 ++++++++++++++++++++++----------------------
 git-rebase.sh              |   32 ++--
 2 files changed, 256 insertions(+), 256 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 824f4f3..2fa348b 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -36,22 +36,22 @@ autosquash         move commits that begin with squash!/fixup! under -i
 . git-sh-setup
 require_work_tree
 
-DOTEST="$GIT_DIR/rebase-merge"
+dotest="$GIT_DIR/rebase-merge"
 
 # The file containing rebase commands, comments, and empty lines.
 # This file is created by "git rebase -i" then edited by the user.  As
 # the lines are processed, they are removed from the front of this
-# file and written to the tail of $DONE.
-TODO="$DOTEST"/git-rebase-todo
+# file and written to the tail of $done.
+todo="$dotest"/git-rebase-todo
 
 # The rebase command lines that have already been processed.  A line
 # is moved here when it is first handled, before any associated user
 # actions.
-DONE="$DOTEST"/done
+done="$dotest"/done
 
 # The commit message that is planned to be used for any changes that
 # need to be committed following a user interaction.
-MSG="$DOTEST"/message
+msg="$dotest"/message
 
 # The file into which is accumulated the suggested commit message for
 # squash/fixup commands.  When the first of a series of squash/fixups
@@ -61,34 +61,34 @@ MSG="$DOTEST"/message
 # is appended to the file as it is processed.
 #
 # The first line of the file is of the form
-#     # This is a combination of $COUNT commits.
-# where $COUNT is the number of commits whose messages have been
+#     # This is a combination of $count commits.
+# where $count is the number of commits whose messages have been
 # written to the file so far (including the initial "pick" commit).
 # Each time that a commit message is processed, this line is read and
 # updated.  It is deleted just before the combined commit is made.
-SQUASH_MSG="$DOTEST"/message-squash
+squash_msg="$dotest"/message-squash
 
 # If the current series of squash/fixups has not yet included a squash
 # command, then this file exists and holds the commit message of the
 # original "pick" commit.  (If the series ends without a "squash"
 # command, then this can be used as the commit message of the combined
 # commit without opening the editor.)
-FIXUP_MSG="$DOTEST"/message-fixup
+fixup_msg="$dotest"/message-fixup
 
-# $REWRITTEN is the name of a directory containing 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
+# $rewritten is the name of a directory containing 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.)
-REWRITTEN="$DOTEST"/rewritten
+rewritten="$dotest"/rewritten
 
-DROPPED="$DOTEST"/dropped
+dropped="$dotest"/dropped
 
 # A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
 # GIT_AUTHOR_DATE that will be used for the commit that is currently
 # being rebased.
-AUTHOR_SCRIPT="$DOTEST"/author-script
+author_script="$dotest"/author-script
 
 # When an "edit" rebase command is being processed, the SHA1 of the
 # commit to be edited is recorded in this file.  When "git rebase
@@ -96,24 +96,24 @@ AUTHOR_SCRIPT="$DOTEST"/author-script
 # will be amended to the HEAD commit, but only provided the HEAD
 # commit is still the commit to be edited.  When any other rebase
 # command is processed, this file is deleted.
-AMEND="$DOTEST"/amend
+amend="$dotest"/amend
 
 # For the post-rewrite hook, we make a list of rewritten commits and
 # their new sha1s.  The rewritten-pending list keeps the sha1s of
 # commits that have been processed, but not committed yet,
 # e.g. because they are waiting for a 'squash' command.
-REWRITTEN_LIST="$DOTEST"/rewritten-list
-REWRITTEN_PENDING="$DOTEST"/rewritten-pending
-
-PRESERVE_MERGES=
-STRATEGY=
-ONTO=
-VERBOSE=
-OK_TO_SKIP_PRE_REBASE=
-REBASE_ROOT=
-AUTOSQUASH=
-test "$(git config --bool rebase.autosquash)" = "true" && AUTOSQUASH=t
-NEVER_FF=
+rewritten_list="$dotest"/rewritten-list
+rewritten_pending="$dotest"/rewritten-pending
+
+preserve_merges=
+strategy=
+onto=
+verbose=
+ok_to_skip_pre_rebase=
+rebase_root=
+autosquash=
+test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
+force_rebase=
 
 GIT_CHERRY_PICK_HELP="\
 hint: after resolving the conflicts, mark the corrected paths
@@ -125,7 +125,7 @@ warn () {
 }
 
 output () {
-	case "$VERBOSE" in
+	case "$verbose" in
 	'')
 		output=$("$@" 2>&1 )
 		status=$?
@@ -144,7 +144,7 @@ commit_message () {
 }
 
 run_pre_rebase_hook () {
-	if test -z "$OK_TO_SKIP_PRE_REBASE" &&
+	if test -z "$ok_to_skip_pre_rebase" &&
 	   test -x "$GIT_DIR/hooks/pre-rebase"
 	then
 		"$GIT_DIR/hooks/pre-rebase" ${1+"$@"} || {
@@ -155,10 +155,10 @@ run_pre_rebase_hook () {
 }
 
 
-ORIG_REFLOG_ACTION="$GIT_REFLOG_ACTION"
+orig_reflog_action="$GIT_REFLOG_ACTION"
 
 comment_for_reflog () {
-	case "$ORIG_REFLOG_ACTION" in
+	case "$orig_reflog_action" in
 	''|rebase*)
 		GIT_REFLOG_ACTION="rebase -i ($1)"
 		export GIT_REFLOG_ACTION
@@ -168,16 +168,16 @@ comment_for_reflog () {
 
 last_count=
 mark_action_done () {
-	sed -e 1q < "$TODO" >> "$DONE"
-	sed -e 1d < "$TODO" >> "$TODO".new
-	mv -f "$TODO".new "$TODO"
-	count=$(sane_grep -c '^[^#]' < "$DONE")
-	total=$(($count+$(sane_grep -c '^[^#]' < "$TODO")))
-	if test "$last_count" != "$count"
+	sed -e 1q < "$todo" >> "$done"
+	sed -e 1d < "$todo" >> "$todo".new
+	mv -f "$todo".new "$todo"
+	new_count=$(sane_grep -c '^[^#]' < "$done")
+	total=$(($new_count+$(sane_grep -c '^[^#]' < "$todo")))
+	if test "$last_count" != "$new_count"
 	then
-		last_count=$count
-		printf "Rebasing (%d/%d)\r" $count $total
-		test -z "$VERBOSE" || echo
+		last_count=$new_count
+		printf "Rebasing (%d/%d)\r" $new_count $total
+		test -z "$verbose" || echo
 	fi
 }
 
@@ -193,22 +193,22 @@ make_patch () {
 	*)
 		echo "Root commit"
 		;;
-	esac > "$DOTEST"/patch
-	test -f "$MSG" ||
-		commit_message "$1" > "$MSG"
-	test -f "$AUTHOR_SCRIPT" ||
-		get_author_ident_from_commit "$1" > "$AUTHOR_SCRIPT"
+	esac > "$dotest"/patch
+	test -f "$msg" ||
+		commit_message "$1" > "$msg"
+	test -f "$author_script" ||
+		get_author_ident_from_commit "$1" > "$author_script"
 }
 
 die_with_patch () {
-	echo "$1" > "$DOTEST"/stopped-sha
+	echo "$1" > "$dotest"/stopped-sha
 	make_patch "$1"
 	git rerere
 	die "$2"
 }
 
 die_abort () {
-	rm -rf "$DOTEST"
+	rm -rf "$dotest"
 	die "$1"
 }
 
@@ -228,11 +228,11 @@ do_with_author () {
 pick_one () {
 	ff=--ff
 	case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac
-	case "$NEVER_FF" in '') ;; ?*) ff= ;; esac
+	case "$force_rebase" in '') ;; ?*) ff= ;; esac
 	output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
-	test -d "$REWRITTEN" &&
+	test -d "$rewritten" &&
 		pick_one_preserving_merges "$@" && return
-	if test -n "$REBASE_ROOT"
+	if test -n "$rebase_root"
 	then
 		output git cherry-pick "$@"
 		return
@@ -253,20 +253,20 @@ pick_one_preserving_merges () {
 	esac
 	sha1=$(git rev-parse $sha1)
 
-	if test -f "$DOTEST"/current-commit
+	if test -f "$dotest"/current-commit
 	then
 		if test "$fast_forward" = t
 		then
 			while read current_commit
 			do
-				git rev-parse HEAD > "$REWRITTEN"/$current_commit
-			done <"$DOTEST"/current-commit
-			rm "$DOTEST"/current-commit ||
+				git rev-parse HEAD > "$rewritten"/$current_commit
+			done <"$dotest"/current-commit
+			rm "$dotest"/current-commit ||
 			die "Cannot write current commit's replacement sha1"
 		fi
 	fi
 
-	echo $sha1 >> "$DOTEST"/current-commit
+	echo $sha1 >> "$dotest"/current-commit
 
 	# rewrite parents; if none were rewritten, we can fast-forward.
 	new_parents=
@@ -280,9 +280,9 @@ pick_one_preserving_merges () {
 		p=$(expr "$pend" : ' \([^ ]*\)')
 		pend="${pend# $p}"
 
-		if test -f "$REWRITTEN"/$p
+		if test -f "$rewritten"/$p
 		then
-			new_p=$(cat "$REWRITTEN"/$p)
+			new_p=$(cat "$rewritten"/$p)
 
 			# If the todo reordered commits, and our parent is marked for
 			# rewriting, but hasn't been gotten to yet, assume the user meant to
@@ -301,10 +301,10 @@ pick_one_preserving_merges () {
 				;;
 			esac
 		else
-			if test -f "$DROPPED"/$p
+			if test -f "$dropped"/$p
 			then
 				fast_forward=f
-				replacement="$(cat "$DROPPED"/$p)"
+				replacement="$(cat "$dropped"/$p)"
 				test -z "$replacement" && replacement=root
 				pend=" $replacement$pend"
 			else
@@ -333,18 +333,18 @@ pick_one_preserving_merges () {
 			test "a$1" = a-n && die "Refusing to squash a merge: $sha1"
 
 			# redo merge
-			author_script=$(get_author_ident_from_commit $sha1)
-			eval "$author_script"
-			msg="$(commit_message $sha1)"
+			author_script_content=$(get_author_ident_from_commit $sha1)
+			eval "$author_script_content"
+			msg_content="$(commit_message $sha1)"
 			# No point in merging the first parent, that's HEAD
 			new_parents=${new_parents# $first_parent}
 			if ! do_with_author output \
-				git merge $STRATEGY -m "$msg" $new_parents
+				git merge $strategy -m "$msg_content" $new_parents
 			then
-				printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
+				printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
 				die_with_patch $sha1 "Error redoing merge $sha1"
 			fi
-			echo "$sha1 $(git rev-parse HEAD^0)" >> "$REWRITTEN_LIST"
+			echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
 			;;
 		*)
 			output git cherry-pick "$@" ||
@@ -365,46 +365,46 @@ nth_string () {
 }
 
 update_squash_messages () {
-	if test -f "$SQUASH_MSG"; then
-		mv "$SQUASH_MSG" "$SQUASH_MSG".bak || exit
-		COUNT=$(($(sed -n \
+	if test -f "$squash_msg"; then
+		mv "$squash_msg" "$squash_msg".bak || exit
+		count=$(($(sed -n \
 			-e "1s/^# This is a combination of \(.*\) commits\./\1/p" \
-			-e "q" < "$SQUASH_MSG".bak)+1))
+			-e "q" < "$squash_msg".bak)+1))
 		{
-			echo "# This is a combination of $COUNT commits."
+			echo "# This is a combination of $count commits."
 			sed -e 1d -e '2,/^./{
 				/^$/d
-			}' <"$SQUASH_MSG".bak
-		} >"$SQUASH_MSG"
+			}' <"$squash_msg".bak
+		} >"$squash_msg"
 	else
-		commit_message HEAD > "$FIXUP_MSG" || die "Cannot write $FIXUP_MSG"
-		COUNT=2
+		commit_message HEAD > "$fixup_msg" || die "Cannot write $fixup_msg"
+		count=2
 		{
 			echo "# This is a combination of 2 commits."
 			echo "# The first commit's message is:"
 			echo
-			cat "$FIXUP_MSG"
-		} >"$SQUASH_MSG"
+			cat "$fixup_msg"
+		} >"$squash_msg"
 	fi
 	case $1 in
 	squash)
-		rm -f "$FIXUP_MSG"
+		rm -f "$fixup_msg"
 		echo
-		echo "# This is the $(nth_string $COUNT) commit message:"
+		echo "# This is the $(nth_string $count) commit message:"
 		echo
 		commit_message $2
 		;;
 	fixup)
 		echo
-		echo "# The $(nth_string $COUNT) commit message will be skipped:"
+		echo "# The $(nth_string $count) commit message will be skipped:"
 		echo
 		commit_message $2 | sed -e 's/^/#	/'
 		;;
-	esac >>"$SQUASH_MSG"
+	esac >>"$squash_msg"
 }
 
 peek_next_command () {
-	sed -n -e "/^#/d" -e '/^$/d' -e "s/ .*//p" -e "q" < "$TODO"
+	sed -n -e "/^#/d" -e '/^$/d' -e "s/ .*//p" -e "q" < "$todo"
 }
 
 # A squash/fixup has failed.  Prepare the long version of the squash
@@ -414,24 +414,24 @@ peek_next_command () {
 # messages, effectively causing the combined commit to be used as the
 # new basis for any further squash/fixups.  Args: sha1 rest
 die_failed_squash() {
-	mv "$SQUASH_MSG" "$MSG" || exit
-	rm -f "$FIXUP_MSG"
-	cp "$MSG" "$GIT_DIR"/MERGE_MSG || exit
+	mv "$squash_msg" "$msg" || exit
+	rm -f "$fixup_msg"
+	cp "$msg" "$GIT_DIR"/MERGE_MSG || exit
 	warn
 	warn "Could not apply $1... $2"
 	die_with_patch $1 ""
 }
 
 flush_rewritten_pending() {
-	test -s "$REWRITTEN_PENDING" || return
+	test -s "$rewritten_pending" || return
 	newsha1="$(git rev-parse HEAD^0)"
-	sed "s/$/ $newsha1/" < "$REWRITTEN_PENDING" >> "$REWRITTEN_LIST"
-	rm -f "$REWRITTEN_PENDING"
+	sed "s/$/ $newsha1/" < "$rewritten_pending" >> "$rewritten_list"
+	rm -f "$rewritten_pending"
 }
 
 record_in_rewritten() {
 	oldsha1="$(git rev-parse $1)"
-	echo "$oldsha1" >> "$REWRITTEN_PENDING"
+	echo "$oldsha1" >> "$rewritten_pending"
 
 	case "$(peek_next_command)" in
 	squash|s|fixup|f)
@@ -443,8 +443,8 @@ record_in_rewritten() {
 }
 
 do_next () {
-	rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" || exit
-	read -r command sha1 rest < "$TODO"
+	rm -f "$msg" "$author_script" "$amend" || exit
+	read -r command sha1 rest < "$todo"
 	case "$command" in
 	'#'*|''|noop)
 		mark_action_done
@@ -472,9 +472,9 @@ do_next () {
 		mark_action_done
 		pick_one $sha1 ||
 			die_with_patch $sha1 "Could not apply $sha1... $rest"
-		echo "$sha1" > "$DOTEST"/stopped-sha
+		echo "$sha1" > "$dotest"/stopped-sha
 		make_patch $sha1
-		git rev-parse --verify HEAD > "$AMEND"
+		git rev-parse --verify HEAD > "$amend"
 		warn "Stopped at $sha1... $rest"
 		warn "You can amend the commit now, with"
 		warn
@@ -497,47 +497,47 @@ do_next () {
 		esac
 		comment_for_reflog $squash_style
 
-		test -f "$DONE" && has_action "$DONE" ||
+		test -f "$done" && has_action "$done" ||
 			die "Cannot '$squash_style' without a previous commit"
 
 		mark_action_done
 		update_squash_messages $squash_style $sha1
-		author_script=$(get_author_ident_from_commit HEAD)
-		echo "$author_script" > "$AUTHOR_SCRIPT"
-		eval "$author_script"
+		author_script_content=$(get_author_ident_from_commit HEAD)
+		echo "$author_script_content" > "$author_script"
+		eval "$author_script_content"
 		output git reset --soft HEAD^
 		pick_one -n $sha1 || die_failed_squash $sha1 "$rest"
 		case "$(peek_next_command)" in
 		squash|s|fixup|f)
 			# This is an intermediate commit; its message will only be
 			# used in case of trouble.  So use the long version:
-			do_with_author output git commit --no-verify -F "$SQUASH_MSG" ||
+			do_with_author output git commit --no-verify -F "$squash_msg" ||
 				die_failed_squash $sha1 "$rest"
 			;;
 		*)
 			# This is the final command of this squash/fixup group
-			if test -f "$FIXUP_MSG"
+			if test -f "$fixup_msg"
 			then
-				do_with_author git commit --no-verify -F "$FIXUP_MSG" ||
+				do_with_author git commit --no-verify -F "$fixup_msg" ||
 					die_failed_squash $sha1 "$rest"
 			else
-				cp "$SQUASH_MSG" "$GIT_DIR"/SQUASH_MSG || exit
+				cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
 				rm -f "$GIT_DIR"/MERGE_MSG
 				do_with_author git commit --no-verify -e ||
 					die_failed_squash $sha1 "$rest"
 			fi
-			rm -f "$SQUASH_MSG" "$FIXUP_MSG"
+			rm -f "$squash_msg" "$fixup_msg"
 			;;
 		esac
 		record_in_rewritten $sha1
 		;;
 	x|"exec")
-		read -r command rest < "$TODO"
+		read -r command rest < "$todo"
 		mark_action_done
 		printf 'Executing: %s\n' "$rest"
 		# "exec" command doesn't take a sha1 in the todo-list.
 		# => can't just use $sha1 here.
-		git rev-parse --verify HEAD > "$DOTEST"/stopped-sha
+		git rev-parse --verify HEAD > "$dotest"/stopped-sha
 		${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
 		status=$?
 		if test "$status" -ne 0
@@ -563,42 +563,42 @@ do_next () {
 		warn "Unknown command: $command $sha1 $rest"
 		if git rev-parse --verify -q "$sha1" >/dev/null
 		then
-			die_with_patch $sha1 "Please fix this in the file $TODO."
+			die_with_patch $sha1 "Please fix this in the file $todo."
 		else
-			die "Please fix this in the file $TODO."
+			die "Please fix this in the file $todo."
 		fi
 		;;
 	esac
-	test -s "$TODO" && return
+	test -s "$todo" && return
 
 	comment_for_reflog finish &&
-	HEADNAME=$(cat "$DOTEST"/head-name) &&
-	OLDHEAD=$(cat "$DOTEST"/head) &&
-	SHORTONTO=$(git rev-parse --short $(cat "$DOTEST"/onto)) &&
-	NEWHEAD=$(git rev-parse HEAD) &&
-	case $HEADNAME in
+	headname=$(cat "$dotest"/head-name) &&
+	oldhead=$(cat "$dotest"/head) &&
+	shortonto=$(git rev-parse --short $(cat "$dotest"/onto)) &&
+	newhead=$(git rev-parse HEAD) &&
+	case $headname in
 	refs/*)
-		message="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO" &&
-		git update-ref -m "$message" $HEADNAME $NEWHEAD $OLDHEAD &&
-		git symbolic-ref HEAD $HEADNAME
+		message="$GIT_REFLOG_ACTION: $headname onto $shortonto" &&
+		git update-ref -m "$message" $headname $newhead $oldhead &&
+		git symbolic-ref HEAD $headname
 		;;
 	esac && {
-		test ! -f "$DOTEST"/verbose ||
-			git diff-tree --stat $(cat "$DOTEST"/head)..HEAD
+		test ! -f "$dotest"/verbose ||
+			git diff-tree --stat $(cat "$dotest"/head)..HEAD
 	} &&
 	{
-		test -s "$REWRITTEN_LIST" &&
-		git notes copy --for-rewrite=rebase < "$REWRITTEN_LIST" ||
+		test -s "$rewritten_list" &&
+		git notes copy --for-rewrite=rebase < "$rewritten_list" ||
 		true # we don't care if this copying failed
 	} &&
 	if test -x "$GIT_DIR"/hooks/post-rewrite &&
-		test -s "$REWRITTEN_LIST"; then
-		"$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST"
+		test -s "$rewritten_list"; then
+		"$GIT_DIR"/hooks/post-rewrite rebase < "$rewritten_list"
 		true # we don't care if this hook failed
 	fi &&
-	rm -rf "$DOTEST" &&
+	rm -rf "$dotest" &&
 	git gc --auto &&
-	warn "Successfully rebased and updated $HEADNAME."
+	warn "Successfully rebased and updated $headname."
 
 	exit
 }
@@ -618,11 +618,11 @@ skip_unnecessary_picks () {
 		# fd=3 means we skip the command
 		case "$fd,$command" in
 		3,pick|3,p)
-			# pick a commit whose parent is current $ONTO -> skip
+			# pick a commit whose parent is current $onto -> skip
 			sha1=${rest%% *}
 			case "$(git rev-parse --verify --quiet "$sha1"^)" in
-			"$ONTO"*)
-				ONTO=$sha1
+			"$onto"*)
+				onto=$sha1
 				;;
 			*)
 				fd=1
@@ -637,11 +637,11 @@ skip_unnecessary_picks () {
 			;;
 		esac
 		printf '%s\n' "$command${rest:+ }$rest" >&$fd
-	done <"$TODO" >"$TODO.new" 3>>"$DONE" &&
-	mv -f "$TODO".new "$TODO" &&
+	done <"$todo" >"$todo.new" 3>>"$done" &&
+	mv -f "$todo".new "$todo" &&
 	case "$(peek_next_command)" in
 	squash|s|fixup|f)
-		record_in_rewritten "$ONTO"
+		record_in_rewritten "$onto"
 		;;
 	esac ||
 	die "Could not skip unnecessary pick commands"
@@ -650,17 +650,17 @@ skip_unnecessary_picks () {
 # check if no other options are set
 is_standalone () {
 	test $# -eq 2 -a "$2" = '--' &&
-	test -z "$ONTO" &&
-	test -z "$PRESERVE_MERGES" &&
-	test -z "$STRATEGY" &&
-	test -z "$VERBOSE"
+	test -z "$onto" &&
+	test -z "$preserve_merges" &&
+	test -z "$strategy" &&
+	test -z "$verbose"
 }
 
 get_saved_options () {
-	test -d "$REWRITTEN" && PRESERVE_MERGES=t
-	test -f "$DOTEST"/strategy && STRATEGY="$(cat "$DOTEST"/strategy)"
-	test -f "$DOTEST"/verbose && VERBOSE=t
-	test -f "$DOTEST"/rebase-root && REBASE_ROOT=t
+	test -d "$rewritten" && preserve_merges=t
+	test -f "$dotest"/strategy && strategy="$(cat "$dotest"/strategy)"
+	test -f "$dotest"/verbose && verbose=t
+	test -f "$dotest"/rebase-root && rebase_root=t
 }
 
 # Rearrange the todo list that has both "pick sha1 msg" and
@@ -699,7 +699,7 @@ rearrange_squash () {
 		esac
 		printf '%s\n' "$pick $sha1 $message"
 		used="$used$sha1 "
-		while read -r squash action msg
+		while read -r squash action msg_content
 		do
 			case " $used" in
 			*" $squash "*) continue ;;
@@ -709,13 +709,13 @@ rearrange_squash () {
 			+*)
 				action="${action#+}"
 				# full sha1 prefix test
-				case "$msg" in "$sha1"*) emit=1;; esac ;;
+				case "$msg_content" in "$sha1"*) emit=1;; esac ;;
 			*)
 				# message prefix test
-				case "$message" in "$msg"*) emit=1;; esac ;;
+				case "$message" in "$msg_content"*) emit=1;; esac ;;
 			esac
 			if test $emit = 1; then
-				printf '%s\n' "$action $squash $action! $msg"
+				printf '%s\n' "$action $squash $action! $msg_content"
 				used="$used$squash "
 			fi
 		done <"$1.sq"
@@ -747,17 +747,17 @@ while test $# != 0
 do
 	case "$1" in
 	--no-verify)
-		OK_TO_SKIP_PRE_REBASE=yes
+		ok_to_skip_pre_rebase=yes
 		;;
 	--verify)
-		OK_TO_SKIP_PRE_REBASE=
+		ok_to_skip_pre_rebase=
 		;;
 	--continue)
 		is_standalone "$@" || usage
 		get_saved_options
 		comment_for_reflog continue
 
-		test -d "$DOTEST" || die "No interactive rebase running"
+		test -d "$dotest" || die "No interactive rebase running"
 
 		# Sanity check
 		git rev-parse --verify HEAD >/dev/null ||
@@ -771,26 +771,26 @@ do
 		then
 			: Nothing to commit -- skip this
 		else
-			. "$AUTHOR_SCRIPT" ||
+			. "$author_script" ||
 				die "Cannot find the author identity"
-			amend=
-			if test -f "$AMEND"
+			current_head=
+			if test -f "$amend"
 			then
-				amend=$(git rev-parse --verify HEAD)
-				test "$amend" = $(cat "$AMEND") ||
+				current_head=$(git rev-parse --verify HEAD)
+				test "$current_head" = $(cat "$amend") ||
 				die "\
 You have uncommitted changes in your working tree. Please, commit them
 first and then run 'git rebase --continue' again."
 				git reset --soft HEAD^ ||
 				die "Cannot rewind the HEAD"
 			fi
-			do_with_author git commit --no-verify -F "$MSG" -e || {
-				test -n "$amend" && git reset --soft $amend
+			do_with_author git commit --no-verify -F "$msg" -e || {
+				test -n "$current_head" && git reset --soft $current_head
 				die "Could not commit staged changes."
 			}
 		fi
 
-		record_in_rewritten "$(cat "$DOTEST"/stopped-sha)"
+		record_in_rewritten "$(cat "$dotest"/stopped-sha)"
 
 		require_clean_work_tree "rebase"
 		do_rest
@@ -801,17 +801,17 @@ first and then run 'git rebase --continue' again."
 		comment_for_reflog abort
 
 		git rerere clear
-		test -d "$DOTEST" || die "No interactive rebase running"
+		test -d "$dotest" || die "No interactive rebase running"
 
-		HEADNAME=$(cat "$DOTEST"/head-name)
-		HEAD=$(cat "$DOTEST"/head)
-		case $HEADNAME in
+		headname=$(cat "$dotest"/head-name)
+		head=$(cat "$dotest"/head)
+		case $headname in
 		refs/*)
-			git symbolic-ref HEAD $HEADNAME
+			git symbolic-ref HEAD $headname
 			;;
 		esac &&
-		output git reset --hard $HEAD &&
-		rm -rf "$DOTEST"
+		output git reset --hard $head &&
+		rm -rf "$dotest"
 		exit
 		;;
 	--skip)
@@ -820,18 +820,18 @@ first and then run 'git rebase --continue' again."
 		comment_for_reflog skip
 
 		git rerere clear
-		test -d "$DOTEST" || die "No interactive rebase running"
+		test -d "$dotest" || die "No interactive rebase running"
 
 		output git reset --hard && do_rest
 		;;
 	-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
 		;;
@@ -839,29 +839,29 @@ first and then run 'git rebase --continue' again."
 		# we use merge anyway
 		;;
 	-v)
-		VERBOSE=t
+		verbose=t
 		;;
 	-p)
-		PRESERVE_MERGES=t
+		preserve_merges=t
 		;;
 	-i)
 		# yeah, we know
 		;;
 	--no-ff)
-		NEVER_FF=t
+		force_rebase=t
 		;;
 	--root)
-		REBASE_ROOT=t
+		rebase_root=t
 		;;
 	--autosquash)
-		AUTOSQUASH=t
+		autosquash=t
 		;;
 	--no-autosquash)
-		AUTOSQUASH=
+		autosquash=
 		;;
 	--onto)
 		shift
-		ONTO=$(parse_onto "$1") ||
+		onto=$(parse_onto "$1") ||
 			die "Does not point to a valid commit: $1"
 		;;
 	--)
@@ -872,27 +872,27 @@ first and then run 'git rebase --continue' again."
 	shift
 done
 
-test -z "$REBASE_ROOT" -a $# -ge 1 -a $# -le 2 ||
-test ! -z "$REBASE_ROOT" -a $# -le 1 || usage
-test -d "$DOTEST" &&
+test -z "$rebase_root" -a $# -ge 1 -a $# -le 2 ||
+test ! -z "$rebase_root" -a $# -le 1 || usage
+test -d "$dotest" &&
 	die "Interactive rebase already started"
 
 git var GIT_COMMITTER_IDENT >/dev/null ||
 	die "You need to set your committer info first"
 
-if test -z "$REBASE_ROOT"
+if test -z "$rebase_root"
 then
-	UPSTREAM_ARG="$1"
-	UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base"
-	test -z "$ONTO" && ONTO=$UPSTREAM
+	upstream_arg="$1"
+	upstream=$(git rev-parse --verify "$1") || die "Invalid base"
+	test -z "$onto" && onto=$upstream
 	shift
 else
-	UPSTREAM=
-	UPSTREAM_ARG=--root
-	test -z "$ONTO" &&
-	die "You must specify --onto when using --root"
+	upstream=
+	upstream_arg=--root
+	test -z "$onto" &&
+		die "You must specify --onto when using --root"
 fi
-run_pre_rebase_hook "$UPSTREAM_ARG" "$@"
+run_pre_rebase_hook "$upstream_arg" "$@"
 
 comment_for_reflog start
 
@@ -904,76 +904,76 @@ then
 		die "Could not checkout $1"
 fi
 
-HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?"
-mkdir "$DOTEST" || die "Could not create temporary $DOTEST"
+head=$(git rev-parse --verify HEAD) || die "No HEAD?"
+mkdir "$dotest" || die "Could not create temporary $dotest"
 
-: > "$DOTEST"/interactive || die "Could not mark as interactive"
-git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
-	echo "detached HEAD" > "$DOTEST"/head-name
+: > "$dotest"/interactive || die "Could not mark as interactive"
+git symbolic-ref HEAD > "$dotest"/head-name 2> /dev/null ||
+	echo "detached HEAD" > "$dotest"/head-name
 
-echo $HEAD > "$DOTEST"/head
-case "$REBASE_ROOT" in
+echo $head > "$dotest"/head
+case "$rebase_root" in
 '')
-	rm -f "$DOTEST"/rebase-root ;;
+	rm -f "$dotest"/rebase-root ;;
 *)
-	: >"$DOTEST"/rebase-root ;;
+	: >"$dotest"/rebase-root ;;
 esac
-echo $ONTO > "$DOTEST"/onto
-test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy
-test t = "$VERBOSE" && : > "$DOTEST"/verbose
-if test t = "$PRESERVE_MERGES"
+echo $onto > "$dotest"/onto
+test -z "$strategy" || echo "$strategy" > "$dotest"/strategy
+test t = "$verbose" && : > "$dotest"/verbose
+if test t = "$preserve_merges"
 then
-	if test -z "$REBASE_ROOT"
+	if test -z "$rebase_root"
 	then
-		mkdir "$REWRITTEN" &&
-		for c in $(git merge-base --all $HEAD $UPSTREAM)
+		mkdir "$rewritten" &&
+		for c in $(git merge-base --all $head $upstream)
 		do
-			echo $ONTO > "$REWRITTEN"/$c ||
+			echo $onto > "$rewritten"/$c ||
 				die "Could not init rewritten commits"
 		done
 	else
-		mkdir "$REWRITTEN" &&
-		echo $ONTO > "$REWRITTEN"/root ||
+		mkdir "$rewritten" &&
+		echo $onto > "$rewritten"/root ||
 			die "Could not init rewritten commits"
 	fi
 	# No cherry-pick because our first pass is to determine
 	# parents to rewrite and skipping dropped commits would
 	# prematurely end our probe
-	MERGES_OPTION=
-	first_after_upstream="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)"
+	merges_option=
+	first_after_upstream="$(git rev-list --reverse --first-parent $upstream..$head | head -n 1)"
 else
-	MERGES_OPTION="--no-merges --cherry-pick"
+	merges_option="--no-merges --cherry-pick"
 fi
 
-SHORTHEAD=$(git rev-parse --short $HEAD)
-SHORTONTO=$(git rev-parse --short $ONTO)
-if test -z "$REBASE_ROOT"
-	# this is now equivalent to ! -z "$UPSTREAM"
+shorthead=$(git rev-parse --short $head)
+shortonto=$(git rev-parse --short $onto)
+if test -z "$rebase_root"
+	# this is now equivalent to ! -z "$upstream"
 then
-	SHORTUPSTREAM=$(git rev-parse --short $UPSTREAM)
-	REVISIONS=$UPSTREAM...$HEAD
-	SHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD
+	shortupstream=$(git rev-parse --short $upstream)
+	revisions=$upstream...$head
+	shortrevisions=$shortupstream..$shorthead
 else
-	REVISIONS=$ONTO...$HEAD
-	SHORTREVISIONS=$SHORTHEAD
+	revisions=$onto...$head
+	shortrevisions=$shorthead
 fi
-git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
+git rev-list $merges_option --pretty=oneline --abbrev-commit \
 	--abbrev=7 --reverse --left-right --topo-order \
-	$REVISIONS | \
+	$revisions | \
 	sed -n "s/^>//p" |
 while read -r shortsha1 rest
 do
-	if test t != "$PRESERVE_MERGES"
+	if test t != "$preserve_merges"
 	then
-		printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
+		printf '%s\n' "pick $shortsha1 $rest" >> "$todo"
 	else
 		sha1=$(git rev-parse $shortsha1)
-		if test -z "$REBASE_ROOT"
+		if test -z "$rebase_root"
 		then
 			preserve=t
 			for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
 			do
-				if test -f "$REWRITTEN"/$p -a \( $p != $ONTO -o $sha1 = $first_after_upstream \)
+				if test -f "$rewritten"/$p -a \( $p != $onto -o $sha1 = $first_after_upstream \)
 				then
 					preserve=f
 				fi
@@ -983,43 +983,43 @@ do
 		fi
 		if test f = "$preserve"
 		then
-			touch "$REWRITTEN"/$sha1
-			printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
+			touch "$rewritten"/$sha1
+			printf '%s\n' "pick $shortsha1 $rest" >> "$todo"
 		fi
 	fi
 done
 
 # Watch for commits that been dropped by --cherry-pick
-if test t = "$PRESERVE_MERGES"
+if test t = "$preserve_merges"
 then
-	mkdir "$DROPPED"
+	mkdir "$dropped"
 	# Save all non-cherry-picked changes
-	git rev-list $REVISIONS --left-right --cherry-pick | \
-		sed -n "s/^>//p" > "$DOTEST"/not-cherry-picks
+	git rev-list $revisions --left-right --cherry-pick | \
+		sed -n "s/^>//p" > "$dotest"/not-cherry-picks
 	# Now all commits and note which ones are missing in
 	# not-cherry-picks and hence being dropped
-	git rev-list $REVISIONS |
+	git rev-list $revisions |
 	while read rev
 	do
-		if test -f "$REWRITTEN"/$rev -a "$(sane_grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
+		if test -f "$rewritten"/$rev -a "$(sane_grep "$rev" "$dotest"/not-cherry-picks)" = ""
 		then
 			# Use -f2 because if rev-list is telling us this commit is
 			# not worthwhile, we don't want to track its multiple heads,
 			# just the history of its first-parent for others that will
 			# be rebasing on top of it
-			git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$DROPPED"/$rev
+			git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
 			short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
-			sane_grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
-			rm "$REWRITTEN"/$rev
+			sane_grep -v "^[a-z][a-z]* $short" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
+			rm "$rewritten"/$rev
 		fi
 	done
 fi
 
-test -s "$TODO" || echo noop >> "$TODO"
-test -n "$AUTOSQUASH" && rearrange_squash "$TODO"
-cat >> "$TODO" << EOF
+test -s "$todo" || echo noop >> "$todo"
+test -n "$autosquash" && rearrange_squash "$todo"
+cat >> "$todo" << EOF
 
-# Rebase $SHORTREVISIONS onto $SHORTONTO
+# Rebase $shortrevisions onto $shortonto
 #
 # Commands:
 #  p, pick = use commit
@@ -1034,18 +1034,18 @@ cat >> "$TODO" << EOF
 #
 EOF
 
-has_action "$TODO" ||
+has_action "$todo" ||
 	die_abort "Nothing to do"
 
-cp "$TODO" "$TODO".backup
-git_editor "$TODO" ||
+cp "$todo" "$todo".backup
+git_editor "$todo" ||
 	die_abort "Could not execute editor"
 
-has_action "$TODO" ||
+has_action "$todo" ||
 	die_abort "Nothing to do"
 
-test -d "$REWRITTEN" || test -n "$NEVER_FF" || skip_unnecessary_picks
+test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
 
-output git checkout $ONTO || die_abort "could not detach HEAD"
-git update-ref ORIG_HEAD $HEAD
+output git checkout $onto || die_abort "could not detach HEAD"
+git update-ref ORIG_HEAD $head
 do_rest
diff --git a/git-rebase.sh b/git-rebase.sh
index d689aad..dfde62f 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -36,13 +36,13 @@ cd_to_toplevel
 
 LF='
 '
-OK_TO_SKIP_PRE_REBASE=
-RESOLVEMSG="
+ok_to_skip_pre_rebase=
+resolvemsg="
 When you have resolved this problem run \"git rebase --continue\".
 If you would prefer to skip this patch, instead run \"git rebase --skip\".
 To restore the original branch and stop rebasing run \"git rebase --abort\".
 "
-unset newbase
+unset onto
 strategy=recursive
 strategy_opts=
 do_merge=
@@ -86,7 +86,7 @@ continue_merge () {
 	then
 		echo "You still have unmerged paths in your index"
 		echo "did you forget to use git add?"
-		die "$RESOLVEMSG"
+		die "$resolvemsg"
 	fi
 
 	cmt=`cat "$merge_dir/current"`
@@ -96,7 +96,7 @@ continue_merge () {
 		then
 			echo "Commit failed, please do not call \"git commit\""
 			echo "directly, but instead do one of the following: "
-			die "$RESOLVEMSG"
+			die "$resolvemsg"
 		fi
 		if test -z "$GIT_QUIET"
 		then
@@ -139,11 +139,11 @@ call_merge () {
 		;;
 	1)
 		git rerere $allow_rerere_autoupdate
-		die "$RESOLVEMSG"
+		die "$resolvemsg"
 		;;
 	2)
 		echo "Strategy: $rv $strategy failed, try another" 1>&2
-		die "$RESOLVEMSG"
+		die "$resolvemsg"
 		;;
 	*)
 		die "Unknown exit code ($rv) from command:" \
@@ -199,7 +199,7 @@ is_interactive () {
 }
 
 run_pre_rebase_hook () {
-	if test -z "$OK_TO_SKIP_PRE_REBASE" &&
+	if test -z "$ok_to_skip_pre_rebase" &&
 	   test -x "$GIT_DIR/hooks/pre-rebase"
 	then
 		"$GIT_DIR/hooks/pre-rebase" ${1+"$@"} ||
@@ -234,10 +234,10 @@ while test $# != 0
 do
 	case "$1" in
 	--no-verify)
-		OK_TO_SKIP_PRE_REBASE=yes
+		ok_to_skip_pre_rebase=yes
 		;;
 	--verify)
-		OK_TO_SKIP_PRE_REBASE=
+		ok_to_skip_pre_rebase=
 		;;
 	--continue|--skip|--abort)
 		test $total_argc -eq 1 || usage
@@ -245,7 +245,7 @@ do
 		;;
 	--onto)
 		test 2 -le "$#" || usage
-		newbase="$2"
+		onto="$2"
 		shift
 		;;
 	-M|-m|--m|--me|--mer|--merg|--merge)
@@ -359,7 +359,7 @@ continue)
 		finish_rb_merge
 		exit
 	fi
-	git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
+	git am --resolved --3way --resolvemsg="$resolvemsg" &&
 	move_to_original_branch
 	exit
 	;;
@@ -378,7 +378,7 @@ skip)
 		finish_rb_merge
 		exit
 	fi
-	git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
+	git am -3 --skip --resolvemsg="$resolvemsg" &&
 	move_to_original_branch
 	exit
 	;;
@@ -425,7 +425,7 @@ then
 	unset root_flag
 	upstream_arg="$upstream_name"
 else
-	test -z "$newbase" && die "--root must be used with --onto"
+	test -z "$onto" && die "--root must be used with --onto"
 	unset upstream_name
 	unset upstream
 	root_flag="--root"
@@ -433,7 +433,7 @@ else
 fi
 
 # Make sure the branch to rebase onto is valid.
-onto_name=${newbase-"$upstream_name"}
+onto_name=${onto-"$upstream_name"}
 case "$onto_name" in
 *...*)
 	if	left=${onto_name%...*} right=${onto_name#*...} &&
@@ -554,7 +554,7 @@ then
 	git format-patch -k --stdout --full-index --ignore-if-in-upstream \
 		--src-prefix=a/ --dst-prefix=b/ \
 		--no-renames $root_flag "$revisions" |
-	git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
+	git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" &&
 	move_to_original_branch
 	ret=$?
 	test 0 != $ret -a -d "$apply_dir" &&
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 09/31] rebase: align variable content
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (7 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 08/31] rebase: align variable names Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 10/31] rebase: factor out command line option processing Martin von Zweigbergk
                     ` (23 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Make sure to interpret variables with the same name in the same way in
git-rebase.sh and git-rebase--interactive.sh. This will make it easier
to factor out code from git-rebase.sh to git-rebase--interactive and
export the variables.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |   16 +++++++++++-----
 git-rebase.sh              |    4 +++-
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 2fa348b..8b0d7b0 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -339,7 +339,8 @@ pick_one_preserving_merges () {
 			# No point in merging the first parent, that's HEAD
 			new_parents=${new_parents# $first_parent}
 			if ! do_with_author output \
-				git merge $strategy -m "$msg_content" $new_parents
+				git merge ${strategy:+-s $strategy} -m \
+					"$msg_content" $new_parents
 			then
 				printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
 				die_with_patch $sha1 "Error redoing merge $sha1"
@@ -827,11 +828,11 @@ first and then run 'git rebase --continue' again."
 	-s)
 		case "$#,$1" in
 		*,*=*)
-			strategy="-s "$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
+			strategy=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
 		1,*)
 			usage ;;
 		*)
-			strategy="-s $2"
+			strategy="$2"
 			shift ;;
 		esac
 		;;
@@ -860,9 +861,9 @@ first and then run 'git rebase --continue' again."
 		autosquash=
 		;;
 	--onto)
+		test 2 -le "$#" || usage
+		onto="$2"
 		shift
-		onto=$(parse_onto "$1") ||
-			die "Does not point to a valid commit: $1"
 		;;
 	--)
 		shift
@@ -872,6 +873,11 @@ first and then run 'git rebase --continue' again."
 	shift
 done
 
+if test -n "$onto"
+then
+	onto=$(parse_onto "$onto") || die "Does not point to a valid commit: $1"
+fi
+
 test -z "$rebase_root" -a $# -ge 1 -a $# -le 2 ||
 test ! -z "$rebase_root" -a $# -le 1 || usage
 test -d "$dotest" &&
diff --git a/git-rebase.sh b/git-rebase.sh
index dfde62f..3eac5a4 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -43,7 +43,7 @@ If you would prefer to skip this patch, instead run \"git rebase --skip\".
 To restore the original branch and stop rebasing run \"git rebase --abort\".
 "
 unset onto
-strategy=recursive
+strategy=
 strategy_opts=
 do_merge=
 merge_dir="$GIT_DIR"/rebase-merge
@@ -130,6 +130,7 @@ call_merge () {
 	then
 		GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
 	fi
+	test -z "$strategy" && strategy=recursive
 	eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
 	rv=$?
 	case "$rv" in
@@ -267,6 +268,7 @@ do
 		esac
 		strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$newopt")"
 		do_merge=t
+		test -z "$strategy" && strategy=recursive
 		;;
 	-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
 		--strateg=*|--strategy=*|\
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 10/31] rebase: factor out command line option processing
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (8 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 09/31] rebase: align variable content Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 11/31] rebase -i: remove now unnecessary directory checks Martin von Zweigbergk
                     ` (22 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Factor out the command line processing in git-rebase--interactive.sh
to git-rebase.sh. Store the options in variables in git-rebase.sh and
then source git-rebase--interactive.sh.

Suggested-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Changes since v1:

 * As suggested by Johannes Sixt, source git-rebase--interactive.sh
   instead of executing it.

Since this removes the command line processing from
git-rebase--interactive.sh, it completely changes its command line
interface. Since it is not listed as even a plumbing command, I hope
this is fine.


 git-rebase--interactive.sh |  224 ++++++++++++--------------------------------
 git-rebase.sh              |   58 ++++++++----
 2 files changed, 100 insertions(+), 182 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 8b0d7b0..9c43c60 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -10,31 +10,7 @@
 # The original idea comes from Eric W. Biederman, in
 # http://article.gmane.org/gmane.comp.version-control.git/22407
 
-OPTIONS_KEEPDASHDASH=
-OPTIONS_SPEC="\
-git-rebase [-i] [options] [--] <upstream> [<branch>]
-git-rebase [-i] (--continue | --abort | --skip)
---
- Available options are
-v,verbose          display a diffstat of what changed upstream
-onto=              rebase onto given branch instead of upstream
-p,preserve-merges  try to recreate merges instead of ignoring them
-s,strategy=        use the given merge strategy
-no-ff              cherry-pick all commits, even if unchanged
-m,merge            always used (no-op)
-i,interactive      always used (no-op)
- Actions:
-continue           continue rebasing process
-abort              abort rebasing process and restore original branch
-skip               skip current patch and continue rebasing process
-no-verify          override pre-rebase hook from stopping the operation
-verify             allow pre-rebase hook to run
-root               rebase all reachable commmits up to the root(s)
-autosquash         move commits that begin with squash!/fixup! under -i
-"
-
 . git-sh-setup
-require_work_tree
 
 dotest="$GIT_DIR/rebase-merge"
 
@@ -105,16 +81,6 @@ amend="$dotest"/amend
 rewritten_list="$dotest"/rewritten-list
 rewritten_pending="$dotest"/rewritten-pending
 
-preserve_merges=
-strategy=
-onto=
-verbose=
-ok_to_skip_pre_rebase=
-rebase_root=
-autosquash=
-test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
-force_rebase=
-
 GIT_CHERRY_PICK_HELP="\
 hint: after resolving the conflicts, mark the corrected paths
 hint: with 'git add <paths>' and run 'git rebase --continue'"
@@ -648,15 +614,6 @@ skip_unnecessary_picks () {
 	die "Could not skip unnecessary pick commands"
 }
 
-# check if no other options are set
-is_standalone () {
-	test $# -eq 2 -a "$2" = '--' &&
-	test -z "$onto" &&
-	test -z "$preserve_merges" &&
-	test -z "$strategy" &&
-	test -z "$verbose"
-}
-
 get_saved_options () {
 	test -d "$rewritten" && preserve_merges=t
 	test -f "$dotest"/strategy && strategy="$(cat "$dotest"/strategy)"
@@ -744,134 +701,77 @@ parse_onto () {
 	git rev-parse --verify "$1^0"
 }
 
-while test $# != 0
-do
-	case "$1" in
-	--no-verify)
-		ok_to_skip_pre_rebase=yes
-		;;
-	--verify)
-		ok_to_skip_pre_rebase=
-		;;
-	--continue)
-		is_standalone "$@" || usage
-		get_saved_options
-		comment_for_reflog continue
-
-		test -d "$dotest" || die "No interactive rebase running"
-
-		# Sanity check
-		git rev-parse --verify HEAD >/dev/null ||
-			die "Cannot read HEAD"
-		git update-index --ignore-submodules --refresh &&
-			git diff-files --quiet --ignore-submodules ||
-			die "Working tree is dirty"
-
-		# do we have anything to commit?
-		if git diff-index --cached --quiet --ignore-submodules HEAD --
+case "$action" in
+continue)
+	get_saved_options
+	comment_for_reflog continue
+
+	test -d "$dotest" || die "No interactive rebase running"
+
+	# Sanity check
+	git rev-parse --verify HEAD >/dev/null ||
+		die "Cannot read HEAD"
+	git update-index --ignore-submodules --refresh &&
+		git diff-files --quiet --ignore-submodules ||
+		die "Working tree is dirty"
+
+	# do we have anything to commit?
+	if git diff-index --cached --quiet --ignore-submodules HEAD --
+	then
+		: Nothing to commit -- skip this
+	else
+		. "$author_script" ||
+			die "Cannot find the author identity"
+		current_head=
+		if test -f "$amend"
 		then
-			: Nothing to commit -- skip this
-		else
-			. "$author_script" ||
-				die "Cannot find the author identity"
-			current_head=
-			if test -f "$amend"
-			then
-				current_head=$(git rev-parse --verify HEAD)
-				test "$current_head" = $(cat "$amend") ||
-				die "\
+			current_head=$(git rev-parse --verify HEAD)
+			test "$current_head" = $(cat "$amend") ||
+			die "\
 You have uncommitted changes in your working tree. Please, commit them
 first and then run 'git rebase --continue' again."
-				git reset --soft HEAD^ ||
-				die "Cannot rewind the HEAD"
-			fi
-			do_with_author git commit --no-verify -F "$msg" -e || {
-				test -n "$current_head" && git reset --soft $current_head
-				die "Could not commit staged changes."
-			}
+			git reset --soft HEAD^ ||
+			die "Cannot rewind the HEAD"
 		fi
+		do_with_author git commit --no-verify -F "$msg" -e || {
+			test -n "$current_head" && git reset --soft $current_head
+			die "Could not commit staged changes."
+		}
+	fi
 
-		record_in_rewritten "$(cat "$dotest"/stopped-sha)"
+	record_in_rewritten "$(cat "$dotest"/stopped-sha)"
 
-		require_clean_work_tree "rebase"
-		do_rest
-		;;
-	--abort)
-		is_standalone "$@" || usage
-		get_saved_options
-		comment_for_reflog abort
-
-		git rerere clear
-		test -d "$dotest" || die "No interactive rebase running"
-
-		headname=$(cat "$dotest"/head-name)
-		head=$(cat "$dotest"/head)
-		case $headname in
-		refs/*)
-			git symbolic-ref HEAD $headname
-			;;
-		esac &&
-		output git reset --hard $head &&
-		rm -rf "$dotest"
-		exit
-		;;
-	--skip)
-		is_standalone "$@" || usage
-		get_saved_options
-		comment_for_reflog skip
+	require_clean_work_tree "rebase"
+	do_rest
+	;;
+abort)
+	get_saved_options
+	comment_for_reflog abort
 
-		git rerere clear
-		test -d "$dotest" || die "No interactive rebase running"
+	git rerere clear
+	test -d "$dotest" || die "No interactive rebase running"
 
-		output git reset --hard && do_rest
-		;;
-	-s)
-		case "$#,$1" in
-		*,*=*)
-			strategy=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
-		1,*)
-			usage ;;
-		*)
-			strategy="$2"
-			shift ;;
-		esac
-		;;
-	-m)
-		# we use merge anyway
-		;;
-	-v)
-		verbose=t
-		;;
-	-p)
-		preserve_merges=t
-		;;
-	-i)
-		# yeah, we know
-		;;
-	--no-ff)
-		force_rebase=t
-		;;
-	--root)
-		rebase_root=t
-		;;
-	--autosquash)
-		autosquash=t
-		;;
-	--no-autosquash)
-		autosquash=
-		;;
-	--onto)
-		test 2 -le "$#" || usage
-		onto="$2"
-		shift
-		;;
-	--)
-		shift
-		break
+	headname=$(cat "$dotest"/head-name)
+	head=$(cat "$dotest"/head)
+	case $headname in
+	refs/*)
+		git symbolic-ref HEAD $headname
 		;;
-	esac
-	shift
-done
+	esac &&
+	output git reset --hard $head &&
+	rm -rf "$dotest"
+	exit
+	;;
+skip)
+	get_saved_options
+	comment_for_reflog skip
+
+	git rerere clear
+	test -d "$dotest" || die "No interactive rebase running"
+
+	output git reset --hard && do_rest
+	;;
+esac
 
 if test -n "$onto"
 then
diff --git a/git-rebase.sh b/git-rebase.sh
index 3eac5a4..aa1bcaf 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -64,6 +64,9 @@ type=
 state_dir=
 # One of {'', continue, skip, abort}, as parsed from command line
 action=
+preserve_merges=
+autosquash=
+test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
 
 read_state () {
 	if test "$type" = merge
@@ -176,27 +179,12 @@ finish_rb_merge () {
 	say All done.
 }
 
-is_interactive () {
-	while test $# != 0
-	do
-		case "$1" in
-			-i|--interactive)
-				interactive_rebase=explicit
-				break
-			;;
-			-p|--preserve-merges)
-				interactive_rebase=implied
-			;;
-		esac
-		shift
-	done
-
+run_interactive_rebase () {
 	if [ "$interactive_rebase" = implied ]; then
 		GIT_EDITOR=:
 		export GIT_EDITOR
 	fi
-
-	test -n "$interactive_rebase" || test -f "$merge_dir"/interactive
+	. git-rebase--interactive "$@"
 }
 
 run_pre_rebase_hook () {
@@ -211,8 +199,6 @@ run_pre_rebase_hook () {
 test -f "$apply_dir"/applying &&
 	die 'It looks like git-am is in progress. Cannot rebase.'
 
-is_interactive "$@" && exec git-rebase--interactive "$@"
-
 if test -d "$apply_dir"
 then
 	type=am
@@ -249,6 +235,19 @@ do
 		onto="$2"
 		shift
 		;;
+	-i|--interactive)
+		interactive_rebase=explicit
+		;;
+	-p|--preserve-merges)
+		preserve_merges=t
+		test -z "$interactive_rebase" && interactive_rebase=implied
+		;;
+	--autosquash)
+		autosquash=t
+		;;
+	--no-autosquash)
+		autosquash=
+		;;
 	-M|-m|--m|--me|--mer|--merg|--merge)
 		do_merge=t
 		;;
@@ -339,7 +338,11 @@ do
 done
 test $# -gt 2 && usage
 
-test -n "$action" && test -z "$in_progress" && die "No rebase in progress?"
+if test -n "$action"
+then
+	test -z "$in_progress" && die "No rebase in progress?"
+	test "$type" = interactive && run_interactive_rebase
+fi
 
 case "$action" in
 continue)
@@ -415,6 +418,21 @@ fi
 
 test $# -eq 0 && test -z "$rebase_root" && usage
 
+if test -n "$interactive_rebase"
+then
+	type=interactive
+	state_dir="$merge_dir"
+elif test -n "$do_merge"
+then
+	type=merge
+	state_dir="$merge_dir"
+else
+	type=am
+	state_dir="$apply_dir"
+fi
+
+test "$type" = interactive && run_interactive_rebase "$@"
+
 require_clean_work_tree "rebase" "Please commit or stash them."
 
 if test -z "$rebase_root"
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 11/31] rebase -i: remove now unnecessary directory checks
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (9 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 10/31] rebase: factor out command line option processing Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 12/31] rebase: reorder validation steps Martin von Zweigbergk
                     ` (21 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Remove directory checks from git-rebase--interactive.sh that are done in
git-rebase.sh.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Squash with previous?


 git-rebase--interactive.sh |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 9c43c60..4f4fb29 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -706,8 +706,6 @@ continue)
 	get_saved_options
 	comment_for_reflog continue
 
-	test -d "$dotest" || die "No interactive rebase running"
-
 	# Sanity check
 	git rev-parse --verify HEAD >/dev/null ||
 		die "Cannot read HEAD"
@@ -749,7 +747,6 @@ abort)
 	comment_for_reflog abort
 
 	git rerere clear
-	test -d "$dotest" || die "No interactive rebase running"
 
 	headname=$(cat "$dotest"/head-name)
 	head=$(cat "$dotest"/head)
@@ -767,7 +764,6 @@ skip)
 	comment_for_reflog skip
 
 	git rerere clear
-	test -d "$dotest" || die "No interactive rebase running"
 
 	output git reset --hard && do_rest
 	;;
@@ -780,8 +776,6 @@ fi
 
 test -z "$rebase_root" -a $# -ge 1 -a $# -le 2 ||
 test ! -z "$rebase_root" -a $# -le 1 || usage
-test -d "$dotest" &&
-	die "Interactive rebase already started"
 
 git var GIT_COMMITTER_IDENT >/dev/null ||
 	die "You need to set your committer info first"
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 12/31] rebase: reorder validation steps
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (10 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 11/31] rebase -i: remove now unnecessary directory checks Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 13/31] rebase: factor out reference parsing Martin von Zweigbergk
                     ` (20 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Reorder validation steps in preparation for the validation to be factored
out from git-rebase--interactive.sh into git-rebase.sh.

The main functional difference is that the pre-rebase hook will no longer
be run if the work tree is dirty.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |    4 ++--
 git-rebase.sh              |   10 +++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 4f4fb29..0f04f36 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -792,12 +792,12 @@ else
 	test -z "$onto" &&
 		die "You must specify --onto when using --root"
 fi
+require_clean_work_tree "rebase" "Please commit or stash them."
+
 run_pre_rebase_hook "$upstream_arg" "$@"
 
 comment_for_reflog start
 
-require_clean_work_tree "rebase" "Please commit or stash them."
-
 if test ! -z "$1"
 then
 	output git checkout "$1" -- ||
diff --git a/git-rebase.sh b/git-rebase.sh
index aa1bcaf..4a83d10 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -433,8 +433,6 @@ fi
 
 test "$type" = interactive && run_interactive_rebase "$@"
 
-require_clean_work_tree "rebase" "Please commit or stash them."
-
 if test -z "$rebase_root"
 then
 	# The upstream head must be given.  Make sure it is valid.
@@ -476,9 +474,6 @@ case "$onto_name" in
 	;;
 esac
 
-# If a hook exists, give it a chance to interrupt
-run_pre_rebase_hook "$upstream_arg" "$@"
-
 # If the branch to rebase is given, that is the branch we will rebase
 # $branch_name -- branch being rebased, or HEAD (already detached)
 # $orig_head -- commit object name of tip of the branch before rebasing
@@ -517,6 +512,8 @@ case "$#" in
 esac
 orig_head=$branch
 
+require_clean_work_tree "rebase" "Please commit or stash them."
+
 # Now we are rebasing commits $upstream..$branch (or with --root,
 # everything leading up to $branch) on top of $onto
 
@@ -538,6 +535,9 @@ then
 	fi
 fi
 
+# If a hook exists, give it a chance to interrupt
+run_pre_rebase_hook "$upstream_arg" "$@"
+
 # Detach HEAD and reset the tree
 say "First, rewinding head to replay your work on top of it..."
 git checkout -q "$onto^0" || die "could not detach HEAD"
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 13/31] rebase: factor out reference parsing
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (11 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 12/31] rebase: reorder validation steps Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 14/31] rebase: factor out clean work tree check Martin von Zweigbergk
                     ` (19 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Remove the parsing and validation of references (onto, upstream, branch)
from git-rebase--interactive.sh and rely on the information exported from
git-rebase.sh.

By using the parsing of the --onto parameter in git-rebase.sh, this
improves the error message when the parameter is invalid.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Should the check for set GIT_COMMITTER_IDENT be done for
non-interactive rebase as well or does it only make sense for
interactive rebase?


 git-rebase--interactive.sh |   48 +++----------------------------------------
 git-rebase.sh              |    9 ++++---
 2 files changed, 9 insertions(+), 48 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 0f04f36..fbe12a6 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -682,25 +682,6 @@ rearrange_squash () {
 	rm -f "$1.sq" "$1.rearranged"
 }
 
-LF='
-'
-parse_onto () {
-	case "$1" in
-	*...*)
-		if	left=${1%...*} right=${1#*...} &&
-			onto=$(git merge-base --all ${left:-HEAD} ${right:-HEAD})
-		then
-			case "$onto" in
-			?*"$LF"?* | '')
-				exit 1 ;;
-			esac
-			echo "$onto"
-			exit 0
-		fi
-	esac
-	git rev-parse --verify "$1^0"
-}
-
 case "$action" in
 continue)
 	get_saved_options
@@ -769,47 +750,26 @@ skip)
 	;;
 esac
 
-if test -n "$onto"
-then
-	onto=$(parse_onto "$onto") || die "Does not point to a valid commit: $1"
-fi
-
-test -z "$rebase_root" -a $# -ge 1 -a $# -le 2 ||
-test ! -z "$rebase_root" -a $# -le 1 || usage
-
 git var GIT_COMMITTER_IDENT >/dev/null ||
 	die "You need to set your committer info first"
 
-if test -z "$rebase_root"
-then
-	upstream_arg="$1"
-	upstream=$(git rev-parse --verify "$1") || die "Invalid base"
-	test -z "$onto" && onto=$upstream
-	shift
-else
-	upstream=
-	upstream_arg=--root
-	test -z "$onto" &&
-		die "You must specify --onto when using --root"
-fi
 require_clean_work_tree "rebase" "Please commit or stash them."
 
 run_pre_rebase_hook "$upstream_arg" "$@"
 
 comment_for_reflog start
 
-if test ! -z "$1"
+if test ! -z "$switch_to"
 then
-	output git checkout "$1" -- ||
-		die "Could not checkout $1"
+	output git checkout "$switch_to" -- ||
+		die "Could not checkout $switch_to"
 fi
 
 head=$(git rev-parse --verify HEAD) || die "No HEAD?"
 mkdir "$dotest" || die "Could not create temporary $dotest"
 
 : > "$dotest"/interactive || die "Could not mark as interactive"
-git symbolic-ref HEAD > "$dotest"/head-name 2> /dev/null ||
-	echo "detached HEAD" > "$dotest"/head-name
+echo "$head_name" > "$dotest"/head-name
 
 echo $head > "$dotest"/head
 case "$rebase_root" in
diff --git a/git-rebase.sh b/git-rebase.sh
index 4a83d10..0f5f5fb 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -431,8 +431,6 @@ else
 	state_dir="$apply_dir"
 fi
 
-test "$type" = interactive && run_interactive_rebase "$@"
-
 if test -z "$rebase_root"
 then
 	# The upstream head must be given.  Make sure it is valid.
@@ -443,7 +441,7 @@ then
 	unset root_flag
 	upstream_arg="$upstream_name"
 else
-	test -z "$onto" && die "--root must be used with --onto"
+	test -z "$onto" && die "You must specify --onto when using --root"
 	unset upstream_name
 	unset upstream
 	root_flag="--root"
@@ -470,7 +468,8 @@ case "$onto_name" in
 	fi
 	;;
 *)
-	onto=$(git rev-parse --verify "${onto_name}^0") || exit
+	onto=$(git rev-parse --verify "${onto_name}^0") ||
+	die "Does not point to a valid commit: $1"
 	;;
 esac
 
@@ -512,6 +511,8 @@ case "$#" in
 esac
 orig_head=$branch
 
+test "$type" = interactive && run_interactive_rebase "$@"
+
 require_clean_work_tree "rebase" "Please commit or stash them."
 
 # Now we are rebasing commits $upstream..$branch (or with --root,
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 14/31] rebase: factor out clean work tree check
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (12 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 13/31] rebase: factor out reference parsing Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 15/31] rebase: factor out call to pre-rebase hook Martin von Zweigbergk
                     ` (18 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Remove the check for clean work tree from git-rebase--interactive.sh and
rely on the check in git-rebase.sh.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |    2 --
 git-rebase.sh              |    4 ++--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index fbe12a6..1ba98a2 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -753,8 +753,6 @@ esac
 git var GIT_COMMITTER_IDENT >/dev/null ||
 	die "You need to set your committer info first"
 
-require_clean_work_tree "rebase" "Please commit or stash them."
-
 run_pre_rebase_hook "$upstream_arg" "$@"
 
 comment_for_reflog start
diff --git a/git-rebase.sh b/git-rebase.sh
index 0f5f5fb..265f01d 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -511,10 +511,10 @@ case "$#" in
 esac
 orig_head=$branch
 
-test "$type" = interactive && run_interactive_rebase "$@"
-
 require_clean_work_tree "rebase" "Please commit or stash them."
 
+test "$type" = interactive && run_interactive_rebase "$@"
+
 # Now we are rebasing commits $upstream..$branch (or with --root,
 # everything leading up to $branch) on top of $onto
 
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 15/31] rebase: factor out call to pre-rebase hook
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (13 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 14/31] rebase: factor out clean work tree check Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 16/31] rebase -i: support --stat Martin von Zweigbergk
                     ` (17 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Remove the call to the pre-rebase hook from
git-rebase--interactive.sh and rely on the call in
git-rebase.sh.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |   14 --------------
 git-rebase.sh              |   12 +++++++-----
 2 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 1ba98a2..f94f057 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -109,18 +109,6 @@ commit_message () {
 	git cat-file commit "$1" | sed "1,/^$/d"
 }
 
-run_pre_rebase_hook () {
-	if test -z "$ok_to_skip_pre_rebase" &&
-	   test -x "$GIT_DIR/hooks/pre-rebase"
-	then
-		"$GIT_DIR/hooks/pre-rebase" ${1+"$@"} || {
-			echo >&2 "The pre-rebase hook refused to rebase."
-			exit 1
-		}
-	fi
-}
-
-
 orig_reflog_action="$GIT_REFLOG_ACTION"
 
 comment_for_reflog () {
@@ -753,8 +741,6 @@ esac
 git var GIT_COMMITTER_IDENT >/dev/null ||
 	die "You need to set your committer info first"
 
-run_pre_rebase_hook "$upstream_arg" "$@"
-
 comment_for_reflog start
 
 if test ! -z "$switch_to"
diff --git a/git-rebase.sh b/git-rebase.sh
index 265f01d..87d7fde 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -184,7 +184,7 @@ run_interactive_rebase () {
 		GIT_EDITOR=:
 		export GIT_EDITOR
 	fi
-	. git-rebase--interactive "$@"
+	. git-rebase--interactive
 }
 
 run_pre_rebase_hook () {
@@ -513,15 +513,15 @@ orig_head=$branch
 
 require_clean_work_tree "rebase" "Please commit or stash them."
 
-test "$type" = interactive && run_interactive_rebase "$@"
-
 # Now we are rebasing commits $upstream..$branch (or with --root,
 # everything leading up to $branch) on top of $onto
 
 # Check if we are already based on $onto with linear history,
-# but this should be done only when upstream and onto are the same.
+# but this should be done only when upstream and onto are the same
+# and if this is not an interactive rebase.
 mb=$(git merge-base "$onto" "$branch")
-if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
+if test "$type" != interactive && test "$upstream" = "$onto" &&
+	test "$mb" = "$onto" &&
 	# linear history?
 	! (git rev-list --parents "$onto".."$branch" | sane_grep " .* ") > /dev/null
 then
@@ -539,6 +539,8 @@ fi
 # If a hook exists, give it a chance to interrupt
 run_pre_rebase_hook "$upstream_arg" "$@"
 
+test "$type" = interactive && run_interactive_rebase
+
 # Detach HEAD and reset the tree
 say "First, rewinding head to replay your work on top of it..."
 git checkout -q "$onto^0" || die "could not detach HEAD"
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 16/31] rebase -i: support --stat
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (14 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 15/31] rebase: factor out call to pre-rebase hook Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 17/31] rebase: remove $branch as synonym for $orig_head Martin von Zweigbergk
                     ` (16 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Move up the code that displays the diffstat if '--stat' is passed, so
that it will be executed before calling git-rebase--interactive.sh.

A side effect is that the diffstat is now displayed before "First,
rewinding head to replay your work on top of it...".

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase.sh |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index 87d7fde..c8a7e4e 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -539,13 +539,6 @@ fi
 # If a hook exists, give it a chance to interrupt
 run_pre_rebase_hook "$upstream_arg" "$@"
 
-test "$type" = interactive && run_interactive_rebase
-
-# Detach HEAD and reset the tree
-say "First, rewinding head to replay your work on top of it..."
-git checkout -q "$onto^0" || die "could not detach HEAD"
-git update-ref ORIG_HEAD $branch
-
 if test -n "$diffstat"
 then
 	if test -n "$verbose"
@@ -556,6 +549,13 @@ then
 	GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
 fi
 
+test "$type" = interactive && run_interactive_rebase
+
+# Detach HEAD and reset the tree
+say "First, rewinding head to replay your work on top of it..."
+git checkout -q "$onto^0" || die "could not detach HEAD"
+git update-ref ORIG_HEAD $branch
+
 # If the $onto is a proper descendant of the tip of the branch, then
 # we just fast-forwarded.
 if test "$mb" = "$branch"
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 17/31] rebase: remove $branch as synonym for $orig_head
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (15 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 16/31] rebase -i: support --stat Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 18/31] rebase: extract merge code to new source file Martin von Zweigbergk
                     ` (15 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

The variables $branch and $orig_head were used as synonyms. To avoid
confusion, remove $branch. The name 'orig_head' seems more suitable,
since that is the name used when the variable is persisted.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase.sh |   19 +++++++++----------
 1 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index c8a7e4e..ed34906 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -485,10 +485,10 @@ case "$#" in
 	switch_to="$1"
 
 	if git show-ref --verify --quiet -- "refs/heads/$1" &&
-	   branch=$(git rev-parse -q --verify "refs/heads/$1")
+	   orig_head=$(git rev-parse -q --verify "refs/heads/$1")
 	then
 		head_name="refs/heads/$1"
-	elif branch=$(git rev-parse -q --verify "$1")
+	elif orig_head=$(git rev-parse -q --verify "$1")
 	then
 		head_name="detached HEAD"
 	else
@@ -506,24 +506,23 @@ case "$#" in
 		head_name="detached HEAD"
 		branch_name=HEAD ;# detached
 	fi
-	branch=$(git rev-parse --verify "${branch_name}^0") || exit
+	orig_head=$(git rev-parse --verify "${branch_name}^0") || exit
 	;;
 esac
-orig_head=$branch
 
 require_clean_work_tree "rebase" "Please commit or stash them."
 
-# Now we are rebasing commits $upstream..$branch (or with --root,
-# everything leading up to $branch) on top of $onto
+# Now we are rebasing commits $upstream..$orig_head (or with --root,
+# everything leading up to $orig_head) on top of $onto
 
 # Check if we are already based on $onto with linear history,
 # but this should be done only when upstream and onto are the same
 # and if this is not an interactive rebase.
-mb=$(git merge-base "$onto" "$branch")
+mb=$(git merge-base "$onto" "$orig_head")
 if test "$type" != interactive && test "$upstream" = "$onto" &&
 	test "$mb" = "$onto" &&
 	# linear history?
-	! (git rev-list --parents "$onto".."$branch" | sane_grep " .* ") > /dev/null
+	! (git rev-list --parents "$onto".."$orig_head" | sane_grep " .* ") > /dev/null
 then
 	if test -z "$force_rebase"
 	then
@@ -554,11 +553,11 @@ test "$type" = interactive && run_interactive_rebase
 # Detach HEAD and reset the tree
 say "First, rewinding head to replay your work on top of it..."
 git checkout -q "$onto^0" || die "could not detach HEAD"
-git update-ref ORIG_HEAD $branch
+git update-ref ORIG_HEAD $orig_head
 
 # If the $onto is a proper descendant of the tip of the branch, then
 # we just fast-forwarded.
-if test "$mb" = "$branch"
+if test "$mb" = "$orig_head"
 then
 	say "Fast-forwarded $branch_name to $onto_name."
 	move_to_original_branch
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 18/31] rebase: extract merge code to new source file
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (16 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 17/31] rebase: remove $branch as synonym for $orig_head Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-14  8:02     ` Johannes Sixt
  2011-02-06 18:43   ` [PATCH v2 19/31] rebase: extract am " Martin von Zweigbergk
                     ` (14 subsequent siblings)
  32 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Extract the code for merge-based rebase to git-rebase--merge.sh.

Suggested-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Changes since v1:

 * As suggested by Johannes Sixt, git-rebase--$type is now sourced
   instead of executed.

What copyright year? Most of the code is just extracted from
git-rebase.sh, which has copyright year 2005. Does that matter?

Would read_initial_state be a better name than read_basic_state?


 .gitignore           |    1 +
 Makefile             |    1 +
 git-rebase--merge.sh |  154 +++++++++++++++++++++++++++++++++++++++++++++++
 git-rebase.sh        |  162 ++++----------------------------------------------
 4 files changed, 167 insertions(+), 151 deletions(-)
 create mode 100644 git-rebase--merge.sh

diff --git a/.gitignore b/.gitignore
index 3dd6ef7..a8b98b4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -103,6 +103,7 @@
 /git-read-tree
 /git-rebase
 /git-rebase--interactive
+/git-rebase--merge
 /git-receive-pack
 /git-reflog
 /git-relink
diff --git a/Makefile b/Makefile
index 775ee83..f47550f 100644
--- a/Makefile
+++ b/Makefile
@@ -370,6 +370,7 @@ SCRIPT_SH += git-mergetool.sh
 SCRIPT_SH += git-pull.sh
 SCRIPT_SH += git-quiltimport.sh
 SCRIPT_SH += git-rebase--interactive.sh
+SCRIPT_SH += git-rebase--merge.sh
 SCRIPT_SH += git-rebase.sh
 SCRIPT_SH += git-repack.sh
 SCRIPT_SH += git-request-pull.sh
diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
new file mode 100644
index 0000000..c04ce8a
--- /dev/null
+++ b/git-rebase--merge.sh
@@ -0,0 +1,154 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Junio C Hamano.
+#
+
+. git-sh-setup
+
+prec=4
+
+read_state () {
+	onto_name=$(cat "$state_dir"/onto_name) &&
+	end=$(cat "$state_dir"/end) &&
+	msgnum=$(cat "$state_dir"/msgnum)
+}
+
+continue_merge () {
+	test -d "$state_dir" || die "$state_dir directory does not exist"
+
+	unmerged=$(git ls-files -u)
+	if test -n "$unmerged"
+	then
+		echo "You still have unmerged paths in your index"
+		echo "did you forget to use git add?"
+		die "$resolvemsg"
+	fi
+
+	cmt=`cat "$state_dir/current"`
+	if ! git diff-index --quiet --ignore-submodules HEAD --
+	then
+		if ! git commit --no-verify -C "$cmt"
+		then
+			echo "Commit failed, please do not call \"git commit\""
+			echo "directly, but instead do one of the following: "
+			die "$resolvemsg"
+		fi
+		if test -z "$GIT_QUIET"
+		then
+			printf "Committed: %0${prec}d " $msgnum
+		fi
+		echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten"
+	else
+		if test -z "$GIT_QUIET"
+		then
+			printf "Already applied: %0${prec}d " $msgnum
+		fi
+	fi
+	test -z "$GIT_QUIET" &&
+	GIT_PAGER='' git log --format=%s -1 "$cmt"
+
+	# onto the next patch:
+	msgnum=$(($msgnum + 1))
+	echo "$msgnum" >"$state_dir/msgnum"
+}
+
+call_merge () {
+	cmt="$(cat "$state_dir/cmt.$1")"
+	echo "$cmt" > "$state_dir/current"
+	hd=$(git rev-parse --verify HEAD)
+	cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
+	msgnum=$(cat "$state_dir/msgnum")
+	eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
+	eval GITHEAD_$hd='$onto_name'
+	export GITHEAD_$cmt GITHEAD_$hd
+	if test -n "$GIT_QUIET"
+	then
+		GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
+	fi
+	test -z "$strategy" && strategy=recursive
+	eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
+	rv=$?
+	case "$rv" in
+	0)
+		unset GITHEAD_$cmt GITHEAD_$hd
+		return
+		;;
+	1)
+		git rerere $allow_rerere_autoupdate
+		die "$resolvemsg"
+		;;
+	2)
+		echo "Strategy: $rv $strategy failed, try another" 1>&2
+		die "$resolvemsg"
+		;;
+	*)
+		die "Unknown exit code ($rv) from command:" \
+			"git-merge-$strategy $cmt^ -- HEAD $cmt"
+		;;
+	esac
+}
+
+finish_rb_merge () {
+	move_to_original_branch
+	git notes copy --for-rewrite=rebase < "$state_dir"/rewritten
+	if test -x "$GIT_DIR"/hooks/post-rewrite &&
+		test -s "$state_dir"/rewritten; then
+		"$GIT_DIR"/hooks/post-rewrite rebase < "$state_dir"/rewritten
+	fi
+	rm -r "$state_dir"
+	say All done.
+}
+
+case "$action" in
+continue)
+	read_state
+	continue_merge
+	while test "$msgnum" -le "$end"
+	do
+		call_merge "$msgnum"
+		continue_merge
+	done
+	finish_rb_merge
+	exit
+	;;
+skip)
+	read_state
+	git rerere clear
+	msgnum=$(($msgnum + 1))
+	while test "$msgnum" -le "$end"
+	do
+		call_merge "$msgnum"
+		continue_merge
+	done
+	finish_rb_merge
+	exit
+	;;
+esac
+
+mkdir -p "$state_dir"
+echo "$onto_name" > "$state_dir/onto_name"
+echo "$head_name" > "$state_dir/head-name"
+echo "$onto" > "$state_dir/onto"
+echo "$orig_head" > "$state_dir/orig-head"
+echo "$GIT_QUIET" > "$state_dir/quiet"
+
+msgnum=0
+for cmt in `git rev-list --reverse --no-merges "$revisions"`
+do
+	msgnum=$(($msgnum + 1))
+	echo "$cmt" > "$state_dir/cmt.$msgnum"
+done
+
+echo 1 >"$state_dir/msgnum"
+echo $msgnum >"$state_dir/end"
+
+end=$msgnum
+msgnum=1
+
+while test "$msgnum" -le "$end"
+do
+	call_merge "$msgnum"
+	continue_merge
+done
+
+finish_rb_merge
diff --git a/git-rebase.sh b/git-rebase.sh
index ed34906..44e169f 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -48,7 +48,6 @@ strategy_opts=
 do_merge=
 merge_dir="$GIT_DIR"/rebase-merge
 apply_dir="$GIT_DIR"/rebase-apply
-prec=4
 verbose=
 diffstat=
 test "$(git config --bool rebase.stat)" = true && diffstat=t
@@ -68,94 +67,13 @@ preserve_merges=
 autosquash=
 test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
 
-read_state () {
-	if test "$type" = merge
-	then
-		onto_name=$(cat "$state_dir"/onto_name) &&
-		end=$(cat "$state_dir"/end) &&
-		msgnum=$(cat "$state_dir"/msgnum)
-	fi &&
+read_basic_state () {
 	head_name=$(cat "$state_dir"/head-name) &&
 	onto=$(cat "$state_dir"/onto) &&
 	orig_head=$(cat "$state_dir"/orig-head) &&
 	GIT_QUIET=$(cat "$state_dir"/quiet)
 }
 
-continue_merge () {
-	test -d "$merge_dir" || die "$merge_dir directory does not exist"
-
-	unmerged=$(git ls-files -u)
-	if test -n "$unmerged"
-	then
-		echo "You still have unmerged paths in your index"
-		echo "did you forget to use git add?"
-		die "$resolvemsg"
-	fi
-
-	cmt=`cat "$merge_dir/current"`
-	if ! git diff-index --quiet --ignore-submodules HEAD --
-	then
-		if ! git commit --no-verify -C "$cmt"
-		then
-			echo "Commit failed, please do not call \"git commit\""
-			echo "directly, but instead do one of the following: "
-			die "$resolvemsg"
-		fi
-		if test -z "$GIT_QUIET"
-		then
-			printf "Committed: %0${prec}d " $msgnum
-		fi
-		echo "$cmt $(git rev-parse HEAD^0)" >> "$merge_dir/rewritten"
-	else
-		if test -z "$GIT_QUIET"
-		then
-			printf "Already applied: %0${prec}d " $msgnum
-		fi
-	fi
-	test -z "$GIT_QUIET" &&
-	GIT_PAGER='' git log --format=%s -1 "$cmt"
-
-	# onto the next patch:
-	msgnum=$(($msgnum + 1))
-	echo "$msgnum" >"$merge_dir/msgnum"
-}
-
-call_merge () {
-	cmt="$(cat "$merge_dir/cmt.$1")"
-	echo "$cmt" > "$merge_dir/current"
-	hd=$(git rev-parse --verify HEAD)
-	cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
-	msgnum=$(cat "$merge_dir/msgnum")
-	eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
-	eval GITHEAD_$hd='$onto_name'
-	export GITHEAD_$cmt GITHEAD_$hd
-	if test -n "$GIT_QUIET"
-	then
-		GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
-	fi
-	test -z "$strategy" && strategy=recursive
-	eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
-	rv=$?
-	case "$rv" in
-	0)
-		unset GITHEAD_$cmt GITHEAD_$hd
-		return
-		;;
-	1)
-		git rerere $allow_rerere_autoupdate
-		die "$resolvemsg"
-		;;
-	2)
-		echo "Strategy: $rv $strategy failed, try another" 1>&2
-		die "$resolvemsg"
-		;;
-	*)
-		die "Unknown exit code ($rv) from command:" \
-			"git-merge-$strategy $cmt^ -- HEAD $cmt"
-		;;
-	esac
-}
-
 move_to_original_branch () {
 	case "$head_name" in
 	refs/*)
@@ -168,23 +86,12 @@ move_to_original_branch () {
 	esac
 }
 
-finish_rb_merge () {
-	move_to_original_branch
-	git notes copy --for-rewrite=rebase < "$merge_dir"/rewritten
-	if test -x "$GIT_DIR"/hooks/post-rewrite &&
-		test -s "$merge_dir"/rewritten; then
-		"$GIT_DIR"/hooks/post-rewrite rebase < "$merge_dir"/rewritten
-	fi
-	rm -r "$merge_dir"
-	say All done.
-}
-
-run_interactive_rebase () {
+run_specific_rebase () {
 	if [ "$interactive_rebase" = implied ]; then
 		GIT_EDITOR=:
 		export GIT_EDITOR
 	fi
-	. git-rebase--interactive
+	test "$type" != am && . git-rebase--$type
 }
 
 run_pre_rebase_hook () {
@@ -341,7 +248,7 @@ test $# -gt 2 && usage
 if test -n "$action"
 then
 	test -z "$in_progress" && die "No rebase in progress?"
-	test "$type" = interactive && run_interactive_rebase
+	test "$type" = interactive && run_specific_rebase
 fi
 
 case "$action" in
@@ -352,44 +259,23 @@ continue)
 		echo "mark them as resolved using git add"
 		exit 1
 	}
-	read_state
-	if test -d "$merge_dir"
-	then
-		continue_merge
-		while test "$msgnum" -le "$end"
-		do
-			call_merge "$msgnum"
-			continue_merge
-		done
-		finish_rb_merge
-		exit
-	fi
+	read_basic_state
+	run_specific_rebase
 	git am --resolved --3way --resolvemsg="$resolvemsg" &&
 	move_to_original_branch
 	exit
 	;;
 skip)
 	git reset --hard HEAD || exit $?
-	read_state
-	if test -d "$merge_dir"
-	then
-		git rerere clear
-		msgnum=$(($msgnum + 1))
-		while test "$msgnum" -le "$end"
-		do
-			call_merge "$msgnum"
-			continue_merge
-		done
-		finish_rb_merge
-		exit
-	fi
+	read_basic_state
+	run_specific_rebase
 	git am -3 --skip --resolvemsg="$resolvemsg" &&
 	move_to_original_branch
 	exit
 	;;
 abort)
 	git rerere clear
-	read_state
+	read_basic_state
 	case "$head_name" in
 	refs/*)
 		git symbolic-ref HEAD $head_name ||
@@ -548,7 +434,7 @@ then
 	GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
 fi
 
-test "$type" = interactive && run_interactive_rebase
+test "$type" = interactive && run_specific_rebase
 
 # Detach HEAD and reset the tree
 say "First, rewinding head to replay your work on top of it..."
@@ -590,30 +476,4 @@ fi
 # start doing a rebase with git-merge
 # this is rename-aware if the recursive (default) strategy is used
 
-mkdir -p "$merge_dir"
-echo "$onto_name" > "$merge_dir/onto_name"
-echo "$head_name" > "$merge_dir/head-name"
-echo "$onto" > "$merge_dir/onto"
-echo "$orig_head" > "$merge_dir/orig-head"
-echo "$GIT_QUIET" > "$merge_dir/quiet"
-
-msgnum=0
-for cmt in `git rev-list --reverse --no-merges "$revisions"`
-do
-	msgnum=$(($msgnum + 1))
-	echo "$cmt" > "$merge_dir/cmt.$msgnum"
-done
-
-echo 1 >"$merge_dir/msgnum"
-echo $msgnum >"$merge_dir/end"
-
-end=$msgnum
-msgnum=1
-
-while test "$msgnum" -le "$end"
-do
-	call_merge "$msgnum"
-	continue_merge
-done
-
-finish_rb_merge
+run_specific_rebase
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 19/31] rebase: extract am code to new source file
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (17 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 18/31] rebase: extract merge code to new source file Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 20/31] rebase: show consistent conflict resolution hint Martin von Zweigbergk
                     ` (13 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Extract the code for am-based rebase to git-rebase--am.sh.

Suggested-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 .gitignore        |    1 +
 Makefile          |    1 +
 git-rebase--am.sh |   34 ++++++++++++++++++++++++++++++++++
 git-rebase.sh     |   31 ++-----------------------------
 4 files changed, 38 insertions(+), 29 deletions(-)
 create mode 100644 git-rebase--am.sh

diff --git a/.gitignore b/.gitignore
index a8b98b4..7aaf5c7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -102,6 +102,7 @@
 /git-quiltimport
 /git-read-tree
 /git-rebase
+/git-rebase--am
 /git-rebase--interactive
 /git-rebase--merge
 /git-receive-pack
diff --git a/Makefile b/Makefile
index f47550f..3cc60cb 100644
--- a/Makefile
+++ b/Makefile
@@ -369,6 +369,7 @@ SCRIPT_SH += git-merge-resolve.sh
 SCRIPT_SH += git-mergetool.sh
 SCRIPT_SH += git-pull.sh
 SCRIPT_SH += git-quiltimport.sh
+SCRIPT_SH += git-rebase--am.sh
 SCRIPT_SH += git-rebase--interactive.sh
 SCRIPT_SH += git-rebase--merge.sh
 SCRIPT_SH += git-rebase.sh
diff --git a/git-rebase--am.sh b/git-rebase--am.sh
new file mode 100644
index 0000000..263987c
--- /dev/null
+++ b/git-rebase--am.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Junio C Hamano.
+#
+
+. git-sh-setup
+
+case "$action" in
+continue)
+	git am --resolved --3way --resolvemsg="$resolvemsg" &&
+	move_to_original_branch
+	exit
+	;;
+skip)
+	git am --skip -3 --resolvemsg="$resolvemsg" &&
+	move_to_original_branch
+	exit
+	;;
+esac
+
+test -n "$rebase_root" && root_flag=--root
+
+git format-patch -k --stdout --full-index --ignore-if-in-upstream \
+	--src-prefix=a/ --dst-prefix=b/ \
+	--no-renames $root_flag "$revisions" |
+git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" &&
+move_to_original_branch
+ret=$?
+test 0 != $ret -a -d "$state_dir" &&
+	echo $head_name > "$state_dir/head-name" &&
+	echo $onto > "$state_dir/onto" &&
+	echo $orig_head > "$state_dir/orig-head" &&
+	echo "$GIT_QUIET" > "$state_dir/quiet"
+exit $ret
diff --git a/git-rebase.sh b/git-rebase.sh
index 44e169f..c60221b 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -91,7 +91,7 @@ run_specific_rebase () {
 		GIT_EDITOR=:
 		export GIT_EDITOR
 	fi
-	test "$type" != am && . git-rebase--$type
+	. git-rebase--$type
 }
 
 run_pre_rebase_hook () {
@@ -261,17 +261,11 @@ continue)
 	}
 	read_basic_state
 	run_specific_rebase
-	git am --resolved --3way --resolvemsg="$resolvemsg" &&
-	move_to_original_branch
-	exit
 	;;
 skip)
 	git reset --hard HEAD || exit $?
 	read_basic_state
 	run_specific_rebase
-	git am -3 --skip --resolvemsg="$resolvemsg" &&
-	move_to_original_branch
-	exit
 	;;
 abort)
 	git rerere clear
@@ -324,14 +318,12 @@ then
 	shift
 	upstream=`git rev-parse --verify "${upstream_name}^0"` ||
 	die "invalid upstream $upstream_name"
-	unset root_flag
 	upstream_arg="$upstream_name"
 else
 	test -z "$onto" && die "You must specify --onto when using --root"
 	unset upstream_name
 	unset upstream
-	root_flag="--root"
-	upstream_arg="$root_flag"
+	upstream_arg=--root
 fi
 
 # Make sure the branch to rebase onto is valid.
@@ -457,23 +449,4 @@ else
 	revisions="$upstream..$orig_head"
 fi
 
-if test -z "$do_merge"
-then
-	git format-patch -k --stdout --full-index --ignore-if-in-upstream \
-		--src-prefix=a/ --dst-prefix=b/ \
-		--no-renames $root_flag "$revisions" |
-	git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" &&
-	move_to_original_branch
-	ret=$?
-	test 0 != $ret -a -d "$apply_dir" &&
-		echo $head_name > "$apply_dir/head-name" &&
-		echo $onto > "$apply_dir/onto" &&
-		echo $orig_head > "$apply_dir/orig-head" &&
-		echo "$GIT_QUIET" > "$apply_dir/quiet"
-	exit $ret
-fi
-
-# start doing a rebase with git-merge
-# this is rename-aware if the recursive (default) strategy is used
-
 run_specific_rebase
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 20/31] rebase: show consistent conflict resolution hint
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (18 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 19/31] rebase: extract am " Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 21/31] rebase -i: align variable names Martin von Zweigbergk
                     ` (12 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

When rebase stops due to conflict, interactive rebase currently
displays a different hint to the user than non-interactive rebase
does. Use the same message for both types of rebase.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Should we include the "mark the corrected paths with 'git add
<paths>'" part?


 git-rebase--interactive.sh |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index f94f057..0499f9e 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -81,9 +81,7 @@ amend="$dotest"/amend
 rewritten_list="$dotest"/rewritten-list
 rewritten_pending="$dotest"/rewritten-pending
 
-GIT_CHERRY_PICK_HELP="\
-hint: after resolving the conflicts, mark the corrected paths
-hint: with 'git add <paths>' and run 'git rebase --continue'"
+GIT_CHERRY_PICK_HELP="$resolvemsg"
 export GIT_CHERRY_PICK_HELP
 
 warn () {
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 21/31] rebase -i: align variable names
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (19 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 20/31] rebase: show consistent conflict resolution hint Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 22/31] rebase: make -v a tiny bit more verbose Martin von Zweigbergk
                     ` (11 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Rename variables HEAD and OLDHEAD to orig_head and HEADNAME to
head_name, which are the names used in git-rebase.sh. This prepares
for factoring out of the code that persists these variables during the
entire rebase process. Using the same variable names to mean the same
thing in both files also makes the code easier to read.

While at it, also remove the DOTEST variable and use the state_dir
variable that was inherited from git-rebase.sh instead.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |  120 +++++++++++++++++++++----------------------
 1 files changed, 59 insertions(+), 61 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 0499f9e..fa8bfda 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -12,22 +12,20 @@
 
 . git-sh-setup
 
-dotest="$GIT_DIR/rebase-merge"
-
 # The file containing rebase commands, comments, and empty lines.
 # This file is created by "git rebase -i" then edited by the user.  As
 # the lines are processed, they are removed from the front of this
 # file and written to the tail of $done.
-todo="$dotest"/git-rebase-todo
+todo="$state_dir"/git-rebase-todo
 
 # The rebase command lines that have already been processed.  A line
 # is moved here when it is first handled, before any associated user
 # actions.
-done="$dotest"/done
+done="$state_dir"/done
 
 # The commit message that is planned to be used for any changes that
 # need to be committed following a user interaction.
-msg="$dotest"/message
+msg="$state_dir"/message
 
 # The file into which is accumulated the suggested commit message for
 # squash/fixup commands.  When the first of a series of squash/fixups
@@ -42,14 +40,14 @@ msg="$dotest"/message
 # written to the file so far (including the initial "pick" commit).
 # Each time that a commit message is processed, this line is read and
 # updated.  It is deleted just before the combined commit is made.
-squash_msg="$dotest"/message-squash
+squash_msg="$state_dir"/message-squash
 
 # If the current series of squash/fixups has not yet included a squash
 # command, then this file exists and holds the commit message of the
 # original "pick" commit.  (If the series ends without a "squash"
 # command, then this can be used as the commit message of the combined
 # commit without opening the editor.)
-fixup_msg="$dotest"/message-fixup
+fixup_msg="$state_dir"/message-fixup
 
 # $rewritten is the name of a directory containing files for each
 # commit that is reachable by at least one merge base of $head and
@@ -57,14 +55,14 @@ fixup_msg="$dotest"/message-fixup
 # might be.  This ensures that commits on merged, but otherwise
 # unrelated side branches are left alone. (Think "X" in the man page's
 # example.)
-rewritten="$dotest"/rewritten
+rewritten="$state_dir"/rewritten
 
-dropped="$dotest"/dropped
+dropped="$state_dir"/dropped
 
 # A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
 # GIT_AUTHOR_DATE that will be used for the commit that is currently
 # being rebased.
-author_script="$dotest"/author-script
+author_script="$state_dir"/author-script
 
 # When an "edit" rebase command is being processed, the SHA1 of the
 # commit to be edited is recorded in this file.  When "git rebase
@@ -72,14 +70,14 @@ author_script="$dotest"/author-script
 # will be amended to the HEAD commit, but only provided the HEAD
 # commit is still the commit to be edited.  When any other rebase
 # command is processed, this file is deleted.
-amend="$dotest"/amend
+amend="$state_dir"/amend
 
 # For the post-rewrite hook, we make a list of rewritten commits and
 # their new sha1s.  The rewritten-pending list keeps the sha1s of
 # commits that have been processed, but not committed yet,
 # e.g. because they are waiting for a 'squash' command.
-rewritten_list="$dotest"/rewritten-list
-rewritten_pending="$dotest"/rewritten-pending
+rewritten_list="$state_dir"/rewritten-list
+rewritten_pending="$state_dir"/rewritten-pending
 
 GIT_CHERRY_PICK_HELP="$resolvemsg"
 export GIT_CHERRY_PICK_HELP
@@ -145,7 +143,7 @@ make_patch () {
 	*)
 		echo "Root commit"
 		;;
-	esac > "$dotest"/patch
+	esac > "$state_dir"/patch
 	test -f "$msg" ||
 		commit_message "$1" > "$msg"
 	test -f "$author_script" ||
@@ -153,14 +151,14 @@ make_patch () {
 }
 
 die_with_patch () {
-	echo "$1" > "$dotest"/stopped-sha
+	echo "$1" > "$state_dir"/stopped-sha
 	make_patch "$1"
 	git rerere
 	die "$2"
 }
 
 die_abort () {
-	rm -rf "$dotest"
+	rm -rf "$state_dir"
 	die "$1"
 }
 
@@ -205,20 +203,20 @@ pick_one_preserving_merges () {
 	esac
 	sha1=$(git rev-parse $sha1)
 
-	if test -f "$dotest"/current-commit
+	if test -f "$state_dir"/current-commit
 	then
 		if test "$fast_forward" = t
 		then
 			while read current_commit
 			do
 				git rev-parse HEAD > "$rewritten"/$current_commit
-			done <"$dotest"/current-commit
-			rm "$dotest"/current-commit ||
+			done <"$state_dir"/current-commit
+			rm "$state_dir"/current-commit ||
 			die "Cannot write current commit's replacement sha1"
 		fi
 	fi
 
-	echo $sha1 >> "$dotest"/current-commit
+	echo $sha1 >> "$state_dir"/current-commit
 
 	# rewrite parents; if none were rewritten, we can fast-forward.
 	new_parents=
@@ -425,7 +423,7 @@ do_next () {
 		mark_action_done
 		pick_one $sha1 ||
 			die_with_patch $sha1 "Could not apply $sha1... $rest"
-		echo "$sha1" > "$dotest"/stopped-sha
+		echo "$sha1" > "$state_dir"/stopped-sha
 		make_patch $sha1
 		git rev-parse --verify HEAD > "$amend"
 		warn "Stopped at $sha1... $rest"
@@ -490,7 +488,7 @@ do_next () {
 		printf 'Executing: %s\n' "$rest"
 		# "exec" command doesn't take a sha1 in the todo-list.
 		# => can't just use $sha1 here.
-		git rev-parse --verify HEAD > "$dotest"/stopped-sha
+		git rev-parse --verify HEAD > "$state_dir"/stopped-sha
 		${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
 		status=$?
 		if test "$status" -ne 0
@@ -525,19 +523,19 @@ do_next () {
 	test -s "$todo" && return
 
 	comment_for_reflog finish &&
-	headname=$(cat "$dotest"/head-name) &&
-	oldhead=$(cat "$dotest"/head) &&
-	shortonto=$(git rev-parse --short $(cat "$dotest"/onto)) &&
+	head_name=$(cat "$state_dir"/head-name) &&
+	orig_head=$(cat "$state_dir"/head) &&
+	shortonto=$(git rev-parse --short $(cat "$state_dir"/onto)) &&
 	newhead=$(git rev-parse HEAD) &&
-	case $headname in
+	case $head_name in
 	refs/*)
-		message="$GIT_REFLOG_ACTION: $headname onto $shortonto" &&
-		git update-ref -m "$message" $headname $newhead $oldhead &&
-		git symbolic-ref HEAD $headname
+		message="$GIT_REFLOG_ACTION: $head_name onto $shortonto" &&
+		git update-ref -m "$message" $head_name $newhead $orig_head &&
+		git symbolic-ref HEAD $head_name
 		;;
 	esac && {
-		test ! -f "$dotest"/verbose ||
-			git diff-tree --stat $(cat "$dotest"/head)..HEAD
+		test ! -f "$state_dir"/verbose ||
+			git diff-tree --stat $(cat "$state_dir"/head)..HEAD
 	} &&
 	{
 		test -s "$rewritten_list" &&
@@ -549,9 +547,9 @@ do_next () {
 		"$GIT_DIR"/hooks/post-rewrite rebase < "$rewritten_list"
 		true # we don't care if this hook failed
 	fi &&
-	rm -rf "$dotest" &&
+	rm -rf "$state_dir" &&
 	git gc --auto &&
-	warn "Successfully rebased and updated $headname."
+	warn "Successfully rebased and updated $head_name."
 
 	exit
 }
@@ -602,9 +600,9 @@ skip_unnecessary_picks () {
 
 get_saved_options () {
 	test -d "$rewritten" && preserve_merges=t
-	test -f "$dotest"/strategy && strategy="$(cat "$dotest"/strategy)"
-	test -f "$dotest"/verbose && verbose=t
-	test -f "$dotest"/rebase-root && rebase_root=t
+	test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
+	test -f "$state_dir"/verbose && verbose=t
+	test -f "$state_dir"/rebase-root && rebase_root=t
 }
 
 # Rearrange the todo list that has both "pick sha1 msg" and
@@ -704,7 +702,7 @@ first and then run 'git rebase --continue' again."
 		}
 	fi
 
-	record_in_rewritten "$(cat "$dotest"/stopped-sha)"
+	record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
 
 	require_clean_work_tree "rebase"
 	do_rest
@@ -715,15 +713,15 @@ abort)
 
 	git rerere clear
 
-	headname=$(cat "$dotest"/head-name)
-	head=$(cat "$dotest"/head)
-	case $headname in
+	head_name=$(cat "$state_dir"/head-name)
+	orig_head=$(cat "$state_dir"/head)
+	case $head_name in
 	refs/*)
-		git symbolic-ref HEAD $headname
+		git symbolic-ref HEAD $head_name
 		;;
 	esac &&
-	output git reset --hard $head &&
-	rm -rf "$dotest"
+	output git reset --hard $orig_head &&
+	rm -rf "$state_dir"
 	exit
 	;;
 skip)
@@ -747,28 +745,28 @@ then
 		die "Could not checkout $switch_to"
 fi
 
-head=$(git rev-parse --verify HEAD) || die "No HEAD?"
-mkdir "$dotest" || die "Could not create temporary $dotest"
+orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
+mkdir "$state_dir" || die "Could not create temporary $state_dir"
 
-: > "$dotest"/interactive || die "Could not mark as interactive"
-echo "$head_name" > "$dotest"/head-name
+: > "$state_dir"/interactive || die "Could not mark as interactive"
+echo "$head_name" > "$state_dir"/head-name
 
-echo $head > "$dotest"/head
+echo $orig_head > "$state_dir"/head
 case "$rebase_root" in
 '')
-	rm -f "$dotest"/rebase-root ;;
+	rm -f "$state_dir"/rebase-root ;;
 *)
-	: >"$dotest"/rebase-root ;;
+	: >"$state_dir"/rebase-root ;;
 esac
-echo $onto > "$dotest"/onto
-test -z "$strategy" || echo "$strategy" > "$dotest"/strategy
-test t = "$verbose" && : > "$dotest"/verbose
+echo $onto > "$state_dir"/onto
+test -z "$strategy" || echo "$strategy" > "$state_dir"/strategy
+test t = "$verbose" && : > "$state_dir"/verbose
 if test t = "$preserve_merges"
 then
 	if test -z "$rebase_root"
 	then
 		mkdir "$rewritten" &&
-		for c in $(git merge-base --all $head $upstream)
+		for c in $(git merge-base --all $orig_head $upstream)
 		do
 			echo $onto > "$rewritten"/$c ||
 				die "Could not init rewritten commits"
@@ -782,21 +780,21 @@ then
 	# parents to rewrite and skipping dropped commits would
 	# prematurely end our probe
 	merges_option=
-	first_after_upstream="$(git rev-list --reverse --first-parent $upstream..$head | head -n 1)"
+	first_after_upstream="$(git rev-list --reverse --first-parent $upstream..$orig_head | head -n 1)"
 else
 	merges_option="--no-merges --cherry-pick"
 fi
 
-shorthead=$(git rev-parse --short $head)
+shorthead=$(git rev-parse --short $orig_head)
 shortonto=$(git rev-parse --short $onto)
 if test -z "$rebase_root"
 	# this is now equivalent to ! -z "$upstream"
 then
 	shortupstream=$(git rev-parse --short $upstream)
-	revisions=$upstream...$head
+	revisions=$upstream...$orig_head
 	shortrevisions=$shortupstream..$shorthead
 else
-	revisions=$onto...$head
+	revisions=$onto...$orig_head
 	shortrevisions=$shorthead
 fi
 git rev-list $merges_option --pretty=oneline --abbrev-commit \
@@ -837,13 +835,13 @@ then
 	mkdir "$dropped"
 	# Save all non-cherry-picked changes
 	git rev-list $revisions --left-right --cherry-pick | \
-		sed -n "s/^>//p" > "$dotest"/not-cherry-picks
+		sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
 	# Now all commits and note which ones are missing in
 	# not-cherry-picks and hence being dropped
 	git rev-list $revisions |
 	while read rev
 	do
-		if test -f "$rewritten"/$rev -a "$(sane_grep "$rev" "$dotest"/not-cherry-picks)" = ""
+		if test -f "$rewritten"/$rev -a "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = ""
 		then
 			# Use -f2 because if rev-list is telling us this commit is
 			# not worthwhile, we don't want to track its multiple heads,
@@ -889,5 +887,5 @@ has_action "$todo" ||
 test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
 
 output git checkout $onto || die_abort "could not detach HEAD"
-git update-ref ORIG_HEAD $head
+git update-ref ORIG_HEAD $orig_head
 do_rest
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 22/31] rebase: make -v a tiny bit more verbose
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (20 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 21/31] rebase -i: align variable names Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 23/31] rebase: factor out sub command handling Martin von Zweigbergk
                     ` (10 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

To make it possible to later remove the handling of --abort from
git-rebase--interactive.sh, align the implementation in git-rebase.sh
with the former by making it a bit more verbose.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
What do we really want to print when -v is passed? Interactive rebase
is currently quite a bit more verbose than non-interactive rebase.


 git-rebase--interactive.sh |   14 --------------
 git-rebase.sh              |   18 ++++++++++++++++--
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index fa8bfda..affa467 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -86,20 +86,6 @@ warn () {
 	printf '%s\n' "$*" >&2
 }
 
-output () {
-	case "$verbose" in
-	'')
-		output=$("$@" 2>&1 )
-		status=$?
-		test $status != 0 && printf "%s\n" "$output"
-		return $status
-		;;
-	*)
-		"$@"
-		;;
-	esac
-}
-
 # Output the commit message for the specified commit.
 commit_message () {
 	git cat-file commit "$1" | sed "1,/^$/d"
diff --git a/git-rebase.sh b/git-rebase.sh
index c60221b..42d635b 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -74,6 +74,20 @@ read_basic_state () {
 	GIT_QUIET=$(cat "$state_dir"/quiet)
 }
 
+output () {
+	case "$verbose" in
+	'')
+		output=$("$@" 2>&1 )
+		status=$?
+		test $status != 0 && printf "%s\n" "$output"
+		return $status
+		;;
+	*)
+		"$@"
+		;;
+	esac
+}
+
 move_to_original_branch () {
 	case "$head_name" in
 	refs/*)
@@ -263,7 +277,7 @@ continue)
 	run_specific_rebase
 	;;
 skip)
-	git reset --hard HEAD || exit $?
+	output git reset --hard HEAD || exit $?
 	read_basic_state
 	run_specific_rebase
 	;;
@@ -276,7 +290,7 @@ abort)
 		die "Could not move back to $head_name"
 		;;
 	esac
-	git reset --hard $orig_head
+	output git reset --hard $orig_head
 	rm -r "$state_dir"
 	exit
 	;;
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 23/31] rebase: factor out sub command handling
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (21 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 22/31] rebase: make -v a tiny bit more verbose Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 24/31] rebase: extract code for writing basic state Martin von Zweigbergk
                     ` (9 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Factor out the common parts of the handling of the sub commands
'--continue', '--skip' and '--abort'. The '--abort' handling can
handled completely in git-rebase.sh.

After this refactoring, the calls to git-rebase--am.sh,
git-rebase--merge.sh and git-rebase--interactive.sh will be better
aligned. There will only be one call to interactive rebase that will
shortcut the very last part of git-rebase.sh.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |   34 +++-------------------------------
 git-rebase.sh              |   17 +++++++++++++++--
 2 files changed, 18 insertions(+), 33 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index affa467..4af0bc6 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -509,9 +509,7 @@ do_next () {
 	test -s "$todo" && return
 
 	comment_for_reflog finish &&
-	head_name=$(cat "$state_dir"/head-name) &&
-	orig_head=$(cat "$state_dir"/head) &&
-	shortonto=$(git rev-parse --short $(cat "$state_dir"/onto)) &&
+	shortonto=$(git rev-parse --short $onto) &&
 	newhead=$(git rev-parse HEAD) &&
 	case $head_name in
 	refs/*)
@@ -521,7 +519,7 @@ do_next () {
 		;;
 	esac && {
 		test ! -f "$state_dir"/verbose ||
-			git diff-tree --stat $(cat "$state_dir"/head)..HEAD
+			git diff-tree --stat $orig_head..HEAD
 	} &&
 	{
 		test -s "$rewritten_list" &&
@@ -655,14 +653,6 @@ rearrange_squash () {
 case "$action" in
 continue)
 	get_saved_options
-	comment_for_reflog continue
-
-	# Sanity check
-	git rev-parse --verify HEAD >/dev/null ||
-		die "Cannot read HEAD"
-	git update-index --ignore-submodules --refresh &&
-		git diff-files --quiet --ignore-submodules ||
-		die "Working tree is dirty"
 
 	# do we have anything to commit?
 	if git diff-index --cached --quiet --ignore-submodules HEAD --
@@ -693,30 +683,12 @@ first and then run 'git rebase --continue' again."
 	require_clean_work_tree "rebase"
 	do_rest
 	;;
-abort)
-	get_saved_options
-	comment_for_reflog abort
-
-	git rerere clear
-
-	head_name=$(cat "$state_dir"/head-name)
-	orig_head=$(cat "$state_dir"/head)
-	case $head_name in
-	refs/*)
-		git symbolic-ref HEAD $head_name
-		;;
-	esac &&
-	output git reset --hard $orig_head &&
-	rm -rf "$state_dir"
-	exit
-	;;
 skip)
 	get_saved_options
-	comment_for_reflog skip
 
 	git rerere clear
 
-	output git reset --hard && do_rest
+	do_rest
 	;;
 esac
 
diff --git a/git-rebase.sh b/git-rebase.sh
index 42d635b..21bb027 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -70,7 +70,12 @@ test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
 read_basic_state () {
 	head_name=$(cat "$state_dir"/head-name) &&
 	onto=$(cat "$state_dir"/onto) &&
-	orig_head=$(cat "$state_dir"/orig-head) &&
+	if test "$type" = interactive
+	then
+		orig_head=$(cat "$state_dir"/head)
+	else
+		orig_head=$(cat "$state_dir"/orig-head)
+	fi &&
 	GIT_QUIET=$(cat "$state_dir"/quiet)
 }
 
@@ -262,11 +267,19 @@ test $# -gt 2 && usage
 if test -n "$action"
 then
 	test -z "$in_progress" && die "No rebase in progress?"
-	test "$type" = interactive && run_specific_rebase
+	# Only interactive rebase uses detailed reflog messages
+	if test "$type" = interactive && test "$GIT_REFLOG_ACTION" = rebase
+	then
+		GIT_REFLOG_ACTION="rebase -i ($action)"
+		export GIT_REFLOG_ACTION
+	fi
 fi
 
 case "$action" in
 continue)
+	# Sanity check
+	git rev-parse --verify HEAD >/dev/null ||
+		die "Cannot read HEAD"
 	git update-index --ignore-submodules --refresh &&
 	git diff-files --quiet --ignore-submodules || {
 		echo "You must edit all merge conflicts and then"
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 24/31] rebase: extract code for writing basic state
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (22 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 23/31] rebase: factor out sub command handling Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 25/31] rebase: remember verbose option Martin von Zweigbergk
                     ` (8 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Extract the code for writing the state to rebase-apply/ or
rebase-merge/ when a rebase is initiated. This will make it easier to
later make both interactive and non-interactive rebase remember the
options used.

Note that non-interactive rebase stores the sha1 of the original head
in a file called orig-head, while interactive rebase stores it in a
file called head. Change this by writing to orig-head in both
cases. When reading, try to read from orig-head. If that fails, read
from head instead. This protects users who upgraded git while they had
an ongoing interactive rebase, while still making it possible to
remove the code that reads from head at some point in the future.

Helped-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Changes since v1:

 * As suggested by Thomas, always write to orig-head file. When
   reading, try orig-head first and fall back to reading from head.


 git-rebase--am.sh          |    6 +-----
 git-rebase--interactive.sh |    5 +----
 git-rebase--merge.sh       |    5 +----
 git-rebase.sh              |   16 +++++++++++++---
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/git-rebase--am.sh b/git-rebase--am.sh
index 263987c..c9604a6 100644
--- a/git-rebase--am.sh
+++ b/git-rebase--am.sh
@@ -26,9 +26,5 @@ git format-patch -k --stdout --full-index --ignore-if-in-upstream \
 git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" &&
 move_to_original_branch
 ret=$?
-test 0 != $ret -a -d "$state_dir" &&
-	echo $head_name > "$state_dir/head-name" &&
-	echo $onto > "$state_dir/onto" &&
-	echo $orig_head > "$state_dir/orig-head" &&
-	echo "$GIT_QUIET" > "$state_dir/quiet"
+test 0 != $ret -a -d "$state_dir" && write_basic_state
 exit $ret
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 4af0bc6..437cc52 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -707,16 +707,13 @@ orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
 mkdir "$state_dir" || die "Could not create temporary $state_dir"
 
 : > "$state_dir"/interactive || die "Could not mark as interactive"
-echo "$head_name" > "$state_dir"/head-name
-
-echo $orig_head > "$state_dir"/head
+write_basic_state
 case "$rebase_root" in
 '')
 	rm -f "$state_dir"/rebase-root ;;
 *)
 	: >"$state_dir"/rebase-root ;;
 esac
-echo $onto > "$state_dir"/onto
 test -z "$strategy" || echo "$strategy" > "$state_dir"/strategy
 test t = "$verbose" && : > "$state_dir"/verbose
 if test t = "$preserve_merges"
diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
index c04ce8a..eb0f7bc 100644
--- a/git-rebase--merge.sh
+++ b/git-rebase--merge.sh
@@ -127,10 +127,7 @@ esac
 
 mkdir -p "$state_dir"
 echo "$onto_name" > "$state_dir/onto_name"
-echo "$head_name" > "$state_dir/head-name"
-echo "$onto" > "$state_dir/onto"
-echo "$orig_head" > "$state_dir/orig-head"
-echo "$GIT_QUIET" > "$state_dir/quiet"
+write_basic_state
 
 msgnum=0
 for cmt in `git rev-list --reverse --no-merges "$revisions"`
diff --git a/git-rebase.sh b/git-rebase.sh
index 21bb027..5a399aa 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -70,15 +70,25 @@ test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
 read_basic_state () {
 	head_name=$(cat "$state_dir"/head-name) &&
 	onto=$(cat "$state_dir"/onto) &&
-	if test "$type" = interactive
+	# We always write to orig-head, but interactive rebase used to write to
+	# head. Fall back to reading from head to cover for the case that the
+	# user upgraded git with an ongoing interactive rebase.
+	if test -f "$state_dir"/orig-head
 	then
-		orig_head=$(cat "$state_dir"/head)
-	else
 		orig_head=$(cat "$state_dir"/orig-head)
+	else
+		orig_head=$(cat "$state_dir"/head)
 	fi &&
 	GIT_QUIET=$(cat "$state_dir"/quiet)
 }
 
+write_basic_state () {
+	echo "$head_name" > "$state_dir"/head-name &&
+	echo "$onto" > "$state_dir"/onto &&
+	echo "$orig_head" > "$state_dir"/orig-head &&
+	echo "$GIT_QUIET" > "$state_dir"/quiet
+}
+
 output () {
 	case "$verbose" in
 	'')
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 25/31] rebase: remember verbose option
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (23 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 24/31] rebase: extract code for writing basic state Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 26/31] rebase: remember strategy and strategy options Martin von Zweigbergk
                     ` (7 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Currently, only interactive rebase remembers the value of the '-v'
flag from the initial invocation. Make non-interactive rebase also
remember it.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |    2 --
 git-rebase.sh              |    6 ++++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 437cc52..f076a6e 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -585,7 +585,6 @@ skip_unnecessary_picks () {
 get_saved_options () {
 	test -d "$rewritten" && preserve_merges=t
 	test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
-	test -f "$state_dir"/verbose && verbose=t
 	test -f "$state_dir"/rebase-root && rebase_root=t
 }
 
@@ -715,7 +714,6 @@ case "$rebase_root" in
 	: >"$state_dir"/rebase-root ;;
 esac
 test -z "$strategy" || echo "$strategy" > "$state_dir"/strategy
-test t = "$verbose" && : > "$state_dir"/verbose
 if test t = "$preserve_merges"
 then
 	if test -z "$rebase_root"
diff --git a/git-rebase.sh b/git-rebase.sh
index 5a399aa..8a36e7a 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -79,14 +79,16 @@ read_basic_state () {
 	else
 		orig_head=$(cat "$state_dir"/head)
 	fi &&
-	GIT_QUIET=$(cat "$state_dir"/quiet)
+	GIT_QUIET=$(cat "$state_dir"/quiet) &&
+	test -f "$state_dir"/verbose && verbose=t
 }
 
 write_basic_state () {
 	echo "$head_name" > "$state_dir"/head-name &&
 	echo "$onto" > "$state_dir"/onto &&
 	echo "$orig_head" > "$state_dir"/orig-head &&
-	echo "$GIT_QUIET" > "$state_dir"/quiet
+	echo "$GIT_QUIET" > "$state_dir"/quiet &&
+	test t = "$verbose" && : > "$state_dir"/verbose
 }
 
 output () {
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 26/31] rebase: remember strategy and strategy options
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (24 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 25/31] rebase: remember verbose option Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 27/31] rebase -m: remember allow_rerere_autoupdate option Martin von Zweigbergk
                     ` (6 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

When a rebase is resumed, interactive rebase remembers any merge
strategy passed when the rebase was initated. Make non-interactive
rebase remember any merge strategy as well. Also make non-interactive
rebase remember any merge strategy options.

To be able to resume a rebase that was initiated with an older version
of git (older than this commit), make sure not to expect the saved
option files to exist.

Test case idea taken from Junio's 71fc224 (t3402: test "rebase
-s<strategy> -X<opt>", 2010-11-11).

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |    2 --
 git-rebase.sh              |    6 ++++++
 t/t3418-rebase-continue.sh |   29 +++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index f076a6e..5773b75 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -584,7 +584,6 @@ skip_unnecessary_picks () {
 
 get_saved_options () {
 	test -d "$rewritten" && preserve_merges=t
-	test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
 	test -f "$state_dir"/rebase-root && rebase_root=t
 }
 
@@ -713,7 +712,6 @@ case "$rebase_root" in
 *)
 	: >"$state_dir"/rebase-root ;;
 esac
-test -z "$strategy" || echo "$strategy" > "$state_dir"/strategy
 if test t = "$preserve_merges"
 then
 	if test -z "$rebase_root"
diff --git a/git-rebase.sh b/git-rebase.sh
index 8a36e7a..f4ad7c1 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -81,6 +81,9 @@ read_basic_state () {
 	fi &&
 	GIT_QUIET=$(cat "$state_dir"/quiet) &&
 	test -f "$state_dir"/verbose && verbose=t
+	test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
+	test -f "$state_dir"/strategy_opts &&
+		strategy_opts="$(cat "$state_dir"/strategy_opts)"
 }
 
 write_basic_state () {
@@ -89,6 +92,9 @@ write_basic_state () {
 	echo "$orig_head" > "$state_dir"/orig-head &&
 	echo "$GIT_QUIET" > "$state_dir"/quiet &&
 	test t = "$verbose" && : > "$state_dir"/verbose
+	test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
+	test -n "$strategy_opts" && echo "$strategy_opts" > \
+		"$state_dir"/strategy_opts
 }
 
 output () {
diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh
index 1d90191..5469546 100755
--- a/t/t3418-rebase-continue.sh
+++ b/t/t3418-rebase-continue.sh
@@ -45,4 +45,33 @@ test_expect_success 'rebase --continue can not be used with other options' '
 	test_must_fail git rebase --continue -v
 '
 
+test_expect_success 'rebase --continue remembers merge strategy and options' '
+	rm -fr .git/rebase-* &&
+	git reset --hard commit-new-file-F2-on-topic-branch &&
+	test_commit "commit-new-file-F3-on-topic-branch" F3 32 &&
+	test_when_finished "rm -fr test-bin funny.was.run" &&
+	mkdir test-bin &&
+	cat >test-bin/git-merge-funny <<-EOF
+	#!$SHELL_PATH
+	case "\$1" in --opt) ;; *) exit 2 ;; esac
+	shift &&
+	>funny.was.run &&
+	exec git merge-recursive "\$@"
+	EOF
+	chmod +x test-bin/git-merge-funny &&
+	(
+		PATH=./test-bin:$PATH
+		test_must_fail git rebase -s funny -Xopt master topic
+	) &&
+	test -f funny.was.run &&
+	rm funny.was.run &&
+	echo "Resolved" >F2 &&
+	git add F2 &&
+	(
+		PATH=./test-bin:$PATH
+		git rebase --continue
+	) &&
+	test -f funny.was.run
+'
+
 test_done
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 27/31] rebase -m: remember allow_rerere_autoupdate option
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (25 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 26/31] rebase: remember strategy and strategy options Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 28/31] rebase -m: don't print exit code 2 when merge fails Martin von Zweigbergk
                     ` (5 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

If '--[no-]allow_rerere_autoupdate' is passed when 'git rebase -m' is
called and a merge conflict occurs, the flag will be forgotten for the
rest of the rebase process. Make rebase remember it by saving the
value.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
allow_rerere_autoupdate is only used by git-rebase--merge. Still ok to
write and read it here?

Should allow_rerere_autoupdate also be added to git_am_opt?


 git-rebase.sh              |    4 ++++
 t/t3418-rebase-continue.sh |   21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index f4ad7c1..be9ec2a 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -84,6 +84,8 @@ read_basic_state () {
 	test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
 	test -f "$state_dir"/strategy_opts &&
 		strategy_opts="$(cat "$state_dir"/strategy_opts)"
+	test -f "$state_dir"/allow_rerere_autoupdate &&
+		allow_rerere_autoupdate="$(cat "$state_dir"/allow_rerere_autoupdate)"
 }
 
 write_basic_state () {
@@ -95,6 +97,8 @@ write_basic_state () {
 	test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
 	test -n "$strategy_opts" && echo "$strategy_opts" > \
 		"$state_dir"/strategy_opts
+	test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \
+		"$state_dir"/allow_rerere_autoupdate
 }
 
 output () {
diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh
index 5469546..1e855cd 100755
--- a/t/t3418-rebase-continue.sh
+++ b/t/t3418-rebase-continue.sh
@@ -74,4 +74,25 @@ test_expect_success 'rebase --continue remembers merge strategy and options' '
 	test -f funny.was.run
 '
 
+test_expect_success 'rebase --continue remembers --rerere-autoupdate' '
+	rm -fr .git/rebase-* &&
+	git reset --hard commit-new-file-F3-on-topic-branch &&
+	git checkout master
+	test_commit "commit-new-file-F3" F3 3 &&
+	git config rerere.enabled true &&
+	test_must_fail git rebase -m master topic &&
+	echo "Resolved" >F2 &&
+	git add F2 &&
+	test_must_fail git rebase --continue &&
+	echo "Resolved" >F3 &&
+	git add F3 &&
+	git rebase --continue &&
+	git reset --hard topic@{1} &&
+	test_must_fail git rebase -m --rerere-autoupdate master &&
+	test "$(cat F2)" = "Resolved" &&
+	test_must_fail git rebase --continue &&
+	test "$(cat F3)" = "Resolved" &&
+	git rebase --continue
+'
+
 test_done
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 28/31] rebase -m: don't print exit code 2 when merge fails
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (26 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 27/31] rebase -m: remember allow_rerere_autoupdate option Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 29/31] git-rebase--am: remove unnecessary --3way option Martin von Zweigbergk
                     ` (4 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

When the merge strategy fails, a message suggesting the user to try
another strategy is displayed. Remove the "$rv" (which is always equal
to "2" in this case) from that message.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--merge.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
index eb0f7bc..26afc75 100644
--- a/git-rebase--merge.sh
+++ b/git-rebase--merge.sh
@@ -78,7 +78,7 @@ call_merge () {
 		die "$resolvemsg"
 		;;
 	2)
-		echo "Strategy: $rv $strategy failed, try another" 1>&2
+		echo "Strategy: $strategy failed, try another" 1>&2
 		die "$resolvemsg"
 		;;
 	*)
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 29/31] git-rebase--am: remove unnecessary --3way option
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (27 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 28/31] rebase -m: don't print exit code 2 when merge fails Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:43   ` [PATCH v2 30/31] rebase -i: don't read unused variable preserve_merges Martin von Zweigbergk
                     ` (3 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Since 22db240 (git-am: propagate --3way options as well, 2008-12-04),
the --3way has been propageted across failure, so it is since
pointless to pass it to git-am when resuming.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--am.sh |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/git-rebase--am.sh b/git-rebase--am.sh
index c9604a6..c815a24 100644
--- a/git-rebase--am.sh
+++ b/git-rebase--am.sh
@@ -7,12 +7,12 @@
 
 case "$action" in
 continue)
-	git am --resolved --3way --resolvemsg="$resolvemsg" &&
+	git am --resolved --resolvemsg="$resolvemsg" &&
 	move_to_original_branch
 	exit
 	;;
 skip)
-	git am --skip -3 --resolvemsg="$resolvemsg" &&
+	git am --skip --resolvemsg="$resolvemsg" &&
 	move_to_original_branch
 	exit
 	;;
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 30/31] rebase -i: don't read unused variable preserve_merges
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (28 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 29/31] git-rebase--am: remove unnecessary --3way option Martin von Zweigbergk
@ 2011-02-06 18:43   ` Martin von Zweigbergk
  2011-02-06 18:44   ` [PATCH v2 31/31] rebase -i: remove unnecessary state rebase-root Martin von Zweigbergk
                     ` (2 subsequent siblings)
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Since 8e4a91b (rebase -i: remember the settings of -v, -s and -p when
interrupted, 2007-07-08), the variable preserve_merges (then called
PRESERVE_MERGES) was detected from the state saved in
$GIT_DIR/rebase-merge in order to be used when the rebase resumed, but
its value was never actually used. The variable's value was only used
when the rebase was initated.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Changes since v1:

 * Added back call to get_saved_options that I had removed by mistake
   while reordering commits.

 git-rebase--interactive.sh |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 5773b75..cf19bf5 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -583,7 +583,6 @@ skip_unnecessary_picks () {
 }
 
 get_saved_options () {
-	test -d "$rewritten" && preserve_merges=t
 	test -f "$state_dir"/rebase-root && rebase_root=t
 }
 
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* [PATCH v2 31/31] rebase -i: remove unnecessary state rebase-root
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (29 preceding siblings ...)
  2011-02-06 18:43   ` [PATCH v2 30/31] rebase -i: don't read unused variable preserve_merges Martin von Zweigbergk
@ 2011-02-06 18:44   ` Martin von Zweigbergk
  2011-02-10 22:44   ` [PATCH v2 00/31] refactor rebase Junio C Hamano
  2011-02-16 14:52   ` Johannes Sixt
  32 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-06 18:44 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast, Martin von Zweigbergk

Before calling 'git cherry-pick', interactive rebase currently checks
if we are rebasing from root (if --root was passed). If we are, the
'--ff' flag to 'git cherry-pick' is omitted. However, according to the
documentation for 'git cherry-pick --ff', "If the current HEAD is the
same as the parent of the cherry-picked commit, then a fast forward to
this commit will be performed.". This should never be the case when
rebasing from root, so it should not matter whether --ff is passed, so
simplify the code by removing the condition.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase--interactive.sh |   19 -------------------
 1 files changed, 0 insertions(+), 19 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index cf19bf5..6566d31 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -168,11 +168,6 @@ pick_one () {
 	output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
 	test -d "$rewritten" &&
 		pick_one_preserving_merges "$@" && return
-	if test -n "$rebase_root"
-	then
-		output git cherry-pick "$@"
-		return
-	fi
 	output git cherry-pick $ff "$@"
 }
 
@@ -582,10 +577,6 @@ skip_unnecessary_picks () {
 	die "Could not skip unnecessary pick commands"
 }
 
-get_saved_options () {
-	test -f "$state_dir"/rebase-root && rebase_root=t
-}
-
 # Rearrange the todo list that has both "pick sha1 msg" and
 # "pick sha1 fixup!/squash! msg" appears in it so that the latter
 # comes immediately after the former, and change "pick" to
@@ -649,8 +640,6 @@ rearrange_squash () {
 
 case "$action" in
 continue)
-	get_saved_options
-
 	# do we have anything to commit?
 	if git diff-index --cached --quiet --ignore-submodules HEAD --
 	then
@@ -681,8 +670,6 @@ first and then run 'git rebase --continue' again."
 	do_rest
 	;;
 skip)
-	get_saved_options
-
 	git rerere clear
 
 	do_rest
@@ -705,12 +692,6 @@ mkdir "$state_dir" || die "Could not create temporary $state_dir"
 
 : > "$state_dir"/interactive || die "Could not mark as interactive"
 write_basic_state
-case "$rebase_root" in
-'')
-	rm -f "$state_dir"/rebase-root ;;
-*)
-	: >"$state_dir"/rebase-root ;;
-esac
 if test t = "$preserve_merges"
 then
 	if test -z "$rebase_root"
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 00/31] refactor rebase
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (30 preceding siblings ...)
  2011-02-06 18:44   ` [PATCH v2 31/31] rebase -i: remove unnecessary state rebase-root Martin von Zweigbergk
@ 2011-02-10 22:44   ` Junio C Hamano
  2011-02-12  0:55     ` Martin von Zweigbergk
  2011-02-16 14:52   ` Johannes Sixt
  32 siblings, 1 reply; 118+ messages in thread
From: Junio C Hamano @ 2011-02-10 22:44 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Johannes Schindelin, Johannes Sixt, Christian Couder, Thomas Rast

I see there are a few minor fix-ups made since the last round.

The majority of the difference between the old one and this round was the
downcasing of the variables, which was a bit distracting to read the
remainder, but overall the result looks better.

I am not sure if forbidding "-v --continue" adds any value; would it be
too much effort to allow "--continue -v" instead to achieve the same
degree of consistency between the two?

Honestly speaking, I do not deeply care either way, but the users may want
to say "ok, keep going but this time with verbose output", no?

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 00/31] refactor rebase
  2011-02-10 22:44   ` [PATCH v2 00/31] refactor rebase Junio C Hamano
@ 2011-02-12  0:55     ` Martin von Zweigbergk
  2011-02-14  1:54       ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-12  0:55 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Martin von Zweigbergk, git, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast

On Thu, 10 Feb 2011, Junio C Hamano wrote:

> I am not sure if forbidding "-v --continue" adds any value;

If I remember correctly, it was just the simplest possible way to not
have to handle cases like "-i/-p/-m --continue" specially.

> would it be
> too much effort to allow "--continue -v" instead to achieve the same
> degree of consistency between the two?

I think it would be doable. Maybe something like:

 * Check that only the allowable options (-v/-q, -s, -X,
   --[no-]rerere-autoupdate) are passed together with --continue or
   --skip. For simplicity, maybe we can just accept the same set of
   flags with --abort as well, even though only -v/-q would make any
   sense.

 * When reading the saved state, first check for each of the options
   if it is already set. If it is, write it to disk instead, to make
   sure it is remembered across future interruptions. Otherwise, just
   read it as usual.

I think that should be all that's needed. I'll have a look at it when
I get some time.


/Martin

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 00/31] refactor rebase
  2011-02-12  0:55     ` Martin von Zweigbergk
@ 2011-02-14  1:54       ` Martin von Zweigbergk
  2011-02-14  3:15         ` Martin von Zweigbergk
                           ` (2 more replies)
  0 siblings, 3 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-14  1:54 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Martin von Zweigbergk, git, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast

On Fri, 11 Feb 2011, Martin von Zweigbergk wrote:

> On Thu, 10 Feb 2011, Junio C Hamano wrote:
> 
> > I am not sure if forbidding "-v --continue" adds any value; would it be
> > too much effort to allow "--continue -v" instead to achieve the same
> > degree of consistency between the two?
> 
> I'll have a look at it when
> I get some time.

This would apply on top of mz/rebase after dropping 95135b0 (rebase:
stricter check of standalone sub command, 2011-02-06). If you agree
with it, I will include it in a future re-roll.

-- 8< --
Subject: [PATCH/RFC] rebase: allow options to be overridden when resuming

The sub commands '--continue', '--skip' or '--abort' may only be used
standalone according to the documentation. Other options following the
sub command are currently not accepted, but options preceeding them
are. For example, 'git rebase --continue -v' is not accepted, while
'git rebase -v --continue' is. In the latter case, the verbose option
will only be used until the rebase is interrupted (e.g. for editing,
or due to conflict). From that point on, the intial settings will be
used again.

Improve the situation by allowing options to be combined with sub
commands both before and after the sub command itself. Persist the new
value to make sure it is remembered across interruptions.

Fail if options that can not be used together with sub commands, such
as '-i', are used. For simplicity, allow the same set of options for
all three sub commands, even though e.g. '-s' makes no sense when
combined with '--abort'.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 Documentation/git-rebase.txt |    2 +-
 git-rebase.sh                |   51 ++++++++++++++++++++++++++++++++----------
 t/t3418-rebase-continue.sh   |   12 ++++++++++
 3 files changed, 52 insertions(+), 13 deletions(-)

diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 96680c8..095a67f 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -13,7 +13,7 @@ SYNOPSIS
 'git rebase' [-i | --interactive] [options] --onto <newbase>
 	--root [<branch>]
 
-'git rebase' --continue | --skip | --abort
+'git rebase' --continue | --skip | --abort [options]
 
 DESCRIPTION
 -----------
diff --git a/git-rebase.sh b/git-rebase.sh
index 34a2a0a..5abfeac 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -67,6 +67,16 @@ preserve_merges=
 autosquash=
 test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
 
+write_options() {
+	echo "$GIT_QUIET" > "$state_dir"/quiet &&
+	test t = "$verbose" && : > "$state_dir"/verbose
+	test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
+	test -n "$strategy_opts" && echo "$strategy_opts" > \
+		"$state_dir"/strategy_opts
+	test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \
+		"$state_dir"/allow_rerere_autoupdate
+}
+
 read_basic_state () {
 	head_name=$(cat "$state_dir"/head-name) &&
 	onto=$(cat "$state_dir"/onto) &&
@@ -78,9 +88,21 @@ read_basic_state () {
 		orig_head=$(cat "$state_dir"/orig-head)
 	else
 		orig_head=$(cat "$state_dir"/head)
-	fi &&
-	GIT_QUIET=$(cat "$state_dir"/quiet) &&
-	test -f "$state_dir"/verbose && verbose=t
+	fi
+	# First write any overriding options from the command line
+	write_options
+	if test -n "$GIT_QUIET"
+	then
+		rm "$state_dir"/verbose
+	else
+		GIT_QUIET=$(cat "$state_dir"/quiet)
+	fi
+	if test t = "$verbose"
+	then
+		rm "$state_dir"/quiet
+	else
+		test -f "$state_dir"/verbose && verbose=t
+	fi
 	test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
 	test -f "$state_dir"/strategy_opts &&
 		strategy_opts="$(cat "$state_dir"/strategy_opts)"
@@ -92,13 +114,7 @@ write_basic_state () {
 	echo "$head_name" > "$state_dir"/head-name &&
 	echo "$onto" > "$state_dir"/onto &&
 	echo "$orig_head" > "$state_dir"/orig-head &&
-	echo "$GIT_QUIET" > "$state_dir"/quiet &&
-	test t = "$verbose" && : > "$state_dir"/verbose
-	test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
-	test -n "$strategy_opts" && echo "$strategy_opts" > \
-		"$state_dir"/strategy_opts
-	test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \
-		"$state_dir"/allow_rerere_autoupdate
+	write_options
 }
 
 output () {
@@ -164,6 +180,7 @@ then
 fi
 test -n "$type" && in_progress=t
 
+resume_incompatible=
 while test $# != 0
 do
 	case "$1" in
@@ -174,11 +191,11 @@ do
 		ok_to_skip_pre_rebase=
 		;;
 	--continue|--skip|--abort)
+		test -n "$action" && usage
 		action=${1##--}
-		shift
-		break
 		;;
 	--onto)
+		resume_incompatible=t
 		test 2 -le "$#" || usage
 		onto="$2"
 		shift
@@ -197,6 +214,7 @@ do
 		autosquash=
 		;;
 	-M|-m|--m|--me|--mer|--merg|--merge)
+		resume_incompatible=t
 		do_merge=t
 		;;
 	-X*|--strategy-option*)
@@ -232,9 +250,11 @@ do
 		do_merge=t
 		;;
 	-n|--no-stat)
+		resume_incompatible=t
 		diffstat=
 		;;
 	--stat)
+		resume_incompatible=t
 		diffstat=t
 		;;
 	-v|--verbose)
@@ -249,6 +269,7 @@ do
 		diffstat=
 		;;
 	--whitespace=*)
+		resume_incompatible=t
 		git_am_opt="$git_am_opt $1"
 		case "$1" in
 		--whitespace=fix|--whitespace=strip)
@@ -257,19 +278,24 @@ do
 		esac
 		;;
 	--ignore-whitespace)
+		resume_incompatible=t
 		git_am_opt="$git_am_opt $1"
 		;;
 	--committer-date-is-author-date|--ignore-date)
+		resume_incompatible=t
 		git_am_opt="$git_am_opt $1"
 		force_rebase=t
 		;;
 	-C*)
+		resume_incompatible=t
 		git_am_opt="$git_am_opt $1"
 		;;
 	--root)
+		resume_incompatible=t
 		rebase_root=t
 		;;
 	-f|--f|--fo|--for|--forc|--force|--force-r|--force-re|--force-reb|--force-reba|--force-rebas|--force-rebase|--no-ff)
+		resume_incompatible=t
 		force_rebase=t
 		;;
 	--rerere-autoupdate|--no-rerere-autoupdate)
@@ -288,6 +314,7 @@ test $# -gt 2 && usage
 
 if test -n "$action"
 then
+	test -n "$resume_incompatible" && "--$action used with incompatible option"
 	test -z "$in_progress" && die "No rebase in progress?"
 	# Only interactive rebase uses detailed reflog messages
 	if test "$type" = interactive && test "$GIT_REFLOG_ACTION" = rebase
diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh
index 15cef3c..1581f00 100755
--- a/t/t3418-rebase-continue.sh
+++ b/t/t3418-rebase-continue.sh
@@ -90,4 +90,16 @@ test_expect_success 'rebase --continue remembers --rerere-autoupdate' '
 	git rebase --continue
 '
 
+test_expect_success 'rebase --continue --no-rerere-autoupdate overrides' '
+	rm -fr .git/rebase-* &&
+	git reset --hard topic@{1} &&
+	test_must_fail git rebase -m --rerere-autoupdate master &&
+	test "$(cat F2)" = "Resolved" &&
+	git rebase --continue --no-rerere-autoupdate &&
+	test "$(cat F3)" = "Resolved" &&
+	test_must_fail git rebase --continue &&
+	git add F3 &&
+	git rebase --continue
+'
+
 test_done
-- 
1.7.4.rc2.33.g8a14f

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 00/31] refactor rebase
  2011-02-14  1:54       ` Martin von Zweigbergk
@ 2011-02-14  3:15         ` Martin von Zweigbergk
  2011-02-15  0:36         ` Junio C Hamano
  2011-02-22 13:58         ` Martin von Zweigbergk
  2 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-14  3:15 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: Junio C Hamano, git, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast

On Sun, 13 Feb 2011, Martin von Zweigbergk wrote:

> On Fri, 11 Feb 2011, Martin von Zweigbergk wrote:
> 
> > On Thu, 10 Feb 2011, Junio C Hamano wrote:
> > 
> > > I am not sure if forbidding "-v --continue" adds any value; would it be
> > > too much effort to allow "--continue -v" instead to achieve the same
> > > degree of consistency between the two?
> > 
> > I'll have a look at it when
> > I get some time.
> 
> This would apply on top of mz/rebase after dropping 95135b0 (rebase:
> stricter check of standalone sub command, 2011-02-06). If you agree
> with it, I will include it in a future re-roll.

Sorry, anyone who intends to test it, squash in this missing
test_must_fail first.

-- 8< --
diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh
index 1581f00..02ac92f 100755
--- a/t/t3418-rebase-continue.sh
+++ b/t/t3418-rebase-continue.sh
@@ -95,7 +95,7 @@ test_expect_success 'rebase --continue --no-rerere-autoupdate overrides' '
 	git reset --hard topic@{1} &&
 	test_must_fail git rebase -m --rerere-autoupdate master &&
 	test "$(cat F2)" = "Resolved" &&
-	git rebase --continue --no-rerere-autoupdate &&
+	test_must_fail git rebase --continue --no-rerere-autoupdate &&
 	test "$(cat F3)" = "Resolved" &&
 	test_must_fail git rebase --continue &&
 	git add F3 &&

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 18/31] rebase: extract merge code to new source file
  2011-02-06 18:43   ` [PATCH v2 18/31] rebase: extract merge code to new source file Martin von Zweigbergk
@ 2011-02-14  8:02     ` Johannes Sixt
  2011-02-14 13:56       ` Martin von Zweigbergk
  2011-02-24  3:27       ` Martin von Zweigbergk
  0 siblings, 2 replies; 118+ messages in thread
From: Johannes Sixt @ 2011-02-14  8:02 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Junio C Hamano, Johannes Schindelin, Christian Couder, Thomas Rast

Am 2/6/2011 19:43, schrieb Martin von Zweigbergk:
> diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
> new file mode 100644
> index 0000000..c04ce8a
> --- /dev/null
> +++ b/git-rebase--merge.sh

This should be mode 100755. (Ditto for git-rebase--am.sh in 19/31)

-- Hannes

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 18/31] rebase: extract merge code to new source file
  2011-02-14  8:02     ` Johannes Sixt
@ 2011-02-14 13:56       ` Martin von Zweigbergk
  2011-02-24  3:27       ` Martin von Zweigbergk
  1 sibling, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-14 13:56 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: Martin von Zweigbergk, git, Junio C Hamano, Johannes Schindelin,
	Christian Couder, Thomas Rast

On Mon, 14 Feb 2011, Johannes Sixt wrote:

> Am 2/6/2011 19:43, schrieb Martin von Zweigbergk:
> > diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
> > new file mode 100644
> > index 0000000..c04ce8a
> > --- /dev/null
> > +++ b/git-rebase--merge.sh
> 
> This should be mode 100755. (Ditto for git-rebase--am.sh in 19/31)

Thanks.

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 00/31] refactor rebase
  2011-02-14  1:54       ` Martin von Zweigbergk
  2011-02-14  3:15         ` Martin von Zweigbergk
@ 2011-02-15  0:36         ` Junio C Hamano
  2011-02-22 13:58         ` Martin von Zweigbergk
  2 siblings, 0 replies; 118+ messages in thread
From: Junio C Hamano @ 2011-02-15  0:36 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Johannes Schindelin, Johannes Sixt, Christian Couder, Thomas Rast

Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:

> Improve the situation by allowing options to be combined with sub
> commands both before and after the sub command itself. Persist the new
> value to make sure it is remembered across interruptions.

I somehow suspected that it would be much more messy, but with your
refactoring, things do not look that bad as I feared ;-)

The only use case it might be useful, however, is to start without -v,
realize that a verbose output may help you resolve conflicts better, and
continuing with the verbose option, which conceptually should be helpful.

But in practice I doubt the ability to ask for -v output in the middle
would be so helpful, so doing this may not be worth it.

I am not a regular rebaser anymore, so I wouldn't be a good judge beyond
just my gut feeling.  Comments from heavy rebase users who often see
conflicts are appreciated.

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 00/31] refactor rebase
  2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
                     ` (31 preceding siblings ...)
  2011-02-10 22:44   ` [PATCH v2 00/31] refactor rebase Junio C Hamano
@ 2011-02-16 14:52   ` Johannes Sixt
  2011-02-17  3:41     ` Martin von Zweigbergk
  2011-02-24  3:07     ` [PATCH] rebase: define options in OPTIONS_SPEC Martin von Zweigbergk
  32 siblings, 2 replies; 118+ messages in thread
From: Johannes Sixt @ 2011-02-16 14:52 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Junio C Hamano, Johannes Schindelin, Christian Couder, Thomas Rast

There's one annoying regression with this series: It does not accept
abbreviated options anymore. In particular, 'git rebase --cont' is now an
error. I use this a lot since I don't have command completion. This used
to work (only) with interactive rebase.

And a side note: the error message is -- during a rebase that stopped at
an 'edit' instruction:

$ git rebase --cont
Usage: git rebase [--interactive | -i] [-v] [--force-rebase | -f]
[--no-ff] [--onto <newbase>] [<upstream>|--root] [<branch>] [--quiet | -q]

It nowhere mentions --continue, --skip, --abort etc. That's perhaps worth
fixing.

-- Hannes

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 00/31] refactor rebase
  2011-02-16 14:52   ` Johannes Sixt
@ 2011-02-17  3:41     ` Martin von Zweigbergk
  2011-02-24  3:07     ` [PATCH] rebase: define options in OPTIONS_SPEC Martin von Zweigbergk
  1 sibling, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-17  3:41 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: Martin von Zweigbergk, git, Junio C Hamano, Johannes Schindelin,
	Christian Couder, Thomas Rast

On Wed, 16 Feb 2011, Johannes Sixt wrote:

> There's one annoying regression with this series: It does not accept
> abbreviated options anymore. In particular, 'git rebase --cont' is now an
> error. I use this a lot since I don't have command completion. This used
> to work (only) with interactive rebase.

Sorry about that :-(. That must of course be because I removed the
OPTIONS_SPEC from git-rebase--interactive.sh. Sounds like I should add
it back in git-rebase.sh. Can someone explain what the
OPTIONS_KEEPDASHDASH is for? Should I add that as well?

> And a side note: the error message is -- during a rebase that stopped at
> an 'edit' instruction:
> 
> $ git rebase --cont
> Usage: git rebase [--interactive | -i] [-v] [--force-rebase | -f]
> [--no-ff] [--onto <newbase>] [<upstream>|--root] [<branch>] [--quiet | -q]
> 
> It nowhere mentions --continue, --skip, --abort etc. That's perhaps worth
> fixing.

Makes sense. If others agree, I will add that as well.

/Martin

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 00/31] refactor rebase
  2011-02-14  1:54       ` Martin von Zweigbergk
  2011-02-14  3:15         ` Martin von Zweigbergk
  2011-02-15  0:36         ` Junio C Hamano
@ 2011-02-22 13:58         ` Martin von Zweigbergk
  2011-02-22 19:21           ` Junio C Hamano
  2 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-22 13:58 UTC (permalink / raw)
  To: git
  Cc: Martin von Zweigbergk, Junio C Hamano, Johannes Schindelin,
	Johannes Sixt, Christian Couder, Thomas Rast

On Sun, 13 Feb 2011, Martin von Zweigbergk wrote:

> On Fri, 11 Feb 2011, Martin von Zweigbergk wrote:
> 
> > On Thu, 10 Feb 2011, Junio C Hamano wrote:
> > 
> > > I am not sure if forbidding "-v --continue" adds any value; would it be
> > > too much effort to allow "--continue -v" instead to achieve the same
> > > degree of consistency between the two?
> > 
> > I'll have a look at it when
> > I get some time.
> 
> This would apply on top of mz/rebase after dropping 95135b0 (rebase:
> stricter check of standalone sub command, 2011-02-06). If you agree
> with it, I will include it in a future re-roll.

Any opinions about this, anyone? I have one example: I was rebasing
some things the other day where I thought there would be no conflicts.
After applying a number of patches, it turned out there were
conflicts. I think allowing 'git rebase --continue -sours' would have
been useful in that case. It's rare enough that I don't care much,
though.

The reason I'm asking is that I have a patch that fixes the problems
with the command line parsing that Johannes Sixt pointed out in
another mail on this thread and would like to know if I should make it
apply on top of this patch or not.


/Martin

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 00/31] refactor rebase
  2011-02-22 13:58         ` Martin von Zweigbergk
@ 2011-02-22 19:21           ` Junio C Hamano
  2011-02-23 11:26             ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Junio C Hamano @ 2011-02-22 19:21 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Johannes Schindelin, Johannes Sixt, Christian Couder, Thomas Rast

Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:

> On Sun, 13 Feb 2011, Martin von Zweigbergk wrote:
> ...
>> This would apply on top of mz/rebase after dropping 95135b0 (rebase:
>> stricter check of standalone sub command, 2011-02-06). If you agree
>> with it, I will include it in a future re-roll.
>
> Any opinions about this, anyone? I have one example: I was rebasing
> some things the other day where I thought there would be no conflicts.
> After applying a number of patches, it turned out there were
> conflicts. I think allowing 'git rebase --continue -sours' would have
> been useful in that case. It's rare enough that I don't care much,
> though.

Hmm, do you think applying -sours throughout to the rest of the series
would have been a safe thing, or do you think you would rather wanted to
see -sours applied only to that particular one?

> The reason I'm asking is that I have a patch that fixes the problems
> with the command line parsing that Johannes Sixt pointed out in
> another mail on this thread and would like to know if I should make it
> apply on top of this patch or not.

It is a good idea to build a change you are more certain of first,
excluding the ones you have doubts about.

Besides, this part of the patch would need fixing anyway ;-)

@@ -288,6 +314,7 @@ test $# -gt 2 && usage
 
 if test -n "$action"
 then
+	test -n "$resume_incompatible" && "--$action used with incompatible option"
 	test -z "$in_progress" && die "No rebase in progress?"
 	# Only interactive rebase uses detailed reflog messages
 	if test "$type" = interactive && test "$GIT_REFLOG_ACTION" = rebase

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 00/31] refactor rebase
  2011-02-22 19:21           ` Junio C Hamano
@ 2011-02-23 11:26             ` Martin von Zweigbergk
  0 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-23 11:26 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Martin von Zweigbergk, git, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast

On Tue, 22 Feb 2011, Junio C Hamano wrote:

> Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:
> 
> > On Sun, 13 Feb 2011, Martin von Zweigbergk wrote:
> > ...
> >> This would apply on top of mz/rebase after dropping 95135b0 (rebase:
> >> stricter check of standalone sub command, 2011-02-06). If you agree
> >> with it, I will include it in a future re-roll.
> >
> > Any opinions about this, anyone? I have one example: I was rebasing
> > some things the other day where I thought there would be no conflicts.
> > After applying a number of patches, it turned out there were
> > conflicts. I think allowing 'git rebase --continue -sours' would have
> > been useful in that case. It's rare enough that I don't care much,
> > though.
> 
> Hmm, do you think applying -sours throughout to the rest of the series
> would have been a safe thing, or do you think you would rather wanted to
> see -sours applied only to that particular one?

In this particular case, I actually wanted it on the rest of the
series, but it was such a degenerate case that it doesn't really
matter (I just wanted the history graph for testing and didn't care
about the trees).

> > The reason I'm asking is that I have a patch that fixes the problems
> > with the command line parsing that Johannes Sixt pointed out in
> > another mail on this thread and would like to know if I should make it
> > apply on top of this patch or not.
> 
> It is a good idea to build a change you are more certain of first,
> excluding the ones you have doubts about.

True. Will do.

Let's leave this patch for now then and get back to it in a few years
when/if someone actually requests it ;-). I agree that it's not clear
at this point what the desired behavior is.

^ permalink raw reply	[flat|nested] 118+ messages in thread

* [PATCH] rebase: define options in OPTIONS_SPEC
  2011-02-16 14:52   ` Johannes Sixt
  2011-02-17  3:41     ` Martin von Zweigbergk
@ 2011-02-24  3:07     ` Martin von Zweigbergk
  2011-02-27 10:59       ` Junio C Hamano
  1 sibling, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-24  3:07 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: git, Junio C Hamano, Johannes Schindelin, Christian Couder,
	Thomas Rast, Martin von Zweigbergk

Interactive rebase used to have its own command line processing. Since
it used the 'git rev-parse --parseopt' functionality exposed through
git-sh-setup, it had some flexibility, like matching prefixes of long
options, that non-interactive rebase didn't. When interactive rebase's
command line processing was factored out into git-rebase.sh in cf432ca
(rebase: factor out command line option processing, 2011-02-06), this
flexibility was lost. Give back that flexibility to interactive and
non-interactive.

Also improve the usage message to contain the --continue, --skip and
--abort commands.
---

Applies on top of mz/rebase.

Are USAGE and LONG_USAGE still needed?

I based the definitions on the now-lost OPTIONS_SPEC from interactive
rebase. I added some descriptions that were not too hard to describe
in a concise way. The rest, I simply hid (with the "*" marker). Should
the list be exhaustive?

What is the difference between the "options" and "actions" sections?

 git-rebase.sh |  104 ++++++++++++++++++++++++++++++++------------------------
 1 files changed, 59 insertions(+), 45 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index a040ab5..7857059 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -28,7 +28,42 @@ Example:       git-rebase master~1 topic
 '
 
 SUBDIRECTORY_OK=Yes
-OPTIONS_SPEC=
+OPTIONS_KEEPDASHDASH=
+OPTIONS_SPEC="\
+git rebase [-i] [options] [--onto <newbase>] [<upstream>] [<branch>]
+git rebase [-i] [options] --onto <newbase> --root [<branch>]
+git-rebase [-i] --continue | --abort | --skip
+--
+ Available options are
+v,verbose          display a diffstat of what changed upstream
+q,quiet            be quiet. implies --no-stat
+onto=              rebase onto given branch instead of upstream
+p,preserve-merges  try to recreate merges instead of ignoring them
+s,strategy=        use the given merge strategy
+no-ff              cherry-pick all commits, even if unchanged
+m,merge            use merging strategies to rebase
+i,interactive      let the user edit the list of commits to rebase
+f,force-rebase*    -
+X,strategy-option= pass the argument through to the merge strategy
+stat*              -
+n,no-stat*         -
+whitespace=*       -
+ignore-whitespace* -
+committer-date-is-author-date* -
+ignore-date*       -
+C=*                -
+rerere-autoupdate* -
+no-rerere-autoupdate* -
+ Actions:
+continue           continue rebasing process
+abort              abort rebasing process and restore original branch
+skip               skip current patch and continue rebasing process
+no-verify          override pre-rebase hook from stopping the operation
+verify             allow pre-rebase hook to run
+root               rebase all reachable commmits up to the root(s)
+autosquash         move commits that begin with squash!/fixup! under -i
+no-autosquash*     -
+"
 . git-sh-setup
 set_reflog_action rebase
 require_work_tree
@@ -175,7 +210,7 @@ do
 		ok_to_skip_pre_rebase=
 		;;
 	--continue|--skip|--abort)
-		test $total_argc -eq 1 || usage
+		test $total_argc -eq 2 || usage
 		action=${1##--}
 		;;
 	--onto)
@@ -183,10 +218,10 @@ do
 		onto="$2"
 		shift
 		;;
-	-i|--interactive)
+	-i)
 		interactive_rebase=explicit
 		;;
-	-p|--preserve-merges)
+	-p)
 		preserve_merges=t
 		test -z "$interactive_rebase" && interactive_rebase=implied
 		;;
@@ -196,62 +231,42 @@ do
 	--no-autosquash)
 		autosquash=
 		;;
-	-M|-m|--m|--me|--mer|--merg|--merge)
+	-M|-m)
 		do_merge=t
 		;;
-	-X*|--strategy-option*)
-		case "$#,$1" in
-		1,-X|1,--strategy-option)
-			usage ;;
-		*,-X|*,--strategy-option)
-			newopt="$2"
-			shift ;;
-		*,--strategy-option=*)
-			newopt="$(expr " $1" : ' --strategy-option=\(.*\)')" ;;
-		*,-X*)
-			newopt="$(expr " $1" : ' -X\(.*\)')" ;;
-		1,*)
-			usage ;;
-		esac
-		strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$newopt")"
+	-X)
+		shift
+		strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$1")"
 		do_merge=t
 		test -z "$strategy" && strategy=recursive
 		;;
-	-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
-		--strateg=*|--strategy=*|\
-	-s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
-		case "$#,$1" in
-		*,*=*)
-			strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
-		1,*)
-			usage ;;
-		*)
-			strategy="$2"
-			shift ;;
-		esac
+	-s)
+		shift
+		strategy="$1"
 		do_merge=t
 		;;
-	-n|--no-stat)
+	-n)
 		diffstat=
 		;;
 	--stat)
 		diffstat=t
 		;;
-	-v|--verbose)
+	-v)
 		verbose=t
 		diffstat=t
 		GIT_QUIET=
 		;;
-	-q|--quiet)
+	-q)
 		GIT_QUIET=t
 		git_am_opt="$git_am_opt -q"
 		verbose=
 		diffstat=
 		;;
-	--whitespace=*)
-		git_am_opt="$git_am_opt $1"
+	--whitespace)
+		shift
+		git_am_opt="$git_am_opt --whitespace=$1"
 		case "$1" in
-		--whitespace=fix|--whitespace=strip)
+		fix|strip)
 			force_rebase=t
 			;;
 		esac
@@ -263,22 +278,21 @@ do
 		git_am_opt="$git_am_opt $1"
 		force_rebase=t
 		;;
-	-C*)
-		git_am_opt="$git_am_opt $1"
+	-C)
+		shift
+		git_am_opt="$git_am_opt -C$1"
 		;;
 	--root)
 		rebase_root=t
 		;;
-	-f|--f|--fo|--for|--forc|--force|--force-r|--force-re|--force-reb|--force-reba|--force-rebas|--force-rebase|--no-ff)
+	-f|--no-ff)
 		force_rebase=t
 		;;
 	--rerere-autoupdate|--no-rerere-autoupdate)
 		allow_rerere_autoupdate="$1"
 		;;
-	-*)
-		usage
-		;;
-	*)
+	--)
+		shift
 		break
 		;;
 	esac
-- 
1.7.4.1.79.gba571.dirty

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 18/31] rebase: extract merge code to new source file
  2011-02-14  8:02     ` Johannes Sixt
  2011-02-14 13:56       ` Martin von Zweigbergk
@ 2011-02-24  3:27       ` Martin von Zweigbergk
  2011-02-24  8:07         ` Jeff King
  1 sibling, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-24  3:27 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: Martin von Zweigbergk, git, Junio C Hamano, Johannes Schindelin,
	Christian Couder, Thomas Rast

On Mon, 14 Feb 2011, Johannes Sixt wrote:

> Am 2/6/2011 19:43, schrieb Martin von Zweigbergk:
> > diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
> > new file mode 100644
> > index 0000000..c04ce8a
> > --- /dev/null
> > +++ b/git-rebase--merge.sh
> 
> This should be mode 100755. (Ditto for git-rebase--am.sh in 19/31)

I was just about to fix now and I noticed that quite a few other
script files are mode 100644. Should all be changed to mode 100755 or
is there some kind of rule as to which mode they should be? Both
git-sh-setup.sh and git-parse-remote.sh are also mode 100644 and I
(think I) know that both are always sourced. If the rule is that
sourced scripts should be mode 100644 (but I'm just guessing here),
then I should actually have changed the mode of
git-rebase--interactive.sh to that mode instead. Please advice.


/Martin

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 18/31] rebase: extract merge code to new source file
  2011-02-24  3:27       ` Martin von Zweigbergk
@ 2011-02-24  8:07         ` Jeff King
  2011-02-24  8:09           ` Jeff King
  0 siblings, 1 reply; 118+ messages in thread
From: Jeff King @ 2011-02-24  8:07 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: Johannes Sixt, git, Junio C Hamano, Johannes Schindelin,
	Christian Couder, Thomas Rast

On Wed, Feb 23, 2011 at 10:27:23PM -0500, Martin von Zweigbergk wrote:

> > > +++ b/git-rebase--merge.sh
> > 
> > This should be mode 100755. (Ditto for git-rebase--am.sh in 19/31)
> 
> I was just about to fix now and I noticed that quite a few other
> script files are mode 100644. Should all be changed to mode 100755 or
> is there some kind of rule as to which mode they should be? Both
> git-sh-setup.sh and git-parse-remote.sh are also mode 100644 and I
> (think I) know that both are always sourced. If the rule is that
> sourced scripts should be mode 100644 (but I'm just guessing here),
> then I should actually have changed the mode of
> git-rebase--interactive.sh to that mode instead. Please advice.

Yes, sourced scripts should not have an executable bit. See 46bac90 for
rationale.

-Peff

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 18/31] rebase: extract merge code to new source file
  2011-02-24  8:07         ` Jeff King
@ 2011-02-24  8:09           ` Jeff King
  2011-02-25  3:32             ` Martin von Zweigbergk
  2011-02-25 20:27             ` Jakub Narebski
  0 siblings, 2 replies; 118+ messages in thread
From: Jeff King @ 2011-02-24  8:09 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: Johannes Sixt, git, Junio C Hamano, Johannes Schindelin,
	Christian Couder, Thomas Rast

On Thu, Feb 24, 2011 at 03:07:34AM -0500, Jeff King wrote:

> On Wed, Feb 23, 2011 at 10:27:23PM -0500, Martin von Zweigbergk wrote:
> 
> > > > +++ b/git-rebase--merge.sh
> > > 
> > > This should be mode 100755. (Ditto for git-rebase--am.sh in 19/31)
> > 
> > I was just about to fix now and I noticed that quite a few other
> > script files are mode 100644. Should all be changed to mode 100755 or
> > is there some kind of rule as to which mode they should be? Both
> > git-sh-setup.sh and git-parse-remote.sh are also mode 100644 and I
> > (think I) know that both are always sourced. If the rule is that
> > sourced scripts should be mode 100644 (but I'm just guessing here),
> > then I should actually have changed the mode of
> > git-rebase--interactive.sh to that mode instead. Please advice.
> 
> Yes, sourced scripts should not have an executable bit. See 46bac90 for
> rationale.

And I should have mentioned: they should go in SCRIPT_LIB in the
Makefile, not SCRIPT_SH.

-Peff

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 18/31] rebase: extract merge code to new source file
  2011-02-24  8:09           ` Jeff King
@ 2011-02-25  3:32             ` Martin von Zweigbergk
  2011-02-25  9:02               ` Jeff King
  2011-02-25 20:27             ` Jakub Narebski
  1 sibling, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-02-25  3:32 UTC (permalink / raw)
  To: Jeff King
  Cc: Martin von Zweigbergk, Johannes Sixt, git, Junio C Hamano,
	Johannes Schindelin, Christian Couder, Thomas Rast

On Thu, 24 Feb 2011, Jeff King wrote:

> On Thu, Feb 24, 2011 at 03:07:34AM -0500, Jeff King wrote:
> 
> > On Wed, Feb 23, 2011 at 10:27:23PM -0500, Martin von Zweigbergk wrote:
> > 
> > > > > +++ b/git-rebase--merge.sh
> > > > 
> > > > This should be mode 100755. (Ditto for git-rebase--am.sh in 19/31)
> > > 
> > > I was just about to fix now and I noticed that quite a few other
> > > script files are mode 100644. Should all be changed to mode 100755 or
> > > is there some kind of rule as to which mode they should be? Both
> > > git-sh-setup.sh and git-parse-remote.sh are also mode 100644 and I
> > > (think I) know that both are always sourced. If the rule is that
> > > sourced scripts should be mode 100644 (but I'm just guessing here),
> > > then I should actually have changed the mode of
> > > git-rebase--interactive.sh to that mode instead. Please advice.
> > 
> > Yes, sourced scripts should not have an executable bit. See 46bac90 for
> > rationale.
> 
> And I should have mentioned: they should go in SCRIPT_LIB in the
> Makefile, not SCRIPT_SH.

Thanks. The below should hopefully fix my mistakes.

-- 8< --
Subject: [PATCH] Makefile: do not install sourced rebase scripts

When git-rebase.sh recently started sourcing
git-rebase--interactive.sh instead of executing it, executable bit of
the latter file should have been turned off and it should have been
moved from SCRIPT_SH to SCRIPT_LIB in the Makefile. Its two new
siblings, git-rebase--am.sh and git-rebase--merge.sh (whose executable
bits are already off) should also be moved to SCRIPT_LIB in the
Makefile.

Reported-by: Johannes Sixt <j6t@kdbg.org>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Applies on top of mz/rebase.

 Makefile                   |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
 mode change 100755 => 100644 git-rebase--interactive.sh

diff --git a/Makefile b/Makefile
index b2501cc..e722b95 100644
--- a/Makefile
+++ b/Makefile
@@ -369,9 +369,6 @@ SCRIPT_SH += git-merge-resolve.sh
 SCRIPT_SH += git-mergetool.sh
 SCRIPT_SH += git-pull.sh
 SCRIPT_SH += git-quiltimport.sh
-SCRIPT_SH += git-rebase--am.sh
-SCRIPT_SH += git-rebase--interactive.sh
-SCRIPT_SH += git-rebase--merge.sh
 SCRIPT_SH += git-rebase.sh
 SCRIPT_SH += git-repack.sh
 SCRIPT_SH += git-request-pull.sh
@@ -382,6 +379,9 @@ SCRIPT_SH += git-web--browse.sh
 SCRIPT_LIB += git-mergetool--lib
 SCRIPT_LIB += git-parse-remote
 SCRIPT_LIB += git-sh-setup
+SCRIPT_LIB += git-rebase--am.sh
+SCRIPT_LIB += git-rebase--interactive.sh
+SCRIPT_LIB += git-rebase--merge.sh
 
 SCRIPT_PERL += git-add--interactive.perl
 SCRIPT_PERL += git-difftool.perl
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
old mode 100755
new mode 100644
-- 
1.7.4.1.79.gba571.dirty

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 18/31] rebase: extract merge code to new source file
  2011-02-25  3:32             ` Martin von Zweigbergk
@ 2011-02-25  9:02               ` Jeff King
  2011-02-25 20:24                 ` Junio C Hamano
  0 siblings, 1 reply; 118+ messages in thread
From: Jeff King @ 2011-02-25  9:02 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: Johannes Sixt, git, Junio C Hamano, Johannes Schindelin,
	Christian Couder, Thomas Rast

On Thu, Feb 24, 2011 at 10:32:06PM -0500, Martin von Zweigbergk wrote:

> Subject: [PATCH] Makefile: do not install sourced rebase scripts
> 
> When git-rebase.sh recently started sourcing
> git-rebase--interactive.sh instead of executing it, executable bit of
> the latter file should have been turned off and it should have been
> moved from SCRIPT_SH to SCRIPT_LIB in the Makefile. Its two new
> siblings, git-rebase--am.sh and git-rebase--merge.sh (whose executable
> bits are already off) should also be moved to SCRIPT_LIB in the
> Makefile.

Looks right, but...

> @@ -382,6 +379,9 @@ SCRIPT_SH += git-web--browse.sh
>  SCRIPT_LIB += git-mergetool--lib
>  SCRIPT_LIB += git-parse-remote
>  SCRIPT_LIB += git-sh-setup
> +SCRIPT_LIB += git-rebase--am.sh
> +SCRIPT_LIB += git-rebase--interactive.sh
> +SCRIPT_LIB += git-rebase--merge.sh

We usually keep these sorted.

-Peff

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 18/31] rebase: extract merge code to new source file
  2011-02-25  9:02               ` Jeff King
@ 2011-02-25 20:24                 ` Junio C Hamano
  0 siblings, 0 replies; 118+ messages in thread
From: Junio C Hamano @ 2011-02-25 20:24 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: Jeff King, Johannes Sixt, git, Johannes Schindelin,
	Christian Couder, Thomas Rast

Jeff King <peff@peff.net> writes:

> Looks right, but...
>
>> @@ -382,6 +379,9 @@ SCRIPT_SH += git-web--browse.sh
>>  SCRIPT_LIB += git-mergetool--lib
>>  SCRIPT_LIB += git-parse-remote
>>  SCRIPT_LIB += git-sh-setup
>> +SCRIPT_LIB += git-rebase--am.sh
>> +SCRIPT_LIB += git-rebase--interactive.sh
>> +SCRIPT_LIB += git-rebase--merge.sh
>
> We usually keep these sorted.

Also SCRIPT_LIB omits .sh (which feels inconsistent) and the above will
break the build.

No need to resend, as I've already fixed it up.

Thanks.

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 18/31] rebase: extract merge code to new source file
  2011-02-24  8:09           ` Jeff King
  2011-02-25  3:32             ` Martin von Zweigbergk
@ 2011-02-25 20:27             ` Jakub Narebski
  2011-03-01 22:04               ` Jeff King
  1 sibling, 1 reply; 118+ messages in thread
From: Jakub Narebski @ 2011-02-25 20:27 UTC (permalink / raw)
  To: Jeff King
  Cc: Martin von Zweigbergk, Johannes Sixt, git, Junio C Hamano,
	Johannes Schindelin, Christian Couder, Thomas Rast

Jeff King <peff@peff.net> writes:
> On Thu, Feb 24, 2011 at 03:07:34AM -0500, Jeff King wrote:
> > On Wed, Feb 23, 2011 at 10:27:23PM -0500, Martin von Zweigbergk wrote:
> > 
> > > > > +++ b/git-rebase--merge.sh
> > > > 
> > > > This should be mode 100755. (Ditto for git-rebase--am.sh in 19/31)
> > > 
> > > I was just about to fix now and I noticed that quite a few other
> > > script files are mode 100644. Should all be changed to mode 100755 or
> > > is there some kind of rule as to which mode they should be? Both
> > > git-sh-setup.sh and git-parse-remote.sh are also mode 100644 and I
> > > (think I) know that both are always sourced. If the rule is that
> > > sourced scripts should be mode 100644 (but I'm just guessing here),
> > > then I should actually have changed the mode of
> > > git-rebase--interactive.sh to that mode instead. Please advice.
> > 
> > Yes, sourced scripts should not have an executable bit. See 46bac90 for
> > rationale.
> 
> And I should have mentioned: they should go in SCRIPT_LIB in the
> Makefile, not SCRIPT_SH.

Shouldn't this information be in Documentation/CodingGuidelines, and
perhaps also (checking if one doesn't accidentally change executable
bit on sourced scripts) in Documentation/SubmittingPatches?

-- 
Jakub Narebski
Poland
ShadeHawk on #git

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH] rebase: define options in OPTIONS_SPEC
  2011-02-24  3:07     ` [PATCH] rebase: define options in OPTIONS_SPEC Martin von Zweigbergk
@ 2011-02-27 10:59       ` Junio C Hamano
  2011-03-01  1:59         ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Junio C Hamano @ 2011-02-27 10:59 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: Johannes Sixt, git, Johannes Schindelin, Christian Couder, Thomas Rast

Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:

> What is the difference between the "options" and "actions" sections?

For historical reasons, "git rebase" does not take subcommands in the way
many other commands do (e.g. "git bisect start", "git rerere remaining",
"git stash save").  Some --option to the command are used for specifying
the subcommand.  "git rebase --continue", if it were designed to be
consistent with the other commands, would have been "git rebase continue"
instead.  "Actions" part lists them.

This is somewhat unfortunate, but is understandable given that "rebase"
didn't have its own options at all, and there was only one mode of
operation, namely, to start the rebase process.  It allowed the user to be
terse, i.e. instead off having to say "git rebase onto master", it was
sufficient to say "git rebase master".

When "git rebase --continue" was introduced (before, you were supposed to
say "git am --resolved", which was nonsense from the UI point of view),
somebody should have noticed this as a problem and started a process to
deprecate the "git rebase <branchname>" and to require explicit subcommand
names, just like we did to "git stash [save]", but that didn't happen.

Perhaps this is something to consider at 2.0 boundary.

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH] rebase: define options in OPTIONS_SPEC
  2011-02-27 10:59       ` Junio C Hamano
@ 2011-03-01  1:59         ` Martin von Zweigbergk
  0 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-03-01  1:59 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Martin von Zweigbergk, Johannes Sixt, git, Johannes Schindelin,
	Christian Couder, Thomas Rast

On Sun, 27 Feb 2011, Junio C Hamano wrote:

> Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:
> 
> > What is the difference between the "options" and "actions" sections?
> 
> For historical reasons, "git rebase" does not take subcommands in the way
> many other commands do (e.g. "git bisect start", "git rerere remaining",
> "git stash save").  Some --option to the command are used for specifying
> the subcommand.  "git rebase --continue", if it were designed to be
> consistent with the other commands, would have been "git rebase continue"
> instead.  "Actions" part lists them.
> 
> This is somewhat unfortunate, but is understandable given that "rebase"
> didn't have its own options at all, and there was only one mode of
> operation, namely, to start the rebase process.  It allowed the user to be
> terse, i.e. instead off having to say "git rebase onto master", it was
> sufficient to say "git rebase master".
> 
> When "git rebase --continue" was introduced (before, you were supposed to
> say "git am --resolved", which was nonsense from the UI point of view),
> somebody should have noticed this as a problem and started a process to
> deprecate the "git rebase <branchname>" and to require explicit subcommand
> names, just like we did to "git stash [save]", but that didn't happen.
> 
> Perhaps this is something to consider at 2.0 boundary.
> 

Thanks for the explanation. It sounds like I should leave only
--continue, --skip and --abort in the "Actions" section.

I just noticed another problem with my patch. I had assumed that
specifying 'n,no-stat ...' on one line would give me a '-n' argument
to handle if e.g. '-n', '--no-stat' or '--no-sta' was passed. To my
surprise, when passing '--no-stat' on the command line, parse-options
gives me the long form back. If I pass '--no-sta', I get the curious

error: Ambiguous option: no-sta (could be --no-stat or --no-stat)

I figured these are related to the automatic support for negative
options (now I understand what you were talking about when you
mentioned that to someone a few days ago). So here comes an updated
patch where I have marked all of the options except for a few
(e.g. 'autosquash') with a '!' to tell parse-options that they have no
negative forms.


And thanks for fixing up my patch that moved the rebase scripts to
SCRIPT_LIB.


-- 8< --
Subject: [PATCH v2] rebase: define options in OPTIONS_SPEC

Interactive rebase used to have its own command line processing. Since
it used the 'git rev-parse --parseopt' functionality exposed through
git-sh-setup, it had some flexibility, like matching prefixes of long
options, that non-interactive rebase didn't. When interactive rebase's
command line processing was factored out into git-rebase.sh in cf432ca
(rebase: factor out command line option processing, 2011-02-06), this
flexibility was lost. Give back that flexibility to interactive and
non-interactive by defining its options in OPTIONS_SPEC.

Also improve the usage message to contain the --continue, --skip and
--abort sub commands.

Reported-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Applies on top of mz/rebase.

Are USAGE and LONG_USAGE still needed?

I based the definitions on the now-lost OPTIONS_SPEC from interactive
rebase and on Documentation/git-rebase.txt.

 git-rebase.sh |  101 +++++++++++++++++++++++++++++++-------------------------
 1 files changed, 56 insertions(+), 45 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index a040ab5..7a54bfc 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -28,7 +28,39 @@ Example:       git-rebase master~1 topic
 '
 
 SUBDIRECTORY_OK=Yes
-OPTIONS_SPEC=
+OPTIONS_KEEPDASHDASH=
+OPTIONS_SPEC="\
+git rebase [-i] [options] [--onto <newbase>] [<upstream>] [<branch>]
+git rebase [-i] [options] --onto <newbase> --root [<branch>]
+git-rebase [-i] --continue | --abort | --skip
+--
+ Available options are
+v,verbose!         display a diffstat of what changed upstream
+q,quiet!           be quiet. implies --no-stat
+onto=!             rebase onto given branch instead of upstream
+p,preserve-merges! try to recreate merges instead of ignoring them
+s,strategy=!       use the given merge strategy
+no-ff!             cherry-pick all commits, even if unchanged
+m,merge!           use merging strategies to rebase
+i,interactive!     let the user edit the list of commits to rebase
+f,force-rebase!    force rebase even if branch is up to date
+X,strategy-option=! pass the argument through to the merge strategy
+stat!              display a diffstat of what changed upstream
+n,no-stat!         do not show diffstat of what changed upstream
+verify             allow pre-rebase hook to run
+rerere-autoupdate  allow rerere to update index with resolved conflicts
+root!              rebase all reachable commits up to the root(s)
+autosquash         move commits that begin with squash!/fixup! under -i
+committer-date-is-author-date! passed to 'git am'
+ignore-date!       passed to 'git am'
+whitespace=!       passed to 'git apply'
+ignore-whitespace! passed to 'git apply'
+C=!                passed to 'git apply'
+ Actions:
+continue!          continue rebasing process
+abort!             abort rebasing process and restore original branch
+skip!              skip current patch and continue rebasing process
+"
 . git-sh-setup
 set_reflog_action rebase
 require_work_tree
@@ -175,7 +207,7 @@ do
 		ok_to_skip_pre_rebase=
 		;;
 	--continue|--skip|--abort)
-		test $total_argc -eq 1 || usage
+		test $total_argc -eq 2 || usage
 		action=${1##--}
 		;;
 	--onto)
@@ -183,10 +215,10 @@ do
 		onto="$2"
 		shift
 		;;
-	-i|--interactive)
+	-i)
 		interactive_rebase=explicit
 		;;
-	-p|--preserve-merges)
+	-p)
 		preserve_merges=t
 		test -z "$interactive_rebase" && interactive_rebase=implied
 		;;
@@ -196,62 +228,42 @@ do
 	--no-autosquash)
 		autosquash=
 		;;
-	-M|-m|--m|--me|--mer|--merg|--merge)
+	-M|-m)
 		do_merge=t
 		;;
-	-X*|--strategy-option*)
-		case "$#,$1" in
-		1,-X|1,--strategy-option)
-			usage ;;
-		*,-X|*,--strategy-option)
-			newopt="$2"
-			shift ;;
-		*,--strategy-option=*)
-			newopt="$(expr " $1" : ' --strategy-option=\(.*\)')" ;;
-		*,-X*)
-			newopt="$(expr " $1" : ' -X\(.*\)')" ;;
-		1,*)
-			usage ;;
-		esac
-		strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$newopt")"
+	-X)
+		shift
+		strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$1")"
 		do_merge=t
 		test -z "$strategy" && strategy=recursive
 		;;
-	-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
-		--strateg=*|--strategy=*|\
-	-s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
-		case "$#,$1" in
-		*,*=*)
-			strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
-		1,*)
-			usage ;;
-		*)
-			strategy="$2"
-			shift ;;
-		esac
+	-s)
+		shift
+		strategy="$1"
 		do_merge=t
 		;;
-	-n|--no-stat)
+	-n)
 		diffstat=
 		;;
 	--stat)
 		diffstat=t
 		;;
-	-v|--verbose)
+	-v)
 		verbose=t
 		diffstat=t
 		GIT_QUIET=
 		;;
-	-q|--quiet)
+	-q)
 		GIT_QUIET=t
 		git_am_opt="$git_am_opt -q"
 		verbose=
 		diffstat=
 		;;
-	--whitespace=*)
-		git_am_opt="$git_am_opt $1"
+	--whitespace)
+		shift
+		git_am_opt="$git_am_opt --whitespace=$1"
 		case "$1" in
-		--whitespace=fix|--whitespace=strip)
+		fix|strip)
 			force_rebase=t
 			;;
 		esac
@@ -263,22 +275,21 @@ do
 		git_am_opt="$git_am_opt $1"
 		force_rebase=t
 		;;
-	-C*)
-		git_am_opt="$git_am_opt $1"
+	-C)
+		shift
+		git_am_opt="$git_am_opt -C$1"
 		;;
 	--root)
 		rebase_root=t
 		;;
-	-f|--f|--fo|--for|--forc|--force|--force-r|--force-re|--force-reb|--force-reba|--force-rebas|--force-rebase|--no-ff)
+	-f|--no-ff)
 		force_rebase=t
 		;;
 	--rerere-autoupdate|--no-rerere-autoupdate)
 		allow_rerere_autoupdate="$1"
 		;;
-	-*)
-		usage
-		;;
-	*)
+	--)
+		shift
 		break
 		;;
 	esac
-- 
1.7.4.79.gcbe20

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 18/31] rebase: extract merge code to new source file
  2011-02-25 20:27             ` Jakub Narebski
@ 2011-03-01 22:04               ` Jeff King
  2011-03-01 22:43                 ` Jakub Narebski
  0 siblings, 1 reply; 118+ messages in thread
From: Jeff King @ 2011-03-01 22:04 UTC (permalink / raw)
  To: Jakub Narebski
  Cc: Martin von Zweigbergk, Johannes Sixt, git, Junio C Hamano,
	Johannes Schindelin, Christian Couder, Thomas Rast

On Fri, Feb 25, 2011 at 12:27:03PM -0800, Jakub Narebski wrote:

> > > Yes, sourced scripts should not have an executable bit. See 46bac90 for
> > > rationale.
> > 
> > And I should have mentioned: they should go in SCRIPT_LIB in the
> > Makefile, not SCRIPT_SH.
> 
> Shouldn't this information be in Documentation/CodingGuidelines, and
> perhaps also (checking if one doesn't accidentally change executable
> bit on sourced scripts) in Documentation/SubmittingPatches?

I think it might make more sense as comments in the Makefile, which is
not very well commented for people tweaking non-config bits. Patches
welcome.

-Peff

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 18/31] rebase: extract merge code to new source file
  2011-03-01 22:04               ` Jeff King
@ 2011-03-01 22:43                 ` Jakub Narebski
  0 siblings, 0 replies; 118+ messages in thread
From: Jakub Narebski @ 2011-03-01 22:43 UTC (permalink / raw)
  To: Jeff King
  Cc: Martin von Zweigbergk, Johannes Sixt, git, Junio C Hamano,
	Johannes Schindelin, Christian Couder, Thomas Rast

On Tue, 1 Mar 2011, Jeff King wrote:
> On Fri, Feb 25, 2011 at 12:27:03PM -0800, Jakub Narebski wrote:
> 
> > > > Yes, sourced scripts should not have an executable bit. See 46bac90 for
> > > > rationale.
> > > 
> > > And I should have mentioned: they should go in SCRIPT_LIB in the
> > > Makefile, not SCRIPT_SH.
> > 
> > Shouldn't this information be in Documentation/CodingGuidelines, and
> > perhaps also (checking if one doesn't accidentally change executable
> > bit on sourced scripts) in Documentation/SubmittingPatches?
> 
> I think it might make more sense as comments in the Makefile, which is
> not very well commented for people tweaking non-config bits. Patches
> welcome.

I meant here describing that sourced scripts should not have an executable
bit in CodingGuidelines, ensure that it didn't acquire executable bit in
SubmittingPatches, the fact that added new scripts got to SCRIPT_SH and
new sourced scripts to SCRIPT_LIB in CodingGuidelines / SubmittingPatches.

Description of SCRIPT_SH and SCRIPT_LIB in Makefile comments would be
also nice, and perhaps replace some of proposed additions to 
CodingGuidelines and SubmittingPatches documents.

-- 
Jakub Narebski
Poland

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 07/31] rebase: stricter check of standalone sub command
  2011-02-06 18:43   ` [PATCH v2 07/31] rebase: stricter check of standalone sub command Martin von Zweigbergk
@ 2011-07-01  3:55     ` Jonathan Nieder
  2011-07-01 13:16       ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Jonathan Nieder @ 2011-07-01  3:55 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast

Hi Martin,

Martin von Zweigbergk wrote:

> The sub commands '--continue', '--skip' or '--abort' may only be used
> standalone according to the documentation.
[...]
> Is this too simplistic? Do we forsee that we want to support passing
> options when resuming a rebase? Is it better to check for each other
> option that it is not passed (i.e. no '-v', no '-s' etc.)?
>
> Might some users be depending on the current behavior, even though it
> is undocumented?

Yes.

I have no clue why, but my fingers are wired to do

	git rebase -i --continue

when resuming an interactive rebase.  So with v1.7.6, I use two commands
instead of one.

It's possible that I was crazy, and we should just mention this in the
release notes and move on.  Another possibility would be to make "git
rebase -i --continue" mean "check if in the middle of an interactive
rebase, and if so, continue".  Yet another possibility would be to
allow transforming a non-interactive rebase into an interactive one
after a conflict with that command (though I can't imagine why someone
would want to).  I'm tempted to say the first way (keeping the command
broken and documenting the change) is the way to go, since it means it
would be possible to make commands like this mean something else in
the future.

What do you think?

*searches*

Ah, it seems you already wrote a patch at [1].  The commit message
says it fails for "-i --continue" but I don't any code doing that;
what am I missing?

[1] http://thread.gmane.org/gmane.comp.version-control.git/164241/focus=166684

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 07/31] rebase: stricter check of standalone sub command
  2011-07-01  3:55     ` Jonathan Nieder
@ 2011-07-01 13:16       ` Martin von Zweigbergk
  2011-07-01 22:29         ` Jonathan Nieder
  0 siblings, 1 reply; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-07-01 13:16 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Martin von Zweigbergk, git, Junio C Hamano, Johannes Schindelin,
	Johannes Sixt, Christian Couder, Thomas Rast

Hi Jonathan,

On Thu, 30 Jun 2011, Jonathan Nieder wrote:

> Hi Martin,
> 
> Martin von Zweigbergk wrote:
> 
> > The sub commands '--continue', '--skip' or '--abort' may only be used
> > standalone according to the documentation.
> [...]
> > Is this too simplistic? Do we forsee that we want to support passing
> > options when resuming a rebase? Is it better to check for each other
> > option that it is not passed (i.e. no '-v', no '-s' etc.)?
> >
> > Might some users be depending on the current behavior, even though it
> > is undocumented?
> 
> Yes.
> 
> I have no clue why, but my fingers are wired to do
> 
> 	git rebase -i --continue
> 
> when resuming an interactive rebase.  So with v1.7.6, I use two commands
> instead of one.
> 
> It's possible that I was crazy, and we should just mention this in the
> release notes and move on.  Another possibility would be to make "git
> rebase -i --continue" mean "check if in the middle of an interactive
> rebase, and if so, continue".  Yet another possibility would be to
> allow transforming a non-interactive rebase into an interactive one
> after a conflict with that command (though I can't imagine why someone
> would want to).  I'm tempted to say the first way (keeping the command
> broken and documenting the change) is the way to go, since it means it
> would be possible to make commands like this mean something else in
> the future.
> 
> What do you think?

I think it feels like 'git rebase -i --continue' to resume a
non-interactive rebase should be an error until we actually support
transforming it into an interactive rebase (if ever). I agree that if
the rebase was already interactive, it would not harm to accept
it. OTOH, since the -i means nothing in this context, I don't see much
need to accept it either. In short, I agree with you that documenting
it is enough. Is the below patch what you had in mind?


> *searches*
> 
> Ah, it seems you already wrote a patch at [1].  The commit message
> says it fails for "-i --continue" but I don't any code doing that;
> what am I missing?

That patch was never accepted, but 95135b0 (rebase: stricter check of
standalone sub command, 2011-02-06) was.

> [1] http://thread.gmane.org/gmane.comp.version-control.git/164241/focus=166684
> 


-- >8 --
Subject: [PATCH] rebase usage: subcommands can not be combined with -i

Since 95135b0 (rebase: stricter check of standalone sub command,
2011-02-06), git-rebase has not allowed to use -i together with
e.g. --continue. Yet, when rebase started using OPTIONS_SPEC in
45e2acf (rebase: define options in OPTIONS_SPEC, 2011-02-28), the
usage message included

  git-rebase [-i] --continue | --abort | --skip

Remove the "[-i]" from this line.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 git-rebase.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index d7855ea..6afc596 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -32,7 +32,7 @@ OPTIONS_KEEPDASHDASH=
 OPTIONS_SPEC="\
 git rebase [-i] [options] [--onto <newbase>] [<upstream>] [<branch>]
 git rebase [-i] [options] --onto <newbase> --root [<branch>]
-git-rebase [-i] --continue | --abort | --skip
+git-rebase --continue | --abort | --skip
 --
  Available options are
 v,verbose!         display a diffstat of what changed upstream
-- 
1.7.5.3.640.gd1066

^ permalink raw reply related	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 07/31] rebase: stricter check of standalone sub command
  2011-07-01 13:16       ` Martin von Zweigbergk
@ 2011-07-01 22:29         ` Jonathan Nieder
  2011-07-06  1:48           ` Martin von Zweigbergk
  0 siblings, 1 reply; 118+ messages in thread
From: Jonathan Nieder @ 2011-07-01 22:29 UTC (permalink / raw)
  To: Martin von Zweigbergk
  Cc: git, Junio C Hamano, Johannes Schindelin, Johannes Sixt,
	Christian Couder, Thomas Rast

Martin von Zweigbergk wrote:

> Is the below patch what you had in mind?

No, but it looks good to me ("rebase usage: subcommands can not be
combined with -i").

>> Ah, it seems you already wrote a patch at [1].  The commit message
>> says it fails for "-i --continue" but I don't any code doing that;
>> what am I missing?
>
> That patch was never accepted, but 95135b0 (rebase: stricter check of
> standalone sub command, 2011-02-06) was.
>
>> [1] http://thread.gmane.org/gmane.comp.version-control.git/164241/focus=166684

I'll play around with [1] and try to revive it.  Thanks.

^ permalink raw reply	[flat|nested] 118+ messages in thread

* Re: [PATCH v2 07/31] rebase: stricter check of standalone sub command
  2011-07-01 22:29         ` Jonathan Nieder
@ 2011-07-06  1:48           ` Martin von Zweigbergk
  0 siblings, 0 replies; 118+ messages in thread
From: Martin von Zweigbergk @ 2011-07-06  1:48 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Martin von Zweigbergk, git, Junio C Hamano, Johannes Schindelin,
	Johannes Sixt, Christian Couder, Thomas Rast

On Fri, 1 Jul 2011, Jonathan Nieder wrote:

> Martin von Zweigbergk wrote:
> 
> > Is the below patch what you had in mind?
> 
> No, but it looks good to me ("rebase usage: subcommands can not be
> combined with -i").
> 
> >> Ah, it seems you already wrote a patch at [1].  The commit message
> >> says it fails for "-i --continue" but I don't any code doing that;
> >> what am I missing?
> >
> > That patch was never accepted, but 95135b0 (rebase: stricter check of
> > standalone sub command, 2011-02-06) was.
> >
> >> [1] http://thread.gmane.org/gmane.comp.version-control.git/164241/focus=166684
> 
> I'll play around with [1] and try to revive it.  Thanks.

I'm not sure I understand what you want to achieve. Do you want to
revive [1] but also make it allow "-i --continue"? If so, is one of
the following your goal when used with "--continue"?

 1. Always accept "-i", but ignore it (the behavior before 1.7.6)

 2. Only accept "-i" if the rebase was already interactive

 3. Always accept "-i" and transform a non-interactive rebase to an
 interative one

Just curious. Thanks for working on it.


Martin

^ permalink raw reply	[flat|nested] 118+ messages in thread

end of thread, other threads:[~2011-07-06  1:49 UTC | newest]

Thread overview: 118+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-28  9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 01/31] rebase: clearer names for directory variables Martin von Zweigbergk
2010-12-28 23:08   ` Junio C Hamano
2010-12-28 20:53     ` Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 02/31] rebase: refactor reading of state Martin von Zweigbergk
2010-12-28 23:08   ` Junio C Hamano
2010-12-29  8:09     ` Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 03/31] rebase: read state outside loop Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 04/31] rebase: remove unused rebase state 'prev_head' Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 05/31] rebase: improve detection of rebase in progress Martin von Zweigbergk
2010-12-28 23:08   ` Junio C Hamano
2010-12-28 20:35     ` Martin von Zweigbergk
2011-01-12 10:20       ` Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 06/31] rebase: act on command line outside parsing loop Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 07/31] rebase: stricter check of standalone sub command Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 08/31] rebase: align variable names Martin von Zweigbergk
2011-01-04 19:12   ` Thomas Rast
2011-01-05  2:25     ` Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 09/31] rebase: align variable content Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 10/31] rebase: factor out command line option processing Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 11/31] rebase -i: remove now unnecessary directory checks Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 12/31] rebase: reorder validation steps Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 13/31] rebase: factor out reference parsing Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 14/31] rebase: factor out clean work tree check Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 15/31] rebase: factor out call to pre-rebase hook Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 16/31] rebase -i: support --stat Martin von Zweigbergk
2010-12-28 17:59   ` Johannes Schindelin
2010-12-28 13:24     ` Martin von Zweigbergk
2010-12-28 23:36     ` Junio C Hamano
2010-12-28 23:44       ` Johannes Schindelin
2010-12-28  9:30 ` [PATCH 17/31] rebase: remove $branch as synonym for $orig_head Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 18/31] rebase: extract merge code to new source file Martin von Zweigbergk
2010-12-29 21:31   ` Johannes Sixt
2010-12-29 22:24     ` Martin von Zweigbergk
2010-12-31 12:23       ` Thomas Rast
2010-12-31 14:05         ` Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 19/31] rebase: extract am " Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 20/31] rebase: show consistent conflict resolution hint Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 21/31] rebase -i: align variable names Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 22/31] rebase: make -v a tiny bit more verbose Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 23/31] rebase: factor out sub command handling Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 24/31] rebase: extract code for writing basic state Martin von Zweigbergk
2011-01-04 19:19   ` Thomas Rast
2011-01-05  2:40     ` Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 25/31] rebase: remember verbose option Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 26/31] rebase: remember strategy and strategy options Martin von Zweigbergk
2011-01-04 19:27   ` Thomas Rast
2011-01-05  3:33     ` Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 27/31] rebase -m: remember allow_rerere_autoupdate option Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 28/31] rebase -m: don't print exit code 2 when merge fails Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 29/31] git-rebase--am: remove unnecessary --3way option Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 30/31] rebase -i: don't read unused variable preserve_merges Martin von Zweigbergk
2010-12-28  9:30 ` [PATCH 31/31] rebase -i: remove unnecessary state rebase-root Martin von Zweigbergk
2010-12-28 16:40   ` Thomas Rast
2010-12-29 22:31     ` Martin von Zweigbergk
2010-12-31  5:41       ` Christian Couder
2011-01-04 19:57 ` [PATCH 00/31] Refactor rebase Thomas Rast
2011-01-05  3:39   ` Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 01/31] rebase: clearer names for directory variables Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 02/31] rebase: refactor reading of state Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 03/31] rebase: read state outside loop Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 04/31] rebase: remove unused rebase state 'prev_head' Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 05/31] rebase: improve detection of rebase in progress Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 06/31] rebase: act on command line outside parsing loop Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 07/31] rebase: stricter check of standalone sub command Martin von Zweigbergk
2011-07-01  3:55     ` Jonathan Nieder
2011-07-01 13:16       ` Martin von Zweigbergk
2011-07-01 22:29         ` Jonathan Nieder
2011-07-06  1:48           ` Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 08/31] rebase: align variable names Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 09/31] rebase: align variable content Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 10/31] rebase: factor out command line option processing Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 11/31] rebase -i: remove now unnecessary directory checks Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 12/31] rebase: reorder validation steps Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 13/31] rebase: factor out reference parsing Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 14/31] rebase: factor out clean work tree check Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 15/31] rebase: factor out call to pre-rebase hook Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 16/31] rebase -i: support --stat Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 17/31] rebase: remove $branch as synonym for $orig_head Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 18/31] rebase: extract merge code to new source file Martin von Zweigbergk
2011-02-14  8:02     ` Johannes Sixt
2011-02-14 13:56       ` Martin von Zweigbergk
2011-02-24  3:27       ` Martin von Zweigbergk
2011-02-24  8:07         ` Jeff King
2011-02-24  8:09           ` Jeff King
2011-02-25  3:32             ` Martin von Zweigbergk
2011-02-25  9:02               ` Jeff King
2011-02-25 20:24                 ` Junio C Hamano
2011-02-25 20:27             ` Jakub Narebski
2011-03-01 22:04               ` Jeff King
2011-03-01 22:43                 ` Jakub Narebski
2011-02-06 18:43   ` [PATCH v2 19/31] rebase: extract am " Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 20/31] rebase: show consistent conflict resolution hint Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 21/31] rebase -i: align variable names Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 22/31] rebase: make -v a tiny bit more verbose Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 23/31] rebase: factor out sub command handling Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 24/31] rebase: extract code for writing basic state Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 25/31] rebase: remember verbose option Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 26/31] rebase: remember strategy and strategy options Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 27/31] rebase -m: remember allow_rerere_autoupdate option Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 28/31] rebase -m: don't print exit code 2 when merge fails Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 29/31] git-rebase--am: remove unnecessary --3way option Martin von Zweigbergk
2011-02-06 18:43   ` [PATCH v2 30/31] rebase -i: don't read unused variable preserve_merges Martin von Zweigbergk
2011-02-06 18:44   ` [PATCH v2 31/31] rebase -i: remove unnecessary state rebase-root Martin von Zweigbergk
2011-02-10 22:44   ` [PATCH v2 00/31] refactor rebase Junio C Hamano
2011-02-12  0:55     ` Martin von Zweigbergk
2011-02-14  1:54       ` Martin von Zweigbergk
2011-02-14  3:15         ` Martin von Zweigbergk
2011-02-15  0:36         ` Junio C Hamano
2011-02-22 13:58         ` Martin von Zweigbergk
2011-02-22 19:21           ` Junio C Hamano
2011-02-23 11:26             ` Martin von Zweigbergk
2011-02-16 14:52   ` Johannes Sixt
2011-02-17  3:41     ` Martin von Zweigbergk
2011-02-24  3:07     ` [PATCH] rebase: define options in OPTIONS_SPEC Martin von Zweigbergk
2011-02-27 10:59       ` Junio C Hamano
2011-03-01  1:59         ` Martin von Zweigbergk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.