subtree: use more explicit variable names for cmdline args

Make it painfully obvious when reading the code which variables are
direct parsings of command line arguments.

Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Luke Shumaker
2021-04-27 15:17:35 -06:00
committed by Junio C Hamano
parent 6d43585a68
commit e2b11e4211

View File

@ -30,19 +30,19 @@ squash merge subtree changes as a single commit
PATH=$PATH:$(git --exec-path) PATH=$PATH:$(git --exec-path)
branch= arg_debug=
debug= arg_command=
command= arg_prefix=
onto= arg_split_branch=
rejoin= arg_split_onto=
ignore_joins= arg_split_rejoin=
annotate= arg_split_ignore_joins=
squash= arg_split_annotate=
message= arg_addmerge_squash=
prefix= arg_addmerge_message=
debug () { debug () {
if test -n "$debug" if test -n "$arg_debug"
then then
printf "%s\n" "$*" >&2 printf "%s\n" "$*" >&2
fi fi
@ -88,54 +88,54 @@ main () {
GIT_QUIET=1 GIT_QUIET=1
;; ;;
-d) -d)
debug=1 arg_debug=1
;; ;;
--annotate) --annotate)
annotate="$1" arg_split_annotate="$1"
shift shift
;; ;;
--no-annotate) --no-annotate)
annotate= arg_split_annotate=
;; ;;
-b) -b)
branch="$1" arg_split_branch="$1"
shift shift
;; ;;
-P) -P)
prefix="${1%/}" arg_prefix="${1%/}"
shift shift
;; ;;
-m) -m)
message="$1" arg_addmerge_message="$1"
shift shift
;; ;;
--no-prefix) --no-prefix)
prefix= arg_prefix=
;; ;;
--onto) --onto)
onto="$1" arg_split_onto="$1"
shift shift
;; ;;
--no-onto) --no-onto)
onto= arg_split_onto=
;; ;;
--rejoin) --rejoin)
rejoin=1 arg_split_rejoin=1
;; ;;
--no-rejoin) --no-rejoin)
rejoin= arg_split_rejoin=
;; ;;
--ignore-joins) --ignore-joins)
ignore_joins=1 arg_split_ignore_joins=1
;; ;;
--no-ignore-joins) --no-ignore-joins)
ignore_joins= arg_split_ignore_joins=
;; ;;
--squash) --squash)
squash=1 arg_addmerge_squash=1
;; ;;
--no-squash) --no-squash)
squash= arg_addmerge_squash=
;; ;;
--) --)
break break
@ -146,10 +146,10 @@ main () {
esac esac
done done
command="$1" arg_command="$1"
shift shift
case "$command" in case "$arg_command" in
add|merge|pull) add|merge|pull)
default= default=
;; ;;
@ -157,31 +157,31 @@ main () {
default="--default HEAD" default="--default HEAD"
;; ;;
*) *)
die "Unknown command '$command'" die "Unknown command '$arg_command'"
;; ;;
esac esac
if test -z "$prefix" if test -z "$arg_prefix"
then then
die "You must provide the --prefix option." die "You must provide the --prefix option."
fi fi
case "$command" in case "$arg_command" in
add) add)
test -e "$prefix" && test -e "$arg_prefix" &&
die "prefix '$prefix' already exists." die "prefix '$arg_prefix' already exists."
;; ;;
*) *)
test -e "$prefix" || test -e "$arg_prefix" ||
die "'$prefix' does not exist; use 'git subtree add'" die "'$arg_prefix' does not exist; use 'git subtree add'"
;; ;;
esac esac
dir="$(dirname "$prefix/.")" dir="$(dirname "$arg_prefix/.")"
if test "$command" != "pull" && if test "$arg_command" != "pull" &&
test "$command" != "add" && test "$arg_command" != "add" &&
test "$command" != "push" test "$arg_command" != "push"
then then
revs=$(git rev-parse $default --revs-only "$@") || exit $? revs=$(git rev-parse $default --revs-only "$@") || exit $?
dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $? dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $?
@ -192,14 +192,14 @@ main () {
fi fi
fi fi
debug "command: {$command}" debug "command: {$arg_command}"
debug "quiet: {$GIT_QUIET}" debug "quiet: {$GIT_QUIET}"
debug "revs: {$revs}" debug "revs: {$revs}"
debug "dir: {$dir}" debug "dir: {$dir}"
debug "opts: {$*}" debug "opts: {$*}"
debug debug
"cmd_$command" "$@" "cmd_$arg_command" "$@"
} }
cache_setup () { cache_setup () {
@ -333,7 +333,7 @@ find_existing_splits () {
main= main=
sub= sub=
local grep_format="^git-subtree-dir: $dir/*\$" local grep_format="^git-subtree-dir: $dir/*\$"
if test -n "$ignore_joins" if test -n "$arg_split_ignore_joins"
then then
grep_format="^Add '$dir/' from commit '" grep_format="^Add '$dir/' from commit '"
fi fi
@ -394,7 +394,7 @@ copy_commit () {
GIT_COMMITTER_EMAIL \ GIT_COMMITTER_EMAIL \
GIT_COMMITTER_DATE GIT_COMMITTER_DATE
( (
printf "%s" "$annotate" printf "%s" "$arg_split_annotate"
cat cat
) | ) |
git commit-tree "$2" $3 # reads the rest of stdin git commit-tree "$2" $3 # reads the rest of stdin
@ -405,9 +405,9 @@ add_msg () {
dir="$1" dir="$1"
latest_old="$2" latest_old="$2"
latest_new="$3" latest_new="$3"
if test -n "$message" if test -n "$arg_addmerge_message"
then then
commit_message="$message" commit_message="$arg_addmerge_message"
else else
commit_message="Add '$dir/' from commit '$latest_new'" commit_message="Add '$dir/' from commit '$latest_new'"
fi fi
@ -421,9 +421,9 @@ add_msg () {
} }
add_squashed_msg () { add_squashed_msg () {
if test -n "$message" if test -n "$arg_addmerge_message"
then then
echo "$message" echo "$arg_addmerge_message"
else else
echo "Merge commit '$1' as '$2'" echo "Merge commit '$1' as '$2'"
fi fi
@ -433,9 +433,9 @@ rejoin_msg () {
dir="$1" dir="$1"
latest_old="$2" latest_old="$2"
latest_new="$3" latest_new="$3"
if test -n "$message" if test -n "$arg_addmerge_message"
then then
commit_message="$message" commit_message="$arg_addmerge_message"
else else
commit_message="Split '$dir/' into commit '$latest_new'" commit_message="Split '$dir/' into commit '$latest_new'"
fi fi
@ -722,7 +722,7 @@ cmd_add_commit () {
headp= headp=
fi fi
if test -n "$squash" if test -n "$arg_addmerge_squash"
then then
rev=$(new_squash_commit "" "" "$rev") || exit $? rev=$(new_squash_commit "" "" "$rev") || exit $?
commit=$(add_squashed_msg "$rev" "$dir" | commit=$(add_squashed_msg "$rev" "$dir" |
@ -741,10 +741,10 @@ cmd_split () {
debug "Splitting $dir..." debug "Splitting $dir..."
cache_setup || exit $? cache_setup || exit $?
if test -n "$onto" if test -n "$arg_split_onto"
then then
debug "Reading history for --onto=$onto..." debug "Reading history for --onto=$arg_split_onto..."
git rev-list $onto | git rev-list $arg_split_onto |
while read rev while read rev
do do
# the 'onto' history is already just the subdir, so # the 'onto' history is already just the subdir, so
@ -776,7 +776,7 @@ cmd_split () {
die "No new revisions were found" die "No new revisions were found"
fi fi
if test -n "$rejoin" if test -n "$arg_split_rejoin"
then then
debug "Merging split branch into HEAD..." debug "Merging split branch into HEAD..."
latest_old=$(cache_get latest_old) || exit $? latest_old=$(cache_get latest_old) || exit $?
@ -785,21 +785,21 @@ cmd_split () {
-m "$(rejoin_msg "$dir" "$latest_old" "$latest_new")" \ -m "$(rejoin_msg "$dir" "$latest_old" "$latest_new")" \
"$latest_new" >&2 || exit $? "$latest_new" >&2 || exit $?
fi fi
if test -n "$branch" if test -n "$arg_split_branch"
then then
if rev_exists "refs/heads/$branch" if rev_exists "refs/heads/$arg_split_branch"
then then
if ! git merge-base --is-ancestor "$branch" "$latest_new" if ! git merge-base --is-ancestor "$arg_split_branch" "$latest_new"
then then
die "Branch '$branch' is not an ancestor of commit '$latest_new'." die "Branch '$arg_split_branch' is not an ancestor of commit '$latest_new'."
fi fi
action='Updated' action='Updated'
else else
action='Created' action='Created'
fi fi
git update-ref -m 'subtree split' \ git update-ref -m 'subtree split' \
"refs/heads/$branch" "$latest_new" || exit $? "refs/heads/$arg_split_branch" "$latest_new" || exit $?
say >&2 "$action branch '$branch'" say >&2 "$action branch '$arg_split_branch'"
fi fi
echo "$latest_new" echo "$latest_new"
exit 0 exit 0
@ -810,7 +810,7 @@ cmd_merge () {
ensure_single_rev $rev ensure_single_rev $rev
ensure_clean ensure_clean
if test -n "$squash" if test -n "$arg_addmerge_squash"
then then
first_split="$(find_latest_squash "$dir")" || exit $? first_split="$(find_latest_squash "$dir")" || exit $?
if test -z "$first_split" if test -z "$first_split"
@ -830,12 +830,12 @@ cmd_merge () {
rev="$new" rev="$new"
fi fi
if test -n "$message" if test -n "$arg_addmerge_message"
then then
git merge -Xsubtree="$prefix" \ git merge -Xsubtree="$arg_prefix" \
--message="$message" "$rev" --message="$arg_addmerge_message" "$rev"
else else
git merge -Xsubtree="$prefix" $rev git merge -Xsubtree="$arg_prefix" $rev
fi fi
} }
@ -863,7 +863,7 @@ cmd_push () {
repository=$1 repository=$1
refspec=$2 refspec=$2
echo "git push using: " "$repository" "$refspec" echo "git push using: " "$repository" "$refspec"
localrev=$(git subtree split --prefix="$prefix") || die localrev=$(git subtree split --prefix="$arg_prefix") || die
git push "$repository" "$localrev":"refs/heads/$refspec" git push "$repository" "$localrev":"refs/heads/$refspec"
else else
die "'$dir' must already exist. Try 'git subtree add'." die "'$dir' must already exist. Try 'git subtree add'."