From 437142daa5856c76b7587bef0d5e64e2e39ae814 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 29 Oct 2020 00:17:36 -0700 Subject: [PATCH] version: calculate version info without using git tags. This makes it easier to integrate this version math into a submodule-ful world. We'll continue to have regular git tags that parallel the information in VERSION, so that builds out of this repository behave the same. Signed-off-by: David Anderson --- VERSION | 1 + build_dist.sh | 6 ++---- version/describe.sh | 26 ++++++++++++++++++++++++++ version/describe.txt.do | 3 +-- 4 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 VERSION create mode 100755 version/describe.sh diff --git a/VERSION b/VERSION new file mode 100644 index 000000000..4c902a289 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.1.0 f81233524fddeec450940af8dc1a0dd8841bf28c diff --git a/build_dist.sh b/build_dist.sh index 3818a6207..07d82a4c1 100755 --- a/build_dist.sh +++ b/build_dist.sh @@ -11,10 +11,8 @@ set -euo pipefail -describe=$(git describe --long --abbrev=9) -# --abbrev=200 is an arbitrary large number to capture the entire git -# hash without trying to compact it. -commit=$(git describe --dirty --exclude "*" --always --abbrev=200) +describe=$(./version/describe.sh) +commit=$(git rev-parse --verify --quiet HEAD) long=$(./version/mkversion.sh long "$describe" "") short=$(./version/mkversion.sh short "$describe" "") diff --git a/version/describe.sh b/version/describe.sh new file mode 100755 index 000000000..5e12aa266 --- /dev/null +++ b/version/describe.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# +# Constructs a "git describe" compatible version number by using the +# information in the VERSION file, rather than git tags. + +set -eu + +dir="$(dirname $0)" +verfile="$dir/../VERSION" + +read -r version hash <"$verfile" + +if [ -z "$hash" ]; then + # If no explicit hash was given, use the last time the version + # file changed as the "origin" hash for this version. + hash="$(git rev-list --max-count=1 HEAD -- $verfile)" +fi + +if [ -z "$hash" ]; then + echo "Couldn't find base git hash for version '$version'" >2 + exit 1 +fi + +head="$(git rev-parse --short=9 HEAD)" +changecount="$(git rev-list ${hash}..HEAD | wc -l)" +echo "v${version}-${changecount}-g${head}" diff --git a/version/describe.txt.do b/version/describe.txt.do index 0bdf6651a..9fb1095d6 100644 --- a/version/describe.txt.do +++ b/version/describe.txt.do @@ -1,4 +1,3 @@ -describe=$(git describe --long --abbrev=9) -echo "$describe" >$3 +./describe.sh >$3 redo-always redo-stamp <$3