3 # Copyright 2008 Paul Wise
4 # Copyright 2009 Konstantin Dmitriev
6 # This package is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of
9 # the License, or (at your option) any later version.
11 # This package is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
18 export REVISION_ID=`cd "$1"; git log --no-color -1 | head -n 1 | cut -f 2 -d ' '`
19 export BRANCH=`cd "$1"; git branch -a --no-color --contains HEAD | sed -e s/\*\ // | sed -e s/\(no\ branch\)// | tr '\n' ' ' | tr -s ' ' | sed s/^' '//`
20 if ( echo $BRANCH | egrep origin/master > /dev/null ); then
21 #give a priority to master branch
24 BRANCH=`echo $BRANCH | cut -d ' ' -f 1`
27 export REVISION=`git show --pretty=format:%ci HEAD | head -c 10`
28 REVISION=${REVISION:0:4}${REVISION:5:2}${REVISION:8:2}
29 export COMPARE="$1/.git/"
30 # The extra * at the end is for Modified
31 #REVISION="$REVISION"`cd "$1"; [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"`
36 export REVISION=`cd "$1"; git svn find-rev HEAD`
37 export COMPARE="$1/.git/"
38 if [ x = "x$REVISION" ] ; then
39 # The extra M at the end is for Modified
40 export REVISION=`cd "$1"; git svn find-rev \`git rev-list --max-count=1 --grep='git-svn-id: ' HEAD\``M
42 export REVISION="$REVISION"`cd "$1"; git diff --quiet HEAD || echo M`
48 export REVISION=`cd "$1"; svnversion || svn info | sed -n 's/^Revision: \(.*\)/\1/p'`
52 HEADER="$2/autorevision.h"
56 if [ ! -f "$HEADER" ] ; then
57 touch -t 197001010101 "$HEADER"
61 # Extract the revision from SVN/git/etc
62 if [ -e "$1/../../.git/refs/remotes/origin" ] ; then
64 elif [ -d "$1/.git/svn" ] ; then
66 elif [ -d "$1/../.git/svn" ] ; then
67 get_git_svn_id "$1/.."
68 elif [ -d "$1/../../.git/svn" ] ; then
69 get_git_svn_id "$1/../.."
70 elif [ -d "$1/.svn" ] ; then
73 elif [ -d "$1/_svn" ] ; then
79 # Allow overriding both REVISION and DEVEL_VERSION
80 if [ -f "$2/autorevision.conf" ] ; then
82 . "$2/autorevision.conf"
86 # Abort if the header is newer
87 if [ "$COMPARE" -ot "$HEADER" ] ; then exit; fi
89 # Set the development version string
90 if [ x = "x$DEVEL_VERSION" ] ; then
91 if [ x != "x$REVISION" ] ; then
92 if [ $SCM = svn ] ; then
93 DEVEL_VERSION="SVN r$REVISION"
94 elif [ $SCM = git-svn ] ; then
95 DEVEL_VERSION="SVN r$REVISION (via git)"
96 elif [ $SCM = git ] ; then
97 DEVEL_VERSION="Revision: $REVISION\\nBranch: ${BRANCH}\\nRevision ID: $REVISION_ID"
98 elif [ $SCM = manual ] ; then
99 DEVEL_VERSION="$REVISION (manually configured)"
106 if [ x != "x$DEVEL_VERSION" ] ; then
107 echo "#define SHOW_EXTRA_INFO" > "$HEADER"
108 echo "#define DEVEL_VERSION \"$DEVEL_VERSION\"" >> "$HEADER"