#!/bin/sh
# Print additional version information from repository.

usage() {
    echo "Usage: $0 [srctree]" >&2
    exit 1
}

cd "${1:-.}" || usage

# Check for git and a git repo.
if head=`git rev-parse --verify HEAD 2>/dev/null`; then

    if [ $(git tag -l | wc -l) == 0 ]; then
	# If no tags are found, show git-id only
	printf '%s%s' -g `echo "$head" | cut -c1-8`
    else
	printf '%s%s' -t `git describe`
    fi

    # Are there uncommitted changes?
    if git diff-index HEAD | read dummy; then
	printf '%s' -dirty
    fi

    exit 0
fi

# Check for arch and arch repository.
if tla tree-root -s 2>/dev/null; then
    printf '%s%s' - `tla revisions -f -r | head -1 | cut -d '/' -f 2`

    # 'tla changes' takes too long so '-dirty' is not implemented.

    exit 0
fi
