2008-09-07 15:24:49 +02:00
#!/bin/sh
2009-08-21 22:21:05 +02:00
# This file is part of OpenTTD.
# OpenTTD 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, version 2.
# OpenTTD 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. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
2008-09-07 15:24:49 +02:00
# Arguments given? Show help text.
if [ " $# " != "0" ] ; then
cat <<EOF
Usage: ./findversion.sh
Finds the current revision and if the code is modified.
2018-04-12 20:59:03 +02:00
Output: <VERSION>\t <ISODATE>\t <MODIFIED>\t <HASH>
VERSION
2008-09-07 15:24:49 +02:00
a string describing what version of the code the current checkout is
2018-04-12 20:59:03 +02:00
based on.
This also includes the commit date, an indication of whether the checkout
was modified and which branch was checked out. This value is not
2008-09-07 15:24:49 +02:00
guaranteed to be sortable, but is mainly meant for identifying the
revision and user display.
If no revision identifier could be found, this is left empty.
2018-04-12 20:59:03 +02:00
ISODATE
the commit date of the revision this checkout is based on.
The commit date may differ from the author date.
This can be used to decide upon the age of the source.
If no timestamp could be found, this is left empty.
2008-09-07 15:24:49 +02:00
MODIFIED
Whether ( the src directory of) this checkout is modified or not. A
value of 0 means not modified, a value of 2 means it was modified.
A value of 1 means that the modified status is unknown, because this
2018-04-12 20:59:03 +02:00
is not an git checkout for example.
2008-09-07 15:24:49 +02:00
2018-04-12 20:59:03 +02:00
HASH
the git revision hash
2008-09-08 12:08:55 +02:00
2008-09-07 15:24:49 +02:00
By setting the AWK environment variable, a caller can determine which
version of "awk" is used. If nothing is set, this script defaults to
"awk" .
EOF
exit 1;
fi
# Allow awk to be provided by the caller.
if [ -z " $AWK " ] ; then
AWK = awk
fi
# Find out some dirs
cd ` dirname " $0 " `
ROOT_DIR = ` pwd `
# Determine if we are using a modified version
# Assume the dir is not modified
MODIFIED = "0"
2019-08-28 23:45:36 +02:00
if [ -d " $ROOT_DIR /.git " ] || [ -f " $ROOT_DIR /.git " ] ; then
2008-09-07 15:24:49 +02:00
# We are a git checkout
2010-05-26 05:31:05 +02:00
# Refresh the index to make sure file stat info is in sync, then look for modifications
git update-index --refresh >/dev/null
2010-08-02 18:38:26 +02:00
if [ -n "`git diff-index HEAD`" ] ; then
2008-09-07 15:24:49 +02:00
MODIFIED = "2"
fi
2008-10-23 00:07:43 +02:00
HASH = ` LC_ALL = C git rev-parse --verify HEAD 2>/dev/null`
2019-01-27 14:04:49 +01:00
SHORTHASH = ` echo ${ HASH } | cut -c1-10`
2018-04-12 20:59:03 +02:00
ISODATE = ` LC_ALL = C git show -s --pretty= 'format:%ci' HEAD | " $AWK " '{ gsub("-", "", $1); print $1 }' `
2020-05-05 18:36:27 +02:00
YEAR = ` echo ${ ISODATE } | cut -c1-4`
2018-04-13 19:44:39 +02:00
BRANCH = "`git symbolic-ref -q HEAD 2>/dev/null | sed 's@.*/@@'`"
2011-05-07 17:13:52 +02:00
TAG = " `git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null | sed 's@\^0 $@ @'` "
2018-04-12 20:59:03 +02:00
2019-01-27 14:04:49 +01:00
if [ " $MODIFIED " -eq "0" ] ; then
hashprefix = "-g"
elif [ " $MODIFIED " -eq "2" ] ; then
hashprefix = "-m"
else
hashprefix = "-u"
fi
2011-01-18 22:27:30 +01:00
if [ -n " $TAG " ] ; then
2018-04-12 20:59:03 +02:00
VERSION = " ${ TAG } "
2019-02-10 18:01:30 +01:00
ISTAG = "1"
2019-03-03 20:08:28 +01:00
if [ -n " `echo \" ${ TAG } \" | grep \"^[0-9.]* $\"` " ] ; then
ISSTABLETAG = "1"
else
ISSTABLETAG = "0"
fi
2018-04-12 20:59:03 +02:00
else
2019-01-27 14:04:49 +01:00
VERSION = " ${ ISODATE } - ${ BRANCH } ${ hashprefix } ${ SHORTHASH } "
2019-02-10 18:01:30 +01:00
ISTAG = "0"
2019-03-03 20:08:28 +01:00
ISSTABLETAG = "0"
2011-01-18 22:27:35 +01:00
fi
2018-04-12 20:59:03 +02:00
2010-11-29 13:49:27 +01:00
elif [ -f " $ROOT_DIR /.ottdrev " ] ; then
# We are an exported source bundle
cat $ROOT_DIR /.ottdrev
exit
2008-09-07 15:24:49 +02:00
else
# We don't know
MODIFIED = "1"
2018-04-12 20:59:03 +02:00
HASH = ""
SHORTHASH = ""
2008-09-07 15:24:49 +02:00
BRANCH = ""
2018-04-12 20:59:03 +02:00
ISODATE = ""
2020-05-05 18:36:27 +02:00
YEAR = ""
2018-04-12 20:59:03 +02:00
TAG = ""
VERSION = ""
2019-02-10 18:01:30 +01:00
ISTAG = "0"
2019-03-03 20:08:28 +01:00
ISSTABLETAG = "0"
2008-09-07 15:24:49 +02:00
fi
2020-05-05 18:36:27 +02:00
echo " $VERSION $ISODATE $MODIFIED $HASH $ISTAG $ISSTABLETAG $YEAR "