Skip to content

Commit e2b11e4

Browse files
LukeShugitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6d43585 commit e2b11e4

File tree

1 file changed

+66
-66
lines changed

1 file changed

+66
-66
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ squash merge subtree changes as a single commit
3030

3131
PATH=$PATH:$(git --exec-path)
3232

33-
branch=
34-
debug=
35-
command=
36-
onto=
37-
rejoin=
38-
ignore_joins=
39-
annotate=
40-
squash=
41-
message=
42-
prefix=
33+
arg_debug=
34+
arg_command=
35+
arg_prefix=
36+
arg_split_branch=
37+
arg_split_onto=
38+
arg_split_rejoin=
39+
arg_split_ignore_joins=
40+
arg_split_annotate=
41+
arg_addmerge_squash=
42+
arg_addmerge_message=
4343

4444
debug () {
45-
if test -n "$debug"
45+
if test -n "$arg_debug"
4646
then
4747
printf "%s\n" "$*" >&2
4848
fi
@@ -88,54 +88,54 @@ main () {
8888
GIT_QUIET=1
8989
;;
9090
-d)
91-
debug=1
91+
arg_debug=1
9292
;;
9393
--annotate)
94-
annotate="$1"
94+
arg_split_annotate="$1"
9595
shift
9696
;;
9797
--no-annotate)
98-
annotate=
98+
arg_split_annotate=
9999
;;
100100
-b)
101-
branch="$1"
101+
arg_split_branch="$1"
102102
shift
103103
;;
104104
-P)
105-
prefix="${1%/}"
105+
arg_prefix="${1%/}"
106106
shift
107107
;;
108108
-m)
109-
message="$1"
109+
arg_addmerge_message="$1"
110110
shift
111111
;;
112112
--no-prefix)
113-
prefix=
113+
arg_prefix=
114114
;;
115115
--onto)
116-
onto="$1"
116+
arg_split_onto="$1"
117117
shift
118118
;;
119119
--no-onto)
120-
onto=
120+
arg_split_onto=
121121
;;
122122
--rejoin)
123-
rejoin=1
123+
arg_split_rejoin=1
124124
;;
125125
--no-rejoin)
126-
rejoin=
126+
arg_split_rejoin=
127127
;;
128128
--ignore-joins)
129-
ignore_joins=1
129+
arg_split_ignore_joins=1
130130
;;
131131
--no-ignore-joins)
132-
ignore_joins=
132+
arg_split_ignore_joins=
133133
;;
134134
--squash)
135-
squash=1
135+
arg_addmerge_squash=1
136136
;;
137137
--no-squash)
138-
squash=
138+
arg_addmerge_squash=
139139
;;
140140
--)
141141
break
@@ -146,42 +146,42 @@ main () {
146146
esac
147147
done
148148

149-
command="$1"
149+
arg_command="$1"
150150
shift
151151

152-
case "$command" in
152+
case "$arg_command" in
153153
add|merge|pull)
154154
default=
155155
;;
156156
split|push)
157157
default="--default HEAD"
158158
;;
159159
*)
160-
die "Unknown command '$command'"
160+
die "Unknown command '$arg_command'"
161161
;;
162162
esac
163163

164-
if test -z "$prefix"
164+
if test -z "$arg_prefix"
165165
then
166166
die "You must provide the --prefix option."
167167
fi
168168

169-
case "$command" in
169+
case "$arg_command" in
170170
add)
171-
test -e "$prefix" &&
172-
die "prefix '$prefix' already exists."
171+
test -e "$arg_prefix" &&
172+
die "prefix '$arg_prefix' already exists."
173173
;;
174174
*)
175-
test -e "$prefix" ||
176-
die "'$prefix' does not exist; use 'git subtree add'"
175+
test -e "$arg_prefix" ||
176+
die "'$arg_prefix' does not exist; use 'git subtree add'"
177177
;;
178178
esac
179179

180-
dir="$(dirname "$prefix/.")"
180+
dir="$(dirname "$arg_prefix/.")"
181181

182-
if test "$command" != "pull" &&
183-
test "$command" != "add" &&
184-
test "$command" != "push"
182+
if test "$arg_command" != "pull" &&
183+
test "$arg_command" != "add" &&
184+
test "$arg_command" != "push"
185185
then
186186
revs=$(git rev-parse $default --revs-only "$@") || exit $?
187187
dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $?
@@ -192,14 +192,14 @@ main () {
192192
fi
193193
fi
194194

195-
debug "command: {$command}"
195+
debug "command: {$arg_command}"
196196
debug "quiet: {$GIT_QUIET}"
197197
debug "revs: {$revs}"
198198
debug "dir: {$dir}"
199199
debug "opts: {$*}"
200200
debug
201201

202-
"cmd_$command" "$@"
202+
"cmd_$arg_command" "$@"
203203
}
204204

205205
cache_setup () {
@@ -333,7 +333,7 @@ find_existing_splits () {
333333
main=
334334
sub=
335335
local grep_format="^git-subtree-dir: $dir/*\$"
336-
if test -n "$ignore_joins"
336+
if test -n "$arg_split_ignore_joins"
337337
then
338338
grep_format="^Add '$dir/' from commit '"
339339
fi
@@ -394,7 +394,7 @@ copy_commit () {
394394
GIT_COMMITTER_EMAIL \
395395
GIT_COMMITTER_DATE
396396
(
397-
printf "%s" "$annotate"
397+
printf "%s" "$arg_split_annotate"
398398
cat
399399
) |
400400
git commit-tree "$2" $3 # reads the rest of stdin
@@ -405,9 +405,9 @@ add_msg () {
405405
dir="$1"
406406
latest_old="$2"
407407
latest_new="$3"
408-
if test -n "$message"
408+
if test -n "$arg_addmerge_message"
409409
then
410-
commit_message="$message"
410+
commit_message="$arg_addmerge_message"
411411
else
412412
commit_message="Add '$dir/' from commit '$latest_new'"
413413
fi
@@ -421,9 +421,9 @@ add_msg () {
421421
}
422422

423423
add_squashed_msg () {
424-
if test -n "$message"
424+
if test -n "$arg_addmerge_message"
425425
then
426-
echo "$message"
426+
echo "$arg_addmerge_message"
427427
else
428428
echo "Merge commit '$1' as '$2'"
429429
fi
@@ -433,9 +433,9 @@ rejoin_msg () {
433433
dir="$1"
434434
latest_old="$2"
435435
latest_new="$3"
436-
if test -n "$message"
436+
if test -n "$arg_addmerge_message"
437437
then
438-
commit_message="$message"
438+
commit_message="$arg_addmerge_message"
439439
else
440440
commit_message="Split '$dir/' into commit '$latest_new'"
441441
fi
@@ -722,7 +722,7 @@ cmd_add_commit () {
722722
headp=
723723
fi
724724

725-
if test -n "$squash"
725+
if test -n "$arg_addmerge_squash"
726726
then
727727
rev=$(new_squash_commit "" "" "$rev") || exit $?
728728
commit=$(add_squashed_msg "$rev" "$dir" |
@@ -741,10 +741,10 @@ cmd_split () {
741741
debug "Splitting $dir..."
742742
cache_setup || exit $?
743743

744-
if test -n "$onto"
744+
if test -n "$arg_split_onto"
745745
then
746-
debug "Reading history for --onto=$onto..."
747-
git rev-list $onto |
746+
debug "Reading history for --onto=$arg_split_onto..."
747+
git rev-list $arg_split_onto |
748748
while read rev
749749
do
750750
# the 'onto' history is already just the subdir, so
@@ -776,7 +776,7 @@ cmd_split () {
776776
die "No new revisions were found"
777777
fi
778778

779-
if test -n "$rejoin"
779+
if test -n "$arg_split_rejoin"
780780
then
781781
debug "Merging split branch into HEAD..."
782782
latest_old=$(cache_get latest_old) || exit $?
@@ -785,21 +785,21 @@ cmd_split () {
785785
-m "$(rejoin_msg "$dir" "$latest_old" "$latest_new")" \
786786
"$latest_new" >&2 || exit $?
787787
fi
788-
if test -n "$branch"
788+
if test -n "$arg_split_branch"
789789
then
790-
if rev_exists "refs/heads/$branch"
790+
if rev_exists "refs/heads/$arg_split_branch"
791791
then
792-
if ! git merge-base --is-ancestor "$branch" "$latest_new"
792+
if ! git merge-base --is-ancestor "$arg_split_branch" "$latest_new"
793793
then
794-
die "Branch '$branch' is not an ancestor of commit '$latest_new'."
794+
die "Branch '$arg_split_branch' is not an ancestor of commit '$latest_new'."
795795
fi
796796
action='Updated'
797797
else
798798
action='Created'
799799
fi
800800
git update-ref -m 'subtree split' \
801-
"refs/heads/$branch" "$latest_new" || exit $?
802-
say >&2 "$action branch '$branch'"
801+
"refs/heads/$arg_split_branch" "$latest_new" || exit $?
802+
say >&2 "$action branch '$arg_split_branch'"
803803
fi
804804
echo "$latest_new"
805805
exit 0
@@ -810,7 +810,7 @@ cmd_merge () {
810810
ensure_single_rev $rev
811811
ensure_clean
812812

813-
if test -n "$squash"
813+
if test -n "$arg_addmerge_squash"
814814
then
815815
first_split="$(find_latest_squash "$dir")" || exit $?
816816
if test -z "$first_split"
@@ -830,12 +830,12 @@ cmd_merge () {
830830
rev="$new"
831831
fi
832832

833-
if test -n "$message"
833+
if test -n "$arg_addmerge_message"
834834
then
835-
git merge -Xsubtree="$prefix" \
836-
--message="$message" "$rev"
835+
git merge -Xsubtree="$arg_prefix" \
836+
--message="$arg_addmerge_message" "$rev"
837837
else
838-
git merge -Xsubtree="$prefix" $rev
838+
git merge -Xsubtree="$arg_prefix" $rev
839839
fi
840840
}
841841

@@ -863,7 +863,7 @@ cmd_push () {
863863
repository=$1
864864
refspec=$2
865865
echo "git push using: " "$repository" "$refspec"
866-
localrev=$(git subtree split --prefix="$prefix") || die
866+
localrev=$(git subtree split --prefix="$arg_prefix") || die
867867
git push "$repository" "$localrev":"refs/heads/$refspec"
868868
else
869869
die "'$dir' must already exist. Try 'git subtree add'."

0 commit comments

Comments
 (0)