]> xenbits.xensource.com Git - people/iwj/xen.git/commitdiff
Use {git, hg, svn} commit id if available for xen_changeset
authorMarek Marczykowski <marmarek@invisiblethingslab.com>
Wed, 8 May 2013 23:07:05 +0000 (01:07 +0200)
committerIan Campbell <ian.campbell@citrix.com>
Mon, 13 May 2013 13:07:39 +0000 (14:07 +0100)
As Xen uses git as primary repository, get git commit id for
xen_changeset info.

Signed-off-by: Marek Marczykowski <marmarek@invisiblethingslab.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Keir Fraser <keir@xen.org>
xen/Makefile
xen/tools/scmversion [new file with mode: 0755]

index 0fb3db737675416e7d4ab11f54272725e8ff0d1d..201d9bca16b0b46ef6e7e40d9a85ff0ef2afc43d 100644 (file)
@@ -126,7 +126,7 @@ include/xen/compile.h: include/xen/compile.h.in .banner
            -e 's/@@version@@/$(XEN_VERSION)/g' \
            -e 's/@@subversion@@/$(XEN_SUBVERSION)/g' \
            -e 's/@@extraversion@@/$(XEN_EXTRAVERSION)/g' \
-           -e 's!@@changeset@@!$(shell ((hg parents --template "{date|date} {rev}:{node|short}" >/dev/null && hg parents --template "{date|date} {rev}:{node|short}") || echo "unavailable") 2>/dev/null)!g' \
+           -e 's!@@changeset@@!$(shell tools/scmversion $(XEN_ROOT) || echo "unavailable")!g' \
            < include/xen/compile.h.in > $@.new
        @grep \" .banner >> $@.new
        @grep -v \" .banner
diff --git a/xen/tools/scmversion b/xen/tools/scmversion
new file mode 100755 (executable)
index 0000000..219d898
--- /dev/null
@@ -0,0 +1,101 @@
+#!/bin/sh
+#
+# This scripts adds local version information from the version
+# control systems git, mercurial (hg) and subversion (svn).
+#
+# If something goes wrong, send a mail the kernel build mailinglist
+# (see MAINTAINERS) and CC Nico Schottelius
+# <nico-linuxsetlocalversion -at- schottelius.org>.
+#
+# Based on setlocalversion from Linux kernel
+#
+#
+
+usage() {
+       echo "Usage: $0 [--save-scmversion] [srctree]" >&2
+       exit 1
+}
+
+scm_only=false
+srctree=.
+if test "$1" = "--save-scmversion"; then
+       scm_only=true
+       shift
+fi
+if test $# -gt 0; then
+       srctree=$1
+       shift
+fi
+if test $# -gt 0 -o ! -d "$srctree"; then
+       usage
+fi
+
+scm_version()
+{
+       local short
+       short=false
+
+       cd "$srctree"
+       if test -e .scmversion; then
+               cat .scmversion
+               return
+       fi
+       if test "$1" = "--short"; then
+               short=true
+       fi
+
+       # Check for git and a git repo.
+       if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+               date=`git show -s --pretty="%ad" HEAD`
+
+               printf '%s %s%s' "$date" git: $head
+
+               # Is this git on svn?
+               if git config --get svn-remote.svn.url >/dev/null; then
+                       printf -- 'svn:%s' "`git svn find-rev $head`"
+               fi
+
+               # Update index only on r/w media
+               [ -w . ] && git update-index --refresh --unmerged > /dev/null
+
+               # Check for uncommitted changes
+               if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
+                       printf '%s' -dirty
+               fi
+
+               # All done with git
+               return
+       fi
+
+       # Check for mercurial and a mercurial repo.
+       if test -d .hg && hgid=`hg id 2>/dev/null`; then
+               id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
+               date=`hg parents --template "{date|date}"`
+               printf '%s %s%s' "$date" hg: "$id"
+
+               # Are there uncommitted changes?
+               # These are represented by + after the changeset id.
+               case "$hgid" in
+                       *+|*+\ *) printf '%s' -dirty ;;
+               esac
+
+               # All done with mercurial
+               return
+       fi
+
+       # Check for svn and a svn repo.
+       if rev=`LANG= LC_ALL= LC_MESSAGES=C svn info 2>/dev/null | grep '^Last Changed Rev'`; then
+               rev=`echo $rev | awk '{print $NF}'`
+               printf -- 'svn:%s' "$rev"
+
+               # All done with svn
+               return
+       fi
+}
+
+cd $srctree
+
+# full scm version string
+res="$(scm_version)"
+
+echo "$res"