rebase: clearer names for directory variables

Instead of using the old variable name 'dotest' for
"$GIT_DIR"/rebase-merge and no variable for "$GIT_DIR"/rebase-apply,
introduce two variables 'merge_dir' and 'apply_dir' for these paths.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Martin von Zweigbergk 2011-02-06 13:43:30 -05:00 committed by Junio C Hamano
parent 1a9fe45326
commit 69a636ad1a

View File

@ -46,7 +46,8 @@ unset newbase
strategy=recursive strategy=recursive
strategy_opts= strategy_opts=
do_merge= do_merge=
dotest="$GIT_DIR"/rebase-merge merge_dir="$GIT_DIR"/rebase-merge
apply_dir="$GIT_DIR"/rebase-apply
prec=4 prec=4
verbose= verbose=
diffstat= diffstat=
@ -58,7 +59,7 @@ allow_rerere_autoupdate=
continue_merge () { continue_merge () {
test -n "$prev_head" || die "prev_head must be defined" test -n "$prev_head" || die "prev_head must be defined"
test -d "$dotest" || die "$dotest directory does not exist" test -d "$merge_dir" || die "$merge_dir directory does not exist"
unmerged=$(git ls-files -u) unmerged=$(git ls-files -u)
if test -n "$unmerged" if test -n "$unmerged"
@ -68,7 +69,7 @@ continue_merge () {
die "$RESOLVEMSG" die "$RESOLVEMSG"
fi fi
cmt=`cat "$dotest/current"` cmt=`cat "$merge_dir/current"`
if ! git diff-index --quiet --ignore-submodules HEAD -- if ! git diff-index --quiet --ignore-submodules HEAD --
then then
if ! git commit --no-verify -C "$cmt" if ! git commit --no-verify -C "$cmt"
@ -81,7 +82,7 @@ continue_merge () {
then then
printf "Committed: %0${prec}d " $msgnum printf "Committed: %0${prec}d " $msgnum
fi fi
echo "$cmt $(git rev-parse HEAD^0)" >> "$dotest/rewritten" echo "$cmt $(git rev-parse HEAD^0)" >> "$merge_dir/rewritten"
else else
if test -z "$GIT_QUIET" if test -z "$GIT_QUIET"
then then
@ -93,22 +94,22 @@ continue_merge () {
prev_head=`git rev-parse HEAD^0` prev_head=`git rev-parse HEAD^0`
# save the resulting commit so we can read-tree on it later # save the resulting commit so we can read-tree on it later
echo "$prev_head" > "$dotest/prev_head" echo "$prev_head" > "$merge_dir/prev_head"
# onto the next patch: # onto the next patch:
msgnum=$(($msgnum + 1)) msgnum=$(($msgnum + 1))
echo "$msgnum" >"$dotest/msgnum" echo "$msgnum" >"$merge_dir/msgnum"
} }
call_merge () { call_merge () {
cmt="$(cat "$dotest/cmt.$1")" cmt="$(cat "$merge_dir/cmt.$1")"
echo "$cmt" > "$dotest/current" echo "$cmt" > "$merge_dir/current"
hd=$(git rev-parse --verify HEAD) hd=$(git rev-parse --verify HEAD)
cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD) cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
msgnum=$(cat "$dotest/msgnum") msgnum=$(cat "$merge_dir/msgnum")
end=$(cat "$dotest/end") end=$(cat "$merge_dir/end")
eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"' eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
eval GITHEAD_$hd='$(cat "$dotest/onto_name")' eval GITHEAD_$hd='$(cat "$merge_dir/onto_name")'
export GITHEAD_$cmt GITHEAD_$hd export GITHEAD_$cmt GITHEAD_$hd
if test -n "$GIT_QUIET" if test -n "$GIT_QUIET"
then then
@ -138,9 +139,9 @@ call_merge () {
move_to_original_branch () { move_to_original_branch () {
test -z "$head_name" && test -z "$head_name" &&
head_name="$(cat "$dotest"/head-name)" && head_name="$(cat "$merge_dir"/head-name)" &&
onto="$(cat "$dotest"/onto)" && onto="$(cat "$merge_dir"/onto)" &&
orig_head="$(cat "$dotest"/orig-head)" orig_head="$(cat "$merge_dir"/orig-head)"
case "$head_name" in case "$head_name" in
refs/*) refs/*)
message="rebase finished: $head_name onto $onto" message="rebase finished: $head_name onto $onto"
@ -154,12 +155,12 @@ move_to_original_branch () {
finish_rb_merge () { finish_rb_merge () {
move_to_original_branch move_to_original_branch
git notes copy --for-rewrite=rebase < "$dotest"/rewritten git notes copy --for-rewrite=rebase < "$merge_dir"/rewritten
if test -x "$GIT_DIR"/hooks/post-rewrite && if test -x "$GIT_DIR"/hooks/post-rewrite &&
test -s "$dotest"/rewritten; then test -s "$merge_dir"/rewritten; then
"$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten "$GIT_DIR"/hooks/post-rewrite rebase < "$merge_dir"/rewritten
fi fi
rm -r "$dotest" rm -r "$merge_dir"
say All done. say All done.
} }
@ -183,7 +184,7 @@ is_interactive () {
export GIT_EDITOR export GIT_EDITOR
fi fi
test -n "$interactive_rebase" || test -f "$dotest"/interactive test -n "$interactive_rebase" || test -f "$merge_dir"/interactive
} }
run_pre_rebase_hook () { run_pre_rebase_hook () {
@ -195,7 +196,7 @@ run_pre_rebase_hook () {
fi fi
} }
test -f "$GIT_DIR"/rebase-apply/applying && test -f "$apply_dir"/applying &&
die 'It looks like git-am is in progress. Cannot rebase.' die 'It looks like git-am is in progress. Cannot rebase.'
is_interactive "$@" && exec git-rebase--interactive "$@" is_interactive "$@" && exec git-rebase--interactive "$@"
@ -210,7 +211,7 @@ do
OK_TO_SKIP_PRE_REBASE= OK_TO_SKIP_PRE_REBASE=
;; ;;
--continue) --continue)
test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || test -d "$merge_dir" -o -d "$apply_dir" ||
die "No rebase in progress?" die "No rebase in progress?"
git update-index --ignore-submodules --refresh && git update-index --ignore-submodules --refresh &&
@ -219,13 +220,13 @@ do
echo "mark them as resolved using git add" echo "mark them as resolved using git add"
exit 1 exit 1
} }
if test -d "$dotest" if test -d "$merge_dir"
then then
prev_head=$(cat "$dotest/prev_head") prev_head=$(cat "$merge_dir/prev_head")
end=$(cat "$dotest/end") end=$(cat "$merge_dir/end")
msgnum=$(cat "$dotest/msgnum") msgnum=$(cat "$merge_dir/msgnum")
onto=$(cat "$dotest/onto") onto=$(cat "$merge_dir/onto")
GIT_QUIET=$(cat "$dotest/quiet") GIT_QUIET=$(cat "$merge_dir/quiet")
continue_merge continue_merge
while test "$msgnum" -le "$end" while test "$msgnum" -le "$end"
do do
@ -235,28 +236,28 @@ do
finish_rb_merge finish_rb_merge
exit exit
fi fi
head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) && head_name=$(cat "$apply_dir"/head-name) &&
onto=$(cat "$GIT_DIR"/rebase-apply/onto) && onto=$(cat "$apply_dir"/onto) &&
orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) && orig_head=$(cat "$apply_dir"/orig-head) &&
GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet) GIT_QUIET=$(cat "$apply_dir"/quiet)
git am --resolved --3way --resolvemsg="$RESOLVEMSG" && git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
move_to_original_branch move_to_original_branch
exit exit
;; ;;
--skip) --skip)
test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || test -d "$merge_dir" -o -d "$apply_dir" ||
die "No rebase in progress?" die "No rebase in progress?"
git reset --hard HEAD || exit $? git reset --hard HEAD || exit $?
if test -d "$dotest" if test -d "$merge_dir"
then then
git rerere clear git rerere clear
prev_head=$(cat "$dotest/prev_head") prev_head=$(cat "$merge_dir/prev_head")
end=$(cat "$dotest/end") end=$(cat "$merge_dir/end")
msgnum=$(cat "$dotest/msgnum") msgnum=$(cat "$merge_dir/msgnum")
msgnum=$(($msgnum + 1)) msgnum=$(($msgnum + 1))
onto=$(cat "$dotest/onto") onto=$(cat "$merge_dir/onto")
GIT_QUIET=$(cat "$dotest/quiet") GIT_QUIET=$(cat "$merge_dir/quiet")
while test "$msgnum" -le "$end" while test "$msgnum" -le "$end"
do do
call_merge "$msgnum" call_merge "$msgnum"
@ -265,31 +266,31 @@ do
finish_rb_merge finish_rb_merge
exit exit
fi fi
head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) && head_name=$(cat "$apply_dir"/head-name) &&
onto=$(cat "$GIT_DIR"/rebase-apply/onto) && onto=$(cat "$apply_dir"/onto) &&
orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) && orig_head=$(cat "$apply_dir"/orig-head) &&
GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet) GIT_QUIET=$(cat "$apply_dir"/quiet)
git am -3 --skip --resolvemsg="$RESOLVEMSG" && git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
move_to_original_branch move_to_original_branch
exit exit
;; ;;
--abort) --abort)
test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || test -d "$merge_dir" -o -d "$apply_dir" ||
die "No rebase in progress?" die "No rebase in progress?"
git rerere clear git rerere clear
test -d "$dotest" || dotest="$GIT_DIR"/rebase-apply test -d "$merge_dir" || merge_dir="$apply_dir"
head_name="$(cat "$dotest"/head-name)" && head_name="$(cat "$merge_dir"/head-name)" &&
case "$head_name" in case "$head_name" in
refs/*) refs/*)
git symbolic-ref HEAD $head_name || git symbolic-ref HEAD $head_name ||
die "Could not move back to $head_name" die "Could not move back to $head_name"
;; ;;
esac esac
git reset --hard $(cat "$dotest/orig-head") git reset --hard $(cat "$merge_dir/orig-head")
rm -r "$dotest" rm -r "$merge_dir"
exit exit
;; ;;
--onto) --onto)
@ -388,31 +389,31 @@ test $# -gt 2 && usage
if test $# -eq 0 && test -z "$rebase_root" if test $# -eq 0 && test -z "$rebase_root"
then then
test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || usage test -d "$merge_dir" -o -d "$apply_dir" || usage
test -d "$dotest" -o -f "$GIT_DIR"/rebase-apply/rebasing && test -d "$merge_dir" -o -f "$apply_dir"/rebasing &&
die 'A rebase is in progress, try --continue, --skip or --abort.' die 'A rebase is in progress, try --continue, --skip or --abort.'
fi fi
# Make sure we do not have $GIT_DIR/rebase-apply # Make sure we do not have $apply_dir or $merge_dir
if test -z "$do_merge" if test -z "$do_merge"
then then
if mkdir "$GIT_DIR"/rebase-apply 2>/dev/null if mkdir "$apply_dir" 2>/dev/null
then then
rmdir "$GIT_DIR"/rebase-apply rmdir "$apply_dir"
else else
echo >&2 ' echo >&2 '
It seems that I cannot create a rebase-apply directory, and It seems that I cannot create a rebase-apply directory, and
I wonder if you are in the middle of patch application or another I wonder if you are in the middle of patch application or another
rebase. If that is not the case, please rebase. If that is not the case, please
rm -fr '"$GIT_DIR"'/rebase-apply rm -fr '"$apply_dir"'
and run me again. I am stopping in case you still have something and run me again. I am stopping in case you still have something
valuable there.' valuable there.'
exit 1 exit 1
fi fi
else else
if test -d "$dotest" if test -d "$merge_dir"
then then
die "previous rebase directory $dotest still exists." \ die "previous rebase directory $merge_dir still exists." \
'Try git rebase (--continue | --abort | --skip)' 'Try git rebase (--continue | --abort | --skip)'
fi fi
fi fi
@ -561,35 +562,35 @@ then
git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" && git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
move_to_original_branch move_to_original_branch
ret=$? ret=$?
test 0 != $ret -a -d "$GIT_DIR"/rebase-apply && test 0 != $ret -a -d "$apply_dir" &&
echo $head_name > "$GIT_DIR"/rebase-apply/head-name && echo $head_name > "$apply_dir/head-name" &&
echo $onto > "$GIT_DIR"/rebase-apply/onto && echo $onto > "$apply_dir/onto" &&
echo $orig_head > "$GIT_DIR"/rebase-apply/orig-head && echo $orig_head > "$apply_dir/orig-head" &&
echo "$GIT_QUIET" > "$GIT_DIR"/rebase-apply/quiet echo "$GIT_QUIET" > "$apply_dir/quiet"
exit $ret exit $ret
fi fi
# start doing a rebase with git-merge # start doing a rebase with git-merge
# this is rename-aware if the recursive (default) strategy is used # this is rename-aware if the recursive (default) strategy is used
mkdir -p "$dotest" mkdir -p "$merge_dir"
echo "$onto" > "$dotest/onto" echo "$onto" > "$merge_dir/onto"
echo "$onto_name" > "$dotest/onto_name" echo "$onto_name" > "$merge_dir/onto_name"
prev_head=$orig_head prev_head=$orig_head
echo "$prev_head" > "$dotest/prev_head" echo "$prev_head" > "$merge_dir/prev_head"
echo "$orig_head" > "$dotest/orig-head" echo "$orig_head" > "$merge_dir/orig-head"
echo "$head_name" > "$dotest/head-name" echo "$head_name" > "$merge_dir/head-name"
echo "$GIT_QUIET" > "$dotest/quiet" echo "$GIT_QUIET" > "$merge_dir/quiet"
msgnum=0 msgnum=0
for cmt in `git rev-list --reverse --no-merges "$revisions"` for cmt in `git rev-list --reverse --no-merges "$revisions"`
do do
msgnum=$(($msgnum + 1)) msgnum=$(($msgnum + 1))
echo "$cmt" > "$dotest/cmt.$msgnum" echo "$cmt" > "$merge_dir/cmt.$msgnum"
done done
echo 1 >"$dotest/msgnum" echo 1 >"$merge_dir/msgnum"
echo $msgnum >"$dotest/end" echo $msgnum >"$merge_dir/end"
end=$msgnum end=$msgnum
msgnum=1 msgnum=1