git-version-gen: add --match argument
[bpt/guile.git] / build-aux / git-version-gen
index c7a58af..0b51154 100755 (executable)
@@ -1,8 +1,8 @@
 #!/bin/sh
 # Print a version string.
-scriptversion=2011-11-13.13; # UTC
+scriptversion=2012-07-06.14; # UTC
 
-# Copyright (C) 2007-2011 Free Software Foundation, Inc.
+# Copyright (C) 2007-2012 Free Software Foundation, Inc.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -85,21 +85,28 @@ Print a version string.
 
 Options:
 
-   --prefix           prefix of git tags (default 'v')
+   --prefix     prefix of git tags to strip from version (default 'v')
+   --match      pattern for git tags to match (default: '\$prefix*')
 
-   --help             display this help and exit
-   --version          output version information and exit
+   --help       display this help and exit
+   --version    output version information and exit
 
-Running without arguments will suffice in most cases."
+Running without arguments will suffice in most cases.  If no --match
+argument is given, only match tags that begin with the --prefix."
+
+prefix=v
+unset match
+unset tag_sed_script
 
 while test $# -gt 0; do
   case $1 in
     --help) echo "$usage"; exit 0;;
     --version) echo "$version"; exit 0;;
     --prefix) shift; prefix="$1";;
+    --match) shift; match="$1";;
     -*)
-      echo "$0: Unknown option \`$1'." >&2
-      echo "$0: Try \`--help' for more information." >&2
+      echo "$0: Unknown option '$1'." >&2
+      echo "$0: Try '--help' for more information." >&2
       exit 1;;
     *)
       if test -z "$tarball_version_file"; then
@@ -107,7 +114,7 @@ while test $# -gt 0; do
       elif test -z "$tag_sed_script"; then
         tag_sed_script="$1"
       else
-        echo "$0: extra non-option argument \`$1'." >&2
+        echo "$0: extra non-option argument '$1'." >&2
         exit 1
       fi;;
   esac
@@ -119,8 +126,8 @@ if test -z "$tarball_version_file"; then
     exit 1
 fi
 
+match="${match:-$prefix*}"
 tag_sed_script="${tag_sed_script:-s/x/x/}"
-prefix="${prefix:-v}"
 
 nl='
 '
@@ -150,8 +157,7 @@ then
 # directory, and "git describe" output looks sensible, use that to
 # derive a version string.
 elif test "`git log -1 --pretty=format:x . 2>&1`" = x \
-    && v=`git describe --abbrev=4 --match="$prefix*" HEAD 2>/dev/null \
-          || git describe --abbrev=4 HEAD 2>/dev/null` \
+    && v=`git describe --abbrev=4 --match="$match" HEAD 2>/dev/null` \
     && v=`printf '%s\n' "$v" | sed "$tag_sed_script"` \
     && case $v in
          $prefix[0-9]*) ;;