blob: 32c8554f3946dee390b56eda335facd94f0764fa [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
Nico Schotteliusa182ad32009-04-25 09:48:39 +020013 # Do we have an untagged tag?
14 if atag=`git describe 2>/dev/null`; then
15 echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
16 # add -g${head}, if there is no usable tag
17 else
18 printf '%s%s' -g $head
Rene Scharfe117a93d2006-01-04 20:42:03 +010019 fi
Ryan Andersonaaebf432005-07-31 04:57:49 -040020
Peter Korsgaardff80aa92008-12-02 21:58:06 +010021 # Is this git on svn?
22 if git config --get svn-remote.svn.url >/dev/null; then
Peter Korsgaard4774bb12009-03-26 21:58:04 +010023 printf -- '-svn%s' "`git svn find-rev $head`"
Peter Korsgaardff80aa92008-12-02 21:58:06 +010024 fi
25
Rene Scharfe117a93d2006-01-04 20:42:03 +010026 # Are there uncommitted changes?
Theodore Ts'o4e7434f2007-11-02 21:53:00 -040027 git update-index --refresh --unmerged > /dev/null
Theodore Ts'ob052ce42007-11-02 21:53:01 -040028 if git diff-index --name-only HEAD | grep -v "^scripts/package" \
29 | read dummy; then
Ryan Anderson24d49752006-01-08 04:35:36 -050030 printf '%s' -dirty
Rene Scharfe117a93d2006-01-04 20:42:03 +010031 fi
Aron Griffis3dce1742007-11-28 16:55:44 -050032
33 # All done with git
34 exit
35fi
36
37# Check for mercurial and a mercurial repo.
38if hgid=`hg id 2>/dev/null`; then
39 tag=`printf '%s' "$hgid" | cut -d' ' -f2`
40
41 # Do we have an untagged version?
42 if [ -z "$tag" -o "$tag" = tip ]; then
43 id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
44 printf '%s%s' -hg "$id"
45 fi
46
47 # Are there uncommitted changes?
48 # These are represented by + after the changeset id.
49 case "$hgid" in
50 *+|*+\ *) printf '%s' -dirty ;;
51 esac
52
53 # All done with mercurial
54 exit
Rene Scharfe117a93d2006-01-04 20:42:03 +010055fi
Bryan Wuba3d05f2008-02-03 14:13:26 +080056
57# Check for svn and a svn repo.
Peter Korsgaard167d6a02008-12-02 21:58:05 +010058if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then
Bryan Wuba3d05f2008-02-03 14:13:26 +080059 rev=`echo $rev | awk '{print $NF}'`
Mike Frysingerd21d52d2009-02-05 16:13:32 +080060 printf -- '-svn%s' "$rev"
Bryan Wuba3d05f2008-02-03 14:13:26 +080061
62 # All done with svn
63 exit
64fi