git/contrib/examples/git-verify-tag.sh
David Kastrup 822f7c7349 Supplant the "while case ... break ;; esac" idiom
A lot of shell scripts contained stuff starting with

	while case "$#" in 0) break ;; esac

and similar.  I consider breaking out of the condition instead of the
body od the loop ugly, and the implied "true" value of the
non-matching case is not really obvious to humans at first glance.  It
happens not to be obvious to some BSD shells, either, but that's
because they are not POSIX-compliant.  In most cases, this has been
replaced by a straight condition using "test".  "case" has the
advantage of being faster than "test" on vintage shells where "test"
is not a builtin.  Since none of them is likely to run the git
scripts, anyway, the added readability should be worth the change.

A few loops have had their termination condition expressed
differently.

Signed-off-by: David Kastrup <dak@gnu.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-09-23 16:12:00 -07:00

46 lines
749 B
Bash
Executable file

#!/bin/sh
USAGE='<tag>'
SUBDIRECTORY_OK='Yes'
. git-sh-setup
verbose=
while test $# != 0
do
case "$1" in
-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
verbose=t ;;
*)
break ;;
esac
shift
done
if [ "$#" != "1" ]
then
usage
fi
type="$(git cat-file -t "$1" 2>/dev/null)" ||
die "$1: no such object."
test "$type" = tag ||
die "$1: cannot verify a non-tag object of type $type."
case "$verbose" in
t)
git cat-file -p "$1" |
sed -n -e '/^-----BEGIN PGP SIGNATURE-----/q' -e p
;;
esac
trap 'rm -f "$GIT_DIR/.tmp-vtag"' 0
git cat-file tag "$1" >"$GIT_DIR/.tmp-vtag" || exit 1
sed -n -e '
/^-----BEGIN PGP SIGNATURE-----$/q
p
' <"$GIT_DIR/.tmp-vtag" |
gpg --verify "$GIT_DIR/.tmp-vtag" - || exit 1
rm -f "$GIT_DIR/.tmp-vtag"