Make inter-release --version output more useful.
authorJim Meyering <jim@meyering.net>
Sat, 25 Aug 2007 22:48:41 +0000 (00:48 +0200)
committerJim Meyering <jim@meyering.net>
Thu, 30 Aug 2007 15:26:31 +0000 (17:26 +0200)
Now, each snapshot has a version "number" like 6.9-219-g58ddd,
which indicates that it is built using the 219th change set
(in _some_ repository) following the "v6.9" tag, and that 58ddd
is a prefix of the commit SHA1.
* build-aux/git-version-gen: New file.
* configure.ac: Run it to set the version.
* Makefile.am (dist-hook): Arrange so that .version appears only
in distribution tarballs, never in a checked-out repository.
* .gitignore: Add .version here, too.  Just in case.

Signed-off-by: Jim Meyering <jim@meyering.net>
.gitignore
ChangeLog
Makefile.am
build-aux/git-version-gen [new file with mode: 0755]
configure.ac

index abe485e..d231c96 100644 (file)
@@ -6,6 +6,7 @@
 *~
 .gdb-history
 .kludge-stamp
+.version
 ABOUT-NLS
 INSTALL
 Makefile
index a32834d..7c1b36f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 
 2007-08-29  Jim Meyering  <jim@meyering.net>
 
+       Make inter-release --version output more useful.
+       Now, each snapshot has a version "number" like 6.9-219-g58ddd,
+       which indicates that it is built using the 219th change set
+       (in _some_ repository) following the "v6.9" tag, and that 58ddd
+       is a prefix of the commit SHA1.
+       * build-aux/git-version-gen: New file.
+       * configure.ac: Run it to set the version.
+       * Makefile.am (dist-hook): Arrange so that .version appears only
+       in distribution tarballs, never in a checked-out repository.
+       * .gitignore: Add .version here, too.  Just in case.
+
        Ensure that TMPDIR is valid.  Otherwise, it would cause test failures.
        * tests/misc/tty-eof: Set TMPDIR=.
        * tests/misc/sort-compress: Likewise.
index c1a629b..dad84fb 100644 (file)
@@ -32,6 +32,7 @@ EXTRA_DIST = Makefile.cfg Makefile.maint GNUmakefile \
   bootstrap \
   bootstrap.conf \
   build-aux/cvsu \
+  build-aux/git-version-gen \
   build-aux/vc-list-files \
   gl/modules/getloadavg.diff \
   m4/ChangeLog \
@@ -53,7 +54,10 @@ ACLOCAL_AMFLAGS = -I m4
 check-root:
        cd tests && $(MAKE) $@
 
+# Arrange so that .version appears only in distribution tarballs,
+# never in a checked-out repository.
 dist-hook:
+       echo $(VERSION) > $(distdir)/.version
        test -x $(srcdir)/build-aux/install-sh
 
 distcheck-hook:
diff --git a/build-aux/git-version-gen b/build-aux/git-version-gen
new file mode 100755 (executable)
index 0000000..4a63111
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+# Print a version string.
+# This script is derived from GIT-VERSION-GEN from GIT: http://git.or.cz/.
+
+case $# in
+    2) ;;
+    *) echo 1>&2 "Usage: $0 \$VERSION \$srcdir/.version"; exit 1;;
+esac
+
+default_version=$1
+tarball_version_file=$2
+nl='
+'
+
+# First see if there is a tarball-only version file.
+# then try git-describe, then default.
+if test -f $tarball_version_file
+then
+    v=`cat $tarball_version_file` || exit 1
+    case $v in
+       *$nl*) v= ;; # reject multi-line output
+       [0-9]*) ;;
+       *) v= ;;
+    esac
+    test -z "$v" \
+       && echo "$0: WARNING: $tarball_version_file seems to be damaged" 1>&2
+fi
+
+if test -n "$v"
+then
+    : # use $v
+elif test -d .git \
+    && v=`git describe --abbrev=4 HEAD 2>/dev/null` \
+    && case $v in
+        # FIXME: remove this after v6.10.
+        COREUTILS-[0-9]*) v=`echo "$v" | sed 's/^COREUTILS-//;s/_/./g'` ;;
+        v[0-9]*) ;;
+        *) (exit 1) ;;
+       esac
+then
+    v=`echo "$v" | sed 's/-/./g'`;
+else
+    v=$default_version
+fi
+
+v=`echo "$v" |sed 's/^v//'`
+
+dirty=`sh -c 'git diff-index --name-only HEAD' 2>/dev/null` || dirty=
+case "$dirty" in
+    '') ;;
+    *) # Append the suffix only if there isn't one already.
+       case $v in
+         *-dirty) ;;
+         *) v="$v-dirty" ;;
+       esac ;;
+esac
+
+# Omit the trailing newline, so that m4_esyscmd can use the result directly.
+echo "$v" | tr -d '\012'
index 33088e8..df9b2a8 100644 (file)
 dnl Written by Jim Meyering.
 
 AC_PREREQ(2.61)
-AC_INIT([GNU coreutils],[6.9+],[bug-coreutils@gnu.org])
+
+# Make inter-release version strings look like, e.g., v6.9-219-g58ddd, which
+# indicates that it is built from the 219th delta (in _some_ repository)
+# following the v6.9 tag, and that 58ddd is a prefix of the commit SHA1.
+AC_INIT([GNU coreutils], m4_esyscmd([build-aux/git-version-gen 9.6+ .version]),
+       [bug-coreutils@gnu.org])
+
 AC_CONFIG_SRCDIR(src/ls.c)
 
 AC_CONFIG_AUX_DIR(build-aux)