bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: git-version-gen: Add support for a git tag transformation sed script


From: Jim Meyering
Subject: Re: git-version-gen: Add support for a git tag transformation sed script
Date: Fri, 28 May 2010 17:00:39 +0200

Ludovic Courtès wrote:
> The patch below changes ‘git-version-gen’ so that users can pass a sed
> script to transform the output of ‘git describe’, thus making it usable
> to repositories where release tags don’t have the ‘vX.Y’ form currently
> expected.
>
> For example, Guile’s release tags look like ‘release_X-Y-Z’.  Thus, the
> transformation script would be:
>
>   s/^release_\([0-9]\+\)-\([0-9]\+\)-\([0-9]\+\)-/v\1.\2\.\3-/g
>
> My copyright assignment for Gnulib isn’t complete yet, but it’s a tiny
> change.
>
> Thanks,
> Ludo’.
>
>>From 3a106f178fc24b0c547dab6da1a7f4d274d1d2f0 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <address@hidden>
> Date: Fri, 28 May 2010 11:57:18 +0200
> Subject: [PATCH] Make `git-version-gen' take a sed script to transform the 
> git tag.
>
> * build-aux/git-version-gen (tag_sed_script): New variable.  Use it to
>   transform the output of "git describe" to the canonical form.
>
> * top/GNUmakefile (_curr-ver): Pass $(git-version-gen-tag-sed-script) as
>   a second argument to `git-version-gen'.
...
>  case $# in
> -    1) ;;
> -    *) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version"; exit 1;;
> +    1|2) ;;
> +    *) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version 
> [TAG-NORMALIZATION-SED-SCRIPT]"
> +       exit 1;;
>  esac
...
> -    && v=`git describe --abbrev=4 --match='v*' HEAD 2>/dev/null \
> +    && v=`git describe --abbrev=4 --match="v*" HEAD 2>/dev/null \
>         || git describe --abbrev=4 HEAD 2>/dev/null` \
> +    && v=`echo $v | sed "$tag_sed_script"` \
>      && case $v in
>        v[0-9]*) ;;
>        *) (exit 1) ;;

Hi Ludo,
Thanks for the patch.

I'll take care of applying it, along with the minor tweaks below.
  - wrap a long line
  - revert back to using single quotes, since I see no need for
      double quotes there, and prefer to use single quotes when
      the quoted quantity contains nothing to be expanded.

diff --git a/build-aux/git-version-gen b/build-aux/git-version-gen
index 8d7cb11..b0aa863 100755
--- a/build-aux/git-version-gen
+++ b/build-aux/git-version-gen
@@ -68,7 +68,8 @@ scriptversion=2010-05-28.10; # UTC

 case $# in
     1|2) ;;
-    *) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version 
[TAG-NORMALIZATION-SED-SCRIPT]"
+    *) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version" \
+         '[TAG-NORMALIZATION-SED-SCRIPT]'
        exit 1;;
 esac

@@ -95,7 +96,7 @@ if test -n "$v"
 then
     : # use $v
 elif test -d .git \
-    && v=`git describe --abbrev=4 --match="v*" HEAD 2>/dev/null \
+    && v=`git describe --abbrev=4 --match='v*' HEAD 2>/dev/null \
          || git describe --abbrev=4 HEAD 2>/dev/null` \
     && v=`echo $v | sed "$tag_sed_script"` \
     && case $v in

Hmm... as I write this I realized that one more change is required:
quote $v here:

-    && v=`echo $v | sed "$tag_sed_script"` \
+    && v=`echo "$v" | sed "$tag_sed_script"` \

Or better still, don't use echo at all, in case
some tag starts with "-":

-    && v=`echo $v | sed "$tag_sed_script"` \
+    && v=`printf %s "$v" | sed "$tag_sed_script"` \

Here's the amended result:

>From 690712e6ae448bae3987f469aa6362b59cfbb0dd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <address@hidden>
Date: Fri, 28 May 2010 12:15:23 +0200
Subject: [PATCH] git-version-gen: take a sed script to transform the git tag

* build-aux/git-version-gen (tag_sed_script): New variable.  Use it to
transform the output of "git describe" to the canonical form.
* top/GNUmakefile (_curr-ver): Pass $(git-version-gen-tag-sed-script) as
a second argument to `git-version-gen'.
---
 build-aux/git-version-gen |   10 +++++++---
 top/GNUmakefile           |    6 ++++--
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/build-aux/git-version-gen b/build-aux/git-version-gen
index 5a7e989..25753a3 100755
--- a/build-aux/git-version-gen
+++ b/build-aux/git-version-gen
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Print a version string.
-scriptversion=2010-04-26.16; # UTC
+scriptversion=2010-05-28.14; # UTC

 # Copyright (C) 2007-2010 Free Software Foundation, Inc.
 #
@@ -67,11 +67,14 @@ scriptversion=2010-04-26.16; # UTC
 #      echo $(VERSION) > $(distdir)/.tarball-version

 case $# in
-    1) ;;
-    *) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version"; exit 1;;
+    1|2) ;;
+    *) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version" \
+         '[TAG-NORMALIZATION-SED-SCRIPT]'
+       exit 1;;
 esac

 tarball_version_file=$1
+tag_sed_script="${2:-s/x/x/}"
 nl='
 '

@@ -95,6 +98,7 @@ then
 elif test -d .git \
     && v=`git describe --abbrev=4 --match='v*' HEAD 2>/dev/null \
          || git describe --abbrev=4 HEAD 2>/dev/null` \
+    && v=`printf %s "$v" | sed "$tag_sed_script"` \
     && case $v in
         v[0-9]*) ;;
         *) (exit 1) ;;
diff --git a/top/GNUmakefile b/top/GNUmakefile
index daba47a..97fea36 100644
--- a/top/GNUmakefile
+++ b/top/GNUmakefile
@@ -60,8 +60,10 @@ ifeq ($(_have-git-version-gen)0,yes$(MAKELEVEL))
     $(filter maintainer-% dist% alpha beta major,$(MAKECMDGOALS)))
   _is-install-target ?= $(filter-out %check, $(filter 
install%,$(MAKECMDGOALS)))
   ifneq (,$(_is-dist-target)$(_is-install-target))
-    _curr-ver := $(shell cd $(srcdir) \
-                   && $(_build-aux)/git-version-gen .tarball-version)
+    _curr-ver := $(shell cd $(srcdir)                          \
+                   && $(_build-aux)/git-version-gen            \
+                         .tarball-version                      \
+                         $(git-version-gen-tag-sed-script))
     ifneq ($(_curr-ver),$(VERSION))
       ifeq ($(_curr-ver),UNKNOWN)
         $(info WARNING: unable to verify if $(VERSION) is the correct version)
--
1.7.1.348.gb26ba



reply via email to

[Prev in Thread] Current Thread [Next in Thread]