From: Aaron Schrab <aa...@schrab.com> Put the code to build a detailed version string using mercurial into an if block rather than immediately using the fallback if mercurial can't be used. This will allow checking for other sources of detailed version info, such as using git which will be supported in an upcoming commit. --- version.sh | 96 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 50 insertions(+), 46 deletions(-)
diff --git a/version.sh b/version.sh index 1e02e98..39709a0 100644 --- a/version.sh +++ b/version.sh @@ -5,61 +5,65 @@ HG=hg # 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 .hg ] && $HG >/dev/null 2>&1; } || exec cat VERSION +# If there's a mercurial repo and hg is installed, +# use that to build a detailed version string +if [ -d .hg ] && $HG >/dev/null 2>&1; then + # This is a mercurial repo and we have the hg command. -# This is a mercurial repo and we have the hg command. + # Get essential properties of the current working copy + set -- `$HG parents --template='{rev} {node|short}\n'` + rev="$1" + node="$2" -# Get essential properties of the current working copy -set -- `$HG parents --template='{rev} {node|short}\n'` -rev="$1" -node="$2" + # translate release tags into ##.##.## notation + cleantag () { + case "$1" in + mutt-*-rel) echo "$1" | sed -e 's/mutt-//' -e 's/-rel//' | tr - . ;; + *) echo "$1" ;; + esac + } -# translate release tags into ##.##.## notation -cleantag () { - case "$1" in - mutt-*-rel) echo "$1" | sed -e 's/mutt-//' -e 's/-rel//' | tr - . ;; - *) echo "$1" ;; - esac -} + getdistance_old () { + # fudge it + set -- `$HG tags | sort -n -k 2 | egrep 'mutt-.*rel' | tail -1 | cut -d: -f1` + latesttag="$1" + latestrev="$2" + distance=`expr $rev - $latestrev` + echo $latesttag $distance + } -getdistance_old () { - # fudge it - set -- `$HG tags | sort -n -k 2 | egrep 'mutt-.*rel' | tail -1 | cut -d: -f1` - latesttag="$1" - latestrev="$2" - distance=`expr $rev - $latestrev` - echo $latesttag $distance -} + getdistance_new () { + $HG parents --template='{latesttag} {latesttagdistance}\n' + } -getdistance_new () { - $HG parents --template='{latesttag} {latesttagdistance}\n' -} + # latesttag appeared in hg 1.4. Test for it. + [ "`$HG log -r . --template='{latesttag}'`" = '' ] && + set -- `getdistance_old` || + set -- `getdistance_new` -# latesttag appeared in hg 1.4. Test for it. -[ "`$HG log -r . --template='{latesttag}'`" = '' ] && -set -- `getdistance_old` || -set -- `getdistance_new` + tag=`cleantag "$1"` + dist=$2 -tag=`cleantag "$1"` -dist=$2 + if [ $dist -eq 0 ]; then + dist= + else + dist="+$dist" + fi -if [ $dist -eq 0 ]; then - dist= -else - dist="+$dist" -fi + # if we have mq patches applied, mention it + qparent=`$HG log -r qparent --template='{rev}\n' 2>/dev/null || echo $rev` + qdelta=`expr $rev - $qparent` + if [ $qdelta -eq 0 ]; then + qdist="" + else + qdist=",mq+$qdelta" + fi -# if we have mq patches applied, mention it -qparent=`$HG log -r qparent --template='{rev}\n' 2>/dev/null || echo $rev` -qdelta=`expr $rev - $qparent` -if [ $qdelta -eq 0 ]; then - qdist="" -else - qdist=",mq+$qdelta" + echo "$tag$dist$qdist ($node)" + exit 0 fi -echo "$tag$dist$qdist ($node)" -exit 0 +# If nothing else worked, just cat the VERSION file; +# it contains the latest release number. +cat VERSION -- 1.7.10.4