summaryrefslogtreecommitdiffstats
path: root/setlocalversion
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2017-01-23 10:28:55 +0100
committerRalf Baechle <ralf@linux-mips.org>2017-01-23 20:33:06 +0100
commit47349482ee7b737c3cd2a8a1acb18fc3d9b95b0a (patch)
treed4fb09d11b2998124032c7d1be70841cc42a9df1 /setlocalversion
parent31a21cc0187ceea70a826010476eb260823c5a45 (diff)
Provide scm version define.
This can be used by code to provide a more exact definition than a release version. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'setlocalversion')
-rwxr-xr-xsetlocalversion83
1 files changed, 83 insertions, 0 deletions
diff --git a/setlocalversion b/setlocalversion
new file mode 100755
index 0000000..e353d68
--- /dev/null
+++ b/setlocalversion
@@ -0,0 +1,83 @@
+srctree=.
+if test $# -gt 0; then
+ srctree=$1
+ shift
+fi
+if test $# -gt 0 -o ! -d "$srctree"; then
+ usage
+fi
+
+scm_version()
+{
+ cd "$srctree"
+
+ # Check for git and a git repo.
+ if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
+ head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+
+ # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
+ # it, because this version is defined in the top level Makefile.
+ if [ -z "`git describe --exact-match 2>/dev/null`" ]; then
+ # If we are past a tagged commit (like
+ # "v2.6.30-rc5-302-g72357d5"), we pretty print it.
+ if atag="`git describe 2>/dev/null`"; then
+ echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
+
+ # If we don't have a tag at all we print -g{commitish}.
+ else
+ printf '%s%s' -g $head
+ fi
+ fi
+
+ # 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
+
+ # 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
+ # Do we have an tagged version? If so, latesttagdistance == 1
+ if [ "`hg log -r . --template '{latesttagdistance}'`" == "1" ]; then
+ id=`hg log -r . --template '{latesttag}'`
+ printf '%s%s' -hg "$id"
+ else
+ tag=`printf '%s' "$hgid" | cut -d' ' -f2`
+ if [ -z "$tag" -o "$tag" = tip ]; then
+ id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
+ printf '%s%s' -hg "$id"
+ fi
+ fi
+
+ # 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
+}
+
+# full scm version string
+res="$res$(scm_version)"
+
+echo "$res"