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>
This commit is contained in:
parent
55071ea248
commit
c7b64aa0f3
1
.gitignore
vendored
1
.gitignore
vendored
@ -117,6 +117,7 @@
|
||||
/git-read-tree
|
||||
/git-rebase
|
||||
/git-rebase--am
|
||||
/git-rebase--common
|
||||
/git-rebase--helper
|
||||
/git-rebase--interactive
|
||||
/git-rebase--merge
|
||||
|
1
Makefile
1
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
|
||||
|
@ -57,12 +57,7 @@ cd_to_toplevel
|
||||
LF='
|
||||
'
|
||||
ok_to_skip_pre_rebase=
|
||||
resolvemsg="
|
||||
$(gettext 'Resolve all conflicts manually, mark them as resolved with
|
||||
"git add/rm <conflicted_files>", then run "git rebase --continue".
|
||||
You can instead skip this commit: run "git rebase --skip".
|
||||
To abort and get back to the state before "git rebase", run "git rebase --abort".')
|
||||
"
|
||||
|
||||
squash_onto=
|
||||
unset onto
|
||||
unset restrict_revision
|
||||
@ -102,6 +97,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 +128,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 &&
|
||||
|
68
git-rebase--common.sh
Normal file
68
git-rebase--common.sh
Normal file
@ -0,0 +1,68 @@
|
||||
|
||||
resolvemsg="
|
||||
$(gettext 'Resolve all conflicts manually, mark them as resolved with
|
||||
"git add/rm <conflicted_files>", then run "git rebase --continue".
|
||||
You can instead skip this commit: run "git rebase --skip".
|
||||
To abort and get back to the state before "git rebase", run "git rebase --abort".')
|
||||
"
|
||||
|
||||
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
|
||||
}
|
Loading…
Reference in New Issue
Block a user