chiark / gitweb /
auto-version.in: Factor out Debian version checking. master
authorMark Wooding <mdw@distorted.org.uk>
Fri, 3 May 2024 21:51:43 +0000 (22:51 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 3 May 2024 21:51:43 +0000 (22:51 +0100)
Also fixes a bug: we assumed that `debian/changelog' existed if we had a
Git version to check.

auto-version.in

index 5e0e59ddb8564d1eb8cf9c98a0e5d51171a6581b..59c75c0d8426c02e60f24eb894e38acde040e381 100755 (executable)
@@ -70,6 +70,13 @@ fi
 ###--------------------------------------------------------------------------
 ### Main program.
 
+## Get the Debian version, if there is one.
+if [ -f debian/changelog ]; then
+  debver=$(sed -n '/^.*(\(.*\)).*$/ { s::\1:p; q; }' debian/changelog)
+else
+  unset debver
+fi
+
 ## If this is a Git checkout then Git should be able to identify the version.
 ## If there's also a Debian version, and that ends in a `~', then prefix the
 ## Git version with this.  Note that `pkg-config' is not very good, and, in
@@ -78,8 +85,7 @@ fi
 ## version-comparison algorithm which specifies this behaviour, so one must
 ## be careful when choosing `~' prefixes.
 if [ -e .git ] && version=$(git describe --abbrev=4 --dirty=+ 2>/dev/null); then
-  debver=$(sed -n '/^.*(\(.*\)).*$/ { s::\1:p; q; }' debian/changelog)
-  case $debver in *~) version=$debver$version ;; esac
+  case ${debver+t} in t) version=$debver$version ;; esac
   echo "$version"
   exit 0
 fi
@@ -92,10 +98,9 @@ if [ -f RELEASE ]; then
 fi
 
 ## If we're Debianized, then the Debian changelog ought to know.
-if [ -f debian/changelog ]; then
-  sed -n '/^.*(\(.*\)).*$/ { s::\1:p; q; }' debian/changelog
-  exit 0
-fi
+case ${debver+t} in
+  t) echo "$debver"; exit 0 ;;
+esac
 
 ## Otherwise we're screwed.
 echo UNKNOWN