From 76042cb389d18726c60103a5d0d84ad756a56143 Mon Sep 17 00:00:00 2001 From: Andrew Mahone Date: Mon, 19 Jan 2009 16:18:30 +0000 Subject: new version.sh that works exactly like svnversion.sh, but functions correctly with pure git repositories git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19799 a1c6a512-1295-4272-9138-f99709370657 --- tools/version.sh | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 tools/version.sh (limited to 'tools/version.sh') diff --git a/tools/version.sh b/tools/version.sh new file mode 100755 index 0000000000..9f47afcfd2 --- /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. +# +# The format is rNNNNN[M]-YYMMDD +# +# The M indicates the revision isn't matched to a pure Subversion ID, usually +# because it's built from something like GIT. + +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 + + # Get the svn revision of the most recent git-svn commit + version=`git log --pretty=format:'%b' --grep='git-svn-id: svn' -1 | head -n 1 | perl -ne 'm/@(\d*)/; print "r" . $1;'` + mod="" + # Is this a git-svn commit? + if ! git log HEAD^.. --pretty=format:"%b" | grep -q "git-svn-id: svn" ; then + mod="M" + fi + + # Are there uncommitted changes? + git update-index --refresh --unmerged > /dev/null + if git diff-index --name-only HEAD | read dummy; then + mod="M" + fi + + echo "${version}${mod}" + # 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 + -- cgit