bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] bzr-version-gen: New module.


From: Giuseppe Scrivano
Subject: Re: [PATCH] bzr-version-gen: New module.
Date: Sun, 07 Aug 2011 02:57:27 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Hello again Bruno,

I have attached the diff against git-version-gen as it makes easier to
see differences from the original file.

How to handle better git-version-gen?  Do you have any suggestion?

Thanks,
Giuseppe


--- git-version-gen     2011-08-07 02:21:36.000000000 +0200
+++ vc-version-gen      2011-08-07 02:53:26.000000000 +0200
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Print a version string.
-scriptversion=2011-07-31.12; # UTC
+scriptversion=2011-08-07.00; # UTC
 
 # Copyright (C) 2007-2011 Free Software Foundation, Inc.
 #
@@ -18,19 +18,21 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # This script is derived from GIT-VERSION-GEN from GIT: http://git.or.cz/.
-# It may be run two ways:
+# It may be run three ways:
 # - from a git repository in which the "git describe" command below
 #   produces useful output (thus requiring at least one signed tag)
-# - from a non-git-repo directory containing a .tarball-version file, which
-#   presumes this script is invoked like "./git-version-gen .tarball-version".
+# - from a Bazaar repository
+# - from a non git-repo or bzr-repo directory containing a .tarball-version
+#   file, which presumes this script is invoked like:
+#   "./vc-version-gen .tarball-version".
 
 # In order to use intra-version strings in your project, you will need two
 # separate generated version string files:
 #
 # .tarball-version - present only in a distribution tarball, and not in
 #   a checked-out repository.  Created with contents that were learned at
-#   the last time autoconf was run, and used by git-version-gen.  Must not
-#   be present in either $(srcdir) or $(builddir) for git-version-gen to
+#   the last time autoconf was run, and used by vc-version-gen.  Must not
+#   be present in either $(srcdir) or $(builddir) for vc-version-gen to
 #   give accurate answers during normal development with a checked out tree,
 #   but must be present in a tarball when there is no version control system.
 #   Therefore, it cannot be used in any dependencies.  GNUmakefile has
@@ -44,8 +46,8 @@
 #   files to pick up a version string change; and leave it stale to
 #   minimize rebuild time after unrelated changes to configure sources.
 #
-# It is probably wise to add these two files to .gitignore, so that you
-# don't accidentally commit either generated file.
+# It is probably wise to add these two files to .gitignore or .bzrignore, so
+# that you don't accidentally commit either generated file.
 #
 # Use the following line in your configure.ac, so that $(VERSION) will
 # automatically be up-to-date each time configure is run (and note that
@@ -53,7 +55,7 @@
 # should not depend on configure.ac for version updates).
 #
 # AC_INIT([GNU project],
-#         m4_esyscmd([build-aux/git-version-gen .tarball-version]),
+#         m4_esyscmd([build-aux/vc-version-gen .tarball-version]),
 #         address@hidden)
 #
 # Then use the following lines in your Makefile.am, so that .version
@@ -82,6 +84,7 @@
 # Avoid meddling by environment variable of the same name.
 v=
 v_from_git=
+v_from_bzr=
 
 # First see if there is a tarball-only version file.
 # then try "git describe", then default.
@@ -137,6 +140,18 @@
     # Remove the "g" in git describe's output string, to save a byte.
     v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`;
     v_from_git=1
+elif bzr status > /dev/null 2>&1
+then
+    revno=`bzr revno`
+    v=`bzr tags -r $revno | cut -d' ' -f1`
+    if test -z "$v"
+    then
+        tag=`bzr tags -r ..$revno | cut -d' ' -f1`
+        # No tags yet
+        test -z "$tag" && tag=UNKNOWN
+    fi
+    v=$tag-$revno
+    v_from_bzr=1
 else
     v=UNKNOWN
 fi
@@ -144,8 +159,8 @@
 v=`echo "$v" |sed 's/^v//'`
 
 # Test whether to append the "-dirty" suffix only if the version
-# string we're using came from git.  I.e., skip the test if it's "UNKNOWN"
-# or if it came from .tarball-version.
+# string we're using came from a vc system.  I.e., skip the test if it's
+# "UNKNOWN" or if it came from .tarball-version.
 if test -n "$v_from_git"; then
   # Don't declare a version "dirty" merely because a time stamp has changed.
   git update-index --refresh > /dev/null 2>&1
@@ -161,6 +176,13 @@
   esac
 fi
 
+if test -n "$v_from_bzr"; then
+    if test -n "`bzr diff | tr -d '\n'`"; then
+        v="$v-dirty"
+    fi
+fi
+
+
 # Omit the trailing newline, so that m4_esyscmd can use the result directly.
 echo "$v" | tr -d "$nl"


and here the git formatted patch:

>From b568914ca35d2bc4767663f65571902d6837ce1c Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <address@hidden>
Date: Sun, 7 Aug 2011 02:35:56 +0200
Subject: [PATCH] vc-version-gen: New module.

* build-aux/vc-version-gen: New file.
* modules/vc-version-gen: Likewise.
* modules/git-version-gen: Mark the module as deprecated.
---
 ChangeLog                |    7 ++
 build-aux/vc-version-gen |  195 ++++++++++++++++++++++++++++++++++++++++++++++
 modules/git-version-gen  |    6 ++
 modules/vc-version-gen   |   19 +++++
 4 files changed, 227 insertions(+), 0 deletions(-)
 create mode 100755 build-aux/vc-version-gen
 create mode 100644 modules/vc-version-gen

diff --git a/ChangeLog b/ChangeLog
index 72e7611..091ba51 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-08-07  Giuseppe Scrivano  <address@hidden>
+
+       vc-version-gen: New module.
+       * build-aux/vc-version-gen: New file.
+       * modules/vc-version-gen: Likewise.
+       * modules/git-version-gen: Mark the module as deprecated.
+
 2011-08-06  Karl Berry  <address@hidden>
 
        * MODULES.html.sh (func_all_files): _Noreturn is no longer
diff --git a/build-aux/vc-version-gen b/build-aux/vc-version-gen
new file mode 100755
index 0000000..1fc127e
--- /dev/null
+++ b/build-aux/vc-version-gen
@@ -0,0 +1,195 @@
+#!/bin/sh
+# Print a version string.
+scriptversion=2011-08-07.00; # UTC
+
+# Copyright (C) 2007-2011 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
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This script is derived from GIT-VERSION-GEN from GIT: http://git.or.cz/.
+# It may be run three ways:
+# - from a git repository in which the "git describe" command below
+#   produces useful output (thus requiring at least one signed tag)
+# - from a Bazaar repository
+# - from a non git-repo or bzr-repo directory containing a .tarball-version
+#   file, which presumes this script is invoked like:
+#   "./vc-version-gen .tarball-version".
+
+# In order to use intra-version strings in your project, you will need two
+# separate generated version string files:
+#
+# .tarball-version - present only in a distribution tarball, and not in
+#   a checked-out repository.  Created with contents that were learned at
+#   the last time autoconf was run, and used by vc-version-gen.  Must not
+#   be present in either $(srcdir) or $(builddir) for vc-version-gen to
+#   give accurate answers during normal development with a checked out tree,
+#   but must be present in a tarball when there is no version control system.
+#   Therefore, it cannot be used in any dependencies.  GNUmakefile has
+#   hooks to force a reconfigure at distribution time to get the value
+#   correct, without penalizing normal development with extra reconfigures.
+#
+# .version - present in a checked-out repository and in a distribution
+#   tarball.  Usable in dependencies, particularly for files that don't
+#   want to depend on config.h but do want to track version changes.
+#   Delete this file prior to any autoconf run where you want to rebuild
+#   files to pick up a version string change; and leave it stale to
+#   minimize rebuild time after unrelated changes to configure sources.
+#
+# It is probably wise to add these two files to .gitignore or .bzrignore, so
+# that you don't accidentally commit either generated file.
+#
+# Use the following line in your configure.ac, so that $(VERSION) will
+# automatically be up-to-date each time configure is run (and note that
+# since configure.ac no longer includes a version string, Makefile rules
+# should not depend on configure.ac for version updates).
+#
+# AC_INIT([GNU project],
+#         m4_esyscmd([build-aux/vc-version-gen .tarball-version]),
+#         address@hidden)
+#
+# Then use the following lines in your Makefile.am, so that .version
+# will be present for dependencies, and so that .version and
+# .tarball-version will exist in distribution tarballs.
+#
+# EXTRA_DIST = $(top_srcdir)/.version
+# BUILT_SOURCES = $(top_srcdir)/.version
+# $(top_srcdir)/.version:
+#      echo $(VERSION) > address@hidden && mv address@hidden $@
+# dist-hook:
+#      echo $(VERSION) > $(distdir)/.tarball-version
+
+case $# in
+    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='
+'
+
+# Avoid meddling by environment variable of the same name.
+v=
+v_from_git=
+v_from_bzr=
+
+# 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` || v=
+    case $v in
+        *$nl*) v= ;; # reject multi-line output
+        [0-9]*) ;;
+        *) v= ;;
+    esac
+    test -z "$v" \
+        && echo "$0: WARNING: $tarball_version_file is missing or damaged" 1>&2
+fi
+
+if test -n "$v"
+then
+    : # use $v
+# Otherwise, if there is at least one git commit involving the working
+# 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='v*' HEAD 2>/dev/null \
+          || git describe --abbrev=4 HEAD 2>/dev/null` \
+    && v=`printf '%s\n' "$v" | sed "$tag_sed_script"` \
+    && case $v in
+         v[0-9]*) ;;
+         *) (exit 1) ;;
+       esac
+then
+    # Is this a new git that lists number of commits since the last
+    # tag or the previous older version that did not?
+    #   Newer: v6.10-77-g0f8faeb
+    #   Older: v6.10-g0f8faeb
+    case $v in
+        *-*-*) : git describe is okay three part flavor ;;
+        *-*)
+            : git describe is older two part flavor
+            # Recreate the number of commits and rewrite such that the
+            # result is the same as if we were using the newer version
+            # of git describe.
+            vtag=`echo "$v" | sed 's/-.*//'`
+            commit_list=`git rev-list "$vtag"..HEAD 2>/dev/null` \
+                || { commit_list=failed;
+                     echo "$0: WARNING: git rev-list failed" 1>&2; }
+            numcommits=`echo "$commit_list" | wc -l`
+            v=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`;
+            test "$commit_list" = failed && v=UNKNOWN
+            ;;
+    esac
+
+    # Change the first '-' to a '.', so version-comparing tools work properly.
+    # Remove the "g" in git describe's output string, to save a byte.
+    v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`;
+    v_from_git=1
+elif bzr status > /dev/null 2>&1
+then
+    revno=`bzr revno`
+    v=`bzr tags -r $revno | cut -d' ' -f1`
+    if test -z "$v"
+    then
+        tag=`bzr tags -r ..$revno | cut -d' ' -f1`
+        # No tags yet
+        test -z "$tag" && tag=UNKNOWN
+    fi
+    v=$tag-$revno
+    v_from_bzr=1
+else
+    v=UNKNOWN
+fi
+
+v=`echo "$v" |sed 's/^v//'`
+
+# Test whether to append the "-dirty" suffix only if the version
+# string we're using came from a vc system.  I.e., skip the test if it's
+# "UNKNOWN" or if it came from .tarball-version.
+if test -n "$v_from_git"; then
+  # Don't declare a version "dirty" merely because a time stamp has changed.
+  git update-index --refresh > /dev/null 2>&1
+
+  dirty=`exec 2>/dev/null;git diff-index --name-only HEAD` || dirty=
+  case "$dirty" in
+      '') ;;
+      *) # Append the suffix only if there isn't one already.
+          case $v in
+            *-dirty) ;;
+            *) v="$v-dirty" ;;
+          esac ;;
+  esac
+fi
+
+if test -n "$v_from_bzr"; then
+    if test -n "`bzr diff | tr -d '\n'`"; then
+        v="$v-dirty"
+    fi
+fi
+
+
+# Omit the trailing newline, so that m4_esyscmd can use the result directly.
+echo "$v" | tr -d "$nl"
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/modules/git-version-gen b/modules/git-version-gen
index a783ac5..7b89c06 100644
--- a/modules/git-version-gen
+++ b/modules/git-version-gen
@@ -1,6 +1,12 @@
 Description:
 Compute a version string from a git repository.
 
+Status:
+deprecated
+
+Notice:
+This module is deprecated. Use the module 'vc-version-gen' instead.
+
 Files:
 build-aux/git-version-gen
 
diff --git a/modules/vc-version-gen b/modules/vc-version-gen
new file mode 100644
index 0000000..0c2c742
--- /dev/null
+++ b/modules/vc-version-gen
@@ -0,0 +1,19 @@
+Description:
+Compute a version string from a version-controlled repository.
+
+Files:
+build-aux/vc-version-gen
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+
+Include:
+
+License:
+GPLed build tool
+
+Maintainer:
+coreutils
-- 
1.7.5.4



reply via email to

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