Skip to content

Commit

Permalink
rebase: extract code for writing basic state
Browse files Browse the repository at this point in the history
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 <trast@student.ethz.ch>
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Martin von Zweigbergk authored and gitster committed Feb 10, 2011
1 parent 2959c28 commit 84df456
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 1 addition & 5 deletions git-rebase--am.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,5 @@ git format-patch -k --stdout --full-index --ignore-if-in-upstream \
git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" &&
move_to_original_branch
ret=$?
test 0 != $ret -a -d "$state_dir" &&
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 0 != $ret -a -d "$state_dir" && write_basic_state
exit $ret
5 changes: 1 addition & 4 deletions git-rebase--interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -707,16 +707,13 @@ orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
mkdir "$state_dir" || die "Could not create temporary $state_dir"

: > "$state_dir"/interactive || die "Could not mark as interactive"
echo "$head_name" > "$state_dir"/head-name

echo $orig_head > "$state_dir"/head
write_basic_state
case "$rebase_root" in
'')
rm -f "$state_dir"/rebase-root ;;
*)
: >"$state_dir"/rebase-root ;;
esac
echo $onto > "$state_dir"/onto
test -z "$strategy" || echo "$strategy" > "$state_dir"/strategy
test t = "$verbose" && : > "$state_dir"/verbose
if test t = "$preserve_merges"
Expand Down
5 changes: 1 addition & 4 deletions git-rebase--merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ esac

mkdir -p "$state_dir"
echo "$onto_name" > "$state_dir/onto_name"
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"
write_basic_state

msgnum=0
for cmt in `git rev-list --reverse --no-merges "$revisions"`
Expand Down
16 changes: 13 additions & 3 deletions git-rebase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,25 @@ test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
read_basic_state () {
head_name=$(cat "$state_dir"/head-name) &&
onto=$(cat "$state_dir"/onto) &&
if test "$type" = interactive
# We always write to orig-head, but interactive rebase used to write to
# head. Fall back to reading from head to cover for the case that the
# user upgraded git with an ongoing interactive rebase.
if test -f "$state_dir"/orig-head
then
orig_head=$(cat "$state_dir"/head)
else
orig_head=$(cat "$state_dir"/orig-head)
else
orig_head=$(cat "$state_dir"/head)
fi &&
GIT_QUIET=$(cat "$state_dir"/quiet)
}

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
}

output () {
case "$verbose" in
'')
Expand Down

0 comments on commit 84df456

Please sign in to comment.