3 # This scripts adds local version information from the version
4 # control systems git, mercurial (hg) and subversion (svn).
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>.
13 echo "Usage: $0 [srctree]" >&2
19 # Check for git and a git repo.
20 if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
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
26 # If we are past a tagged commit (like "v2.6.30-rc5-302-g72357d5"),
28 if atag="`git describe 2>/dev/null`"; then
29 echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
31 # If we don't have a tag at all we print -g{commitish}.
33 printf '%s%s' -g $head
38 if git config --get svn-remote.svn.url >/dev/null; then
39 printf -- '-svn%s' "`git svn find-rev $head`"
42 # Are there uncommitted changes?
43 git update-index --refresh --unmerged > /dev/null
44 if git diff-index --name-only HEAD | grep -v "^scripts/package" \
53 # Check for mercurial and a mercurial repo.
54 if hgid=`hg id 2>/dev/null`; then
55 tag=`printf '%s' "$hgid" | cut -d' ' -f2`
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"
63 # Are there uncommitted changes?
64 # These are represented by + after the changeset id.
66 *+|*+\ *) printf '%s' -dirty ;;
69 # All done with mercurial
73 # Check for svn and a svn repo.
74 if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then
75 rev=`echo $rev | awk '{print $NF}'`
76 printf -- '-svn%s' "$rev"