Remove tabs.
[kugel-rb.git] / tools / version.sh
blob04c765119245b265f0cb0fe873c8c4be49ebbf62
1 #!/bin/sh
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
8 # $Id$
11 # Usage: version.sh [source-root]
13 # Prints the revision of the repository.
15 # The format is rNNNNN[M]-YYMMDD
17 # The M indicates the revision isn't matched to a pure Subversion ID, usually
18 # because it's built from something like GIT.
20 svnversion_safe() {
21 # LANG=C forces svnversion to not localize "exported".
22 if OUTPUT=`LANG=C svnversion "$@"`; then
23 if [ "$OUTPUT" = "exported" ]; then
24 echo "unknown"
25 else
26 echo "r$OUTPUT"
28 else
29 echo "unknown"
33 # This logic is pulled from the Linux's scripts/setlocalversion (also GPL) and tweaked for
34 # rockbox. If the commit information for HEAD has a svn-id in it we report that instead of
35 # the git id
36 gitversion() {
37 export GIT_DIR="$1/.git"
39 # This verifies we are in a git directory
40 if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
42 # Get the svn revision of the most recent git-svn commit
43 version=`git log --pretty=format:'%b' --grep='git-svn-id: svn' -1 | tail -n 1 | perl -ne 'm/@(\d*)/; print "r" . $1;'`
44 mod=""
45 # Is this a git-svn commit?
46 if ! git log -1 --pretty=format:"%b" | grep -q "git-svn-id: svn" ; then
47 version="$version+$head"
49 # Are there uncommitted changes?
50 export GIT_WORK_TREE="$1"
51 if git diff --name-only HEAD | read dummy; then
52 mod="M"
53 elif git diff --name-only --cached HEAD | read dummy; then
54 mod="M"
57 echo "${version}${mod}"
58 # All done with git
59 exit
63 # Work out the latest svn id and also the latest bzr revno
64 bzrversion() {
66 # look for a svn revno in the current head
67 svnver=`LANG=C bzr log -l1 $1 | grep '^ *svn revno: ' | cut -d : -f2 | cut -d ' ' -f 2`
69 if [ -n "$svnver" ]; then
70 # current head is a svn version so we don't care about bzr
71 version="r$svnver"
72 else
73 # look for a svn revno anywhere in history including in merges
74 svnver=`LANG=C bzr log -n0 $1 | grep '^ *svn revno: ' | head -n 1 | cut -d : -f2 | cut -d ' ' -f 2`
75 if [ -n "$svnver" ]; then
76 version="r$svnver+bzr`bzr revno $1`"
77 else
78 version="bzr`bzr revno $1`"
81 if ! bzr diff $1 >/dev/null; then
82 mod="M"
84 echo "${version}${mod}"
88 # First locate the top of the src tree (passed in usually)
90 if [ -n "$1" ]; then TOP=$1; else TOP=..; fi
92 # setting VERSION var on commandline has precedence
93 if [ -z $VERSION ]; then
94 # If the VERSIONFILE exisits we use that
95 VERSIONFILE=docs/VERSION
96 if [ -r $TOP/$VERSIONFILE ]; then VER=`cat $TOP/$VERSIONFILE`;
97 else
98 # Ok, we need to derive it from the Version Control system
99 if [ -d "$TOP/.git" ]; then
100 VER=`gitversion $TOP`
101 elif [ -d "$TOP/.bzr" ]; then
102 VER=`bzrversion $TOP`
103 else
104 VER=`svnversion_safe $TOP`;
105 if [ "$VER" = "unknown" ]; then
106 # try getting it from a subdir to test if perhaps they are symlinked
107 # from the root
108 VER=`svnversion_safe $TOP/tools`;
112 VERSION=$VER-`date -u +%y%m%d`
114 echo $VERSION