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 | tr -d '-'`
28 export COMPARE=`git rev-parse --git-dir`
29 # The extra * at the end is for Modified
30 #REVISION="$REVISION"`cd "$1"; [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"`
35 export REVISION=`cd "$1"; git svn find-rev HEAD`
36 export COMPARE="$1/.git/"
37 if [ x = "x$REVISION" ] ; then
38 # The extra M at the end is for Modified
39 export REVISION=`cd "$1"; git svn find-rev \`git rev-list --max-count=1 --grep='git-svn-id: ' HEAD\``M
41 export REVISION="$REVISION"`cd "$1"; git diff --quiet HEAD || echo M`
47 export REVISION=`cd "$1"; svnversion || svn info | sed -n 's/^Revision: \(.*\)/\1/p'`
51 HEADER="$2/autorevision.h"
55 if [ ! -f "$HEADER" ] ; then
56 touch -t 197001010101 "$HEADER"
60 # Extract the revision from SVN/git/etc
61 if git rev-parse --git-dir > /dev/null 2>&1 ; then
63 elif [ -d "$1/.git/svn" ] ; then
65 elif [ -d "$1/../.git/svn" ] ; then
66 get_git_svn_id "$1/.."
67 elif [ -d "$1/../../.git/svn" ] ; then
68 get_git_svn_id "$1/../.."
69 elif [ -d "$1/.svn" ] ; then
72 elif [ -d "$1/_svn" ] ; then
78 # Allow overriding both REVISION and DEVEL_VERSION
79 if [ -f "$2/autorevision.conf" ] ; then
81 . "$2/autorevision.conf"
85 # Abort if the header is newer
86 if [ "$COMPARE" -ot "$HEADER" ] ; then exit; fi
88 # Set the development version string
89 if [ x = "x$DEVEL_VERSION" ] ; then
90 if [ x != "x$REVISION" ] ; then
91 if [ $SCM = svn ] ; then
92 DEVEL_VERSION="SVN r$REVISION"
93 elif [ $SCM = git-svn ] ; then
94 DEVEL_VERSION="SVN r$REVISION (via git)"
95 elif [ $SCM = git ] ; then
96 DEVEL_VERSION="Revision: ${REVISION}\\\\nBranch: ${BRANCH}\\\\nRevision ID: ${REVISION_ID}"
97 elif [ $SCM = manual ] ; then
98 DEVEL_VERSION="$REVISION (manually configured)"
105 if [ x != "x$DEVEL_VERSION" ] ; then
106 printf "#define SHOW_EXTRA_INFO\n" > "$HEADER"
107 printf "#define DEVEL_VERSION \"$DEVEL_VERSION\"\n" >> "$HEADER"