blob: f6946cf99ce1bd0a06f9835157f39d4b2b80e971 [file] [log] [blame]
Rene Scharfe117a93d2006-01-04 20:42:03 +01001#!/bin/sh
2# Print additional version information for non-release trees.
Ryan Andersonaaebf432005-07-31 04:57:49 -04003
Rene Scharfe117a93d2006-01-04 20:42:03 +01004usage() {
5 echo "Usage: $0 [srctree]" >&2
6 exit 1
Ryan Andersonaaebf432005-07-31 04:57:49 -04007}
8
Rene Scharfe117a93d2006-01-04 20:42:03 +01009cd "${1:-.}" || usage
Ryan Andersonaaebf432005-07-31 04:57:49 -040010
Rene Scharfe117a93d2006-01-04 20:42:03 +010011# Check for git and a git repo.
Trent Piephof03b2832008-09-12 12:26:24 -070012if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
Rene Scharfe117a93d2006-01-04 20:42:03 +010013 # Do we have an untagged version?
Uwe Zeisberger29b0c892006-06-16 08:47:57 +020014 if git name-rev --tags HEAD | grep -E '^HEAD[[:space:]]+(.*~[0-9]*|undefined)$' > /dev/null; then
Sebastian Siewior56b2f072008-07-02 00:18:08 +020015 if tag=`git describe 2>/dev/null`; then
16 echo $tag | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
Trent Piephof03b2832008-09-12 12:26:24 -070017 else
18 printf '%s%s' -g $head
Sebastian Siewior56b2f072008-07-02 00:18:08 +020019 fi
Rene Scharfe117a93d2006-01-04 20:42:03 +010020 fi
Ryan Andersonaaebf432005-07-31 04:57:49 -040021
Peter Korsgaardff80aa92008-12-02 21:58:06 +010022 # Is this git on svn?
23 if git config --get svn-remote.svn.url >/dev/null; then
24 printf -- '-svn%s' "`git-svn find-rev $head`"
25 fi
26
Rene Scharfe117a93d2006-01-04 20:42:03 +010027 # Are there uncommitted changes?
Theodore Ts'o4e7434f2007-11-02 21:53:00 -040028 git update-index --refresh --unmerged > /dev/null
Theodore Ts'ob052ce42007-11-02 21:53:01 -040029 if git diff-index --name-only HEAD | grep -v "^scripts/package" \
30 | read dummy; then
Ryan Anderson24d49752006-01-08 04:35:36 -050031 printf '%s' -dirty
Rene Scharfe117a93d2006-01-04 20:42:03 +010032 fi
Aron Griffis3dce1742007-11-28 16:55:44 -050033
34 # All done with git
35 exit
36fi
37
38# Check for mercurial and a mercurial repo.
39if hgid=`hg id 2>/dev/null`; then
40 tag=`printf '%s' "$hgid" | cut -d' ' -f2`
41
42 # Do we have an untagged version?
43 if [ -z "$tag" -o "$tag" = tip ]; then
44 id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
45 printf '%s%s' -hg "$id"
46 fi
47
48 # Are there uncommitted changes?
49 # These are represented by + after the changeset id.
50 case "$hgid" in
51 *+|*+\ *) printf '%s' -dirty ;;
52 esac
53
54 # All done with mercurial
55 exit
Rene Scharfe117a93d2006-01-04 20:42:03 +010056fi
Bryan Wuba3d05f2008-02-03 14:13:26 +080057
58# Check for svn and a svn repo.
Peter Korsgaard167d6a02008-12-02 21:58:05 +010059if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then
Bryan Wuba3d05f2008-02-03 14:13:26 +080060 rev=`echo $rev | awk '{print $NF}'`
61 changes=`svn status 2>/dev/null | grep '^[AMD]' | wc -l`
62
63 # Are there uncommitted changes?
64 if [ $changes != 0 ]; then
Mike Frysingere3da2fb2008-10-25 17:43:50 -040065 printf -- '-svn%s%s' "$rev" -dirty
Bryan Wuba3d05f2008-02-03 14:13:26 +080066 else
67 printf -- '-svn%s' "$rev"
68 fi
69
70 # All done with svn
71 exit
72fi