]> git.ipfire.org Git - thirdparty/git.git/commitdiff
contrib/subtree: convert subtree type check to use case statement
authorPatrick Steinhardt <ps@pks.im>
Fri, 10 Nov 2023 10:01:24 +0000 (11:01 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 11 Nov 2023 00:21:00 +0000 (09:21 +0900)
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>
contrib/subtree/git-subtree.sh

index 8af0a81ba3fc64eb112ed557b7aaee8bb265c7d4..3028029ac2ddf67608dad1f6538b37a347aebe29 100755 (executable)
@@ -641,10 +641,16 @@ subtree_for_commit () {
        while read mode type tree name
        do
                assert test "$name" = "$dir"
-               assert test "$type" = "tree" -o "$type" = "commit"
-               test "$type" = "commit" && continue  # ignore submodules
-               echo $tree
-               break
+
+               case "$type" in
+               commit)
+                       continue;; # ignore submodules
+               tree)
+                       echo $tree
+                       break;;
+               *)
+                       die "fatal: tree entry is of type ${type}, expected tree or commit";;
+               esac
        done || exit $?
 }