@matheusbsbs / matheus-bagliano / commits / 71786f54c4
Fork 0

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 <martin.von.zweigbergk@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin von Zweigbergk committed Feb 6, 2011 at 13:43 UTC 71786f54c4128821eab8a23f258848c76b5a2071
2 files changed +9 -48
git-rebase--interactive.sh
+4 -44
@@ -682,25 +682,6 @@ rearrange_squash () {
682 rm -f "$1.sq" "$1.rearranged"
683 }
684
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 -
685 case "$action" in
686 continue)
687 get_saved_options
@@ -769,47 +750,26 @@ skip)
750 ;;
751 esac
752
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 -
753 git var GIT_COMMITTER_IDENT >/dev/null ||
754 die "You need to set your committer info first"
755
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
756 require_clean_work_tree "rebase" "Please commit or stash them."
757
758 run_pre_rebase_hook "$upstream_arg" "$@"
759
760 comment_for_reflog start
761
801 -if test ! -z "$1"
762 +if test ! -z "$switch_to"
763 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"
766 fi
767
768 head=$(git rev-parse --verify HEAD) || die "No HEAD?"
769 mkdir "$dotest" || die "Could not create temporary $dotest"
770
771 : > "$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
773
774 echo $head > "$dotest"/head
775 case "$rebase_root" in
git-rebase.sh
+5 -4
@@ -431,8 +431,6 @@ else
431 state_dir="$apply_dir"
432 fi
433
434 -test "$type" = interactive && run_interactive_rebase "$@"
435 -
434 if test -z "$rebase_root"
435 then
436 # The upstream head must be given. Make sure it is valid.
@@ -443,7 +441,7 @@ then
441 unset root_flag
442 upstream_arg="$upstream_name"
443 else
446 - test -z "$onto" && die "--root must be used with --onto"
444 + test -z "$onto" && die "You must specify --onto when using --root"
445 unset upstream_name
446 unset upstream
447 root_flag="--root"
@@ -470,7 +468,8 @@ case "$onto_name" in
468 fi
469 ;;
470 *)
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"
473 ;;
474 esac
475
@@ -512,6 +511,8 @@ case "$#" in
511 esac
512 orig_head=$branch
513
514 +test "$type" = interactive && run_interactive_rebase "$@"
515 +
516 require_clean_work_tree "rebase" "Please commit or stash them."
517
518 # Now we are rebasing commits $upstream..$branch (or with --root,