Linux 2.6.26-rc5
[linux-2.6/openmoko-kernel/knife-kernel.git] / scripts / setlocalversion
blob1c1bdaf7348a61fc3606165cb1cc5c6725831e05
1 #!/bin/sh
2 # Print additional version information for non-release trees.
4 usage() {
5 echo "Usage: $0 [srctree]" >&2
6 exit 1
9 cd "${1:-.}" || usage
11 # Check for git and a git repo.
12 if head=`git rev-parse --verify HEAD 2>/dev/null`; then
13 # Do we have an untagged version?
14 if git name-rev --tags HEAD | grep -E '^HEAD[[:space:]]+(.*~[0-9]*|undefined)$' > /dev/null; then
15 git describe | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
18 # Are there uncommitted changes?
19 git update-index --refresh --unmerged > /dev/null
20 if git diff-index --name-only HEAD | grep -v "^scripts/package" \
21 | read dummy; then
22 printf '%s' -dirty
25 # All done with git
26 exit
29 # Check for mercurial and a mercurial repo.
30 if hgid=`hg id 2>/dev/null`; then
31 tag=`printf '%s' "$hgid" | cut -d' ' -f2`
33 # Do we have an untagged version?
34 if [ -z "$tag" -o "$tag" = tip ]; then
35 id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
36 printf '%s%s' -hg "$id"
39 # Are there uncommitted changes?
40 # These are represented by + after the changeset id.
41 case "$hgid" in
42 *+|*+\ *) printf '%s' -dirty ;;
43 esac
45 # All done with mercurial
46 exit
49 # Check for svn and a svn repo.
50 if rev=`svn info 2>/dev/null | grep '^Revision'`; then
51 rev=`echo $rev | awk '{print $NF}'`
52 changes=`svn status 2>/dev/null | grep '^[AMD]' | wc -l`
54 # Are there uncommitted changes?
55 if [ $changes != 0 ]; then
56 printf -- '-svn%s%s%s' "$rev" -dirty "$changes"
57 else
58 printf -- '-svn%s' "$rev"
61 # All done with svn
62 exit