rebase: refactor common shell functions into their own file
The functions present in `git-legacy-rebase.sh` are used by the rebase backends as they are implemented as shell script functions in the `git-rebase--<backend>` files. To make the `builtin/rebase.c` work, we have to provide support via a Unix shell script snippet that uses these functions and so, we want to use the rebase backends *directly* from the builtin rebase without going through `git-legacy-rebase.sh`. This commit extracts the functions to a separate file, `git-rebase--common`, that will be read by `git-legacy-rebase.sh` and by the shell script snippets which will be used extensively in the following commits. Signed-off-by: Pratik Karki <predatoramigo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pratik Karki committed
Aug 7, 2018 at 01:16 UTC
c7b64aa0f3a83ed574d9d374bf2639c3c091120c
4 files changed
+72
-67
.gitignore
+1
@@ -117,6 +117,7 @@
117
/git-read-tree
118
/git-rebase
119
/git-rebase--am
120
+/git-rebase--common
121
/git-rebase--helper
122
/git-rebase--interactive
123
/git-rebase--merge
Makefile
+1
@@ -619,6 +619,7 @@ SCRIPT_SH += git-web--browse.sh
619
SCRIPT_LIB += git-mergetool--lib
620
SCRIPT_LIB += git-parse-remote
621
SCRIPT_LIB += git-rebase--am
622
+SCRIPT_LIB += git-rebase--common
623
SCRIPT_LIB += git-rebase--interactive
624
SCRIPT_LIB += git-rebase--preserve-merges
625
SCRIPT_LIB += git-rebase--merge
git-legacy-rebase.sh
+2
-67
@@ -57,12 +57,7 @@ cd_to_toplevel
57
LF='
58
'
59
ok_to_skip_pre_rebase=
60
-resolvemsg="
61
-$(gettext 'Resolve all conflicts manually, mark them as resolved with
62
-"git add/rm <conflicted_files>", then run "git rebase --continue".
63
-You can instead skip this commit: run "git rebase --skip".
64
-To abort and get back to the state before "git rebase", run "git rebase --abort".')
65
-"
60
+
61
squash_onto=
62
unset onto
63
unset restrict_revision
@@ -102,6 +97,7 @@ case "$(git config --bool commit.gpgsign)" in
97
true) gpg_sign_opt=-S ;;
98
*) gpg_sign_opt= ;;
99
esac
100
+. git-rebase--common
101
102
read_basic_state () {
103
test -f "$state_dir/head-name" &&
@@ -132,67 +128,6 @@ read_basic_state () {
128
}
129
}
130
135
-write_basic_state () {
136
- echo "$head_name" > "$state_dir"/head-name &&
137
- echo "$onto" > "$state_dir"/onto &&
138
- echo "$orig_head" > "$state_dir"/orig-head &&
139
- echo "$GIT_QUIET" > "$state_dir"/quiet &&
140
- test t = "$verbose" && : > "$state_dir"/verbose
141
- test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
142
- test -n "$strategy_opts" && echo "$strategy_opts" > \
143
- "$state_dir"/strategy_opts
144
- test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \
145
- "$state_dir"/allow_rerere_autoupdate
146
- test -n "$gpg_sign_opt" && echo "$gpg_sign_opt" > "$state_dir"/gpg_sign_opt
147
- test -n "$signoff" && echo "$signoff" >"$state_dir"/signoff
148
-}
149
-
150
-output () {
151
- case "$verbose" in
152
- '')
153
- output=$("$@" 2>&1 )
154
- status=$?
155
- test $status != 0 && printf "%s\n" "$output"
156
- return $status
157
- ;;
158
- *)
159
- "$@"
160
- ;;
161
- esac
162
-}
163
-
164
-move_to_original_branch () {
165
- case "$head_name" in
166
- refs/*)
167
- message="rebase finished: $head_name onto $onto"
168
- git update-ref -m "$message" \
169
- $head_name $(git rev-parse HEAD) $orig_head &&
170
- git symbolic-ref \
171
- -m "rebase finished: returning to $head_name" \
172
- HEAD $head_name ||
173
- die "$(eval_gettext "Could not move back to \$head_name")"
174
- ;;
175
- esac
176
-}
177
-
178
-apply_autostash () {
179
- if test -f "$state_dir/autostash"
180
- then
181
- stash_sha1=$(cat "$state_dir/autostash")
182
- if git stash apply $stash_sha1 >/dev/null 2>&1
183
- then
184
- echo "$(gettext 'Applied autostash.')" >&2
185
- else
186
- git stash store -m "autostash" -q $stash_sha1 ||
187
- die "$(eval_gettext "Cannot store \$stash_sha1")"
188
- gettext 'Applying autostash resulted in conflicts.
189
-Your changes are safe in the stash.
190
-You can run "git stash pop" or "git stash drop" at any time.
191
-' >&2
192
- fi
193
- fi
194
-}
195
-
131
finish_rebase () {
132
rm -f "$(git rev-parse --git-path REBASE_HEAD)"
133
apply_autostash &&
git-rebase--common.sh
new
+68
@@ -0,0 +1,68 @@
1
+
2
+resolvemsg="
3
+$(gettext 'Resolve all conflicts manually, mark them as resolved with
4
+"git add/rm <conflicted_files>", then run "git rebase --continue".
5
+You can instead skip this commit: run "git rebase --skip".
6
+To abort and get back to the state before "git rebase", run "git rebase --abort".')
7
+"
8
+
9
+write_basic_state () {
10
+ echo "$head_name" > "$state_dir"/head-name &&
11
+ echo "$onto" > "$state_dir"/onto &&
12
+ echo "$orig_head" > "$state_dir"/orig-head &&
13
+ echo "$GIT_QUIET" > "$state_dir"/quiet &&
14
+ test t = "$verbose" && : > "$state_dir"/verbose
15
+ test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
16
+ test -n "$strategy_opts" && echo "$strategy_opts" > \
17
+ "$state_dir"/strategy_opts
18
+ test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \
19
+ "$state_dir"/allow_rerere_autoupdate
20
+ test -n "$gpg_sign_opt" && echo "$gpg_sign_opt" > "$state_dir"/gpg_sign_opt
21
+ test -n "$signoff" && echo "$signoff" >"$state_dir"/signoff
22
+}
23
+
24
+apply_autostash () {
25
+ if test -f "$state_dir/autostash"
26
+ then
27
+ stash_sha1=$(cat "$state_dir/autostash")
28
+ if git stash apply $stash_sha1 >/dev/null 2>&1
29
+ then
30
+ echo "$(gettext 'Applied autostash.')" >&2
31
+ else
32
+ git stash store -m "autostash" -q $stash_sha1 ||
33
+ die "$(eval_gettext "Cannot store \$stash_sha1")"
34
+ gettext 'Applying autostash resulted in conflicts.
35
+Your changes are safe in the stash.
36
+You can run "git stash pop" or "git stash drop" at any time.
37
+' >&2
38
+ fi
39
+ fi
40
+}
41
+
42
+move_to_original_branch () {
43
+ case "$head_name" in
44
+ refs/*)
45
+ message="rebase finished: $head_name onto $onto"
46
+ git update-ref -m "$message" \
47
+ $head_name $(git rev-parse HEAD) $orig_head &&
48
+ git symbolic-ref \
49
+ -m "rebase finished: returning to $head_name" \
50
+ HEAD $head_name ||
51
+ die "$(eval_gettext "Could not move back to \$head_name")"
52
+ ;;
53
+ esac
54
+}
55
+
56
+output () {
57
+ case "$verbose" in
58
+ '')
59
+ output=$("$@" 2>&1 )
60
+ status=$?
61
+ test $status != 0 && printf "%s\n" "$output"
62
+ return $status
63
+ ;;
64
+ *)
65
+ "$@"
66
+ ;;
67
+ esac
68
+}