# HG changeset patch # User ark # Date 1792505210 -7200 # Node ID 28e1fc486be541e014540a8e78945e783e83a4a9 # Parent ecd94cc6bf804c5fbc59e453c09d0fb07234b6b3 get_version.sh diff -r ecd94cc6bf80 -r 28e1fc486be5 tools/get_version.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/get_version.sh Tue Oct 20 16:06:50 2026 +0200 @@ -0,0 +1,65 @@ +#!/bin/sh +USAGE="usage: ./get_version.sh [-f] + +parses tags, status and summary of current repository, prints current version. + +if the current repo revision is the tagging revision, the tag is the version. + +otherwise the script aborts with an error, unless forced with -f flag. in that +case the version is the latest tag with - appended. + +options: + -f force version output even if not on tagged revision or dirty repo + +" + +VERBOSE=1 +FORCE=0 +TIMESTAMP=$(date "+%Y%m%d_%H%M") + +while [ $# != 0 ] +do + case $1 in + -f) + FORCE=1 + ;; + *) + echo "unrecognized option '$1'" + echo "$USAGE" + exit 1 + esac + shift +done + +# parse hg su, hg tags +SUMMARY=$(LC_ALL=C hg su) +PARENT=$(echo "$SUMMARY" | grep "parent:" | cut -b 9- | cut -d : -f 1) +LATESTTAG=$(hg log -r$PARENT -T "{latesttag}") +TAGGEDREV=$(hg tags -T "{rev},{tag}\n"| grep ",$LATESTTAG" | cut -d , -f 1) +TAGGINGREV=$(( $TAGGEDREV + 1 )) +CLEAN=$(echo "$SUMMARY" | grep -c "commit: (clean)") + +VERSION=$LATESTTAG + +if [ "$PARENT" != "$TAGGEDREV" ] && [ "$PARENT" != "$TAGGINGREV" ] ; then + if [ $FORCE = 1 ] ; then + (>&2 echo "warning: not a tagged revision") + VERSION="${LATESTTAG}.${TIMESTAMP}" + else + (>&2 echo "error: not a tagged revision") + exit 1 + fi +fi + +if [ $CLEAN = 0 ] ; then + if [ $FORCE = 1 ] ; then + (>&2 echo "warning: working directory not clean") + VERSION="${LATESTTAG}.${TIMESTAMP}" + else + (>&2 echo "error: working directory not clean") + exit 1 + fi +fi + +echo $VERSION +