From: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Johannes Sixt <j.sixt@viscovery.net>,
Christian Couder <chriscool@tuxfamily.org>,
Thomas Rast <trast@student.ethz.ch>,
Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Subject: [PATCH v2 10/31] rebase: factor out command line option processing
Date: Sun, 6 Feb 2011 13:43:39 -0500 [thread overview]
Message-ID: <1297017841-20678-11-git-send-email-martin.von.zweigbergk@gmail.com> (raw)
In-Reply-To: <1297017841-20678-1-git-send-email-martin.von.zweigbergk@gmail.com>
Factor out the command line processing in git-rebase--interactive.sh
to git-rebase.sh. Store the options in variables in git-rebase.sh and
then source git-rebase--interactive.sh.
Suggested-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Changes since v1:
* As suggested by Johannes Sixt, source git-rebase--interactive.sh
instead of executing it.
Since this removes the command line processing from
git-rebase--interactive.sh, it completely changes its command line
interface. Since it is not listed as even a plumbing command, I hope
this is fine.
git-rebase--interactive.sh | 224 ++++++++++++--------------------------------
git-rebase.sh | 58 ++++++++----
2 files changed, 100 insertions(+), 182 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 8b0d7b0..9c43c60 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -10,31 +10,7 @@
# The original idea comes from Eric W. Biederman, in
# http://article.gmane.org/gmane.comp.version-control.git/22407
-OPTIONS_KEEPDASHDASH=
-OPTIONS_SPEC="\
-git-rebase [-i] [options] [--] <upstream> [<branch>]
-git-rebase [-i] (--continue | --abort | --skip)
---
- Available options are
-v,verbose display a diffstat of what changed upstream
-onto= rebase onto given branch instead of upstream
-p,preserve-merges try to recreate merges instead of ignoring them
-s,strategy= use the given merge strategy
-no-ff cherry-pick all commits, even if unchanged
-m,merge always used (no-op)
-i,interactive always used (no-op)
- Actions:
-continue continue rebasing process
-abort abort rebasing process and restore original branch
-skip skip current patch and continue rebasing process
-no-verify override pre-rebase hook from stopping the operation
-verify allow pre-rebase hook to run
-root rebase all reachable commmits up to the root(s)
-autosquash move commits that begin with squash!/fixup! under -i
-"
-
. git-sh-setup
-require_work_tree
dotest="$GIT_DIR/rebase-merge"
@@ -105,16 +81,6 @@ amend="$dotest"/amend
rewritten_list="$dotest"/rewritten-list
rewritten_pending="$dotest"/rewritten-pending
-preserve_merges=
-strategy=
-onto=
-verbose=
-ok_to_skip_pre_rebase=
-rebase_root=
-autosquash=
-test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
-force_rebase=
-
GIT_CHERRY_PICK_HELP="\
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' and run 'git rebase --continue'"
@@ -648,15 +614,6 @@ skip_unnecessary_picks () {
die "Could not skip unnecessary pick commands"
}
-# check if no other options are set
-is_standalone () {
- test $# -eq 2 -a "$2" = '--' &&
- test -z "$onto" &&
- test -z "$preserve_merges" &&
- test -z "$strategy" &&
- test -z "$verbose"
-}
-
get_saved_options () {
test -d "$rewritten" && preserve_merges=t
test -f "$dotest"/strategy && strategy="$(cat "$dotest"/strategy)"
@@ -744,134 +701,77 @@ parse_onto () {
git rev-parse --verify "$1^0"
}
-while test $# != 0
-do
- case "$1" in
- --no-verify)
- ok_to_skip_pre_rebase=yes
- ;;
- --verify)
- ok_to_skip_pre_rebase=
- ;;
- --continue)
- is_standalone "$@" || usage
- get_saved_options
- comment_for_reflog continue
-
- test -d "$dotest" || die "No interactive rebase running"
-
- # Sanity check
- git rev-parse --verify HEAD >/dev/null ||
- die "Cannot read HEAD"
- git update-index --ignore-submodules --refresh &&
- git diff-files --quiet --ignore-submodules ||
- die "Working tree is dirty"
-
- # do we have anything to commit?
- if git diff-index --cached --quiet --ignore-submodules HEAD --
+case "$action" in
+continue)
+ get_saved_options
+ comment_for_reflog continue
+
+ test -d "$dotest" || die "No interactive rebase running"
+
+ # Sanity check
+ git rev-parse --verify HEAD >/dev/null ||
+ die "Cannot read HEAD"
+ git update-index --ignore-submodules --refresh &&
+ git diff-files --quiet --ignore-submodules ||
+ die "Working tree is dirty"
+
+ # do we have anything to commit?
+ if git diff-index --cached --quiet --ignore-submodules HEAD --
+ then
+ : Nothing to commit -- skip this
+ else
+ . "$author_script" ||
+ die "Cannot find the author identity"
+ current_head=
+ if test -f "$amend"
then
- : Nothing to commit -- skip this
- else
- . "$author_script" ||
- die "Cannot find the author identity"
- current_head=
- if test -f "$amend"
- then
- current_head=$(git rev-parse --verify HEAD)
- test "$current_head" = $(cat "$amend") ||
- die "\
+ current_head=$(git rev-parse --verify HEAD)
+ test "$current_head" = $(cat "$amend") ||
+ die "\
You have uncommitted changes in your working tree. Please, commit them
first and then run 'git rebase --continue' again."
- git reset --soft HEAD^ ||
- die "Cannot rewind the HEAD"
- fi
- do_with_author git commit --no-verify -F "$msg" -e || {
- test -n "$current_head" && git reset --soft $current_head
- die "Could not commit staged changes."
- }
+ git reset --soft HEAD^ ||
+ die "Cannot rewind the HEAD"
fi
+ do_with_author git commit --no-verify -F "$msg" -e || {
+ test -n "$current_head" && git reset --soft $current_head
+ die "Could not commit staged changes."
+ }
+ fi
- record_in_rewritten "$(cat "$dotest"/stopped-sha)"
+ record_in_rewritten "$(cat "$dotest"/stopped-sha)"
- require_clean_work_tree "rebase"
- do_rest
- ;;
- --abort)
- is_standalone "$@" || usage
- get_saved_options
- comment_for_reflog abort
-
- git rerere clear
- test -d "$dotest" || die "No interactive rebase running"
-
- headname=$(cat "$dotest"/head-name)
- head=$(cat "$dotest"/head)
- case $headname in
- refs/*)
- git symbolic-ref HEAD $headname
- ;;
- esac &&
- output git reset --hard $head &&
- rm -rf "$dotest"
- exit
- ;;
- --skip)
- is_standalone "$@" || usage
- get_saved_options
- comment_for_reflog skip
+ require_clean_work_tree "rebase"
+ do_rest
+ ;;
+abort)
+ get_saved_options
+ comment_for_reflog abort
- git rerere clear
- test -d "$dotest" || die "No interactive rebase running"
+ git rerere clear
+ test -d "$dotest" || die "No interactive rebase running"
- output git reset --hard && do_rest
- ;;
- -s)
- case "$#,$1" in
- *,*=*)
- strategy=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
- 1,*)
- usage ;;
- *)
- strategy="$2"
- shift ;;
- esac
- ;;
- -m)
- # we use merge anyway
- ;;
- -v)
- verbose=t
- ;;
- -p)
- preserve_merges=t
- ;;
- -i)
- # yeah, we know
- ;;
- --no-ff)
- force_rebase=t
- ;;
- --root)
- rebase_root=t
- ;;
- --autosquash)
- autosquash=t
- ;;
- --no-autosquash)
- autosquash=
- ;;
- --onto)
- test 2 -le "$#" || usage
- onto="$2"
- shift
- ;;
- --)
- shift
- break
+ headname=$(cat "$dotest"/head-name)
+ head=$(cat "$dotest"/head)
+ case $headname in
+ refs/*)
+ git symbolic-ref HEAD $headname
;;
- esac
- shift
-done
+ esac &&
+ output git reset --hard $head &&
+ rm -rf "$dotest"
+ exit
+ ;;
+skip)
+ get_saved_options
+ comment_for_reflog skip
+
+ git rerere clear
+ test -d "$dotest" || die "No interactive rebase running"
+
+ output git reset --hard && do_rest
+ ;;
+esac
if test -n "$onto"
then
diff --git a/git-rebase.sh b/git-rebase.sh
index 3eac5a4..aa1bcaf 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -64,6 +64,9 @@ type=
state_dir=
# One of {'', continue, skip, abort}, as parsed from command line
action=
+preserve_merges=
+autosquash=
+test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
read_state () {
if test "$type" = merge
@@ -176,27 +179,12 @@ finish_rb_merge () {
say All done.
}
-is_interactive () {
- while test $# != 0
- do
- case "$1" in
- -i|--interactive)
- interactive_rebase=explicit
- break
- ;;
- -p|--preserve-merges)
- interactive_rebase=implied
- ;;
- esac
- shift
- done
-
+run_interactive_rebase () {
if [ "$interactive_rebase" = implied ]; then
GIT_EDITOR=:
export GIT_EDITOR
fi
-
- test -n "$interactive_rebase" || test -f "$merge_dir"/interactive
+ . git-rebase--interactive "$@"
}
run_pre_rebase_hook () {
@@ -211,8 +199,6 @@ run_pre_rebase_hook () {
test -f "$apply_dir"/applying &&
die 'It looks like git-am is in progress. Cannot rebase.'
-is_interactive "$@" && exec git-rebase--interactive "$@"
-
if test -d "$apply_dir"
then
type=am
@@ -249,6 +235,19 @@ do
onto="$2"
shift
;;
+ -i|--interactive)
+ interactive_rebase=explicit
+ ;;
+ -p|--preserve-merges)
+ preserve_merges=t
+ test -z "$interactive_rebase" && interactive_rebase=implied
+ ;;
+ --autosquash)
+ autosquash=t
+ ;;
+ --no-autosquash)
+ autosquash=
+ ;;
-M|-m|--m|--me|--mer|--merg|--merge)
do_merge=t
;;
@@ -339,7 +338,11 @@ do
done
test $# -gt 2 && usage
-test -n "$action" && test -z "$in_progress" && die "No rebase in progress?"
+if test -n "$action"
+then
+ test -z "$in_progress" && die "No rebase in progress?"
+ test "$type" = interactive && run_interactive_rebase
+fi
case "$action" in
continue)
@@ -415,6 +418,21 @@ fi
test $# -eq 0 && test -z "$rebase_root" && usage
+if test -n "$interactive_rebase"
+then
+ type=interactive
+ state_dir="$merge_dir"
+elif test -n "$do_merge"
+then
+ type=merge
+ state_dir="$merge_dir"
+else
+ type=am
+ state_dir="$apply_dir"
+fi
+
+test "$type" = interactive && run_interactive_rebase "$@"
+
require_clean_work_tree "rebase" "Please commit or stash them."
if test -z "$rebase_root"
--
1.7.4.rc2.33.g8a14f
next prev parent reply other threads:[~2011-02-06 18:47 UTC|newest]
Thread overview: 118+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-28 9:30 [PATCH 00/31] Refactor rebase Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 01/31] rebase: clearer names for directory variables Martin von Zweigbergk
2010-12-28 23:08 ` Junio C Hamano
2010-12-28 20:53 ` Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 02/31] rebase: refactor reading of state Martin von Zweigbergk
2010-12-28 23:08 ` Junio C Hamano
2010-12-29 8:09 ` Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 03/31] rebase: read state outside loop Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 04/31] rebase: remove unused rebase state 'prev_head' Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 05/31] rebase: improve detection of rebase in progress Martin von Zweigbergk
2010-12-28 23:08 ` Junio C Hamano
2010-12-28 20:35 ` Martin von Zweigbergk
2011-01-12 10:20 ` Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 06/31] rebase: act on command line outside parsing loop Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 07/31] rebase: stricter check of standalone sub command Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 08/31] rebase: align variable names Martin von Zweigbergk
2011-01-04 19:12 ` Thomas Rast
2011-01-05 2:25 ` Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 09/31] rebase: align variable content Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 10/31] rebase: factor out command line option processing Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 11/31] rebase -i: remove now unnecessary directory checks Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 12/31] rebase: reorder validation steps Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 13/31] rebase: factor out reference parsing Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 14/31] rebase: factor out clean work tree check Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 15/31] rebase: factor out call to pre-rebase hook Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 16/31] rebase -i: support --stat Martin von Zweigbergk
2010-12-28 17:59 ` Johannes Schindelin
2010-12-28 13:24 ` Martin von Zweigbergk
2010-12-28 23:36 ` Junio C Hamano
2010-12-28 23:44 ` Johannes Schindelin
2010-12-28 9:30 ` [PATCH 17/31] rebase: remove $branch as synonym for $orig_head Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 18/31] rebase: extract merge code to new source file Martin von Zweigbergk
2010-12-29 21:31 ` Johannes Sixt
2010-12-29 22:24 ` Martin von Zweigbergk
2010-12-31 12:23 ` Thomas Rast
2010-12-31 14:05 ` Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 19/31] rebase: extract am " Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 20/31] rebase: show consistent conflict resolution hint Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 21/31] rebase -i: align variable names Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 22/31] rebase: make -v a tiny bit more verbose Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 23/31] rebase: factor out sub command handling Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 24/31] rebase: extract code for writing basic state Martin von Zweigbergk
2011-01-04 19:19 ` Thomas Rast
2011-01-05 2:40 ` Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 25/31] rebase: remember verbose option Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 26/31] rebase: remember strategy and strategy options Martin von Zweigbergk
2011-01-04 19:27 ` Thomas Rast
2011-01-05 3:33 ` Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 27/31] rebase -m: remember allow_rerere_autoupdate option Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 28/31] rebase -m: don't print exit code 2 when merge fails Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 29/31] git-rebase--am: remove unnecessary --3way option Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 30/31] rebase -i: don't read unused variable preserve_merges Martin von Zweigbergk
2010-12-28 9:30 ` [PATCH 31/31] rebase -i: remove unnecessary state rebase-root Martin von Zweigbergk
2010-12-28 16:40 ` Thomas Rast
2010-12-29 22:31 ` Martin von Zweigbergk
2010-12-31 5:41 ` Christian Couder
2011-01-04 19:57 ` [PATCH 00/31] Refactor rebase Thomas Rast
2011-01-05 3:39 ` Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 00/31] refactor rebase Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 01/31] rebase: clearer names for directory variables Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 02/31] rebase: refactor reading of state Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 03/31] rebase: read state outside loop Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 04/31] rebase: remove unused rebase state 'prev_head' Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 05/31] rebase: improve detection of rebase in progress Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 06/31] rebase: act on command line outside parsing loop Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 07/31] rebase: stricter check of standalone sub command Martin von Zweigbergk
2011-07-01 3:55 ` Jonathan Nieder
2011-07-01 13:16 ` Martin von Zweigbergk
2011-07-01 22:29 ` Jonathan Nieder
2011-07-06 1:48 ` Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 08/31] rebase: align variable names Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 09/31] rebase: align variable content Martin von Zweigbergk
2011-02-06 18:43 ` Martin von Zweigbergk [this message]
2011-02-06 18:43 ` [PATCH v2 11/31] rebase -i: remove now unnecessary directory checks Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 12/31] rebase: reorder validation steps Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 13/31] rebase: factor out reference parsing Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 14/31] rebase: factor out clean work tree check Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 15/31] rebase: factor out call to pre-rebase hook Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 16/31] rebase -i: support --stat Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 17/31] rebase: remove $branch as synonym for $orig_head Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 18/31] rebase: extract merge code to new source file Martin von Zweigbergk
2011-02-14 8:02 ` Johannes Sixt
2011-02-14 13:56 ` Martin von Zweigbergk
2011-02-24 3:27 ` Martin von Zweigbergk
2011-02-24 8:07 ` Jeff King
2011-02-24 8:09 ` Jeff King
2011-02-25 3:32 ` Martin von Zweigbergk
2011-02-25 9:02 ` Jeff King
2011-02-25 20:24 ` Junio C Hamano
2011-02-25 20:27 ` Jakub Narebski
2011-03-01 22:04 ` Jeff King
2011-03-01 22:43 ` Jakub Narebski
2011-02-06 18:43 ` [PATCH v2 19/31] rebase: extract am " Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 20/31] rebase: show consistent conflict resolution hint Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 21/31] rebase -i: align variable names Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 22/31] rebase: make -v a tiny bit more verbose Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 23/31] rebase: factor out sub command handling Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 24/31] rebase: extract code for writing basic state Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 25/31] rebase: remember verbose option Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 26/31] rebase: remember strategy and strategy options Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 27/31] rebase -m: remember allow_rerere_autoupdate option Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 28/31] rebase -m: don't print exit code 2 when merge fails Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 29/31] git-rebase--am: remove unnecessary --3way option Martin von Zweigbergk
2011-02-06 18:43 ` [PATCH v2 30/31] rebase -i: don't read unused variable preserve_merges Martin von Zweigbergk
2011-02-06 18:44 ` [PATCH v2 31/31] rebase -i: remove unnecessary state rebase-root Martin von Zweigbergk
2011-02-10 22:44 ` [PATCH v2 00/31] refactor rebase Junio C Hamano
2011-02-12 0:55 ` Martin von Zweigbergk
2011-02-14 1:54 ` Martin von Zweigbergk
2011-02-14 3:15 ` Martin von Zweigbergk
2011-02-15 0:36 ` Junio C Hamano
2011-02-22 13:58 ` Martin von Zweigbergk
2011-02-22 19:21 ` Junio C Hamano
2011-02-23 11:26 ` Martin von Zweigbergk
2011-02-16 14:52 ` Johannes Sixt
2011-02-17 3:41 ` Martin von Zweigbergk
2011-02-24 3:07 ` [PATCH] rebase: define options in OPTIONS_SPEC Martin von Zweigbergk
2011-02-27 10:59 ` Junio C Hamano
2011-03-01 1:59 ` 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=1297017841-20678-11-git-send-email-martin.von.zweigbergk@gmail.com \
--to=martin.von.zweigbergk@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j.sixt@viscovery.net \
--cc=trast@student.ethz.ch \
/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).