commit 8421b3cb223eced0e07ae65eaf21486d22beb573
Author: Oswald Buddenhagen <o...@users.sf.net>
Date:   Fri Aug 2 09:56:02 2024 +0200

    automate setting package version
    
    this avoids the need for bumping the version, which is particularly
    helpful if one doesn't know yet whether the next release will be a
    patch, minor, or major.
    
    we cache the version extracted from git, which also provides a fallback
    for the case of somebody rebuilding configure from a tar-ball.
    
    note that it's impossible to determine the version at configure time, so
    after git-tagging you need to remember to run version.sh (or autoconf)
    prior to rolling a tar-ball.

 .gitignore   |  1 +
 Makefile.am  |  2 +-
 configure.ac |  3 ++-
 version.sh   | 36 ++++++++++++++++++++++++++++++++++++
 4 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index 6b9c837..66a12ec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
 /.autoconf_trace
 /ChangeLog
 /INSTALL
+/VERSION
 /autom4te.cache/
 /aclocal.m4
 /autodefs.h
diff --git a/Makefile.am b/Makefile.am
index 901b4a5..79067cb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,7 +4,7 @@
 
 SUBDIRS = src
 bin_SCRIPTS = mbsync-get-cert
-EXTRA_DIST = LICENSES debian isync.spec $(bin_SCRIPTS)
+EXTRA_DIST = LICENSES VERSION debian isync.spec $(bin_SCRIPTS)
 
 LOG_PL = \
     use POSIX qw(strftime); \
diff --git a/configure.ac b/configure.ac
index ee74d96..41670ca 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,8 @@
 # SPDX-FileCopyrightText: 2002-2022 Oswald Buddenhagen <o...@users.sf.net>
 dnl SPDX-License-Identifier: GPL-2.0-or-later
 
-AC_INIT([isync], [1.5.0])
+m4_syscmd([./version.sh])
+AC_INIT([isync], m4_include([VERSION]))
 AC_CONFIG_HEADERS([autodefs.h])
 
 AC_CANONICAL_TARGET
diff --git a/version.sh b/version.sh
new file mode 100755
index 0000000..fc1ed7d
--- /dev/null
+++ b/version.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+# SPDX-FileCopyrightText: (C) 2024 Oswald Buddenhagen <o...@users.sf.net>
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+cd $(dirname $0)
+
+test -e .git || exit
+
+mb=$(git merge-base HEAD "@{upstream}" 2> /dev/null)
+if test -z "$mb"; then
+       # we presume that a failure to find a merge base means no upstream.
+       # and no upstream may mean detached head in the middle of a rebase
+       br=$(git branch | sed -n -e 's/^\* (no branch, rebasing 
\([^\)]*\))$/\1/p')
+       if test -n "$br"; then
+               mb=$(git merge-base HEAD "$br@{upstream}" 2> /dev/null)
+       fi
+fi
+if test -z "$mb"; then
+       # still no upstream, so just describe HEAD as-is.
+       gver=$(git describe --tags HEAD)
+else
+       # find out whether we have local work, and if so, collapse it into
+       # a single suffix. otherwise, we'd cause pointless rebuilds during
+       # development.
+       gver=$(git describe --tags $mb)
+       lcl=$(git rev-list -n 1 $mb..HEAD)
+       if test -n "$lcl"; then
+               gver="$gver-plus"
+       fi
+fi
+gver=${gver#v}
+pgver=$(cat VERSION 2> /dev/null)
+if [ "x$gver" != "x$pgver" ]; then
+       echo "$gver" > VERSION
+fi
+


_______________________________________________
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to