2006-06-24 13:34:35 -05:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# gnc-svnversion <srcdir>
|
|
|
|
#
|
|
|
|
# Prints the revision number to stdout and exits 0 on success
|
2007-01-01 10:47:32 -06:00
|
|
|
# exits with errorcode 1 if we're not in an svn, svk or git checkout
|
2006-06-24 13:34:35 -05:00
|
|
|
#
|
|
|
|
# Written By: Derek Atkins <derek@ihtfp.com>
|
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
# Print an error message and then exit
|
|
|
|
my_die()
|
|
|
|
{
|
|
|
|
echo "$1"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Make sure we have a srcdir
|
|
|
|
[ -n "$1" ] || my_die "Usage: $0 <srcdir>"
|
|
|
|
[ -d "$1" ] || my_die "$0: $1: not a directory"
|
|
|
|
|
|
|
|
# Find the real srcdir.
|
|
|
|
# This handles the case of a symlink (lndir) tree
|
|
|
|
# $real_srcdir will hold the actual source dir
|
|
|
|
if test -h "$1"/Makefile.am
|
|
|
|
then
|
|
|
|
tmp_srcdir=`readlink "$1"/Makefile.am`
|
|
|
|
real_srcdir="$1/`dirname ${tmp_srcdir}`"
|
|
|
|
else
|
|
|
|
real_srcdir="$1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Test if this code is an SVN Checkout
|
|
|
|
# If this is an svn checkout we assume you have svnversion!
|
|
|
|
if test -d "${real_srcdir}"/.svn
|
|
|
|
then
|
|
|
|
svnversion "$real_srcdir"
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
2007-01-01 10:47:32 -06:00
|
|
|
# If we get here then this is NOT an svn checkout.
|
|
|
|
|
|
|
|
# Maybe it's git?
|
|
|
|
if test -d "${real_srcdir}"/.git
|
|
|
|
then
|
|
|
|
githead=`git --git-dir "${real_srcdir}"/.git rev-parse HEAD 2>/dev/null`
|
|
|
|
if test $? = 0 ; then
|
|
|
|
echo $githead
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Maybe it's SVK? First, check if we've got 'svk' in the path. If not,
|
2006-06-24 13:34:35 -05:00
|
|
|
# then exit with an error code of 1..
|
|
|
|
which svk >/dev/null 2>&1
|
|
|
|
if test $? != 0 ; then exit 1 ; fi
|
|
|
|
|
|
|
|
# Okay, we have 'svk'. Now see if $real_srcdir is an svk checkout
|
2006-07-12 14:50:44 -05:00
|
|
|
# Note that the 'echo n' is to protect against having svk installed
|
|
|
|
# without having configured the depotmap.
|
|
|
|
svkinfo=`echo n | svk info "$real_srcdir" 2>&1`
|
2006-06-24 13:34:35 -05:00
|
|
|
if test $? != 0 ; then exit 1 ; fi
|
|
|
|
|
|
|
|
# If we got here, then $real_srcdir is an svk checkout. Parse out
|
|
|
|
# the revision info, print it out, and then output 0. Just combine
|
|
|
|
# all the revision numbers into a single string by combining them
|
|
|
|
# with periods.
|
2007-07-26 14:15:54 -05:00
|
|
|
svkinfo=`svk info "$real_srcdir" | grep Rev | head -5 | sed -e 's/^.* \([0-9:]*\)$/\1/'`
|
2006-06-24 13:34:35 -05:00
|
|
|
echo $svkinfo | sed -e 's/\s/./g'
|
|
|
|
|
|
|
|
exit 0
|