build: add mkrevision.sh helper script which properly infers the revision from either...
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 25 Mar 2013 11:05:34 +0000 (11:05 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Mon, 25 Mar 2013 11:05:34 +0000 (11:05 +0000)
build/mkrevision.sh [new file with mode: 0755]

diff --git a/build/mkrevision.sh b/build/mkrevision.sh
new file mode 100755 (executable)
index 0000000..889ce75
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+TOPDIR="${0%mkrevision.sh}"
+
+[ -d "$TOPDIR/../build" ] || {
+       echo "Please execute as ./build/mkrevision.sh" >&2
+       exit 1
+}
+
+(
+       cd "$TOPDIR"
+       if svn info >/dev/null 2>/dev/null; then
+               revision="svn-r$(LC_ALL=C svn info | sed -ne 's/^Revision: //p')"
+       elif git log -1 >/dev/null 2>/dev/null; then
+               revision="svn-r$(LC_ALL=C git log -1 | sed -ne 's/.*git-svn-id: .*@\([0-9]\+\) .*/\1/p')"
+               if [ "$revision" = "svn-r" ]; then
+                       revision="git-$(LC_ALL=C git log -1 --pretty=%h)"
+               fi
+       else
+               revision="unknown"
+       fi
+
+       echo "$revision"
+)