Show git revision information on "synfig --info".
authorKonstantin Dmitriev <ksee.zelgadis@gmail.com>
Thu, 16 Jul 2009 14:47:30 +0000 (21:47 +0700)
committerKonstantin Dmitriev <ksee.zelgadis@gmail.com>
Thu, 16 Jul 2009 14:47:30 +0000 (21:47 +0700)
.gitignore
synfig-core/trunk/Makefile.am
synfig-core/trunk/build_tools/Makefile.am [new file with mode: 0644]
synfig-core/trunk/build_tools/autorevision.sh [new file with mode: 0644]
synfig-core/trunk/src/tool/main.cpp

index 36dc72b..e990be0 100644 (file)
@@ -64,6 +64,7 @@ synfig-core/trunk/src/synfig/proto/nodebase.h
 synfig-core/trunk/src/tool/synfig
 synfig-core/trunk/synfig.pc.in
 
+synfig-core/trunk/autorevision.h
 synfig-core/trunk/m4/codeset.m4
 synfig-core/trunk/m4/gettext.m4
 synfig-core/trunk/m4/glibc2.m4
index bb201ca..22ad14d 100644 (file)
@@ -43,6 +43,7 @@ MAINTAINERCLEANFILES = \
 
 SUBDIRS = \
        libltdl \
+       build_tools \
        src \
        examples \
        po
diff --git a/synfig-core/trunk/build_tools/Makefile.am b/synfig-core/trunk/build_tools/Makefile.am
new file mode 100644 (file)
index 0000000..29b053f
--- /dev/null
@@ -0,0 +1,8 @@
+dist_noinst_SCRIPTS = autorevision.sh
+
+all-local:
+       sh $(srcdir)/autorevision.sh "$(top_srcdir)" "$(top_builddir)"
+
+clean-local:
+       -rm -f $(top_builddir)/autorevision.h
+
diff --git a/synfig-core/trunk/build_tools/autorevision.sh b/synfig-core/trunk/build_tools/autorevision.sh
new file mode 100644 (file)
index 0000000..2ccdb01
--- /dev/null
@@ -0,0 +1,101 @@
+#!/bin/sh
+
+# Copyright 2008 Paul Wise
+# Copyright 2009 Konstantin Dmitriev
+#
+# This package is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This package is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+get_git_id(){
+       export SCM=git
+       export REVISION=`cd "$1"; git log --no-color -1 | head -n 1 | cut -f 2 -d ' '`
+       export BRANCH=`cd "$1"; git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
+       export DATE=`git-show --pretty=format:%ci HEAD |  head -c 10`
+       DATE=${DATE:0:4}${DATE:5:2}${DATE:8:2}
+       export COMPARE="$1/.git/"
+       # The extra * at the end is for Modified
+       #REVISION="$REVISION"`cd "$1"; [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"`
+}
+
+get_git_svn_id(){
+       export SCM=git-svn
+       export REVISION=`cd "$1"; git svn find-rev HEAD`
+       export COMPARE="$1/.git/"
+       if [ x = "x$REVISION" ] ; then
+               # The extra M at the end is for Modified
+               export REVISION=`cd "$1"; git svn find-rev \`git rev-list --max-count=1 --grep='git-svn-id: ' HEAD\``M
+       else
+               export REVISION="$REVISION"`cd "$1"; git diff --quiet HEAD || echo M`
+       fi
+}
+
+get_svn_id(){
+       export SCM=svn
+       export REVISION=`cd "$1"; svnversion || svn info | sed -n 's/^Revision: \(.*\)/\1/p'`
+}
+
+
+HEADER="$2/autorevision.h"
+SCM=none
+
+
+if [ ! -f "$HEADER" ] ; then
+       touch -t 197001010101 "$HEADER"
+fi
+
+
+# Extract the revision from SVN/git/etc
+if [ -e "$1/../../.git/refs/remotes/origin" ] ; then
+       get_git_id "$1/../.."
+elif [ -d "$1/.git/svn" ] ; then
+       get_git_svn_id "$1"
+elif [ -d "$1/../.git/svn" ] ; then
+       get_git_svn_id "$1/.."
+elif [ -d "$1/../../.git/svn" ] ; then
+       get_git_svn_id "$1/../.."
+elif [ -d "$1/.svn" ] ; then
+       COMPARE="$1/.svn"
+       get_svn_id "$1"
+elif [ -d "$1/_svn" ] ; then
+       COMPARE="$1/_svn"
+       get_svn_id "$1"
+fi
+
+
+# Allow overriding both REVISION and DEVEL_VERSION
+if [ -f "$2/autorevision.conf" ] ; then
+       SCM=manual
+       . "$2/autorevision.conf"
+fi
+
+
+# Abort if the header is newer
+if [ "$COMPARE" -ot "$HEADER" ] ; then exit; fi
+
+# Set the development version string
+if [ x = "x$DEVEL_VERSION" ] ; then
+       if [ x != "x$REVISION" ] ; then
+               if [ $SCM = svn ] ; then
+                       DEVEL_VERSION="SVN r$REVISION"
+               elif [ $SCM = git-svn ] ; then
+                       DEVEL_VERSION="SVN r$REVISION (via git)"
+               elif [ $SCM = git ] ; then
+                       DEVEL_VERSION="Development version: $DATE \\nBranch: ${BRANCH} \\nRevision ID: $REVISION"
+               elif [ $SCM = manual ] ; then
+                       DEVEL_VERSION="$REVISION (manually configured)"
+               fi
+       fi
+fi
+
+
+# Output the header
+if [ x != "x$DEVEL_VERSION" ] ; then
+       echo "#define DEVEL_VERSION \"$DEVEL_VERSION\"" >> "$HEADER"
+fi
index 38a7c64..fbf64b0 100644 (file)
@@ -50,6 +50,7 @@
 #include <synfig/paramdesc.h>
 #include <synfig/main.h>
 #include <synfig/guid.h>
+#include <autorevision.h>
 #endif
 
 using namespace std;
@@ -396,6 +397,9 @@ int process_global_flags(arg_list_t &arg_list)
                if(*iter == "--info")
                {
                        cout<<PACKAGE"-"VERSION<<endl;
+                       #ifdef DEVEL_VERSION
+                               cout<<endl<<DEVEL_VERSION<<endl<<endl;
+                       #endif
                        cout<<"Compiled on "__DATE__ /* " at "__TIME__ */;
 #ifdef __GNUC__
                        cout<<" with GCC "<<__VERSION__;
@@ -406,7 +410,6 @@ int process_global_flags(arg_list_t &arg_list)
 #ifdef __TCPLUSPLUS__
                        cout<<" with Borland Turbo C++ "<<(__TCPLUSPLUS__>>8)<<'.'<<((__TCPLUSPLUS__&255)>>4)<<'.'<<(__TCPLUSPLUS__&15);
 #endif
-
                        cout<<endl<<SYNFIG_COPYRIGHT<<endl;
                        cout<<endl;
                        return SYNFIGTOOL_HELP;