Skip to content

Commit 84df456

Browse files
Martin von Zweigbergkgitster
authored andcommitted
rebase: extract code for writing basic state
Extract the code for writing the state to rebase-apply/ or rebase-merge/ when a rebase is initiated. This will make it easier to later make both interactive and non-interactive rebase remember the options used. Note that non-interactive rebase stores the sha1 of the original head in a file called orig-head, while interactive rebase stores it in a file called head. Change this by writing to orig-head in both cases. When reading, try to read from orig-head. If that fails, read from head instead. This protects users who upgraded git while they had an ongoing interactive rebase, while still making it possible to remove the code that reads from head at some point in the future. Helped-by: Thomas Rast <[email protected]> Signed-off-by: Martin von Zweigbergk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2959c28 commit 84df456

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

git-rebase--am.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,5 @@ git format-patch -k --stdout --full-index --ignore-if-in-upstream \
2626
git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" &&
2727
move_to_original_branch
2828
ret=$?
29-
test 0 != $ret -a -d "$state_dir" &&
30-
echo $head_name > "$state_dir/head-name" &&
31-
echo $onto > "$state_dir/onto" &&
32-
echo $orig_head > "$state_dir/orig-head" &&
33-
echo "$GIT_QUIET" > "$state_dir/quiet"
29+
test 0 != $ret -a -d "$state_dir" && write_basic_state
3430
exit $ret

git-rebase--interactive.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,16 +707,13 @@ orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
707707
mkdir "$state_dir" || die "Could not create temporary $state_dir"
708708

709709
: > "$state_dir"/interactive || die "Could not mark as interactive"
710-
echo "$head_name" > "$state_dir"/head-name
711-
712-
echo $orig_head > "$state_dir"/head
710+
write_basic_state
713711
case "$rebase_root" in
714712
'')
715713
rm -f "$state_dir"/rebase-root ;;
716714
*)
717715
: >"$state_dir"/rebase-root ;;
718716
esac
719-
echo $onto > "$state_dir"/onto
720717
test -z "$strategy" || echo "$strategy" > "$state_dir"/strategy
721718
test t = "$verbose" && : > "$state_dir"/verbose
722719
if test t = "$preserve_merges"

git-rebase--merge.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,7 @@ esac
127127

128128
mkdir -p "$state_dir"
129129
echo "$onto_name" > "$state_dir/onto_name"
130-
echo "$head_name" > "$state_dir/head-name"
131-
echo "$onto" > "$state_dir/onto"
132-
echo "$orig_head" > "$state_dir/orig-head"
133-
echo "$GIT_QUIET" > "$state_dir/quiet"
130+
write_basic_state
134131

135132
msgnum=0
136133
for cmt in `git rev-list --reverse --no-merges "$revisions"`

git-rebase.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,25 @@ test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
7070
read_basic_state () {
7171
head_name=$(cat "$state_dir"/head-name) &&
7272
onto=$(cat "$state_dir"/onto) &&
73-
if test "$type" = interactive
73+
# We always write to orig-head, but interactive rebase used to write to
74+
# head. Fall back to reading from head to cover for the case that the
75+
# user upgraded git with an ongoing interactive rebase.
76+
if test -f "$state_dir"/orig-head
7477
then
75-
orig_head=$(cat "$state_dir"/head)
76-
else
7778
orig_head=$(cat "$state_dir"/orig-head)
79+
else
80+
orig_head=$(cat "$state_dir"/head)
7881
fi &&
7982
GIT_QUIET=$(cat "$state_dir"/quiet)
8083
}
8184

85+
write_basic_state () {
86+
echo "$head_name" > "$state_dir"/head-name &&
87+
echo "$onto" > "$state_dir"/onto &&
88+
echo "$orig_head" > "$state_dir"/orig-head &&
89+
echo "$GIT_QUIET" > "$state_dir"/quiet
90+
}
91+
8292
output () {
8393
case "$verbose" in
8494
'')

0 commit comments

Comments
 (0)