Remove .gitignore do nothing is ignored.
[synfig.git] / synfig-core / trunk / build_tools / autorevision.sh
1 #!/bin/sh
2
3 # Copyright 2008 Paul Wise
4 # Copyright 2009 Konstantin Dmitriev
5 #
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.
10 #
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.
15
16 get_git_id(){
17         export SCM=git
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
22                 BRANCH='master'
23         else
24                 BRANCH=`echo $BRANCH | cut -d ' ' -f 1`
25                 BRANCH=${BRANCH##*/}
26         fi
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 "*"`
31 }
32
33 get_git_svn_id(){
34         export SCM=git-svn
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
40         else
41                 export REVISION="$REVISION"`cd "$1"; git diff --quiet HEAD || echo M`
42         fi
43 }
44
45 get_svn_id(){
46         export SCM=svn
47         export REVISION=`cd "$1"; svnversion || svn info | sed -n 's/^Revision: \(.*\)/\1/p'`
48 }
49
50
51 HEADER="$2/autorevision.h"
52 SCM=none
53
54
55 if [ ! -f "$HEADER" ] ; then
56         touch -t 197001010101 "$HEADER"
57 fi
58
59
60 # Extract the revision from SVN/git/etc
61 if git rev-parse --git-dir > /dev/null  2>&1 ; then
62         get_git_id "."
63 elif [ -d "$1/.git/svn" ] ; then
64         get_git_svn_id "$1"
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
70         COMPARE="$1/.svn"
71         get_svn_id "$1"
72 elif [ -d "$1/_svn" ] ; then
73         COMPARE="$1/_svn"
74         get_svn_id "$1"
75 fi
76
77
78 # Allow overriding both REVISION and DEVEL_VERSION
79 if [ -f "$2/autorevision.conf" ] ; then
80         SCM=manual
81         . "$2/autorevision.conf"
82 fi
83
84
85 # Abort if the header is newer
86 if [ "$COMPARE" -ot "$HEADER" ] ; then exit; fi
87
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)"
99                 fi
100         fi
101 fi
102
103
104 # Output the header
105 if [ x != "x$DEVEL_VERSION" ] ; then
106         printf "#define DEVEL_VERSION \"$DEVEL_VERSION\"\n" > "$HEADER"
107 fi