From a83cf2fcb4d7010c341591a717fc519bfc3c0928 Mon Sep 17 00:00:00 2001 From: Tom Goff Date: Wed, 18 Nov 2015 10:57:47 -0500 Subject: [PATCH] Set the version date string from repository information if available, otherwise use the current date. --- configure.ac | 2 +- revision.sh | 92 +++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index ef3b641f..cca08ef9 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,7 @@ AC_INIT(core, m4_esyscmd_s([./revision.sh 4.8]), core-dev@pf.itd.nrl.navy.mil) VERSION=$PACKAGE_VERSION CORE_VERSION=$PACKAGE_VERSION -CORE_VERSION_DATE=20150605 +CORE_VERSION_DATE=m4_esyscmd_s([./revision.sh -d]) COREDPY_VERSION=$PACKAGE_VERSION # diff --git a/revision.sh b/revision.sh index 0b327daa..517e549a 100755 --- a/revision.sh +++ b/revision.sh @@ -1,9 +1,51 @@ #!/bin/sh -if [ $# -ne 1 ]; then - echo "usage: $(basename $0) " >&2 - exit 1 -fi +usage() +{ + echo "usage: $(basename $0) (-d | )" >&2 + exit $1 +} + +func=revision +while getopts dh f; do + case $f in + d) + func=date + ;; + + h) + usage 0 + ;; + + *) + usage 1 + ;; + esac +done +shift $(($OPTIND - 1)) + +case $func in + revision) + if [ $# -ne 1 ]; then + usage 1 + fi + ;; + + date) + if [ $# -gt 0 ]; then + usage 1 + fi + ;; + + *) + usage 1 + ;; +esac + +_revision() +{ + echo $1 +} git_revision() { @@ -78,10 +120,44 @@ svn_revision() echo ${ver}${untagged}${commits}${rev}${dirty} } +_date() +{ + date '+%Y%m%d' +} + +git_date() +{ + local date + + if git diff --quiet; then + date=$(git log -1 --format='%ci' | \ + awk '{gsub("-", "", $1); print $1}') + else + date=$(_date) + fi + + echo $date +} + +svn_date() +{ + local date + + if ! (svn status -q | grep -q .); then + date=$(svn log -q --limit 1 | \ + awk '/^r[0-9]+/ {gsub("-", "", $5); print $5}') + else + date=$(_date) + fi + + echo $date +} + +repo="" if test -d .git || git rev-parse --git-dir > /dev/null 2>&1; then - git_revision "$@" + repo=git elif test -d .svn || svn info > /dev/null 2>&1; then - svn_revision "$@" -else - echo "$@" + repo=svn fi + +${repo}_${func} "$@"