subtree: don't have loose code outside of a function
Shove all of the loose code inside of a main() function. This comes down to personal preference more than anything else. A preference that I've developed over years of maintaining large Bash scripts, but still a mere personal preference. In this specific case, it's also moving the `set -- -h`, the `git rev-parse --parseopt`, and the `. git-sh-setup` to be closer to all the rest of the argument parsing, which is a readability win on its own, IMO. "Ignore space change" is probably helpful when viewing this diff. Signed-off-by: Luke Shumaker <lukeshu@datawire.io> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
b04538d99f
commit
5a3569774f
|
@ -4,10 +4,7 @@
|
||||||
#
|
#
|
||||||
# Copyright (C) 2009 Avery Pennarun <apenwarr@gmail.com>
|
# Copyright (C) 2009 Avery Pennarun <apenwarr@gmail.com>
|
||||||
#
|
#
|
||||||
if test $# -eq 0
|
|
||||||
then
|
|
||||||
set -- -h
|
|
||||||
fi
|
|
||||||
OPTS_SPEC="\
|
OPTS_SPEC="\
|
||||||
git subtree add --prefix=<prefix> <commit>
|
git subtree add --prefix=<prefix> <commit>
|
||||||
git subtree add --prefix=<prefix> <repository> <ref>
|
git subtree add --prefix=<prefix> <repository> <ref>
|
||||||
|
@ -30,12 +27,8 @@ rejoin merge the new branch back into HEAD
|
||||||
options for 'add', 'merge', and 'pull'
|
options for 'add', 'merge', and 'pull'
|
||||||
squash merge subtree changes as a single commit
|
squash merge subtree changes as a single commit
|
||||||
"
|
"
|
||||||
eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
|
|
||||||
|
|
||||||
PATH=$PATH:$(git --exec-path)
|
PATH=$PATH:$(git --exec-path)
|
||||||
. git-sh-setup
|
|
||||||
|
|
||||||
require_work_tree
|
|
||||||
|
|
||||||
quiet=
|
quiet=
|
||||||
branch=
|
branch=
|
||||||
|
@ -84,6 +77,15 @@ ensure_single_rev () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
if test $# -eq 0
|
||||||
|
then
|
||||||
|
set -- -h
|
||||||
|
fi
|
||||||
|
eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
|
||||||
|
. git-sh-setup
|
||||||
|
require_work_tree
|
||||||
|
|
||||||
while test $# -gt 0
|
while test $# -gt 0
|
||||||
do
|
do
|
||||||
opt="$1"
|
opt="$1"
|
||||||
|
@ -205,6 +207,9 @@ debug "dir: {$dir}"
|
||||||
debug "opts: {$*}"
|
debug "opts: {$*}"
|
||||||
debug
|
debug
|
||||||
|
|
||||||
|
"cmd_$command" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
cache_setup () {
|
cache_setup () {
|
||||||
cachedir="$GIT_DIR/subtree-cache/$$"
|
cachedir="$GIT_DIR/subtree-cache/$$"
|
||||||
rm -rf "$cachedir" ||
|
rm -rf "$cachedir" ||
|
||||||
|
@ -898,4 +903,4 @@ cmd_push () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
"cmd_$command" "$@"
|
main "$@"
|
||||||
|
|
Loading…
Reference in New Issue