#!/bin/sh set -Ceu # Print a version tag. # - If VERSION is marked with +, then invoke hg to include # . number of commits since tag, # . commit id, and # . whether the tree is dirty. # - If VERSION is not marked, report it verbatim without running hg. main=`dirname -- "$0"` version=`cat -- "$main"/VERSION` case $version in *+) version=${version%+} tag_dist=`hg log -r . --template '{latesttag}-{latesttagdistance}'` id_dirty=`hg id -i` case $tag_dist in v$version-0-*) tag_dist=$version;; v$version-*) tag_dist=${tag_dist#v}-m;; *) echo >&2 "inconsistent version: $version, $full";; esac case $id_dirty in *+) id_dirty=${id_dirty%+}-dirty;; esac echo ${tag_dist}${id_dirty} ;; *) echo $version ;; esac