matthijs@10085: #!/bin/sh matthijs@10085: matthijs@10085: # Arguments given? Show help text. matthijs@10085: if [ "$#" != "0" ]; then matthijs@10085: cat <\t\t\t matthijs@10085: REV matthijs@10085: a string describing what version of the code the current checkout is matthijs@10085: based on. The exact format of this string depends on the version matthijs@10085: control system in use, but it tries to identify the revision used as matthijs@10085: close as possible (using the svn revision number or hg/git hash). matthijs@10085: This also includes an indication of whether the checkout was matthijs@10085: modified and which branch was checked out. This value is not matthijs@10085: guaranteed to be sortable, but is mainly meant for identifying the matthijs@10085: revision and user display. matthijs@10085: matthijs@10085: If no revision identifier could be found, this is left empty. matthijs@10085: REV_NR matthijs@10085: the revision number of the svn revision this checkout is based on. matthijs@10085: This can be used to determine which functionality is present in this matthijs@10085: checkout. For trunk svn checkouts and hg/git branches based upon it, matthijs@10085: this number should be accurate. For svn branch checkouts, this matthijs@10085: number is mostly meaningless, at least when comparing with the matthijs@10085: REV_NR from other branches or trunk. matthijs@10085: matthijs@10085: This number should be sortable. Within a given branch or trunk, a matthijs@10085: higher number means a newer version. However, when using git or hg, matthijs@10085: this number will not increase on new commits. matthijs@10085: matthijs@10085: If no revision number could be found, this is left empty. matthijs@10085: MODIFIED matthijs@10085: Whether (the src directory of) this checkout is modified or not. A matthijs@10085: value of 0 means not modified, a value of 2 means it was modified. matthijs@10085: Modification is determined in relation to the commit identified by matthijs@10085: REV, so not in relation to the svn revision identified by REV_NR. matthijs@10085: matthijs@10085: A value of 1 means that the modified status is unknown, because this matthijs@10085: is not an svn/git/hg checkout for example. matthijs@10085: rubidium@10092: CLEAN_REV rubidium@10092: the same as REV but without branch name rubidium@10092: matthijs@10085: By setting the AWK environment variable, a caller can determine which matthijs@10085: version of "awk" is used. If nothing is set, this script defaults to matthijs@10085: "awk". matthijs@10085: EOF matthijs@10085: exit 1; matthijs@10085: fi matthijs@10085: matthijs@10085: # Allow awk to be provided by the caller. matthijs@10085: if [ -z "$AWK" ]; then matthijs@10085: AWK=awk matthijs@10085: fi matthijs@10085: matthijs@10085: # Find out some dirs matthijs@10085: cd `dirname "$0"` matthijs@10085: ROOT_DIR=`pwd` matthijs@10085: SRC_DIR=src matthijs@10085: matthijs@10085: # Determine if we are using a modified version matthijs@10085: # Assume the dir is not modified matthijs@10085: MODIFIED="0" matthijs@10085: if [ -d "$ROOT_DIR/.svn" ]; then matthijs@10085: # We are an svn checkout matthijs@10096: if [ -n "`svnversion \"$SRC_DIR\" | grep 'M'`" ]; then matthijs@10085: MODIFIED="2" matthijs@10085: fi matthijs@10085: # Find the revision like: rXXXXM-branch matthijs@10085: BRANCH=`LC_ALL=C svn info "$SRC_DIR" | "$AWK" '/^URL:.*branches/ { split($2, a, "/"); for(i in a) if (a[i]=="branches") { print a[i+1]; break } }'` matthijs@10097: TAG=`LC_ALL=C svn info "$SRC_DIR" | "$AWK" '/^URL:.*tags/ { split($2, a, "/"); for(i in a) if (a[i]=="tags") { print a[i+1]; break } }'` matthijs@10085: REV_NR=`LC_ALL=C svn info "$SRC_DIR" | "$AWK" '/^Last Changed Rev:/ { print $4 }'` matthijs@10097: if [ -n "$TAG" ]; then matthijs@10097: REV=$TAG rubidium@10092: else rubidium@10092: REV="r$REV_NR" rubidium@10092: fi matthijs@10085: elif [ -d "$ROOT_DIR/.git" ]; then matthijs@10085: # We are a git checkout matthijs@10096: if [ -n "`git diff-index HEAD \"$SRC_DIR\"`" ]; then matthijs@10085: MODIFIED="2" matthijs@10085: fi rubidium@10281: HASH=`LC_ALL=C git rev-parse --verify HEAD 2>/dev/null` rubidium@10281: REV="g`echo $HASH | cut -c1-8`" smatz@10239: BRANCH=`git branch|grep '[*]' | sed 's~\* ~~;s~^master$~~'` smatz@10239: REV_NR=`LC_ALL=C git log --pretty=format:%s "$SRC_DIR" | grep "^(svn r[0-9]*)" | head -n 1 | sed "s~.*(svn r\([0-9]*\)).*~\1~"` matthijs@10085: elif [ -d "$ROOT_DIR/.hg" ]; then matthijs@10085: # We are a hg checkout matthijs@10096: if [ -n "`hg status \"$SRC_DIR\" | grep -v '^?'`" ]; then matthijs@10085: MODIFIED="2" matthijs@10085: fi rubidium@10281: HASH=`LC_ALL=C hg parents 2>/dev/null | head -n 1 | cut -d: -f3` rubidium@10281: REV="h`echo $HASH | cut -c1-8`" smatz@10239: BRANCH=`hg branch | sed 's~^default$~~'` smatz@10239: REV_NR=`LC_ALL=C hg log -r $HASH:0 -k "svn" -l 1 --template "{desc}\n" "$SRC_DIR" | grep "^(svn r[0-9]*)" | head -n 1 | sed "s~.*(svn r\([0-9]*\)).*~\1~"` matthijs@10085: else matthijs@10085: # We don't know matthijs@10085: MODIFIED="1" matthijs@10085: BRANCH="" matthijs@10085: REV="" matthijs@10085: REV_NR="" matthijs@10085: fi matthijs@10085: matthijs@10085: if [ "$MODIFIED" -eq "2" ]; then matthijs@10085: REV="${REV}M" matthijs@10085: fi matthijs@10085: rubidium@10092: CLEAN_REV=${REV} rubidium@10092: matthijs@10085: if [ -n "$BRANCH" ]; then matthijs@10085: REV="${REV}-$BRANCH" matthijs@10085: fi matthijs@10085: rubidium@10092: echo "$REV $REV_NR $MODIFIED $CLEAN_REV"