Code

Correct usages of sed in git-tag for Mac OS X
authorShawn O. Pearce <spearce@spearce.org>
Sat, 30 Jun 2007 06:42:47 +0000 (02:42 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sat, 30 Jun 2007 07:00:30 +0000 (00:00 -0700)
Both `git-tag -l` and `git tag -v` fail on Mac OS X due to their
non-standard uses of sed.  Actually `git tag -v` fails because the
underlying git-tag-verify uses a non-standard sed command.

We now stick to only standard sed, which does make our sed scripts
slightly more complicated, but we can actually list tags with more
than 0 lines of additional context and we can verify signed tags
with gpg.  These major Git functions are much more important than
saving two or three lines of a simple sed script.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-tag.sh
git-verify-tag.sh

index c84043902f9fcaf7c09846b9fd68986bd7fc5108..3917cd829842462ca4e3d196246c637d8c3a58dc 100755 (executable)
@@ -51,12 +51,16 @@ do
                [ "$LINES" -le 0 ] && { echo "$TAG"; continue ;}
                OBJTYPE=$(git cat-file -t "$TAG")
                case $OBJTYPE in
-               tag)    ANNOTATION=$(git cat-file tag "$TAG" |
-                                      sed -e '1,/^$/d' \
-                                          -e '/^-----BEGIN PGP SIGNATURE-----$/Q' )
-                       printf "%-15s %s\n" "$TAG" "$ANNOTATION" |
-                         sed -e '2,$s/^/    /' \
-                             -e "${LINES}q"
+               tag)
+                       ANNOTATION=$(git cat-file tag "$TAG" |
+                               sed -e '1,/^$/d' |
+                               sed -n -e "
+                                       /^-----BEGIN PGP SIGNATURE-----\$/q
+                                       2,\$s/^/    /
+                                       p
+                                       ${LINES}q
+                               ")
+                       printf "%-15s %s\n" "$TAG" "$ANNOTATION"
                        ;;
                *)      echo "$TAG"
                        ;;
index f2d5597dba8921c6381dfd018a97733252cc457d..68858b694df5022530d38d38057331d7487fc6f0 100755 (executable)
@@ -37,8 +37,9 @@ esac
 trap 'rm -f "$GIT_DIR/.tmp-vtag"' 0
 
 git-cat-file tag "$1" >"$GIT_DIR/.tmp-vtag" || exit 1
-
-cat "$GIT_DIR/.tmp-vtag" |
-sed '/-----BEGIN PGP/Q' |
+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"