@matheusbsbs / matheus-bagliano / commits / 84df4560ed
Fork 0

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 <trast@student.ethz.ch> Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin von Zweigbergk committed Feb 6, 2011 at 13:43 UTC 84df4560ed92a771d38081ecca2d40ca35811907
4 files changed +16 -16
git-rebase--am.sh
+1 -5
@@ -26,9 +26,5 @@ git format-patch -k --stdout --full-index --ignore-if-in-upstream \
26 git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" &&
27 move_to_original_branch
28 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
30 exit $ret
git-rebase--interactive.sh
+1 -4
@@ -707,16 +707,13 @@ orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
707 mkdir "$state_dir" || die "Could not create temporary $state_dir"
708
709 : > "$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
711 case "$rebase_root" in
712 '')
713 rm -f "$state_dir"/rebase-root ;;
714 *)
715 : >"$state_dir"/rebase-root ;;
716 esac
719 -echo $onto > "$state_dir"/onto
717 test -z "$strategy" || echo "$strategy" > "$state_dir"/strategy
718 test t = "$verbose" && : > "$state_dir"/verbose
719 if test t = "$preserve_merges"
git-rebase--merge.sh
+1 -4
@@ -127,10 +127,7 @@ esac
127
128 mkdir -p "$state_dir"
129 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
131
132 msgnum=0
133 for cmt in `git rev-list --reverse --no-merges "$revisions"`
git-rebase.sh
+13 -3
@@ -70,15 +70,25 @@ test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
70 read_basic_state () {
71 head_name=$(cat "$state_dir"/head-name) &&
72 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
77 then
75 - orig_head=$(cat "$state_dir"/head)
76 - else
78 orig_head=$(cat "$state_dir"/orig-head)
79 + else
80 + orig_head=$(cat "$state_dir"/head)
81 fi &&
82 GIT_QUIET=$(cat "$state_dir"/quiet)
83 }
84
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 +
92 output () {
93 case "$verbose" in
94 '')