mirror of
https://github.com/git/git
synced 2024-09-13 13:24:41 +00:00
subtree: parse revs in individual cmd_ functions
The main argument parser goes ahead and tries to parse revs to make things simpler for the sub-command implementations. But, it includes enough special cases for different sub-commands. And it's difficult having having to think about "is this info coming from an argument, or a global variable?". So the main argument parser's effort to make things "simpler" ends up just making it more confusing and complicated. Begone with the 'revs' global variable; parse 'rev=$(...)' as needed in individual 'cmd_*' functions. Begone with the 'default' global variable. Its would-be value is knowable just from which function we're in. Begone with the 'ensure_single_rev' function. Its functionality can be achieved by passing '--verify' to 'git rev-parse'. Signed-off-by: Luke Shumaker <lukeshu@datawire.io> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
bbffb02383
commit
e4f8baa88a
|
@ -76,13 +76,6 @@ assert () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure_single_rev () {
|
|
||||||
if test $# -ne 1
|
|
||||||
then
|
|
||||||
die "You must provide exactly one revision. Got: '$*'"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
main () {
|
main () {
|
||||||
if test $# -eq 0
|
if test $# -eq 0
|
||||||
then
|
then
|
||||||
|
@ -164,11 +157,8 @@ main () {
|
||||||
shift
|
shift
|
||||||
|
|
||||||
case "$arg_command" in
|
case "$arg_command" in
|
||||||
add|merge|pull)
|
add|merge|pull|split|push)
|
||||||
default=
|
:
|
||||||
;;
|
|
||||||
split|push)
|
|
||||||
default="--default HEAD"
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
die "Unknown command '$arg_command'"
|
die "Unknown command '$arg_command'"
|
||||||
|
@ -193,22 +183,8 @@ main () {
|
||||||
|
|
||||||
dir="$(dirname "$arg_prefix/.")"
|
dir="$(dirname "$arg_prefix/.")"
|
||||||
|
|
||||||
if test "$arg_command" != "pull" &&
|
|
||||||
test "$arg_command" != "add" &&
|
|
||||||
test "$arg_command" != "push"
|
|
||||||
then
|
|
||||||
revs=$(git rev-parse $default --revs-only "$@") || exit $?
|
|
||||||
dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $?
|
|
||||||
ensure_single_rev $revs
|
|
||||||
if test -n "$dirs"
|
|
||||||
then
|
|
||||||
die "Error: Use --prefix instead of bare filenames."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
debug "command: {$arg_command}"
|
debug "command: {$arg_command}"
|
||||||
debug "quiet: {$GIT_QUIET}"
|
debug "quiet: {$GIT_QUIET}"
|
||||||
debug "revs: {$revs}"
|
|
||||||
debug "dir: {$dir}"
|
debug "dir: {$dir}"
|
||||||
debug "opts: {$*}"
|
debug "opts: {$*}"
|
||||||
debug
|
debug
|
||||||
|
@ -714,14 +690,13 @@ cmd_add_repository () {
|
||||||
repository=$1
|
repository=$1
|
||||||
refspec=$2
|
refspec=$2
|
||||||
git fetch "$@" || exit $?
|
git fetch "$@" || exit $?
|
||||||
revs=FETCH_HEAD
|
cmd_add_commit FETCH_HEAD
|
||||||
set -- $revs
|
|
||||||
cmd_add_commit "$@"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_add_commit () {
|
cmd_add_commit () {
|
||||||
rev=$(git rev-parse $default --revs-only "$@") || exit $?
|
# The rev has already been validated by cmd_add(), we just
|
||||||
ensure_single_rev $rev
|
# need to normalize it.
|
||||||
|
rev=$(git rev-parse --verify "$1^{commit}") || exit $?
|
||||||
|
|
||||||
debug "Adding $dir as '$rev'..."
|
debug "Adding $dir as '$rev'..."
|
||||||
git read-tree --prefix="$dir" $rev || exit $?
|
git read-tree --prefix="$dir" $rev || exit $?
|
||||||
|
@ -752,6 +727,17 @@ cmd_add_commit () {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_split () {
|
cmd_split () {
|
||||||
|
if test $# -eq 0
|
||||||
|
then
|
||||||
|
rev=$(git rev-parse HEAD)
|
||||||
|
elif test $# -eq 1
|
||||||
|
then
|
||||||
|
rev=$(git rev-parse -q --verify "$1^{commit}") ||
|
||||||
|
die "'$1' does not refer to a commit"
|
||||||
|
else
|
||||||
|
die "You must provide exactly one revision. Got: '$*'"
|
||||||
|
fi
|
||||||
|
|
||||||
debug "Splitting $dir..."
|
debug "Splitting $dir..."
|
||||||
cache_setup || exit $?
|
cache_setup || exit $?
|
||||||
|
|
||||||
|
@ -768,12 +754,12 @@ cmd_split () {
|
||||||
done || exit $?
|
done || exit $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
unrevs="$(find_existing_splits "$dir" "$revs")" || exit $?
|
unrevs="$(find_existing_splits "$dir" "$rev")" || exit $?
|
||||||
|
|
||||||
# We can't restrict rev-list to only $dir here, because some of our
|
# We can't restrict rev-list to only $dir here, because some of our
|
||||||
# parents have the $dir contents the root, and those won't match.
|
# parents have the $dir contents the root, and those won't match.
|
||||||
# (and rev-list --follow doesn't seem to solve this)
|
# (and rev-list --follow doesn't seem to solve this)
|
||||||
grl='git rev-list --topo-order --reverse --parents $revs $unrevs'
|
grl='git rev-list --topo-order --reverse --parents $rev $unrevs'
|
||||||
revmax=$(eval "$grl" | wc -l)
|
revmax=$(eval "$grl" | wc -l)
|
||||||
revcount=0
|
revcount=0
|
||||||
createcount=0
|
createcount=0
|
||||||
|
@ -820,8 +806,10 @@ cmd_split () {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_merge () {
|
cmd_merge () {
|
||||||
rev=$(git rev-parse $default --revs-only "$@") || exit $?
|
test $# -eq 1 ||
|
||||||
ensure_single_rev $rev
|
die "You must provide exactly one revision. Got: '$*'"
|
||||||
|
rev=$(git rev-parse -q --verify "$1^{commit}") ||
|
||||||
|
die "'$1' does not refer to a commit"
|
||||||
ensure_clean
|
ensure_clean
|
||||||
|
|
||||||
if test -n "$arg_addmerge_squash"
|
if test -n "$arg_addmerge_squash"
|
||||||
|
@ -861,9 +849,7 @@ cmd_pull () {
|
||||||
ensure_clean
|
ensure_clean
|
||||||
ensure_valid_ref_format "$2"
|
ensure_valid_ref_format "$2"
|
||||||
git fetch "$@" || exit $?
|
git fetch "$@" || exit $?
|
||||||
revs=FETCH_HEAD
|
cmd_merge FETCH_HEAD
|
||||||
set -- $revs
|
|
||||||
cmd_merge "$@"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_push () {
|
cmd_push () {
|
||||||
|
|
Loading…
Reference in a new issue