contrib/subtree: convert subtree type check to use case statement
The `subtree_for_commit ()` helper function asserts that the subtree identified by its parameters are either a commit or tree. This is done via the `-o` parameter of test, which is discouraged. Refactor the code to instead use a switch statement over the type. Despite being aligned with our coding guidelines, the resulting code is arguably also easier to read. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
88983946fa
commit
47c39c28bc
@ -641,10 +641,16 @@ subtree_for_commit () {
|
|||||||
while read mode type tree name
|
while read mode type tree name
|
||||||
do
|
do
|
||||||
assert test "$name" = "$dir"
|
assert test "$name" = "$dir"
|
||||||
assert test "$type" = "tree" -o "$type" = "commit"
|
|
||||||
test "$type" = "commit" && continue # ignore submodules
|
case "$type" in
|
||||||
echo $tree
|
commit)
|
||||||
break
|
continue;; # ignore submodules
|
||||||
|
tree)
|
||||||
|
echo $tree
|
||||||
|
break;;
|
||||||
|
*)
|
||||||
|
die "fatal: tree entry is of type ${type}, expected tree or commit";;
|
||||||
|
esac
|
||||||
done || exit $?
|
done || exit $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user