threads / patch / 8779

patchCorrect usages of sed in git-tag for Mac OS X

Subject: [PATCH] Correct usages of sed in git-tag for Mac OS X

## tl;dr

3 messages between Jun 30, 2007 and Jun 30, 2007. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Shawn O. Pearce· Jun 30, 2007, 06:42 UTC · lore

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>
---
 Boy, it would sure be nice if git-tag was written in a more portable
 programming language, such as C.  No more worries about sed working
 on one platform and not another.  ;-)
 t7004-tag.sh now passes all 65 tests here.
 git-tag.sh        |   16 ++++++++++------
 git-verify-tag.sh |    7 ++++---
 2 files changed, 14 insertions(+), 9 deletions(-)
Show changes to 2 files +14 −9

git-tag.sh, git-verify-tag.sh

diff --git a/git-tag.sh b/git-tag.sh
index c840439..3917cd8 100755
--- a/git-tag.sh
+++ b/git-tag.sh
@@ -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"
 			;;
diff --git a/git-verify-tag.sh b/git-verify-tag.sh
index f2d5597..a54fd48 100755
--- a/git-verify-tag.sh
+++ b/git-verify-tag.sh
@@ -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"
-- 
1.5.2.2.1414.g1e7d-dirty
Junio C Hamano· Jun 30, 2007, 07:00 UTC · re: Shawn O. Pearce · lore

Re: [PATCH] Correct usages of sed in git-tag for Mac OS X

"Shawn O. Pearce" <spearce@spearce.org> writes:
> These major Git functions are much more important than
> saving two or three lines of a simple sed script.

The size of the script does not worry me. The number of sed processes originally did, but the old code also had two invocations of sed, and I do not think you can implement the "strip the header, and then emit ${LINES} lines" behaviour without doing them in separate sed anyway, so I think this is fine. But it makes me wonder why we are not using awk ;-)

Shawn O. Pearce· Jun 30, 2007, 07:03 UTC · re: Junio C Hamano · lore

Re: [PATCH] Correct usages of sed in git-tag for Mac OS X

Junio C Hamano <gitster@pobox.com> wrote:
Show 11 quoted lines
> "Shawn O. Pearce" <spearce@spearce.org> writes:
> 
> > These major Git functions are much more important than
> > saving two or three lines of a simple sed script.
> 
> The size of the script does not worry me.  The number of sed
> processes originally did, but the old code also had two
> invocations of sed, and I do not think you can implement the
> "strip the header, and then emit ${LINES} lines" behaviour
> without doing them in separate sed anyway, so I think this is
> fine.  But it makes me wonder why we are not using awk ;-)
Or perl.  ;-)

But the patch I just sent is sane. And it all will hopefully go away when Carlos has his C version complete and passing the very large test suite he recently contributed. So not really worth worrying about now that its working properly.

But yea, I changed the script the way I did to keep the number of sed processes per tag equal to what we had before. Its not any better, but its also not any worse and it at least runs on more systems.

-- 
Shawn.

← back to recent threads