Rene Scharfe | 117a93d | 2006-01-04 20:42:03 +0100 | [diff] [blame] | 1 | #!/bin/sh |
Nico Schottelius | 3325257 | 2009-05-16 14:00:56 +0200 | [diff] [blame] | 2 | # |
| 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 Anderson | aaebf43 | 2005-07-31 04:57:49 -0400 | [diff] [blame] | 11 | |
Rene Scharfe | 117a93d | 2006-01-04 20:42:03 +0100 | [diff] [blame] | 12 | usage() { |
| 13 | echo "Usage: $0 [srctree]" >&2 |
| 14 | exit 1 |
Ryan Anderson | aaebf43 | 2005-07-31 04:57:49 -0400 | [diff] [blame] | 15 | } |
| 16 | |
Rene Scharfe | 117a93d | 2006-01-04 20:42:03 +0100 | [diff] [blame] | 17 | cd "${1:-.}" || usage |
Ryan Anderson | aaebf43 | 2005-07-31 04:57:49 -0400 | [diff] [blame] | 18 | |
Rene Scharfe | 117a93d | 2006-01-04 20:42:03 +0100 | [diff] [blame] | 19 | # Check for git and a git repo. |
Trent Piepho | f03b283 | 2008-09-12 12:26:24 -0700 | [diff] [blame] | 20 | if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then |
Nico Schottelius | 3325257 | 2009-05-16 14:00:56 +0200 | [diff] [blame] | 21 | |
| 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 Scharfe | 117a93d | 2006-01-04 20:42:03 +0100 | [diff] [blame] | 35 | fi |
Ryan Anderson | aaebf43 | 2005-07-31 04:57:49 -0400 | [diff] [blame] | 36 | |
Peter Korsgaard | ff80aa9 | 2008-12-02 21:58:06 +0100 | [diff] [blame] | 37 | # Is this git on svn? |
| 38 | if git config --get svn-remote.svn.url >/dev/null; then |
Peter Korsgaard | 4774bb1 | 2009-03-26 21:58:04 +0100 | [diff] [blame] | 39 | printf -- '-svn%s' "`git svn find-rev $head`" |
Peter Korsgaard | ff80aa9 | 2008-12-02 21:58:06 +0100 | [diff] [blame] | 40 | fi |
| 41 | |
Nico Schottelius | a2bb90a | 2009-06-12 09:59:52 +0200 | [diff] [blame^] | 42 | # Update index only on r/w media |
| 43 | [ -w . ] && git update-index --refresh --unmerged > /dev/null |
| 44 | |
| 45 | # Check for uncommitted changes |
Theodore Ts'o | b052ce4 | 2007-11-02 21:53:01 -0400 | [diff] [blame] | 46 | if git diff-index --name-only HEAD | grep -v "^scripts/package" \ |
| 47 | | read dummy; then |
Ryan Anderson | 24d4975 | 2006-01-08 04:35:36 -0500 | [diff] [blame] | 48 | printf '%s' -dirty |
Rene Scharfe | 117a93d | 2006-01-04 20:42:03 +0100 | [diff] [blame] | 49 | fi |
Aron Griffis | 3dce174 | 2007-11-28 16:55:44 -0500 | [diff] [blame] | 50 | |
| 51 | # All done with git |
| 52 | exit |
| 53 | fi |
| 54 | |
| 55 | # Check for mercurial and a mercurial repo. |
| 56 | if hgid=`hg id 2>/dev/null`; then |
| 57 | tag=`printf '%s' "$hgid" | cut -d' ' -f2` |
| 58 | |
| 59 | # Do we have an untagged version? |
| 60 | if [ -z "$tag" -o "$tag" = tip ]; then |
| 61 | id=`printf '%s' "$hgid" | sed 's/[+ ].*//'` |
| 62 | printf '%s%s' -hg "$id" |
| 63 | fi |
| 64 | |
| 65 | # Are there uncommitted changes? |
| 66 | # These are represented by + after the changeset id. |
| 67 | case "$hgid" in |
| 68 | *+|*+\ *) printf '%s' -dirty ;; |
| 69 | esac |
| 70 | |
| 71 | # All done with mercurial |
| 72 | exit |
Rene Scharfe | 117a93d | 2006-01-04 20:42:03 +0100 | [diff] [blame] | 73 | fi |
Bryan Wu | ba3d05f | 2008-02-03 14:13:26 +0800 | [diff] [blame] | 74 | |
| 75 | # Check for svn and a svn repo. |
Peter Korsgaard | 167d6a0 | 2008-12-02 21:58:05 +0100 | [diff] [blame] | 76 | if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then |
Bryan Wu | ba3d05f | 2008-02-03 14:13:26 +0800 | [diff] [blame] | 77 | rev=`echo $rev | awk '{print $NF}'` |
Mike Frysinger | d21d52d | 2009-02-05 16:13:32 +0800 | [diff] [blame] | 78 | printf -- '-svn%s' "$rev" |
Bryan Wu | ba3d05f | 2008-02-03 14:13:26 +0800 | [diff] [blame] | 79 | |
| 80 | # All done with svn |
| 81 | exit |
| 82 | fi |