From c48f965902584b98f2fdba5690f66f0f4a38a425 Mon Sep 17 00:00:00 2001 From: Alex Bennee Date: Sun, 11 Jan 2009 14:18:00 +0000 Subject: [PATCH] Not all repos are ones created with git-svn which was causing the svnversion to time out. Besides if you have a git repo you can be a lot more fine grained about where it came from with both the git commit and it's dirty state. The logic comes from the Linux kernel src tree and has been tweaked for rockbox. If the latest git commit is in fact a git-svn generated one (detected by virtue of the git-svn-id in the commit message) it will echo grNNNNN as the version. --- tools/configure | 2 +- tools/svnversion.sh | 59 ----------------------------------- tools/version.sh | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 60 deletions(-) delete mode 100755 tools/svnversion.sh create mode 100755 tools/version.sh diff --git a/tools/configure b/tools/configure index fc12c31..7653aa7 100755 --- a/tools/configure +++ b/tools/configure @@ -2484,7 +2484,7 @@ export BUILDDIR=@PWD@ export LANGUAGE=@LANGUAGE@ export VOICELANGUAGE=@VOICELANGUAGE@ export MEMORYSIZE=@MEMORY@ -export VERSION:=\$(shell \$(ROOTDIR)/tools/svnversion.sh \$(ROOTDIR)) +export VERSION:=\$(shell \$(ROOTDIR)/tools/version.sh \$(ROOTDIR)) export BUILDDATE:=\$(shell date -u +'-DYEAR=%Y -DMONTH=%m -DDAY=%d') export MKFIRMWARE=@TOOL@ export BMP2RB_MONO=@BMP2RB_MONO@ diff --git a/tools/svnversion.sh b/tools/svnversion.sh deleted file mode 100755 index 8fe9804..0000000 --- a/tools/svnversion.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/sh -# __________ __ ___. -# Open \______ \ ____ ____ | | _\_ |__ _______ ___ -# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / -# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < -# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ -# \/ \/ \/ \/ \/ -# $Id$ -# - -# Usage: svnversion.sh [source-root] - -# Prints the revision "rXYZ" of the first argument, as reported by svnversion. -# Prints "unknown" if svnversion fails or says "exported". -svnversion_safe() { - # LANG=C forces svnversion to not localize "exported". - if OUTPUT=`LANG=C svnversion "$@"`; then - if [ "$OUTPUT" = "exported" ]; then - - # Not a SVN repository, maybe a git-svn one ? - if [ -z "$1" ]; then - GITDIR="./.git" - else - GITDIR="$1/.git" - fi - - # First make sure it is a git repository - if [ -d "$GITDIR" ]; then - OUTPUT=`LANG=C git --git-dir="$GITDIR" svn info 2>/dev/null|grep '^Revision: '|cut -d\ -f2` - if [ -z "$OUTPUT" ]; then - echo "unknown" - else - echo "r$OUTPUT" - fi - else # not a git repository - echo "unknown" - fi - else - echo "r$OUTPUT" - fi - else - echo "unknown" - fi -} - -VERSIONFILE=docs/VERSION -if [ -n "$1" ]; then TOP=$1; else TOP=..; fi -if [ -r $TOP/$VERSIONFILE ]; then SVNVER=`cat $TOP/$VERSIONFILE`; -else - SVNVER=`svnversion_safe $TOP`; - if [ "$SVNVER" = "unknown" ]; then - # try getting it from a subdir to test if perhaps they are symlinked - # from the root - SVNVER=`svnversion_safe $TOP/tools`; - fi -fi -VERSION=$SVNVER-`date -u +%y%m%d` -echo $VERSION - diff --git a/tools/version.sh b/tools/version.sh new file mode 100755 index 0000000..cc614c7 --- /dev/null +++ b/tools/version.sh @@ -0,0 +1,85 @@ +#!/bin/sh +# __________ __ ___. +# Open \______ \ ____ ____ | | _\_ |__ _______ ___ +# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +# \/ \/ \/ \/ \/ +# $Id$ +# + +# Usage: version.sh [source-root] + +# Prints the revision of the repository. +# +# For subversion repos thats rNNNNNN +# For git-svn its grNNNNN[-dirty] +# For git its gXXXXX[-dirty] +# Otherwise prints unknown +svnversion_safe() { + # LANG=C forces svnversion to not localize "exported". + if OUTPUT=`LANG=C svnversion "$@"`; then + if [ "$OUTPUT" = "exported" ]; then + echo "unknown" + else + echo "r$OUTPUT" + fi + else + echo "unknown" + fi +} + +# This logic is pulled from the Linux's scripts/setlocalversion (also GPL) and tweaked for +# rockbox. If the commit information for HEAD has a svn-id in it we report that instead of +# the git id +gitversion() { + export GIT_DIR="$1" + + # This verifies we are in a git directory + if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then + + # Is this a git-svn commit? + body=`git log HEAD^.. --pretty=format:"%b" | grep "git-svn-id: svn"` + + if [ "$?" == "0" ]; then + printf 'gr%s' `echo $body | perl -ne 'm/@(\d*)/; print "$1";'` + else + printf 'g%s' $head + fi + + # Are there uncommitted changes? + git update-index --refresh --unmerged > /dev/null + if git diff-index --name-only HEAD | grep -v "^scripts/package" \ + | read dummy; then + printf '%s' -dirty + fi + + # All done with git + exit + fi +} + +# +# First locate the top of the src tree (passed in usually) +# +if [ -n "$1" ]; then TOP=$1; else TOP=..; fi + +# If the VERSIONFILE exisits we use that +VERSIONFILE=docs/VERSION +if [ -r $TOP/$VERSIONFILE ]; then VER=`cat $TOP/$VERSIONFILE`; +else + # Ok, we need to derive it from the Version Control system + if [ -d "$TOP/.git" ]; then + VER=`gitversion $TOP/.git` + else + VER=`svnversion_safe $TOP`; + if [ "$VER" = "unknown" ]; then + # try getting it from a subdir to test if perhaps they are symlinked + # from the root + VER=`svnversion_safe $TOP/tools`; + fi + fi +fi +VERSION=$VER-`date -u +%y%m%d` +echo $VERSION + -- 1.6.0.6