@@ -55,20 +55,23 @@ arg_split_annotate=
5555arg_addmerge_squash=
5656arg_addmerge_message=
5757
58+ # Usage: debug [MSG...]
5859debug () {
5960 if test -n " $arg_debug "
6061 then
6162 printf " %s\n" " $* " >&2
6263 fi
6364}
6465
66+ # Usage: progress [MSG...]
6567progress () {
6668 if test -z " $GIT_QUIET "
6769 then
6870 printf " %s\r" " $* " >&2
6971 fi
7072}
7173
74+ # Usage: assert CMD...
7275assert () {
7376 if ! " $@ "
7477 then
@@ -192,7 +195,9 @@ main () {
192195 " cmd_$arg_command " " $@ "
193196}
194197
198+ # Usage: cache_setup
195199cache_setup () {
200+ assert test $# = 0
196201 cachedir=" $GIT_DIR /subtree-cache/$$ "
197202 rm -rf " $cachedir " ||
198203 die " Can't delete old cachedir: $cachedir "
@@ -203,6 +208,7 @@ cache_setup () {
203208 debug " Using cachedir: $cachedir " >&2
204209}
205210
211+ # Usage: cache_get [REVS...]
206212cache_get () {
207213 for oldrev in " $@ "
208214 do
@@ -214,6 +220,7 @@ cache_get () {
214220 done
215221}
216222
223+ # Usage: cache_miss [REVS...]
217224cache_miss () {
218225 for oldrev in " $@ "
219226 do
@@ -224,7 +231,9 @@ cache_miss () {
224231 done
225232}
226233
234+ # Usage: check_parents PARENTS_EXPR INDENT
227235check_parents () {
236+ assert test $# = 2
228237 missed=$( cache_miss " $1 " ) || exit $?
229238 local indent=$(( $2 + 1 ))
230239 for miss in $missed
@@ -237,11 +246,15 @@ check_parents () {
237246 done
238247}
239248
249+ # Usage: set_notree REV
240250set_notree () {
251+ assert test $# = 1
241252 echo " 1" > " $cachedir /notree/$1 "
242253}
243254
255+ # Usage: cache_set OLDREV NEWREV
244256cache_set () {
257+ assert test $# = 2
245258 oldrev=" $1 "
246259 newrev=" $2 "
247260 if test " $oldrev " ! = " latest_old" &&
@@ -253,7 +266,9 @@ cache_set () {
253266 echo " $newrev " > " $cachedir /$oldrev "
254267}
255268
269+ # Usage: rev_exists REV
256270rev_exists () {
271+ assert test $# = 1
257272 if git rev-parse " $1 " > /dev/null 2>&1
258273 then
259274 return 0
@@ -262,17 +277,22 @@ rev_exists () {
262277 fi
263278}
264279
265- # if a commit doesn't have a parent, this might not work. But we only want
280+ # Usage: try_remove_previous REV
281+ #
282+ # If a commit doesn't have a parent, this might not work. But we only want
266283# to remove the parent from the rev-list, and since it doesn't exist, it won't
267284# be there anyway, so do nothing in that case.
268285try_remove_previous () {
286+ assert test $# = 1
269287 if rev_exists " $1 ^"
270288 then
271289 echo " ^$1 ^"
272290 fi
273291}
274292
293+ # Usage: find_latest_squash DIR
275294find_latest_squash () {
295+ assert test $# = 1
276296 debug " Looking for latest squash ($dir )..."
277297 dir=" $1 "
278298 sq=
@@ -316,10 +336,12 @@ find_latest_squash () {
316336 done || exit $?
317337}
318338
339+ # Usage: find_existing_splits DIR REV
319340find_existing_splits () {
341+ assert test $# = 2
320342 debug " Looking for prior splits..."
321343 dir=" $1 "
322- revs =" $2 "
344+ rev =" $2 "
323345 main=
324346 sub=
325347 local grep_format=" ^git-subtree-dir: $dir /*\$ "
@@ -328,7 +350,7 @@ find_existing_splits () {
328350 grep_format=" ^Add '$dir /' from commit '"
329351 fi
330352 git log --grep=" $grep_format " \
331- --no-show-signature --pretty=format:' START %H%n%s%n%n%b%nEND%n' $revs |
353+ --no-show-signature --pretty=format:' START %H%n%s%n%n%b%nEND%n' " $rev " |
332354 while read a b junk
333355 do
334356 case " $a " in
@@ -365,7 +387,9 @@ find_existing_splits () {
365387 done || exit $?
366388}
367389
390+ # Usage: copy_commit REV TREE FLAGS_STR
368391copy_commit () {
392+ assert test $# = 3
369393 # We're going to set some environment vars here, so
370394 # do it in a subshell to get rid of them safely later
371395 debug copy_commit " {$1 }" " {$2 }" " {$3 }"
@@ -391,7 +415,9 @@ copy_commit () {
391415 ) || die " Can't copy commit $1 "
392416}
393417
418+ # Usage: add_msg DIR LATEST_OLD LATEST_NEW
394419add_msg () {
420+ assert test $# = 3
395421 dir=" $1 "
396422 latest_old=" $2 "
397423 latest_new=" $3 "
@@ -410,7 +436,9 @@ add_msg () {
410436 EOF
411437}
412438
439+ # Usage: add_squashed_msg REV DIR
413440add_squashed_msg () {
441+ assert test $# = 2
414442 if test -n " $arg_addmerge_message "
415443 then
416444 echo " $arg_addmerge_message "
@@ -419,7 +447,9 @@ add_squashed_msg () {
419447 fi
420448}
421449
450+ # Usage: rejoin_msg DIR LATEST_OLD LATEST_NEW
422451rejoin_msg () {
452+ assert test $# = 3
423453 dir=" $1 "
424454 latest_old=" $2 "
425455 latest_new=" $3 "
@@ -438,7 +468,9 @@ rejoin_msg () {
438468 EOF
439469}
440470
471+ # Usage: squash_msg DIR OLD_SUBTREE_COMMIT NEW_SUBTREE_COMMIT
441472squash_msg () {
473+ assert test $# = 3
442474 dir=" $1 "
443475 oldsub=" $2 "
444476 newsub=" $3 "
@@ -460,12 +492,16 @@ squash_msg () {
460492 echo " git-subtree-split: $newsub "
461493}
462494
495+ # Usage: toptree_for_commit COMMIT
463496toptree_for_commit () {
497+ assert test $# = 1
464498 commit=" $1 "
465499 git rev-parse --verify " $commit ^{tree}" || exit $?
466500}
467501
502+ # Usage: subtree_for_commit COMMIT DIR
468503subtree_for_commit () {
504+ assert test $# = 2
469505 commit=" $1 "
470506 dir=" $2 "
471507 git ls-tree " $commit " -- " $dir " |
@@ -479,7 +515,9 @@ subtree_for_commit () {
479515 done || exit $?
480516}
481517
518+ # Usage: tree_changed TREE [PARENTS...]
482519tree_changed () {
520+ assert test $# -gt 0
483521 tree=$1
484522 shift
485523 if test $# -ne 1
@@ -496,7 +534,9 @@ tree_changed () {
496534 fi
497535}
498536
537+ # Usage: new_squash_commit OLD_SQUASHED_COMMIT OLD_NONSQUASHED_COMMIT NEW_NONSQUASHED_COMMIT
499538new_squash_commit () {
539+ assert test $# = 3
500540 old=" $1 "
501541 oldsub=" $2 "
502542 newsub=" $3 "
@@ -511,7 +551,9 @@ new_squash_commit () {
511551 fi
512552}
513553
554+ # Usage: copy_or_skip REV TREE NEWPARENTS
514555copy_or_skip () {
556+ assert test $# = 3
515557 rev=" $1 "
516558 tree=" $2 "
517559 newparents=" $3 "
@@ -586,7 +628,9 @@ copy_or_skip () {
586628 fi
587629}
588630
631+ # Usage: ensure_clean
589632ensure_clean () {
633+ assert test $# = 0
590634 if ! git diff-index HEAD --exit-code --quiet 2>&1
591635 then
592636 die " Working tree has modifications. Cannot add."
@@ -597,12 +641,16 @@ ensure_clean () {
597641 fi
598642}
599643
644+ # Usage: ensure_valid_ref_format REF
600645ensure_valid_ref_format () {
646+ assert test $# = 1
601647 git check-ref-format " refs/heads/$1 " ||
602648 die " '$1 ' does not look like a ref"
603649}
604650
651+ # Usage: process_split_commit REV PARENTS INDENT
605652process_split_commit () {
653+ assert test $# = 3
606654 local rev=" $1 "
607655 local parents=" $2 "
608656 local indent=$3
@@ -654,6 +702,8 @@ process_split_commit () {
654702 cache_set latest_old " $rev "
655703}
656704
705+ # Usage: cmd_add REV
706+ # Or: cmd_add REPOSITORY REF
657707cmd_add () {
658708
659709 ensure_clean
@@ -681,17 +731,21 @@ cmd_add () {
681731 fi
682732}
683733
734+ # Usage: cmd_add_repository REPOSITORY REFSPEC
684735cmd_add_repository () {
736+ assert test $# = 2
685737 echo " git fetch" " $@ "
686738 repository=$1
687739 refspec=$2
688740 git fetch " $@ " || exit $?
689741 cmd_add_commit FETCH_HEAD
690742}
691743
744+ # Usage: cmd_add_commit REV
692745cmd_add_commit () {
693746 # The rev has already been validated by cmd_add(), we just
694747 # need to normalize it.
748+ assert test $# = 1
695749 rev=$( git rev-parse --verify " $1 ^{commit}" ) || exit $?
696750
697751 debug " Adding $dir as '$rev '..."
@@ -722,6 +776,7 @@ cmd_add_commit () {
722776 say >&2 " Added dir '$dir '"
723777}
724778
779+ # Usage: cmd_split [REV]
725780cmd_split () {
726781 if test $# -eq 0
727782 then
@@ -801,6 +856,7 @@ cmd_split () {
801856 exit 0
802857}
803858
859+ # Usage: cmd_merge REV
804860cmd_merge () {
805861 test $# -eq 1 ||
806862 die " You must provide exactly one revision. Got: '$* '"
@@ -837,6 +893,7 @@ cmd_merge () {
837893 fi
838894}
839895
896+ # Usage: cmd_pull REPOSITORY REMOTEREF
840897cmd_pull () {
841898 if test $# -ne 2
842899 then
@@ -848,6 +905,7 @@ cmd_pull () {
848905 cmd_merge FETCH_HEAD
849906}
850907
908+ # Usage: cmd_push REPOSITORY REMOTEREF
851909cmd_push () {
852910 if test $# -ne 2
853911 then
0 commit comments