From: Aaron Schrab <aa...@schrab.com>

Use the directory where the version.sh script is located as the
directory where it is run.  Since this will be run in a separate shell
anyway, there's no need to worry about changing current directory.

This eliminates the need for the caller to specify where the source
directory is located, and doesn't require that the code take special
care to use the appropriate directory.  The fallback method of using
`cat VERSION` was broken in this respect, it would not work when run
from a different directory.
---
 configure.ac |    2 +-
 version.sh   |    7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index c4f5b48..71a6452 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11,7 +11,7 @@ mutt_cv_version=`cat "$srcdir/VERSION"`
 AM_INIT_AUTOMAKE(mutt, $mutt_cv_version)
 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/VERSION'])
 
-MUTT_VERSION=`env HGROOT="$srcdir" sh "$srcdir/version.sh"`
+MUTT_VERSION=`env sh "$srcdir/version.sh"`
 AC_DEFINE_UNQUOTED(MUTT_VERSION,"$MUTT_VERSION", [Full textual version 
string.])
 
 AC_GNU_SOURCE
diff --git a/version.sh b/version.sh
index c3cb543..1e02e98 100644
--- a/version.sh
+++ b/version.sh
@@ -1,12 +1,13 @@
 #!/bin/sh
 
-# Adopt $HGROOT from the environment, if present
 HG=hg
-[ -n "$HGROOT" ] && HG="$HG -R \$HGROOT"
+# Switch to directory where this script lives so that further commands are run
+# from the root directory of the source
+cd `dirname $0`
 
 # Ensure that we have a repo here and that mercurial is installed.  If
 # not, just cat the VERSION file; it contains the latest release number.
-{ [ -d "$HGROOT/.hg" ] && $HG >/dev/null 2>&1; } || exec cat VERSION
+{ [ -d .hg ] && $HG >/dev/null 2>&1; } || exec cat VERSION
 
 # This is a mercurial repo and we have the hg command.
 
-- 
1.7.10.4

Reply via email to