A little patch to give a reasonable version number when building
prosody, for those who work with git as their VCS front-end.  Details
are in the commit message.

-- >8 --
Subject: [PATCH] Makefile: git-based version number

In cases where someone is using a git front-end for VCS, will generate
a prosody-version file based on the git HEAD commit hash.  If that git
front-end repo is bridged from a hg backend repo, will also append the
latest hg commit hash.  Those not using git as their VCS front-end
will not be affected, nor those building a 'release' version.

Also notices if the local working tree has been modified from the
latest git commit and indicates accordingly.

A typical version number would then look like:
        git:157cb4b7/hg:3849b5187d47
Or for a modified local source tree:
        local:dirty/git:0205d863/hg:3849b5187d47

The old behavior was to call the version "unknown".

Signed-off-by: David Favro <pros...@meta-dynamic.com>
---
 Makefile       |  5 +++--
 git-hg-version | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
 create mode 100755 git-hg-version

diff --git a/Makefile b/Makefile
index 06e67c9c..0eba85c0 100644
--- a/Makefile
+++ b/Makefile
@@ -78,7 +78,8 @@ prosody.cfg.lua.install: prosody.cfg.lua.dist
 %.version: .hg/dirstate
        hexdump -n6 -e'6/1 "%02x"' $^ > $@
 
+%.version: .git/objects
+       ./git-hg-version > $@
+
 %.version:
        echo unknown > $@
-
-
diff --git a/git-hg-version b/git-hg-version
new file mode 100755
index 00000000..dcb2b2c6
--- /dev/null
+++ b/git-hg-version
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# Simple script to try to generate a version-number for people
+# installing from a git front-end.
+
+# Deliberately don't consider new untracked files to be a dirty tree
+# (when all untracked files are clean), because this is too likely to
+# be inconsequential files that won't be installed.
+dirty="`git status -uno --short | egrep -q '^ *M' && echo local:dirty/`"
+
+gitv="git:`git -c core.abbrev=8 rev-parse --short HEAD`"
+
+# Hg-backend-to-git-frontend typically keeps a .hg repo inside .git:
+if test -d .git/hg/.hg
+       then
+       # Get the latest commit hash from hg.
+       hgv="/hg:`hg -R .git/hg log --limit 1 | head -1 | sed 's/^.*://'`"
+       fi
+
+echo "${dirty}${gitv}${hgv}"
-- 
2.2.0

-- 
You received this message because you are subscribed to the Google Groups 
"prosody-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to prosody-dev+unsubscr...@googlegroups.com.
To post to this group, send email to prosody-dev@googlegroups.com.
Visit this group at https://groups.google.com/group/prosody-dev.
For more options, visit https://groups.google.com/d/optout.

Reply via email to