Fix bug with the autorevision git-svn support where local, non-committed changes...
[synfig.git] / synfig-studio / trunk / build_tools / autorevision.sh
1 #!/bin/sh
2
3 # Copyright 2008 Paul Wise
4 #
5 # This package is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2 of
8 # the License, or (at your option) any later version.
9 #
10 # This package is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14
15
16 get_git_svn_id(){
17         export SCM=git-svn
18         export REVISION=`cd "$1"; git svn find-rev HEAD`
19         export COMPARE="$1/.git/"
20         if [ x = "x$REVISION" ] ; then
21                 # The extra M at the end is for Modified
22                 export REVISION=`cd "$1"; git svn find-rev \`git rev-list --max-count=1 --grep='git-svn-id: ' HEAD\``M
23         else
24                 if ! git diff --quiet HEAD ; then
25                         export REVISION="$REVISION"M
26                 fi      
27         fi
28 }
29
30 get_svn_id(){
31         export SCM=svn
32         export REVISION=`cd "$1"; svnversion || svn info | sed -n 's/^Revision: \(.*\)/\1/p'`
33 }
34
35
36 HEADER="$2/autorevision.h"
37 SCM=none
38
39
40 if [ ! -f "$HEADER" ] ; then
41         touch -t 197001010101 "$HEADER"
42 fi
43
44
45 # Extract the revision from SVN/git/etc
46 if [ -d "$1/.git/svn" ] ; then
47         get_git_svn_id "$1"
48 elif [ -d "$1/../.git/svn" ] ; then
49         get_git_svn_id "$1/.."
50 elif [ -d "$1/../../.git/svn" ] ; then
51         get_git_svn_id "$1/../.."
52 elif [ -d "$1/.svn" ] ; then
53         COMPARE="$1/.svn"
54         get_svn_id "$1"
55 elif [ -d "$1/_svn" ] ; then
56         COMPARE="$1/_svn"
57         get_svn_id "$1"
58 fi
59
60
61 # Allow overriding both REVISION and DEVEL_VERSION
62 if [ -f "$2/autorevision.conf" ] ; then
63         SCM=manual
64         . "$2/autorevision.conf"
65 fi
66
67
68 # Abort if the header is newer
69 if [ "$COMPARE" -ot "$HEADER" ] ; then return; fi
70
71
72 # Set the development version string
73 if [ x = "x$DEVEL_VERSION" ] ; then
74         if [ x != "x$REVISION" ] ; then
75                 if [ $SCM = svn ] ; then
76                         DEVEL_VERSION="SVN r$REVISION"
77                 elif [ $SCM = git-svn ] ; then
78                         DEVEL_VERSION="SVN r$REVISION (via git)"
79                 elif [ $SCM = manual ] ; then
80                         DEVEL_VERSION="$REVISION (manually configured)"
81                 fi
82         fi
83 fi
84
85
86 # Output the header
87 if [ x != "x$DEVEL_VERSION" ] ; then
88         echo "#define SHOW_EXTRA_INFO" > "$HEADER"
89         echo "#define DEVEL_VERSION \"$DEVEL_VERSION\"" >> "$HEADER"
90 fi