blob: 00790472f641b8cd5990033a4162b0120aa1453e [file] [log] [blame]
Rene Scharfe117a93d2006-01-04 20:42:03 +01001#!/bin/sh
Nico Schottelius33252572009-05-16 14:00:56 +02002#
3# This scripts adds local version information from the version
4# control systems git, mercurial (hg) and subversion (svn).
5#
6# If something goes wrong, send a mail the kernel build mailinglist
7# (see MAINTAINERS) and CC Nico Schottelius
8# <nico-linuxsetlocalversion -at- schottelius.org>.
9#
10#
Ryan Andersonaaebf432005-07-31 04:57:49 -040011
Rene Scharfe117a93d2006-01-04 20:42:03 +010012usage() {
13 echo "Usage: $0 [srctree]" >&2
14 exit 1
Ryan Andersonaaebf432005-07-31 04:57:49 -040015}
16
Rene Scharfe117a93d2006-01-04 20:42:03 +010017cd "${1:-.}" || usage
Ryan Andersonaaebf432005-07-31 04:57:49 -040018
Rene Scharfe117a93d2006-01-04 20:42:03 +010019# Check for git and a git repo.
Trent Piephof03b2832008-09-12 12:26:24 -070020if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
Nico Schottelius33252572009-05-16 14:00:56 +020021
22 # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore it,
23 # because this version is defined in the top level Makefile.
24 if [ -z "`git describe --exact-match 2>/dev/null`" ]; then
25
26 # If we are past a tagged commit (like "v2.6.30-rc5-302-g72357d5"),
27 # we pretty print it.
28 if atag="`git describe 2>/dev/null`"; then
29 echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
30
31 # If we don't have a tag at all we print -g{commitish}.
32 else
33 printf '%s%s' -g $head
34 fi
Rene Scharfe117a93d2006-01-04 20:42:03 +010035 fi
Ryan Andersonaaebf432005-07-31 04:57:49 -040036
Peter Korsgaardff80aa92008-12-02 21:58:06 +010037 # Is this git on svn?
38 if git config --get svn-remote.svn.url >/dev/null; then
Peter Korsgaard4774bb12009-03-26 21:58:04 +010039 printf -- '-svn%s' "`git svn find-rev $head`"
Peter Korsgaardff80aa92008-12-02 21:58:06 +010040 fi
41
Rene Scharfe117a93d2006-01-04 20:42:03 +010042 # Are there uncommitted changes?
Theodore Ts'o4e7434f2007-11-02 21:53:00 -040043 git update-index --refresh --unmerged > /dev/null
Theodore Ts'ob052ce42007-11-02 21:53:01 -040044 if git diff-index --name-only HEAD | grep -v "^scripts/package" \
45 | read dummy; then
Ryan Anderson24d49752006-01-08 04:35:36 -050046 printf '%s' -dirty
Rene Scharfe117a93d2006-01-04 20:42:03 +010047 fi
Aron Griffis3dce1742007-11-28 16:55:44 -050048
49 # All done with git
50 exit
51fi
52
53# Check for mercurial and a mercurial repo.
54if hgid=`hg id 2>/dev/null`; then
55 tag=`printf '%s' "$hgid" | cut -d' ' -f2`
56
57 # Do we have an untagged version?
58 if [ -z "$tag" -o "$tag" = tip ]; then
59 id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
60 printf '%s%s' -hg "$id"
61 fi
62
63 # Are there uncommitted changes?
64 # These are represented by + after the changeset id.
65 case "$hgid" in
66 *+|*+\ *) printf '%s' -dirty ;;
67 esac
68
69 # All done with mercurial
70 exit
Rene Scharfe117a93d2006-01-04 20:42:03 +010071fi
Bryan Wuba3d05f2008-02-03 14:13:26 +080072
73# Check for svn and a svn repo.
Peter Korsgaard167d6a02008-12-02 21:58:05 +010074if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then
Bryan Wuba3d05f2008-02-03 14:13:26 +080075 rev=`echo $rev | awk '{print $NF}'`
Mike Frysingerd21d52d2009-02-05 16:13:32 +080076 printf -- '-svn%s' "$rev"
Bryan Wuba3d05f2008-02-03 14:13:26 +080077
78 # All done with svn
79 exit
80fi