@matheusbsbs / matheus-bagliano / commits / 980ea5c5bb
Fork 0

Teach git-tag about showing tag annotations.

The <pattern> for -l is now a shell pattern, not a list of grep parameters. Option -l may be repeated with another <pattern>. The new -n [<num>] option specifies how many lines from the annotation are to be printed. Not specifieing -n or -n 0 will just produce the tag names Just -n or -n 1 will show the first line of the annotation on the tag line. Other valuse for -n will show that number of lines from the annotation. The exit code used to indicate if any tag was found. This is changed due to a different implementation. A good way to test a tag for existence is to use: git show-ref --quiet --verify refs/tags/$TAGNAME Signed-off-by: Matthijs Melchior <mmelchior@xs4all.nl> Signed-off-by: Junio C Hamano <junkio@cox.net>

Matthijs Melchior committed Jun 3, 2007 at 02:05 UTC 980ea5c5bb1dfbbf93b919942c703b9158c35968
2 files changed +46 -11
Documentation/git-tag.txt
+9 -4
@@ -11,7 +11,7 @@ SYNOPSIS
11 [verse]
12 'git-tag' [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] <name> [<head>]
13 'git-tag' -d <name>...
14 -'git-tag' -l [<pattern>]
14 +'git-tag' [-n [<num>]] -l [<pattern>]
15 'git-tag' -v <name>
16
17 DESCRIPTION
@@ -38,8 +38,8 @@ GnuPG key for signing.
38
39 `-v <tag>` verifies the gpg signature of the tag.
40
41 -`-l <pattern>` lists tags that match the given pattern (or all
42 -if no pattern is given).
41 +`-l <pattern>` lists tags with names that match the given pattern
42 +(or all if no pattern is given).
43
44 OPTIONS
45 -------
@@ -61,8 +61,13 @@ OPTIONS
61 -v::
62 Verify the gpg signature of given the tag
63
64 +-n <num>::
65 + <num> specifies how many lines from the annotation, if any,
66 + are printed when using -l.
67 + The default is not to print any annotation lines.
68 +
69 -l <pattern>::
65 - List tags that match the given pattern (or all if no pattern is given).
70 + List tags with names that match the given pattern (or all if no pattern is given).
71
72 -m <msg>::
73 Use the given tag message (instead of prompting)
git-tag.sh
+37 -7
@@ -1,7 +1,7 @@
1 #!/bin/sh
2 # Copyright (c) 2005 Linus Torvalds
3
4 -USAGE='-l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]'
4 +USAGE='[-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]'
5 SUBDIRECTORY_OK='Yes'
6 . git-sh-setup
7
@@ -13,6 +13,7 @@ message=
13 username=
14 list=
15 verify=
16 +LINES=0
17 while case "$#" in 0) break ;; esac
18 do
19 case "$1" in
@@ -26,14 +27,41 @@ do
27 -f)
28 force=1
29 ;;
29 - -l)
30 - case "$#" in
31 - 1)
32 - set x . ;;
30 + -n)
31 + case $2 in
32 + -*) LINES=1 # no argument
33 + ;;
34 + *) shift
35 + LINES=$(expr "$1" : '\([0-9]*\)')
36 + [ -z "$LINES" ] && LINES=1 # 1 line is default when -n is used
37 + ;;
38 esac
39 + ;;
40 + -l)
41 + list=1
42 shift
35 - git rev-parse --symbolic --tags | sort | grep "$@"
36 - exit $?
43 + PATTERN="$1" # select tags by shell pattern, not re
44 + git rev-parse --symbolic --tags | sort |
45 + while read TAG
46 + do
47 + case "$TAG" in
48 + *$PATTERN*) ;;
49 + *) continue ;;
50 + esac
51 + [ "$LINES" -le 0 ] && { echo "$TAG"; continue ;}
52 + OBJTYPE=$(git cat-file -t "$TAG")
53 + case $OBJTYPE in
54 + tag) ANNOTATION=$(git cat-file tag "$TAG" |
55 + sed -e '1,/^$/d' \
56 + -e '/^-----BEGIN PGP SIGNATURE-----$/Q' )
57 + printf "%-15s %s\n" "$TAG" "$ANNOTATION" |
58 + sed -e '2,$s/^/ /' \
59 + -e "${LINES}q"
60 + ;;
61 + *) echo "$TAG"
62 + ;;
63 + esac
64 + done
65 ;;
66 -m)
67 annotate=1
@@ -97,6 +125,8 @@ do
125 shift
126 done
127
128 +[ -n "$list" ] && exit 0
129 +
130 name="$1"
131 [ "$name" ] || usage
132 prev=0000000000000000000000000000000000000000