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

[PATCH 3/5] rebase: refactor common shell functions into their own file

From
Pratik Karki <predatoramigo@gmail.com>
Date
Jun 28, 2018, 07:46 UTC
Message-ID
<20180628074655.5756-4-predatoramigo@gmail.com>
In-Reply-To
<20180628074655.5756-1-predatoramigo@gmail.com>

The function present in `git-legacy-rebase.sh` are used by backends so, this refactor tries to extract the functions out so that, the `git-legacy-rebase.sh` can be retired easily as the `git-rebase--common.sh` will provide the functions for now.

The motivation behind this is to call the backend functions *directly* from C, bypassing `git-rebase.sh`. Therefore those functions need to live in a separate file: we need to be able to call `.git-rebase--common` in that script snippet so that those functions are defined.

Signed-off-by: Pratik Karki <predatoramigo@gmail.com>
---
 .gitignore            |  1 +
 Makefile              |  1 +
 git-legacy-rebase.sh  | 62 +------------------------------------------
 git-rebase--common.sh | 61 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 64 insertions(+), 61 deletions(-)
 create mode 100644 git-rebase--common.sh
diff --git a/.gitignore b/.gitignore
index ec2395901..824141cba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -117,6 +117,7 @@
 /git-read-tree
 /git-rebase
 /git-rebase--am
+/git-rebase--common
 /git-rebase--helper
 /git-rebase--interactive
 /git-rebase--merge
diff --git a/Makefile b/Makefile
index e88fe2e5f..163e52ad1 100644
--- a/Makefile
+++ b/Makefile
@@ -619,6 +619,7 @@ SCRIPT_SH += git-web--browse.sh
 SCRIPT_LIB += git-mergetool--lib
 SCRIPT_LIB += git-parse-remote
 SCRIPT_LIB += git-rebase--am
+SCRIPT_LIB += git-rebase--common
 SCRIPT_LIB += git-rebase--interactive
 SCRIPT_LIB += git-rebase--preserve-merges
 SCRIPT_LIB += git-rebase--merge
diff --git a/git-legacy-rebase.sh b/git-legacy-rebase.sh
index 19bdebb48..240aac507 100755
--- a/git-legacy-rebase.sh
+++ b/git-legacy-rebase.sh
@@ -102,6 +102,7 @@ case "$(git config --bool commit.gpgsign)" in
 true)	gpg_sign_opt=-S ;;
 *)	gpg_sign_opt= ;;
 esac
+. git-rebase--common
 
 read_basic_state () {
 	test -f "$state_dir/head-name" &&
@@ -132,67 +133,6 @@ read_basic_state () {
 	}
 }
 
-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
-	test -n "$signoff" && echo "$signoff" >"$state_dir"/signoff
-}
-
-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 "$(eval_gettext "Could not move back to \$head_name")"
-		;;
-	esac
-}
-
-apply_autostash () {
-	if test -f "$state_dir/autostash"
-	then
-		stash_sha1=$(cat "$state_dir/autostash")
-		if git stash apply $stash_sha1 >/dev/null 2>&1
-		then
-			echo "$(gettext 'Applied autostash.')" >&2
-		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.
-' >&2
-		fi
-	fi
-}
-
 finish_rebase () {
 	rm -f "$(git rev-parse --git-path REBASE_HEAD)"
 	apply_autostash &&
diff --git a/git-rebase--common.sh b/git-rebase--common.sh
new file mode 100644
index 000000000..5ba060392
--- /dev/null
+++ b/git-rebase--common.sh
@@ -0,0 +1,61 @@
+
+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
+	test -n "$signoff" && echo "$signoff" >"$state_dir"/signoff
+}
+
+apply_autostash () {
+	if test -f "$state_dir/autostash"
+	then
+		stash_sha1=$(cat "$state_dir/autostash")
+		if git stash apply $stash_sha1 >/dev/null 2>&1
+		then
+			echo "$(gettext 'Applied autostash.')" >&2
+		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.
+' >&2
+		fi
+	fi
+}
+
+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 "$(eval_gettext "Could not move back to \$head_name")"
+		;;
+	esac
+}
+
+output () {
+	case "$verbose" in
+	'')
+		output=$("$@" 2>&1 )
+		status=$?
+		test $status != 0 && printf "%s\n" "$output"
+		return $status
+		;;
+	*)
+		"$@"
+		;;
+	esac
+}
-- 
2.18.0
Previous: Stefan BellerNext: Christian Couder
Message 7 of 61 in “rebase: rewrite rebase in C”
  1. Pratik KarkiJun 28, 2018
  2. 1/5 Start TODO-rebase.shPratik Karki, Jun 28, 2018
  3. Pratik KarkiJun 28, 2018
  4. 2/5 rebase: start implementing it as a builtinPratik Karki, Jun 28, 2018
  5. Christian CouderJun 28, 2018
  6. Stefan BellerJun 28, 2018
  7. 3/5 rebase: refactor common shell functions into their own filePratik Karki, Jun 28, 2018
  8. Christian CouderJun 28, 2018
  9. Stefan BellerJun 28, 2018
  10. 4/5 sequencer: refactor the code to detach HEAD to checkout.cPratik Karki, Jun 28, 2018
  11. Christian CouderJun 28, 2018
  12. Stefan BellerJun 28, 2018
  13. 5/5 builtin/rebase: support running "git rebase <upstream>"Pratik Karki, Jun 28, 2018
  14. Stefan BellerJun 28, 2018
  15. [GSoC] [PATCH v2 0/4] rebase: rewrite rebase in CPratik Karki, Jul 2, 2018
  16. 1/4 rebase: start implementing it as a builtinPratik Karki, Jul 2, 2018
  17. Junio C HamanoJul 3, 2018
  18. 2/4 rebase: refactor common shell functions into their own filePratik Karki, Jul 2, 2018
  19. Junio C HamanoJul 3, 2018
  20. 3/4 sequencer: refactor the code to detach HEAD to checkout.cPratik Karki, Jul 2, 2018
  21. Junio C HamanoJul 3, 2018
  22. 4/4 builtin/rebase: support running "git rebase <upstream>"Pratik Karki, Jul 2, 2018
  23. Junio C HamanoJul 3, 2018
  24. [GSoC] [PATCH v3 0/4] rebase: rewrite rebase in CPratik Karki, Jul 6, 2018
  25. 1/4 rebase: start implementing it as a builtinPratik Karki, Jul 6, 2018
  26. Junio C HamanoJul 6, 2018
  27. 2/4 rebase: refactor common shell functions into their own filePratik Karki, Jul 6, 2018
  28. Johannes SchindelinJul 6, 2018
  29. 3/4 sequencer: refactor the code to detach HEAD to checkout.cPratik Karki, Jul 6, 2018
  30. 4/4 builtin/rebase: support running "git rebase <upstream>"Pratik Karki, Jul 6, 2018
  31. Junio C HamanoJul 6, 2018
  32. Christian CouderJul 7, 2018
  33. Johannes SchindelinJul 7, 2018
  34. Junio C HamanoJul 7, 2018
  35. Beat BolliJul 17, 2018
  36. Beat BolliJul 17, 2018
  37. [GSoC] [PATCH v4 0/4] rebase: rewrite rebase in CPratik Karki, Jul 8, 2018
  38. 1/4 rebase: start implementing it as a builtinPratik Karki, Jul 8, 2018
  39. Andrei RybakJul 9, 2018
  40. Eric SunshineJul 9, 2018
  41. Pratik KarkiJul 9, 2018
  42. Duy NguyenJul 22, 2018
  43. 2/4 rebase: refactor common shell functions into their own filePratik Karki, Jul 8, 2018
  44. 3/4 sequencer: refactor the code to detach HEAD to checkout.cPratik Karki, Jul 8, 2018
  45. Johannes SchindelinJul 8, 2018
  46. Pratik KarkiJul 9, 2018
  47. Junio C HamanoJul 9, 2018
  48. Pratik KarkiJul 9, 2018
  49. 4/4 builtin/rebase: support running "git rebase <upstream>"Pratik Karki, Jul 8, 2018
  50. Johannes SchindelinJul 8, 2018
  51. Johannes SchindelinJul 8, 2018
  52. [GSoC] [PATCH v5 0/3] rebase: rewrite rebase in CPratik Karki, Jul 30, 2018
  53. 1/3 rebase: start implementing it as a builtinPratik Karki, Jul 30, 2018
  54. 2/3 rebase: refactor common shell functions into their own filePratik Karki, Jul 30, 2018
  55. 3/3 builtin/rebase: support running "git rebase <upstream>"Pratik Karki, Jul 30, 2018
  56. Pratik KarkiAug 1, 2018
  57. [GSoC] [PATCH v6 0/3] rebase: rewrite rebase in CPratik Karki, Aug 6, 2018
  58. [GSoC] [PATCH v6 3/3] builtin/rebase: support running "git rebase <upstream>"Pratik Karki, Aug 6, 2018
  59. Junio C HamanoAug 16, 2018
  60. [GSoC] [PATCH v6 2/3] rebase: refactor common shell functions into their own filePratik Karki, Aug 6, 2018
  61. [GSoC] [PATCH v6 1/3] rebase: start implementing it as a builtinPratik Karki, Aug 6, 2018

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.