[PATCH 2/3] rebase: move cleanup code to exit_rebase()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 git-rebase--lib.sh (mode +x) | 38 ++++++++++++++++++++++++++++++++++++++
 git-rebase.sh                | 37 +------------------------------------
 2 files changed, 39 insertions(+), 36 deletions(-)
 mode change 100644 => 100755 git-rebase--lib.sh

diff --git a/git-rebase--lib.sh b/git-rebase--lib.sh
old mode 100644
new mode 100755
index 8bec516..a876fc2
--- a/git-rebase--lib.sh
+++ b/git-rebase--lib.sh
@@ -39,3 +39,41 @@ move_to_original_branch () {
 		;;
 	esac
 }
+
+apply_autostash () {
+	if test -f "$state_dir/autostash"
+	then
+		stash_sha1=$(cat "$state_dir/autostash")
+		if git stash apply $stash_sha1 2>&1 >/dev/null
+		then
+			echo "$(gettext 'Applied autostash.')"
+		else
+			git stash store -m "autostash" -q $stash_sha1 ||
+			die "$(eval_gettext "Cannot store \$stash_sha1")"
+			gettext 'Applying autostash resulted in conflicts.
+Your changes are safe in the stash.
+You can run "git stash pop" or "git stash drop" at any time.
+'
+		fi
+	fi
+}
+
+finish_rebase () {
+	apply_autostash &&
+	{ git gc --auto || true; } &&
+	rm -rf "$state_dir"
+}
+
+exit_rebase () {
+	ret=$1
+	if test $ret -eq 0
+	then
+		finish_rebase
+	elif test $ret -eq 2 # special exit status for rebase -i
+	then
+		apply_autostash &&
+		rm -rf "$state_dir" &&
+		die "Nothing to do"
+	fi
+	exit $ret
+}
diff --git a/git-rebase.sh b/git-rebase.sh
index dc29474..0c70381 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -115,31 +115,6 @@ read_basic_state () {
 		gpg_sign_opt="$(cat "$state_dir"/gpg_sign_opt)"
 }
 
-
-apply_autostash () {
-	if test -f "$state_dir/autostash"
-	then
-		stash_sha1=$(cat "$state_dir/autostash")
-		if git stash apply $stash_sha1 2>&1 >/dev/null
-		then
-			echo "$(gettext 'Applied autostash.')"
-		else
-			git stash store -m "autostash" -q $stash_sha1 ||
-			die "$(eval_gettext "Cannot store \$stash_sha1")"
-			gettext 'Applying autostash resulted in conflicts.
-Your changes are safe in the stash.
-You can run "git stash pop" or "git stash drop" at any time.
-'
-		fi
-	fi
-}
-
-finish_rebase () {
-	apply_autostash &&
-	{ git gc --auto || true; } &&
-	rm -rf "$state_dir"
-}
-
 run_specific_rebase () {
 	if [ "$interactive_rebase" = implied ]; then
 		GIT_EDITOR=:
@@ -147,17 +122,7 @@ run_specific_rebase () {
 		autosquash=
 	fi
 	. git-rebase--$type
-	ret=$?
-	if test $ret -eq 0
-	then
-		finish_rebase
-	elif test $ret -eq 2 # special exit status for rebase -i
-	then
-		apply_autostash &&
-		rm -rf "$state_dir" &&
-		die "Nothing to do"
-	fi
-	exit $ret
+	exit_rebase $?
 }
 
 run_pre_rebase_hook () {
-- 
2.7.0.377.g4cd97dd

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]