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>
Luke Shumaker committed
Apr 27, 2021 at 15:17 UTC
e2b11e42110f3c7082b4a5547eb535b0be6153e5
1 file changed
+66
-66
contrib/subtree/git-subtree.sh
+66
-66
@@ -30,19 +30,19 @@ squash merge subtree changes as a single commit
30
31
PATH=$PATH:$(git --exec-path)
32
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=
43
44
debug () {
45
- if test -n "$debug"
45
+ if test -n "$arg_debug"
46
then
47
printf "%s\n" "$*" >&2
48
fi
@@ -88,54 +88,54 @@ main () {
88
GIT_QUIET=1
89
;;
90
-d)
91
- debug=1
91
+ arg_debug=1
92
;;
93
--annotate)
94
- annotate="$1"
94
+ arg_split_annotate="$1"
95
shift
96
;;
97
--no-annotate)
98
- annotate=
98
+ arg_split_annotate=
99
;;
100
-b)
101
- branch="$1"
101
+ arg_split_branch="$1"
102
shift
103
;;
104
-P)
105
- prefix="${1%/}"
105
+ arg_prefix="${1%/}"
106
shift
107
;;
108
-m)
109
- message="$1"
109
+ arg_addmerge_message="$1"
110
shift
111
;;
112
--no-prefix)
113
- prefix=
113
+ arg_prefix=
114
;;
115
--onto)
116
- onto="$1"
116
+ arg_split_onto="$1"
117
shift
118
;;
119
--no-onto)
120
- onto=
120
+ arg_split_onto=
121
;;
122
--rejoin)
123
- rejoin=1
123
+ arg_split_rejoin=1
124
;;
125
--no-rejoin)
126
- rejoin=
126
+ arg_split_rejoin=
127
;;
128
--ignore-joins)
129
- ignore_joins=1
129
+ arg_split_ignore_joins=1
130
;;
131
--no-ignore-joins)
132
- ignore_joins=
132
+ arg_split_ignore_joins=
133
;;
134
--squash)
135
- squash=1
135
+ arg_addmerge_squash=1
136
;;
137
--no-squash)
138
- squash=
138
+ arg_addmerge_squash=
139
;;
140
--)
141
break
@@ -146,10 +146,10 @@ main () {
146
esac
147
done
148
149
- command="$1"
149
+ arg_command="$1"
150
shift
151
152
- case "$command" in
152
+ case "$arg_command" in
153
add|merge|pull)
154
default=
155
;;
@@ -157,31 +157,31 @@ main () {
157
default="--default HEAD"
158
;;
159
*)
160
- die "Unknown command '$command'"
160
+ die "Unknown command '$arg_command'"
161
;;
162
esac
163
164
- if test -z "$prefix"
164
+ if test -z "$arg_prefix"
165
then
166
die "You must provide the --prefix option."
167
fi
168
169
- case "$command" in
169
+ case "$arg_command" in
170
add)
171
- test -e "$prefix" &&
172
- die "prefix '$prefix' already exists."
171
+ test -e "$arg_prefix" &&
172
+ die "prefix '$arg_prefix' already exists."
173
;;
174
*)
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'"
177
;;
178
esac
179
180
- dir="$(dirname "$prefix/.")"
180
+ dir="$(dirname "$arg_prefix/.")"
181
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"
185
then
186
revs=$(git rev-parse $default --revs-only "$@") || exit $?
187
dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $?
@@ -192,14 +192,14 @@ main () {
192
fi
193
fi
194
195
- debug "command: {$command}"
195
+ debug "command: {$arg_command}"
196
debug "quiet: {$GIT_QUIET}"
197
debug "revs: {$revs}"
198
debug "dir: {$dir}"
199
debug "opts: {$*}"
200
debug
201
202
- "cmd_$command" "$@"
202
+ "cmd_$arg_command" "$@"
203
}
204
205
cache_setup () {
@@ -333,7 +333,7 @@ find_existing_splits () {
333
main=
334
sub=
335
local grep_format="^git-subtree-dir: $dir/*\$"
336
- if test -n "$ignore_joins"
336
+ if test -n "$arg_split_ignore_joins"
337
then
338
grep_format="^Add '$dir/' from commit '"
339
fi
@@ -394,7 +394,7 @@ copy_commit () {
394
GIT_COMMITTER_EMAIL \
395
GIT_COMMITTER_DATE
396
(
397
- printf "%s" "$annotate"
397
+ printf "%s" "$arg_split_annotate"
398
cat
399
) |
400
git commit-tree "$2" $3 # reads the rest of stdin
@@ -405,9 +405,9 @@ add_msg () {
405
dir="$1"
406
latest_old="$2"
407
latest_new="$3"
408
- if test -n "$message"
408
+ if test -n "$arg_addmerge_message"
409
then
410
- commit_message="$message"
410
+ commit_message="$arg_addmerge_message"
411
else
412
commit_message="Add '$dir/' from commit '$latest_new'"
413
fi
@@ -421,9 +421,9 @@ add_msg () {
421
}
422
423
add_squashed_msg () {
424
- if test -n "$message"
424
+ if test -n "$arg_addmerge_message"
425
then
426
- echo "$message"
426
+ echo "$arg_addmerge_message"
427
else
428
echo "Merge commit '$1' as '$2'"
429
fi
@@ -433,9 +433,9 @@ rejoin_msg () {
433
dir="$1"
434
latest_old="$2"
435
latest_new="$3"
436
- if test -n "$message"
436
+ if test -n "$arg_addmerge_message"
437
then
438
- commit_message="$message"
438
+ commit_message="$arg_addmerge_message"
439
else
440
commit_message="Split '$dir/' into commit '$latest_new'"
441
fi
@@ -722,7 +722,7 @@ cmd_add_commit () {
722
headp=
723
fi
724
725
- if test -n "$squash"
725
+ if test -n "$arg_addmerge_squash"
726
then
727
rev=$(new_squash_commit "" "" "$rev") || exit $?
728
commit=$(add_squashed_msg "$rev" "$dir" |
@@ -741,10 +741,10 @@ cmd_split () {
741
debug "Splitting $dir..."
742
cache_setup || exit $?
743
744
- if test -n "$onto"
744
+ if test -n "$arg_split_onto"
745
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 |
748
while read rev
749
do
750
# the 'onto' history is already just the subdir, so
@@ -776,7 +776,7 @@ cmd_split () {
776
die "No new revisions were found"
777
fi
778
779
- if test -n "$rejoin"
779
+ if test -n "$arg_split_rejoin"
780
then
781
debug "Merging split branch into HEAD..."
782
latest_old=$(cache_get latest_old) || exit $?
@@ -785,21 +785,21 @@ cmd_split () {
785
-m "$(rejoin_msg "$dir" "$latest_old" "$latest_new")" \
786
"$latest_new" >&2 || exit $?
787
fi
788
- if test -n "$branch"
788
+ if test -n "$arg_split_branch"
789
then
790
- if rev_exists "refs/heads/$branch"
790
+ if rev_exists "refs/heads/$arg_split_branch"
791
then
792
- if ! git merge-base --is-ancestor "$branch" "$latest_new"
792
+ if ! git merge-base --is-ancestor "$arg_split_branch" "$latest_new"
793
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'."
795
fi
796
action='Updated'
797
else
798
action='Created'
799
fi
800
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'"
803
fi
804
echo "$latest_new"
805
exit 0
@@ -810,7 +810,7 @@ cmd_merge () {
810
ensure_single_rev $rev
811
ensure_clean
812
813
- if test -n "$squash"
813
+ if test -n "$arg_addmerge_squash"
814
then
815
first_split="$(find_latest_squash "$dir")" || exit $?
816
if test -z "$first_split"
@@ -830,12 +830,12 @@ cmd_merge () {
830
rev="$new"
831
fi
832
833
- if test -n "$message"
833
+ if test -n "$arg_addmerge_message"
834
then
835
- git merge -Xsubtree="$prefix" \
836
- --message="$message" "$rev"
835
+ git merge -Xsubtree="$arg_prefix" \
836
+ --message="$arg_addmerge_message" "$rev"
837
else
838
- git merge -Xsubtree="$prefix" $rev
838
+ git merge -Xsubtree="$arg_prefix" $rev
839
fi
840
}
841
@@ -863,7 +863,7 @@ cmd_push () {
863
repository=$1
864
refspec=$2
865
echo "git push using: " "$repository" "$refspec"
866
- localrev=$(git subtree split --prefix="$prefix") || die
866
+ localrev=$(git subtree split --prefix="$arg_prefix") || die
867
git push "$repository" "$localrev":"refs/heads/$refspec"
868
else
869
die "'$dir' must already exist. Try 'git subtree add'."