rebase -i: align variable names
Rename variables HEAD and OLDHEAD to orig_head and HEADNAME to head_name, which are the names used in git-rebase.sh. This prepares for factoring out of the code that persists these variables during the entire rebase process. Using the same variable names to mean the same thing in both files also makes the code easier to read. While at it, also remove the DOTEST variable and use the state_dir variable that was inherited from git-rebase.sh instead. 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
431b7e7818fe3d118e4bf9e40ba6807ed2c511be
1 file changed
+59
-61
git-rebase--interactive.sh
+59
-61
@@ -12,22 +12,20 @@
12
13
. git-sh-setup
14
15
-dotest="$GIT_DIR/rebase-merge"
16
-
15
# The file containing rebase commands, comments, and empty lines.
16
# This file is created by "git rebase -i" then edited by the user. As
17
# the lines are processed, they are removed from the front of this
18
# file and written to the tail of $done.
21
-todo="$dotest"/git-rebase-todo
19
+todo="$state_dir"/git-rebase-todo
20
21
# The rebase command lines that have already been processed. A line
22
# is moved here when it is first handled, before any associated user
23
# actions.
26
-done="$dotest"/done
24
+done="$state_dir"/done
25
26
# The commit message that is planned to be used for any changes that
27
# need to be committed following a user interaction.
30
-msg="$dotest"/message
28
+msg="$state_dir"/message
29
30
# The file into which is accumulated the suggested commit message for
31
# squash/fixup commands. When the first of a series of squash/fixups
@@ -42,14 +40,14 @@ msg="$dotest"/message
40
# written to the file so far (including the initial "pick" commit).
41
# Each time that a commit message is processed, this line is read and
42
# updated. It is deleted just before the combined commit is made.
45
-squash_msg="$dotest"/message-squash
43
+squash_msg="$state_dir"/message-squash
44
45
# If the current series of squash/fixups has not yet included a squash
46
# command, then this file exists and holds the commit message of the
47
# original "pick" commit. (If the series ends without a "squash"
48
# command, then this can be used as the commit message of the combined
49
# commit without opening the editor.)
52
-fixup_msg="$dotest"/message-fixup
50
+fixup_msg="$state_dir"/message-fixup
51
52
# $rewritten is the name of a directory containing files for each
53
# commit that is reachable by at least one merge base of $head and
@@ -57,14 +55,14 @@ fixup_msg="$dotest"/message-fixup
55
# might be. This ensures that commits on merged, but otherwise
56
# unrelated side branches are left alone. (Think "X" in the man page's
57
# example.)
60
-rewritten="$dotest"/rewritten
58
+rewritten="$state_dir"/rewritten
59
62
-dropped="$dotest"/dropped
60
+dropped="$state_dir"/dropped
61
62
# A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
63
# GIT_AUTHOR_DATE that will be used for the commit that is currently
64
# being rebased.
67
-author_script="$dotest"/author-script
65
+author_script="$state_dir"/author-script
66
67
# When an "edit" rebase command is being processed, the SHA1 of the
68
# commit to be edited is recorded in this file. When "git rebase
@@ -72,14 +70,14 @@ author_script="$dotest"/author-script
70
# will be amended to the HEAD commit, but only provided the HEAD
71
# commit is still the commit to be edited. When any other rebase
72
# command is processed, this file is deleted.
75
-amend="$dotest"/amend
73
+amend="$state_dir"/amend
74
75
# For the post-rewrite hook, we make a list of rewritten commits and
76
# their new sha1s. The rewritten-pending list keeps the sha1s of
77
# commits that have been processed, but not committed yet,
78
# e.g. because they are waiting for a 'squash' command.
81
-rewritten_list="$dotest"/rewritten-list
82
-rewritten_pending="$dotest"/rewritten-pending
79
+rewritten_list="$state_dir"/rewritten-list
80
+rewritten_pending="$state_dir"/rewritten-pending
81
82
GIT_CHERRY_PICK_HELP="$resolvemsg"
83
export GIT_CHERRY_PICK_HELP
@@ -145,7 +143,7 @@ make_patch () {
143
*)
144
echo "Root commit"
145
;;
148
- esac > "$dotest"/patch
146
+ esac > "$state_dir"/patch
147
test -f "$msg" ||
148
commit_message "$1" > "$msg"
149
test -f "$author_script" ||
@@ -153,14 +151,14 @@ make_patch () {
151
}
152
153
die_with_patch () {
156
- echo "$1" > "$dotest"/stopped-sha
154
+ echo "$1" > "$state_dir"/stopped-sha
155
make_patch "$1"
156
git rerere
157
die "$2"
158
}
159
160
die_abort () {
163
- rm -rf "$dotest"
161
+ rm -rf "$state_dir"
162
die "$1"
163
}
164
@@ -205,20 +203,20 @@ pick_one_preserving_merges () {
203
esac
204
sha1=$(git rev-parse $sha1)
205
208
- if test -f "$dotest"/current-commit
206
+ if test -f "$state_dir"/current-commit
207
then
208
if test "$fast_forward" = t
209
then
210
while read current_commit
211
do
212
git rev-parse HEAD > "$rewritten"/$current_commit
215
- done <"$dotest"/current-commit
216
- rm "$dotest"/current-commit ||
213
+ done <"$state_dir"/current-commit
214
+ rm "$state_dir"/current-commit ||
215
die "Cannot write current commit's replacement sha1"
216
fi
217
fi
218
221
- echo $sha1 >> "$dotest"/current-commit
219
+ echo $sha1 >> "$state_dir"/current-commit
220
221
# rewrite parents; if none were rewritten, we can fast-forward.
222
new_parents=
@@ -425,7 +423,7 @@ do_next () {
423
mark_action_done
424
pick_one $sha1 ||
425
die_with_patch $sha1 "Could not apply $sha1... $rest"
428
- echo "$sha1" > "$dotest"/stopped-sha
426
+ echo "$sha1" > "$state_dir"/stopped-sha
427
make_patch $sha1
428
git rev-parse --verify HEAD > "$amend"
429
warn "Stopped at $sha1... $rest"
@@ -490,7 +488,7 @@ do_next () {
488
printf 'Executing: %s\n' "$rest"
489
# "exec" command doesn't take a sha1 in the todo-list.
490
# => can't just use $sha1 here.
493
- git rev-parse --verify HEAD > "$dotest"/stopped-sha
491
+ git rev-parse --verify HEAD > "$state_dir"/stopped-sha
492
${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
493
status=$?
494
if test "$status" -ne 0
@@ -525,19 +523,19 @@ do_next () {
523
test -s "$todo" && return
524
525
comment_for_reflog finish &&
528
- headname=$(cat "$dotest"/head-name) &&
529
- oldhead=$(cat "$dotest"/head) &&
530
- shortonto=$(git rev-parse --short $(cat "$dotest"/onto)) &&
526
+ head_name=$(cat "$state_dir"/head-name) &&
527
+ orig_head=$(cat "$state_dir"/head) &&
528
+ shortonto=$(git rev-parse --short $(cat "$state_dir"/onto)) &&
529
newhead=$(git rev-parse HEAD) &&
532
- case $headname in
530
+ case $head_name in
531
refs/*)
534
- message="$GIT_REFLOG_ACTION: $headname onto $shortonto" &&
535
- git update-ref -m "$message" $headname $newhead $oldhead &&
536
- git symbolic-ref HEAD $headname
532
+ message="$GIT_REFLOG_ACTION: $head_name onto $shortonto" &&
533
+ git update-ref -m "$message" $head_name $newhead $orig_head &&
534
+ git symbolic-ref HEAD $head_name
535
;;
536
esac && {
539
- test ! -f "$dotest"/verbose ||
540
- git diff-tree --stat $(cat "$dotest"/head)..HEAD
537
+ test ! -f "$state_dir"/verbose ||
538
+ git diff-tree --stat $(cat "$state_dir"/head)..HEAD
539
} &&
540
{
541
test -s "$rewritten_list" &&
@@ -549,9 +547,9 @@ do_next () {
547
"$GIT_DIR"/hooks/post-rewrite rebase < "$rewritten_list"
548
true # we don't care if this hook failed
549
fi &&
552
- rm -rf "$dotest" &&
550
+ rm -rf "$state_dir" &&
551
git gc --auto &&
554
- warn "Successfully rebased and updated $headname."
552
+ warn "Successfully rebased and updated $head_name."
553
554
exit
555
}
@@ -602,9 +600,9 @@ skip_unnecessary_picks () {
600
601
get_saved_options () {
602
test -d "$rewritten" && preserve_merges=t
605
- test -f "$dotest"/strategy && strategy="$(cat "$dotest"/strategy)"
606
- test -f "$dotest"/verbose && verbose=t
607
- test -f "$dotest"/rebase-root && rebase_root=t
603
+ test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
604
+ test -f "$state_dir"/verbose && verbose=t
605
+ test -f "$state_dir"/rebase-root && rebase_root=t
606
}
607
608
# Rearrange the todo list that has both "pick sha1 msg" and
@@ -704,7 +702,7 @@ first and then run 'git rebase --continue' again."
702
}
703
fi
704
707
- record_in_rewritten "$(cat "$dotest"/stopped-sha)"
705
+ record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
706
707
require_clean_work_tree "rebase"
708
do_rest
@@ -715,15 +713,15 @@ abort)
713
714
git rerere clear
715
718
- headname=$(cat "$dotest"/head-name)
719
- head=$(cat "$dotest"/head)
720
- case $headname in
716
+ head_name=$(cat "$state_dir"/head-name)
717
+ orig_head=$(cat "$state_dir"/head)
718
+ case $head_name in
719
refs/*)
722
- git symbolic-ref HEAD $headname
720
+ git symbolic-ref HEAD $head_name
721
;;
722
esac &&
725
- output git reset --hard $head &&
726
- rm -rf "$dotest"
723
+ output git reset --hard $orig_head &&
724
+ rm -rf "$state_dir"
725
exit
726
;;
727
skip)
@@ -747,28 +745,28 @@ then
745
die "Could not checkout $switch_to"
746
fi
747
750
-head=$(git rev-parse --verify HEAD) || die "No HEAD?"
751
-mkdir "$dotest" || die "Could not create temporary $dotest"
748
+orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
749
+mkdir "$state_dir" || die "Could not create temporary $state_dir"
750
753
-: > "$dotest"/interactive || die "Could not mark as interactive"
754
-echo "$head_name" > "$dotest"/head-name
751
+: > "$state_dir"/interactive || die "Could not mark as interactive"
752
+echo "$head_name" > "$state_dir"/head-name
753
756
-echo $head > "$dotest"/head
754
+echo $orig_head > "$state_dir"/head
755
case "$rebase_root" in
756
'')
759
- rm -f "$dotest"/rebase-root ;;
757
+ rm -f "$state_dir"/rebase-root ;;
758
*)
761
- : >"$dotest"/rebase-root ;;
759
+ : >"$state_dir"/rebase-root ;;
760
esac
763
-echo $onto > "$dotest"/onto
764
-test -z "$strategy" || echo "$strategy" > "$dotest"/strategy
765
-test t = "$verbose" && : > "$dotest"/verbose
761
+echo $onto > "$state_dir"/onto
762
+test -z "$strategy" || echo "$strategy" > "$state_dir"/strategy
763
+test t = "$verbose" && : > "$state_dir"/verbose
764
if test t = "$preserve_merges"
765
then
766
if test -z "$rebase_root"
767
then
768
mkdir "$rewritten" &&
771
- for c in $(git merge-base --all $head $upstream)
769
+ for c in $(git merge-base --all $orig_head $upstream)
770
do
771
echo $onto > "$rewritten"/$c ||
772
die "Could not init rewritten commits"
@@ -782,21 +780,21 @@ then
780
# parents to rewrite and skipping dropped commits would
781
# prematurely end our probe
782
merges_option=
785
- first_after_upstream="$(git rev-list --reverse --first-parent $upstream..$head | head -n 1)"
783
+ first_after_upstream="$(git rev-list --reverse --first-parent $upstream..$orig_head | head -n 1)"
784
else
785
merges_option="--no-merges --cherry-pick"
786
fi
787
790
-shorthead=$(git rev-parse --short $head)
788
+shorthead=$(git rev-parse --short $orig_head)
789
shortonto=$(git rev-parse --short $onto)
790
if test -z "$rebase_root"
791
# this is now equivalent to ! -z "$upstream"
792
then
793
shortupstream=$(git rev-parse --short $upstream)
796
- revisions=$upstream...$head
794
+ revisions=$upstream...$orig_head
795
shortrevisions=$shortupstream..$shorthead
796
else
799
- revisions=$onto...$head
797
+ revisions=$onto...$orig_head
798
shortrevisions=$shorthead
799
fi
800
git rev-list $merges_option --pretty=oneline --abbrev-commit \
@@ -837,13 +835,13 @@ then
835
mkdir "$dropped"
836
# Save all non-cherry-picked changes
837
git rev-list $revisions --left-right --cherry-pick | \
840
- sed -n "s/^>//p" > "$dotest"/not-cherry-picks
838
+ sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
839
# Now all commits and note which ones are missing in
840
# not-cherry-picks and hence being dropped
841
git rev-list $revisions |
842
while read rev
843
do
846
- if test -f "$rewritten"/$rev -a "$(sane_grep "$rev" "$dotest"/not-cherry-picks)" = ""
844
+ if test -f "$rewritten"/$rev -a "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = ""
845
then
846
# Use -f2 because if rev-list is telling us this commit is
847
# not worthwhile, we don't want to track its multiple heads,
@@ -889,5 +887,5 @@ has_action "$todo" ||
887
test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
888
889
output git checkout $onto || die_abort "could not detach HEAD"
892
-git update-ref ORIG_HEAD $head
890
+git update-ref ORIG_HEAD $orig_head
891
do_rest