git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Feb 17, 2016, 13:36 UTC
Message-ID
<1455716201-29784-3-git-send-email-pclouds@gmail.com>
In-Reply-To
<1455716201-29784-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 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
Previous: Nguyễn Thái Ngọc DuyNext: Matthieu Moy
Message 16 of 67 in “GSoC 2016: applications open, deadline = Fri, 19/2”
  1. Matthieu MoyFeb 10, 2016
  2. Johannes SchindelinFeb 10, 2016
  3. Stefan BellerFeb 10, 2016
  4. Christian CouderFeb 11, 2016
  5. Matthieu MoyFeb 12, 2016
  6. Lars SchneiderFeb 12, 2016
  7. Matthieu MoyFeb 12, 2016
  8. Jeff KingFeb 12, 2016
  9. Jeff KingFeb 12, 2016
  10. Matthieu MoyFeb 13, 2016
  11. Stefan BellerFeb 16, 2016
  12. Matthieu MoyFeb 17, 2016
  13. Duy NguyenFeb 17, 2016
  14. 0/3 Turn git-rebase--*.sh to external helpersNguyễn Thái Ngọc Duy, Feb 17, 2016
  15. 1/3 rebase: move common functions to rebase--lib.shNguyễn Thái Ngọc Duy, Feb 17, 2016
  16. 2/3 rebase: move cleanup code to exit_rebase()Nguyễn Thái Ngọc Duy, Feb 17, 2016
  17. Matthieu MoyFeb 17, 2016
  18. 3/3 rebase: turn git-rebase--*.sh into separate programsNguyễn Thái Ngọc Duy, Feb 17, 2016
  19. Matthieu MoyFeb 17, 2016
  20. Johannes SchindelinFeb 17, 2016
  21. Duy NguyenFeb 17, 2016
  22. Johannes SchindelinFeb 17, 2016
  23. Christian CouderFeb 17, 2016
  24. Duy NguyenFeb 22, 2016
  25. Matthieu MoyFeb 22, 2016
  26. Jeff KingFeb 22, 2016
  27. Junio C HamanoFeb 22, 2016
  28. Jeff KingFeb 22, 2016
  29. Matthieu MoyFeb 23, 2016
  30. Jeff KingFeb 24, 2016
  31. Thomas GummererFeb 17, 2016
  32. Lars SchneiderFeb 17, 2016
  33. Matthieu MoyFeb 17, 2016
  34. Junio C HamanoFeb 17, 2016
  35. Matthieu MoyFeb 17, 2016
  36. Jeff KingFeb 17, 2016
  37. Junio C HamanoFeb 17, 2016
  38. Carlos Martín NietoFeb 18, 2016
  39. Matthieu MoyFeb 19, 2016
  40. Carlos Martín NietoFeb 19, 2016
  41. Git has been accepted as a GSoC 2016 mentor organization!Matthieu Moy, Feb 29, 2016
  42. Jeff KingMar 8, 2016
  43. Junio C HamanoMar 8, 2016
  44. Jeff KingMar 8, 2016
  45. Matthieu MoyMar 9, 2016
  46. Jeff KingMar 9, 2016
  47. Johannes SchindelinMar 9, 2016
  48. Jeff KingMar 9, 2016
  49. Matthieu MoyFeb 19, 2016
  50. Jeff KingFeb 19, 2016
  51. Matthieu MoyFeb 19, 2016
  52. Jeff KingFeb 19, 2016
  53. Lars SchneiderFeb 18, 2016
  54. Stefan BellerFeb 18, 2016
  55. Junio C HamanoFeb 18, 2016
  56. Matthieu MoyFeb 19, 2016
  57. Junio C HamanoFeb 19, 2016
  58. Johannes SchindelinFeb 20, 2016
  59. Lars SchneiderFeb 19, 2016
  60. Matthieu MoyFeb 19, 2016
  61. Junio C HamanoFeb 19, 2016
  62. Thomas GummererFeb 19, 2016
  63. Duy NguyenFeb 19, 2016
  64. Junio C HamanoFeb 19, 2016
  65. Duy NguyenFeb 19, 2016
  66. Matthieu MoyFeb 19, 2016
  67. Duy NguyenFeb 19, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.