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 --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
20 export REVISION=`git-show --pretty=format:%ci HEAD | head -c 10`
21 REVISION=${REVISION:0:4}${REVISION:5:2}${REVISION:8:2}
22 export COMPARE="$1/.git/"
23 # The extra * at the end is for Modified
24 #REVISION="$REVISION"`cd "$1"; [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"`
29 export REVISION=`cd "$1"; git svn find-rev HEAD`
30 export COMPARE="$1/.git/"
31 if [ x = "x$REVISION" ] ; then
32 # The extra M at the end is for Modified
33 export REVISION=`cd "$1"; git svn find-rev \`git rev-list --max-count=1 --grep='git-svn-id: ' HEAD\``M
35 export REVISION="$REVISION"`cd "$1"; git diff --quiet HEAD || echo M`
41 export REVISION=`cd "$1"; svnversion || svn info | sed -n 's/^Revision: \(.*\)/\1/p'`
45 HEADER="$2/autorevision.h"
49 if [ ! -f "$HEADER" ] ; then
50 touch -t 197001010101 "$HEADER"
54 # Extract the revision from SVN/git/etc
55 if [ -e "$1/../../.git/refs/remotes/origin" ] ; then
57 elif [ -d "$1/.git/svn" ] ; then
59 elif [ -d "$1/../.git/svn" ] ; then
60 get_git_svn_id "$1/.."
61 elif [ -d "$1/../../.git/svn" ] ; then
62 get_git_svn_id "$1/../.."
63 elif [ -d "$1/.svn" ] ; then
66 elif [ -d "$1/_svn" ] ; then
72 # Allow overriding both REVISION and DEVEL_VERSION
73 if [ -f "$2/autorevision.conf" ] ; then
75 . "$2/autorevision.conf"
79 # Abort if the header is newer
80 if [ "$COMPARE" -ot "$HEADER" ] ; then exit; fi
82 # Set the development version string
83 if [ x = "x$DEVEL_VERSION" ] ; then
84 if [ x != "x$REVISION" ] ; then
85 if [ $SCM = svn ] ; then
86 DEVEL_VERSION="SVN r$REVISION"
87 elif [ $SCM = git-svn ] ; then
88 DEVEL_VERSION="SVN r$REVISION (via git)"
89 elif [ $SCM = git ] ; then
90 DEVEL_VERSION="Revision: $REVISION\\nBranch: ${BRANCH}\\nRevision ID: $REVISION_ID"
91 elif [ $SCM = manual ] ; then
92 DEVEL_VERSION="$REVISION (manually configured)"
99 if [ x != "x$DEVEL_VERSION" ] ; then
100 echo "#define SHOW_EXTRA_INFO" > "$HEADER"
101 echo "#define DEVEL_VERSION \"$DEVEL_VERSION\"" >> "$HEADER"