mutt stable branch with some hacks
1#!/bin/sh
2
3HG=hg
4
5# Switch to directory where this script lives so that further commands are run
6# from the root directory of the source. The script path and srcdir are double
7# quoted to allow the space character to appear in the path.
8srcdir=`dirname "$0"` && cd "$srcdir" || exit 1
9
10# Ensure that we have a repo here and that mercurial is installed. If
11# not, just cat the VERSION file; it contains the latest release number.
12{ [ -d ".hg" ] && $HG >/dev/null 2>&1; } \
13|| exec cat VERSION
14
15# This is a mercurial repo and we have the hg command.
16
17# Get essential properties of the current working copy
18set -- `$HG parents --template='{rev} {node|short}\n'`
19rev="$1"
20node="$2"
21
22# translate release tags into ##.##.## notation
23cleantag () {
24 case "$1" in
25 mutt-*-rel) echo "$1" | sed -e 's/mutt-//' -e 's/-rel//' | tr - . ;;
26 *) echo "$1" ;;
27 esac
28}
29
30getdistance_old () {
31 # fudge it
32 set -- `$HG tags | sort -n -k 2 | egrep 'mutt-.*rel' | tail -1 | cut -d: -f1`
33 latesttag="$1"
34 latestrev="$2"
35 distance=`expr $rev - $latestrev`
36 echo $latesttag $distance
37}
38
39getdistance_new () {
40 $HG parents --template='{latesttag} {latesttagdistance}\n'
41}
42
43
44# latesttag appeared in hg 1.4. Test for it.
45[ "`$HG log -r . --template='{latesttag}'`" = '' ] &&
46set -- `getdistance_old` ||
47set -- `getdistance_new`
48
49tag=`cleantag "$1"`
50dist=$2
51
52if [ $dist -eq 0 ]; then
53 dist=
54else
55 dist="+$dist"
56fi
57
58# if we have mq patches applied, mention it
59qparent=`$HG log -r qparent --template='{rev}\n' 2>/dev/null || echo $rev`
60qdelta=`expr $rev - $qparent`
61if [ $qdelta -eq 0 ]; then
62 qdist=""
63else
64 qdist=",mq+$qdelta"
65fi
66
67echo "$tag$dist$qdist ($node)"
68exit 0