]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
{master,doveconf}: Show the version with hg's node id, if unreleased.
authorPascal Volk <user@localhost.localdomain.org>
Sat, 27 Mar 2010 00:35:44 +0000 (00:35 +0000)
committerPascal Volk <user@localhost.localdomain.org>
Sat, 27 Mar 2010 00:35:44 +0000 (00:35 +0000)
Affects output from `dovecot --version` and `doveconf`.

--HG--
branch : HEAD

.hgignore
Makefile.am
is-tagged.py [new file with mode: 0644]
src/config/doveconf.c
src/master/main.c
update-version.sh [new file with mode: 0644]

index 934bc94fba5c319acec384575336f001673eeaae..151c0bd4f25b3d22183f76b117b5f6530c43df78 100644 (file)
--- a/.hgignore
+++ b/.hgignore
@@ -13,6 +13,7 @@ config.sub
 config.rpath
 configure
 configure.scan
+dovecot-version.h
 libtool
 libtool-shared
 ltconfig
index e10eed37f196af70a077e475b7cad7a20b8f7154..07d046f58fcf285d288910eac3e96f78af34ef7a 100644 (file)
@@ -5,13 +5,19 @@ DOCS = doc
 endif
 
 SUBDIRS = \
+       . \
        src \
        $(DOCS)
 
+dist_pkginclude_HEADERS = \
+       dovecot-version.h
+
 EXTRA_DIST = \
        COPYING.LGPL \
        COPYING.MIT \
        ChangeLog \
+       is-tagged.py \
+       update-version.sh \
        $(conf_DATA)
 
 datafiles = \
@@ -31,6 +37,11 @@ endif
 
 aclocal_DATA = dovecot.m4
 
+dovecot-version.h: noop
+       $(SHELL) $(top_srcdir)/update-version.sh $(top_srcdir) $(top_builddir)
+
+noop:
+
 dovecot-config: dovecot-config.in Makefile
        old=`pwd` && cd $(top_builddir) && abs_builddir=`pwd` && cd $$old && \
        cd $(top_srcdir) && abs_srcdir=`pwd` && cd $$old && \
@@ -61,3 +72,5 @@ install-exec-hook:
 endif
 
 CLEANFILES = $(datafiles)
+
+DISTCLEANFILES = $(top_builddir)/dovecot-version.h
diff --git a/is-tagged.py b/is-tagged.py
new file mode 100644 (file)
index 0000000..f48d001
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+    Checks if the current revision of the repository is a tagged revision,
+    but not 'tip'.
+
+    usage:
+    python is-tagged.py [/path/to/repo]
+    if no path is given, the current working directory will be used.
+
+    Exit status:
+      0 if the current revision is a tagged version OR
+        if the current revision was used for signing/tagging OR
+        if path is not a Mercurial repository OR
+        if module import should fail for some reason
+      1 if the current revision has no tag, except 'tip'
+"""
+import re
+import sys
+
+from mercurial import hg, ui
+try:
+    from mercurial.error import Abort, RepoError
+except ImportError:
+    try:
+        from mercurial.repo import RepoError
+        from mercurial.util import Abort
+    except ImportError:  # something old/new?
+        sys.exit(0)
+
+RE = r'^Added\s(?:signature|tag)\s(?:[\w\.]+\s)?for\schangeset\s[\da-f]{12,}$'
+
+
+def main():
+    if len(sys.argv) > 1:
+        path = sys.argv[1].strip()
+    else:
+        path = '.'
+    try:
+        repo = hg.repository(ui.ui(), path)
+    except (Abort, RepoError):  # no/bad repo? no extra version info
+        return 0
+    parents_id = repo.dirstate.parents()[0]
+    ctx = repo.changectx(parents_id)
+    if re.match(RE, ctx.description()):  # tag or sig was added for a release
+        return 0
+    for tag, nodeid in repo.tags().iteritems():
+        if tag != 'tip' and parents_id == nodeid:  # tagged
+            return 0
+    # not tagged
+    return 1
+
+
+if __name__ == '__main__':
+    sys.exit(main())
index 49c7d2bbfa99d5ccc5711348e3f40ccef0e8ac9d..0c3f938884d03d46358a6a248c9fce7051d175bc 100644 (file)
@@ -13,6 +13,7 @@
 #include "config-connection.h"
 #include "config-parser.h"
 #include "config-request.h"
+#include "dovecot-version.h"
 
 #include <stdio.h>
 #include <unistd.h>
@@ -513,7 +514,7 @@ int main(int argc, char *argv[])
        } else {
                /* print the config file path before parsing it, so in case
                   of errors it's still shown */
-               printf("# "VERSION": %s\n", config_path);
+               printf("# "DOVECOT_VERSION_FULL": %s\n", config_path);
                fflush(stdout);
        }
        master_service_init_finish(master_service);
index d770e1afed088519f6179e6de46fc89eba221364..00ff7af897264455f134ae7d94a85703f18092b2 100644 (file)
@@ -21,6 +21,7 @@
 #include "service-monitor.h"
 #include "service-process.h"
 #include "service-log.h"
+#include "dovecot-version.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -694,7 +695,7 @@ int main(int argc, char *argv[])
 
        while (optind < argc) {
                if (strcmp(argv[optind], "--version") == 0) {
-                       printf("%s\n", VERSION);
+                       printf("%s\n", DOVECOT_VERSION_FULL);
                        return 0;
                } else if (strcmp(argv[optind], "--build-options") == 0) {
                        print_build_options();
diff --git a/update-version.sh b/update-version.sh
new file mode 100644 (file)
index 0000000..c4d1fae
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+SRCDIR="${1:-`pwd`}"
+BUILDDIR="${2:-`pwd`}"
+VERSION_H="dovecot-version.h"
+VERSION_HT="dovecot-version.h.tmp"
+
+abspath()
+{ #$1 the path
+  #$2 1 -> SRCDIR || 2 -> BUILDDIR
+       old=`pwd`
+       cd "${1}"
+       if [ ${2} -eq 1 ]; then
+               SRCDIR=`pwd`
+       else
+               BUILDDIR=`pwd`
+       fi
+       cd "$old"
+}
+
+abspath "${SRCDIR}" 1
+abspath "${BUILDDIR}" 2
+
+# when using a different BUILDDIR just copy from SRCDIR, if there is no .hg
+if [ "${BUILDDIR}" != "${SRCDIR}" ]; then
+       if [ ! -d "${SRCDIR}/.hg" ]  && [ -f "${SRCDIR}/${VERSION_H}" ]; then
+               cmp -s "${SRCDIR}/${VERSION_H}" "${BUILDDIR}/${VERSION_H}"
+               if [ $? -ne 0 ]; then
+                       cp "${SRCDIR}/${VERSION_H}" "${BUILDDIR}/${VERSION_H}"
+                       exit 0
+               fi
+       fi
+fi
+
+# Don't generate dovecot-version.h if the source tree has no .hg dir but
+# a dovecot-version.h. This may be the result of a release/nightly tarball.
+[ ! -d "${SRCDIR}/.hg" ] && [ -f "${BUILDDIR}/${VERSION_H}" ] && exit 0
+
+# Lets generate the dovecot-version.h
+[ -f "${BUILDDIR}/${VERSION_HT}" ] && rm -f "${BUILDDIR}/${VERSION_HT}"
+python "${SRCDIR}/is-tagged.py" "${SRCDIR}"
+if [ $? = 1 ]; then
+       # older hg doesn't recognize option -i
+       #HGID=`hg -R ${SRCDIR} id -i 2>/dev/null`
+       HGID=`hg -R ${SRCDIR} id 2>/dev/null | awk '{print $1}'`
+       cat > "${BUILDDIR}/${VERSION_HT}" <<EOF
+#ifndef DOVECOT_VERSION_H
+#define DOVECOT_VERSION_H
+
+#define DOVECOT_VERSION_FULL VERSION" (${HGID})"
+
+#endif /* DOVECOT_VERSION_H */
+EOF
+else
+       cat > "${BUILDDIR}/${VERSION_HT}" <<EOF
+#ifndef DOVECOT_VERSION_H
+#define DOVECOT_VERSION_H
+
+#define DOVECOT_VERSION_FULL VERSION
+
+#endif /* DOVECOT_VERSION_H */
+EOF
+fi
+
+cmp -s "${BUILDDIR}/${VERSION_H}" "${BUILDDIR}/${VERSION_HT}" && \
+       rm -f "${BUILDDIR}/${VERSION_HT}" || \
+       mv "${BUILDDIR}/${VERSION_HT}" "${BUILDDIR}/${VERSION_H}"