rebase: factor out command line option processing
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									9765b6abeb
								
							
						
					
					
						commit
						cf432ca051
					
				|  | @ -10,31 +10,7 @@ | ||||||
| # The original idea comes from Eric W. Biederman, in | # The original idea comes from Eric W. Biederman, in | ||||||
| # http://article.gmane.org/gmane.comp.version-control.git/22407 | # 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 | . git-sh-setup | ||||||
| require_work_tree |  | ||||||
|  |  | ||||||
| dotest="$GIT_DIR/rebase-merge" | dotest="$GIT_DIR/rebase-merge" | ||||||
|  |  | ||||||
|  | @ -105,16 +81,6 @@ amend="$dotest"/amend | ||||||
| rewritten_list="$dotest"/rewritten-list | rewritten_list="$dotest"/rewritten-list | ||||||
| rewritten_pending="$dotest"/rewritten-pending | 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="\ | GIT_CHERRY_PICK_HELP="\ | ||||||
| hint: after resolving the conflicts, mark the corrected paths | hint: after resolving the conflicts, mark the corrected paths | ||||||
| hint: with 'git add <paths>' and run 'git rebase --continue'" | hint: with 'git add <paths>' and run 'git rebase --continue'" | ||||||
|  | @ -648,15 +614,6 @@ skip_unnecessary_picks () { | ||||||
| 	die "Could not skip unnecessary pick commands" | 	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 () { | get_saved_options () { | ||||||
| 	test -d "$rewritten" && preserve_merges=t | 	test -d "$rewritten" && preserve_merges=t | ||||||
| 	test -f "$dotest"/strategy && strategy="$(cat "$dotest"/strategy)" | 	test -f "$dotest"/strategy && strategy="$(cat "$dotest"/strategy)" | ||||||
|  | @ -744,17 +701,8 @@ parse_onto () { | ||||||
| 	git rev-parse --verify "$1^0" | 	git rev-parse --verify "$1^0" | ||||||
| } | } | ||||||
|  |  | ||||||
| while test $# != 0 | case "$action" in | ||||||
| do | continue) | ||||||
| 	case "$1" in |  | ||||||
| 	--no-verify) |  | ||||||
| 		ok_to_skip_pre_rebase=yes |  | ||||||
| 		;; |  | ||||||
| 	--verify) |  | ||||||
| 		ok_to_skip_pre_rebase= |  | ||||||
| 		;; |  | ||||||
| 	--continue) |  | ||||||
| 		is_standalone "$@" || usage |  | ||||||
| 	get_saved_options | 	get_saved_options | ||||||
| 	comment_for_reflog continue | 	comment_for_reflog continue | ||||||
|  |  | ||||||
|  | @ -796,8 +744,7 @@ first and then run 'git rebase --continue' again." | ||||||
| 	require_clean_work_tree "rebase" | 	require_clean_work_tree "rebase" | ||||||
| 	do_rest | 	do_rest | ||||||
| 	;; | 	;; | ||||||
| 	--abort) | abort) | ||||||
| 		is_standalone "$@" || usage |  | ||||||
| 	get_saved_options | 	get_saved_options | ||||||
| 	comment_for_reflog abort | 	comment_for_reflog abort | ||||||
|  |  | ||||||
|  | @ -815,8 +762,7 @@ first and then run 'git rebase --continue' again." | ||||||
| 	rm -rf "$dotest" | 	rm -rf "$dotest" | ||||||
| 	exit | 	exit | ||||||
| 	;; | 	;; | ||||||
| 	--skip) | skip) | ||||||
| 		is_standalone "$@" || usage |  | ||||||
| 	get_saved_options | 	get_saved_options | ||||||
| 	comment_for_reflog skip | 	comment_for_reflog skip | ||||||
|  |  | ||||||
|  | @ -825,53 +771,7 @@ first and then run 'git rebase --continue' again." | ||||||
|  |  | ||||||
| 	output git reset --hard && do_rest | 	output git reset --hard && do_rest | ||||||
| 	;; | 	;; | ||||||
| 	-s) |  | ||||||
| 		case "$#,$1" in |  | ||||||
| 		*,*=*) |  | ||||||
| 			strategy=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;; |  | ||||||
| 		1,*) |  | ||||||
| 			usage ;; |  | ||||||
| 		*) |  | ||||||
| 			strategy="$2" |  | ||||||
| 			shift ;; |  | ||||||
| esac | 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 |  | ||||||
| 		;; |  | ||||||
| 	esac |  | ||||||
| 	shift |  | ||||||
| done |  | ||||||
|  |  | ||||||
| if test -n "$onto" | if test -n "$onto" | ||||||
| then | then | ||||||
|  |  | ||||||
|  | @ -64,6 +64,9 @@ type= | ||||||
| state_dir= | state_dir= | ||||||
| # One of {'', continue, skip, abort}, as parsed from command line | # One of {'', continue, skip, abort}, as parsed from command line | ||||||
| action= | action= | ||||||
|  | preserve_merges= | ||||||
|  | autosquash= | ||||||
|  | test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t | ||||||
|  |  | ||||||
| read_state () { | read_state () { | ||||||
| 	if test "$type" = merge | 	if test "$type" = merge | ||||||
|  | @ -176,27 +179,12 @@ finish_rb_merge () { | ||||||
| 	say All done. | 	say All done. | ||||||
| } | } | ||||||
|  |  | ||||||
| is_interactive () { | run_interactive_rebase () { | ||||||
| 	while test $# != 0 |  | ||||||
| 	do |  | ||||||
| 		case "$1" in |  | ||||||
| 			-i|--interactive) |  | ||||||
| 				interactive_rebase=explicit |  | ||||||
| 				break |  | ||||||
| 			;; |  | ||||||
| 			-p|--preserve-merges) |  | ||||||
| 				interactive_rebase=implied |  | ||||||
| 			;; |  | ||||||
| 		esac |  | ||||||
| 		shift |  | ||||||
| 	done |  | ||||||
|  |  | ||||||
| 	if [ "$interactive_rebase" = implied ]; then | 	if [ "$interactive_rebase" = implied ]; then | ||||||
| 		GIT_EDITOR=: | 		GIT_EDITOR=: | ||||||
| 		export GIT_EDITOR | 		export GIT_EDITOR | ||||||
| 	fi | 	fi | ||||||
|  | 	. git-rebase--interactive "$@" | ||||||
| 	test -n "$interactive_rebase" || test -f "$merge_dir"/interactive |  | ||||||
| } | } | ||||||
|  |  | ||||||
| run_pre_rebase_hook () { | run_pre_rebase_hook () { | ||||||
|  | @ -211,8 +199,6 @@ run_pre_rebase_hook () { | ||||||
| test -f "$apply_dir"/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 "$@" |  | ||||||
|  |  | ||||||
| if test -d "$apply_dir" | if test -d "$apply_dir" | ||||||
| then | then | ||||||
| 	type=am | 	type=am | ||||||
|  | @ -249,6 +235,19 @@ do | ||||||
| 		onto="$2" | 		onto="$2" | ||||||
| 		shift | 		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) | 	-M|-m|--m|--me|--mer|--merg|--merge) | ||||||
| 		do_merge=t | 		do_merge=t | ||||||
| 		;; | 		;; | ||||||
|  | @ -339,7 +338,11 @@ do | ||||||
| done | done | ||||||
| test $# -gt 2 && usage | 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 | case "$action" in | ||||||
| continue) | continue) | ||||||
|  | @ -415,6 +418,21 @@ fi | ||||||
|  |  | ||||||
| test $# -eq 0 && test -z "$rebase_root" && usage | 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." | require_clean_work_tree "rebase" "Please commit or stash them." | ||||||
|  |  | ||||||
| if test -z "$rebase_root" | if test -z "$rebase_root" | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Martin von Zweigbergk
						Martin von Zweigbergk