From: martin.von.zweigbergk@gmail.com
To: git@vger.kernel.org, gitster@pobox.com
Cc: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Subject: [PATCH 2/5] rebase: refactor reading of state
Date: Wed, 3 Nov 2010 22:09:37 +0100 [thread overview]
Message-ID: <1288818580-7576-3-git-send-email-martin.von.zweigbergk@gmail.com> (raw)
In-Reply-To: <1288818580-7576-1-git-send-email-martin.von.zweigbergk@gmail.com>
From: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
The code reading the state saved in $merge_dir or $rebase_dir is
currently spread out in many places, making it harder to read and to
introduce additional state. Extract this code into one method that reads
the state.
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
git-rebase.sh | 59 +++++++++++++++++++++++---------------------------------
1 files changed, 24 insertions(+), 35 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh
index 8d5cf03..e0842e3 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -56,6 +56,22 @@ rebase_root=
force_rebase=
allow_rerere_autoupdate=
+read_state () {
+ if test -d "$merge_dir"
+ then
+ state_dir="$merge_dir"
+ prev_head=$(cat "$merge_dir"/prev_head) &&
+ end=$(cat "$merge_dir"/end) &&
+ msgnum=$(cat "$merge_dir"/msgnum)
+ else
+ state_dir="$apply_dir"
+ fi &&
+ head_name=$(cat "$state_dir"/head-name) &&
+ onto=$(cat "$state_dir"/onto) &&
+ orig_head=$(cat "$state_dir"/orig-head) &&
+ GIT_QUIET=$(cat "$state_dir"/quiet)
+}
+
continue_merge () {
test -n "$prev_head" || die "prev_head must be defined"
test -d "$merge_dir" || die "$merge_dir directory does not exist"
@@ -137,10 +153,7 @@ call_merge () {
}
move_to_original_branch () {
- test -z "$head_name" &&
- head_name="$(cat "$merge_dir"/head-name)" &&
- onto="$(cat "$merge_dir"/onto)" &&
- orig_head="$(cat "$merge_dir"/orig-head)"
+ test -z "$head_name" && read_state
case "$head_name" in
refs/*)
message="rebase finished: $head_name onto $onto"
@@ -216,13 +229,9 @@ do
echo "mark them as resolved using git add"
exit 1
}
+ read_state
if test -d "$merge_dir"
then
- prev_head=$(cat "$merge_dir/prev_head")
- end=$(cat "$merge_dir/end")
- msgnum=$(cat "$merge_dir/msgnum")
- onto=$(cat "$merge_dir/onto")
- GIT_QUIET=$(cat "$merge_dir/quiet")
continue_merge
while test "$msgnum" -le "$end"
do
@@ -232,10 +241,6 @@ do
finish_rb_merge
exit
fi
- head_name=$(cat "$apply_dir"/head-name) &&
- onto=$(cat "$apply_dir"/onto) &&
- orig_head=$(cat "$apply_dir"/orig-head) &&
- GIT_QUIET=$(cat "$apply_dir"/quiet)
git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
move_to_original_branch
exit
@@ -245,15 +250,11 @@ do
die "No rebase in progress?"
git reset --hard HEAD || exit $?
+ read_state
if test -d "$merge_dir"
then
git rerere clear
- prev_head=$(cat "$merge_dir/prev_head")
- end=$(cat "$merge_dir/end")
- msgnum=$(cat "$merge_dir/msgnum")
msgnum=$(($msgnum + 1))
- onto=$(cat "$merge_dir/onto")
- GIT_QUIET=$(cat "$merge_dir/quiet")
while test "$msgnum" -le "$end"
do
call_merge "$msgnum"
@@ -262,10 +263,6 @@ do
finish_rb_merge
exit
fi
- head_name=$(cat "$apply_dir"/head-name) &&
- onto=$(cat "$apply_dir"/onto) &&
- orig_head=$(cat "$apply_dir"/orig-head) &&
- GIT_QUIET=$(cat "$apply_dir"/quiet)
git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
move_to_original_branch
exit
@@ -275,17 +272,9 @@ do
die "No rebase in progress?"
git rerere clear
- if test -d "$merge_dir"
- then
- GIT_QUIET=$(cat "$merge_dir/quiet")
- move_to_original_branch
- else
- merge_dir="$apply_dir"
- GIT_QUIET=$(cat "$merge_dir/quiet")
- move_to_original_branch
- fi
- git reset --hard $(cat "$merge_dir/orig-head")
- rm -r "$merge_dir"
+ move_to_original_branch
+ git reset --hard $orig_head
+ rm -r "$state_dir"
exit
;;
--onto)
@@ -584,12 +573,12 @@ fi
# this is rename-aware if the recursive (default) strategy is used
mkdir -p "$merge_dir"
-echo "$onto" > "$merge_dir/onto"
echo "$onto_name" > "$merge_dir/onto_name"
prev_head=$orig_head
echo "$prev_head" > "$merge_dir/prev_head"
-echo "$orig_head" > "$merge_dir/orig-head"
echo "$head_name" > "$merge_dir/head-name"
+echo "$onto" > "$merge_dir/onto"
+echo "$orig_head" > "$merge_dir/orig-head"
echo "$GIT_QUIET" > "$merge_dir/quiet"
msgnum=0
--
1.7.3.rc1.4.g5879b6
next prev parent reply other threads:[~2010-11-04 3:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-03 21:09 [PATCH 0/5] Make git-rebase.sh more readable and easier to extend martin.von.zweigbergk
2010-11-03 21:09 ` [PATCH 1/5] rebase: clearer names for directory variables martin.von.zweigbergk
2010-11-03 21:09 ` martin.von.zweigbergk [this message]
2010-11-03 21:09 ` [PATCH 3/5] rebase: read state outside loop martin.von.zweigbergk
2010-11-03 21:09 ` [PATCH 4/5] rebase: remove unused rebase state 'prev_head' martin.von.zweigbergk
2010-11-03 21:09 ` [PATCH 5/5] rebase: read state explicitly in '--abort' martin.von.zweigbergk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1288818580-7576-3-git-send-email-martin.von.zweigbergk@gmail.com \
--to=martin.von.zweigbergk@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).