Skip to content

Commit 71786f5

Browse files
Martin von Zweigbergkgitster
authored andcommitted
rebase: factor out reference parsing
Remove the parsing and validation of references (onto, upstream, branch) from git-rebase--interactive.sh and rely on the information exported from git-rebase.sh. By using the parsing of the --onto parameter in git-rebase.sh, this improves the error message when the parameter is invalid. Signed-off-by: Martin von Zweigbergk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f9bfb6 commit 71786f5

File tree

2 files changed

+9
-48
lines changed

2 files changed

+9
-48
lines changed

git-rebase--interactive.sh

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -682,25 +682,6 @@ rearrange_squash () {
682682
rm -f "$1.sq" "$1.rearranged"
683683
}
684684

685-
LF='
686-
'
687-
parse_onto () {
688-
case "$1" in
689-
*...*)
690-
if left=${1%...*} right=${1#*...} &&
691-
onto=$(git merge-base --all ${left:-HEAD} ${right:-HEAD})
692-
then
693-
case "$onto" in
694-
?*"$LF"?* | '')
695-
exit 1 ;;
696-
esac
697-
echo "$onto"
698-
exit 0
699-
fi
700-
esac
701-
git rev-parse --verify "$1^0"
702-
}
703-
704685
case "$action" in
705686
continue)
706687
get_saved_options
@@ -769,47 +750,26 @@ skip)
769750
;;
770751
esac
771752

772-
if test -n "$onto"
773-
then
774-
onto=$(parse_onto "$onto") || die "Does not point to a valid commit: $1"
775-
fi
776-
777-
test -z "$rebase_root" -a $# -ge 1 -a $# -le 2 ||
778-
test ! -z "$rebase_root" -a $# -le 1 || usage
779-
780753
git var GIT_COMMITTER_IDENT >/dev/null ||
781754
die "You need to set your committer info first"
782755

783-
if test -z "$rebase_root"
784-
then
785-
upstream_arg="$1"
786-
upstream=$(git rev-parse --verify "$1") || die "Invalid base"
787-
test -z "$onto" && onto=$upstream
788-
shift
789-
else
790-
upstream=
791-
upstream_arg=--root
792-
test -z "$onto" &&
793-
die "You must specify --onto when using --root"
794-
fi
795756
require_clean_work_tree "rebase" "Please commit or stash them."
796757

797758
run_pre_rebase_hook "$upstream_arg" "$@"
798759

799760
comment_for_reflog start
800761

801-
if test ! -z "$1"
762+
if test ! -z "$switch_to"
802763
then
803-
output git checkout "$1" -- ||
804-
die "Could not checkout $1"
764+
output git checkout "$switch_to" -- ||
765+
die "Could not checkout $switch_to"
805766
fi
806767

807768
head=$(git rev-parse --verify HEAD) || die "No HEAD?"
808769
mkdir "$dotest" || die "Could not create temporary $dotest"
809770

810771
: > "$dotest"/interactive || die "Could not mark as interactive"
811-
git symbolic-ref HEAD > "$dotest"/head-name 2> /dev/null ||
812-
echo "detached HEAD" > "$dotest"/head-name
772+
echo "$head_name" > "$dotest"/head-name
813773

814774
echo $head > "$dotest"/head
815775
case "$rebase_root" in

git-rebase.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,6 @@ else
431431
state_dir="$apply_dir"
432432
fi
433433

434-
test "$type" = interactive && run_interactive_rebase "$@"
435-
436434
if test -z "$rebase_root"
437435
then
438436
# The upstream head must be given. Make sure it is valid.
@@ -443,7 +441,7 @@ then
443441
unset root_flag
444442
upstream_arg="$upstream_name"
445443
else
446-
test -z "$onto" && die "--root must be used with --onto"
444+
test -z "$onto" && die "You must specify --onto when using --root"
447445
unset upstream_name
448446
unset upstream
449447
root_flag="--root"
@@ -470,7 +468,8 @@ case "$onto_name" in
470468
fi
471469
;;
472470
*)
473-
onto=$(git rev-parse --verify "${onto_name}^0") || exit
471+
onto=$(git rev-parse --verify "${onto_name}^0") ||
472+
die "Does not point to a valid commit: $1"
474473
;;
475474
esac
476475

@@ -512,6 +511,8 @@ case "$#" in
512511
esac
513512
orig_head=$branch
514513

514+
test "$type" = interactive && run_interactive_rebase "$@"
515+
515516
require_clean_work_tree "rebase" "Please commit or stash them."
516517

517518
# Now we are rebasing commits $upstream..$branch (or with --root,

0 commit comments

Comments
 (0)