Skip to content

Commit c7b64aa

Browse files
prertikgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 55071ea commit c7b64aa

File tree

4 files changed

+72
-67
lines changed

4 files changed

+72
-67
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
/git-read-tree
118118
/git-rebase
119119
/git-rebase--am
120+
/git-rebase--common
120121
/git-rebase--helper
121122
/git-rebase--interactive
122123
/git-rebase--merge

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ SCRIPT_SH += git-web--browse.sh
619619
SCRIPT_LIB += git-mergetool--lib
620620
SCRIPT_LIB += git-parse-remote
621621
SCRIPT_LIB += git-rebase--am
622+
SCRIPT_LIB += git-rebase--common
622623
SCRIPT_LIB += git-rebase--interactive
623624
SCRIPT_LIB += git-rebase--preserve-merges
624625
SCRIPT_LIB += git-rebase--merge

git-legacy-rebase.sh

+2-67
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,7 @@ cd_to_toplevel
5757
LF='
5858
'
5959
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+
6661
squash_onto=
6762
unset onto
6863
unset restrict_revision
@@ -102,6 +97,7 @@ case "$(git config --bool commit.gpgsign)" in
10297
true) gpg_sign_opt=-S ;;
10398
*) gpg_sign_opt= ;;
10499
esac
100+
. git-rebase--common
105101

106102
read_basic_state () {
107103
test -f "$state_dir/head-name" &&
@@ -132,67 +128,6 @@ read_basic_state () {
132128
}
133129
}
134130

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-
196131
finish_rebase () {
197132
rm -f "$(git rev-parse --git-path REBASE_HEAD)"
198133
apply_autostash &&

git-rebase--common.sh

+68
Original file line numberDiff line numberDiff line change
@@ -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+
}

0 commit comments

Comments
 (0)