Skip to content

Commit 431b7e7

Browse files
Martin von Zweigbergkgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 89c7ae9 commit 431b7e7

File tree

1 file changed

+59
-61
lines changed

1 file changed

+59
-61
lines changed

git-rebase--interactive.sh

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@
1212

1313
. git-sh-setup
1414

15-
dotest="$GIT_DIR/rebase-merge"
16-
1715
# The file containing rebase commands, comments, and empty lines.
1816
# This file is created by "git rebase -i" then edited by the user. As
1917
# the lines are processed, they are removed from the front of this
2018
# file and written to the tail of $done.
21-
todo="$dotest"/git-rebase-todo
19+
todo="$state_dir"/git-rebase-todo
2220

2321
# The rebase command lines that have already been processed. A line
2422
# is moved here when it is first handled, before any associated user
2523
# actions.
26-
done="$dotest"/done
24+
done="$state_dir"/done
2725

2826
# The commit message that is planned to be used for any changes that
2927
# need to be committed following a user interaction.
30-
msg="$dotest"/message
28+
msg="$state_dir"/message
3129

3230
# The file into which is accumulated the suggested commit message for
3331
# squash/fixup commands. When the first of a series of squash/fixups
@@ -42,44 +40,44 @@ msg="$dotest"/message
4240
# written to the file so far (including the initial "pick" commit).
4341
# Each time that a commit message is processed, this line is read and
4442
# updated. It is deleted just before the combined commit is made.
45-
squash_msg="$dotest"/message-squash
43+
squash_msg="$state_dir"/message-squash
4644

4745
# If the current series of squash/fixups has not yet included a squash
4846
# command, then this file exists and holds the commit message of the
4947
# original "pick" commit. (If the series ends without a "squash"
5048
# command, then this can be used as the commit message of the combined
5149
# commit without opening the editor.)
52-
fixup_msg="$dotest"/message-fixup
50+
fixup_msg="$state_dir"/message-fixup
5351

5452
# $rewritten is the name of a directory containing files for each
5553
# commit that is reachable by at least one merge base of $head and
5654
# $upstream. They are not necessarily rewritten, but their children
5755
# might be. This ensures that commits on merged, but otherwise
5856
# unrelated side branches are left alone. (Think "X" in the man page's
5957
# example.)
60-
rewritten="$dotest"/rewritten
58+
rewritten="$state_dir"/rewritten
6159

62-
dropped="$dotest"/dropped
60+
dropped="$state_dir"/dropped
6361

6462
# A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
6563
# GIT_AUTHOR_DATE that will be used for the commit that is currently
6664
# being rebased.
67-
author_script="$dotest"/author-script
65+
author_script="$state_dir"/author-script
6866

6967
# When an "edit" rebase command is being processed, the SHA1 of the
7068
# commit to be edited is recorded in this file. When "git rebase
7169
# --continue" is executed, if there are any staged changes then they
7270
# will be amended to the HEAD commit, but only provided the HEAD
7371
# commit is still the commit to be edited. When any other rebase
7472
# command is processed, this file is deleted.
75-
amend="$dotest"/amend
73+
amend="$state_dir"/amend
7674

7775
# For the post-rewrite hook, we make a list of rewritten commits and
7876
# their new sha1s. The rewritten-pending list keeps the sha1s of
7977
# commits that have been processed, but not committed yet,
8078
# 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
8381

8482
GIT_CHERRY_PICK_HELP="$resolvemsg"
8583
export GIT_CHERRY_PICK_HELP
@@ -145,22 +143,22 @@ make_patch () {
145143
*)
146144
echo "Root commit"
147145
;;
148-
esac > "$dotest"/patch
146+
esac > "$state_dir"/patch
149147
test -f "$msg" ||
150148
commit_message "$1" > "$msg"
151149
test -f "$author_script" ||
152150
get_author_ident_from_commit "$1" > "$author_script"
153151
}
154152

155153
die_with_patch () {
156-
echo "$1" > "$dotest"/stopped-sha
154+
echo "$1" > "$state_dir"/stopped-sha
157155
make_patch "$1"
158156
git rerere
159157
die "$2"
160158
}
161159

162160
die_abort () {
163-
rm -rf "$dotest"
161+
rm -rf "$state_dir"
164162
die "$1"
165163
}
166164

@@ -205,20 +203,20 @@ pick_one_preserving_merges () {
205203
esac
206204
sha1=$(git rev-parse $sha1)
207205

208-
if test -f "$dotest"/current-commit
206+
if test -f "$state_dir"/current-commit
209207
then
210208
if test "$fast_forward" = t
211209
then
212210
while read current_commit
213211
do
214212
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 ||
217215
die "Cannot write current commit's replacement sha1"
218216
fi
219217
fi
220218

221-
echo $sha1 >> "$dotest"/current-commit
219+
echo $sha1 >> "$state_dir"/current-commit
222220

223221
# rewrite parents; if none were rewritten, we can fast-forward.
224222
new_parents=
@@ -425,7 +423,7 @@ do_next () {
425423
mark_action_done
426424
pick_one $sha1 ||
427425
die_with_patch $sha1 "Could not apply $sha1... $rest"
428-
echo "$sha1" > "$dotest"/stopped-sha
426+
echo "$sha1" > "$state_dir"/stopped-sha
429427
make_patch $sha1
430428
git rev-parse --verify HEAD > "$amend"
431429
warn "Stopped at $sha1... $rest"
@@ -490,7 +488,7 @@ do_next () {
490488
printf 'Executing: %s\n' "$rest"
491489
# "exec" command doesn't take a sha1 in the todo-list.
492490
# => 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
494492
${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
495493
status=$?
496494
if test "$status" -ne 0
@@ -525,19 +523,19 @@ do_next () {
525523
test -s "$todo" && return
526524

527525
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)) &&
531529
newhead=$(git rev-parse HEAD) &&
532-
case $headname in
530+
case $head_name in
533531
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
537535
;;
538536
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
541539
} &&
542540
{
543541
test -s "$rewritten_list" &&
@@ -549,9 +547,9 @@ do_next () {
549547
"$GIT_DIR"/hooks/post-rewrite rebase < "$rewritten_list"
550548
true # we don't care if this hook failed
551549
fi &&
552-
rm -rf "$dotest" &&
550+
rm -rf "$state_dir" &&
553551
git gc --auto &&
554-
warn "Successfully rebased and updated $headname."
552+
warn "Successfully rebased and updated $head_name."
555553

556554
exit
557555
}
@@ -602,9 +600,9 @@ skip_unnecessary_picks () {
602600

603601
get_saved_options () {
604602
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
608606
}
609607

610608
# Rearrange the todo list that has both "pick sha1 msg" and
@@ -704,7 +702,7 @@ first and then run 'git rebase --continue' again."
704702
}
705703
fi
706704

707-
record_in_rewritten "$(cat "$dotest"/stopped-sha)"
705+
record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
708706

709707
require_clean_work_tree "rebase"
710708
do_rest
@@ -715,15 +713,15 @@ abort)
715713

716714
git rerere clear
717715

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
721719
refs/*)
722-
git symbolic-ref HEAD $headname
720+
git symbolic-ref HEAD $head_name
723721
;;
724722
esac &&
725-
output git reset --hard $head &&
726-
rm -rf "$dotest"
723+
output git reset --hard $orig_head &&
724+
rm -rf "$state_dir"
727725
exit
728726
;;
729727
skip)
@@ -747,28 +745,28 @@ then
747745
die "Could not checkout $switch_to"
748746
fi
749747

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"
752750

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
755753

756-
echo $head > "$dotest"/head
754+
echo $orig_head > "$state_dir"/head
757755
case "$rebase_root" in
758756
'')
759-
rm -f "$dotest"/rebase-root ;;
757+
rm -f "$state_dir"/rebase-root ;;
760758
*)
761-
: >"$dotest"/rebase-root ;;
759+
: >"$state_dir"/rebase-root ;;
762760
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
766764
if test t = "$preserve_merges"
767765
then
768766
if test -z "$rebase_root"
769767
then
770768
mkdir "$rewritten" &&
771-
for c in $(git merge-base --all $head $upstream)
769+
for c in $(git merge-base --all $orig_head $upstream)
772770
do
773771
echo $onto > "$rewritten"/$c ||
774772
die "Could not init rewritten commits"
@@ -782,21 +780,21 @@ then
782780
# parents to rewrite and skipping dropped commits would
783781
# prematurely end our probe
784782
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)"
786784
else
787785
merges_option="--no-merges --cherry-pick"
788786
fi
789787

790-
shorthead=$(git rev-parse --short $head)
788+
shorthead=$(git rev-parse --short $orig_head)
791789
shortonto=$(git rev-parse --short $onto)
792790
if test -z "$rebase_root"
793791
# this is now equivalent to ! -z "$upstream"
794792
then
795793
shortupstream=$(git rev-parse --short $upstream)
796-
revisions=$upstream...$head
794+
revisions=$upstream...$orig_head
797795
shortrevisions=$shortupstream..$shorthead
798796
else
799-
revisions=$onto...$head
797+
revisions=$onto...$orig_head
800798
shortrevisions=$shorthead
801799
fi
802800
git rev-list $merges_option --pretty=oneline --abbrev-commit \
@@ -837,13 +835,13 @@ then
837835
mkdir "$dropped"
838836
# Save all non-cherry-picked changes
839837
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
841839
# Now all commits and note which ones are missing in
842840
# not-cherry-picks and hence being dropped
843841
git rev-list $revisions |
844842
while read rev
845843
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)" = ""
847845
then
848846
# Use -f2 because if rev-list is telling us this commit is
849847
# not worthwhile, we don't want to track its multiple heads,
@@ -889,5 +887,5 @@ has_action "$todo" ||
889887
test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
890888

891889
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
893891
do_rest

0 commit comments

Comments
 (0)