X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=synfig-core%2Ftrunk%2Fbuild_tools%2Fautorevision.sh;fp=synfig-core%2Ftrunk%2Fbuild_tools%2Fautorevision.sh;h=2ccdb013ab6a8585d13aeb955972d4242b94e1fc;hb=eb646e952b600199e2f1a0c27ea1c4fde87a1f50;hp=0000000000000000000000000000000000000000;hpb=e9a42a585dec26a8c0aabcfd6e12755f0f0f1156;p=synfig.git diff --git a/synfig-core/trunk/build_tools/autorevision.sh b/synfig-core/trunk/build_tools/autorevision.sh new file mode 100644 index 0000000..2ccdb01 --- /dev/null +++ b/synfig-core/trunk/build_tools/autorevision.sh @@ -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