Subject: [PATCH 1/3] rebase: move common functions to rebase--lib.sh

From: Nguyễn Thái Ngọc Duy <[email-masked]>
Date: Wed, 17 Feb 2016 20:36:39 +0700

These functions are used by git-rebase--*.sh, which will be made
separate programs later. At that point, we can reinclude rebase--lib.sh
to provide the functions without duplicating code.

Signed-off-by: Nguyễn Thái Ngọc Duy <[email-masked]>
---
 Makefile                 |  1 +
 git-rebase--lib.sh (new) | 41 +++++++++++++++++++++++++++++++++++++++++
 git-rebase.sh            | 42 +-----------------------------------------
 3 files changed, 43 insertions(+), 41 deletions(-)
 create mode 100644 git-rebase--lib.sh

diff --git a/Makefile b/Makefile
index fc2f1ab..1ee0ed3 100644
--- a/Makefile
+++ b/Makefile
@@ -496,6 +496,7 @@ SCRIPT_LIB += git-parse-remote
 SCRIPT_LIB += git-rebase--am
 SCRIPT_LIB += git-rebase--interactive
 SCRIPT_LIB += git-rebase--merge
+SCRIPT_LIB += git-rebase--lib
 SCRIPT_LIB += git-sh-setup
 SCRIPT_LIB += git-sh-i18n
 
diff --git a/git-rebase--lib.sh b/git-rebase--lib.sh
new file mode 100644
index 0000000..8bec516
--- /dev/null
+++ b/git-rebase--lib.sh
@@ -0,0 +1,41 @@
+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
+	test -n "$gpg_sign_opt" && echo "$gpg_sign_opt" > "$state_dir"/gpg_sign_opt
+}
+
+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/*)
+		message="rebase finished: $head_name onto $onto"
+		git update-ref -m "$message" \
+			$head_name $(git rev-parse HEAD) $orig_head &&
+		git symbolic-ref \
+			-m "rebase finished: returning to $head_name" \
+			HEAD $head_name ||
+		die "$(gettext "Could not move back to $head_name")"
+		;;
+	esac
+}
diff --git a/git-rebase.sh b/git-rebase.sh
index cf60c43..dc29474 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -46,6 +46,7 @@ edit-todo!         edit the todo list during an interactive rebase
 "
 . git-sh-setup
 . git-sh-i18n
+. git-rebase--lib
 set_reflog_action rebase
 require_work_tree_exists
 cd_to_toplevel
@@ -114,47 +115,6 @@ read_basic_state () {
 		gpg_sign_opt="$(cat "$state_dir"/gpg_sign_opt)"
 }
 
-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
-	test -n "$gpg_sign_opt" && echo "$gpg_sign_opt" > "$state_dir"/gpg_sign_opt
-}
-
-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/*)
-		message="rebase finished: $head_name onto $onto"
-		git update-ref -m "$message" \
-			$head_name $(git rev-parse HEAD) $orig_head &&
-		git symbolic-ref \
-			-m "rebase finished: returning to $head_name" \
-			HEAD $head_name ||
-		die "$(gettext "Could not move back to $head_name")"
-		;;
-	esac
-}
 
 apply_autostash () {
 	if test -f "$state_dir/autostash"
-- 
2.7.0.377.g4cd97dd