| 1 | #!/bin/sh |
| 2 | |
| 3 | GIT=${GIT:-git} |
| 4 | SED=${SED:-sed} |
| 5 | AWK=${AWK:-awk} |
| 6 | |
| 7 | if [ -f ${1}/.version ]; then |
| 8 | cat ${1}/.version |
| 9 | exit 0 |
| 10 | fi |
| 11 | |
| 12 | if [ ! -d ${1}/.git ]; then |
| 13 | echo "UNKNOWN__and_probably_unsupported" |
| 14 | exit 0 |
| 15 | fi |
| 16 | |
| 17 | if [ -z ${GIT} ]; then |
| 18 | GIT="git" |
| 19 | fi |
| 20 | |
| 21 | if ! command -v ${GIT} >/dev/null 2>&1; then |
| 22 | echo "UNKNOWN__and_probably_unsupported" |
| 23 | exit 1 |
| 24 | fi |
| 25 | |
| 26 | GITCHECK=$(${GIT} describe --always 2>/dev/null || echo gitfail 2>/dev/null) |
| 27 | if [ "x${GITCHECK}" = "xgitfail" ]; then |
| 28 | echo "UNKNOWN__git_check_fail" |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
| 32 | cd ${1} || exit 1 |
| 33 | |
| 34 | MODIFIED="" |
| 35 | |
| 36 | # If MAINLINE_BRANCH is already set in the environment, use it. |
| 37 | if [ -z "${MAINLINE_BRANCH}" ] ; then |
| 38 | # Try to retrieve MAINLINE_BRANCH from a local .develvars file first. |
| 39 | # .develvars is keyed by the branch name so we need to get that first. |
| 40 | BRANCH=$(${GIT} symbolic-ref --short HEAD 2>/dev/null) |
| 41 | if [ -f .develvars ] ; then |
| 42 | MAINLINE_BRANCH=$(${GIT} config -f .develvars --get branch.${BRANCH}.mainline-branch) |
| 43 | fi |
| 44 | |
| 45 | # If we didn't find it, see if this is a well-known development branch. |
| 46 | # development/<mainline_branch>/<branchname> or |
| 47 | # devel/<mainline_branch>/<branchname> |
| 48 | if [ "x${MAINLINE_BRANCH}" = "x" ] ; then |
| 49 | MAINLINE_BRANCH=$(echo "${BRANCH}" | ${SED} -n -r -e "s@devel(opment)?/([0-9]+)/.+@\2@p") |
| 50 | fi |
| 51 | |
| 52 | # If we didn't find it, get it from configure.ac. |
| 53 | if [ "x${MAINLINE_BRANCH}" = "x" ] ; then |
| 54 | MAINLINE_BRANCH=$(${AWK} '/AC_INIT/ { print substr($2, 2, length($2) - 3) }' configure.ac) |
| 55 | fi |
| 56 | fi |
| 57 | |
| 58 | VERSION=`${GIT} describe --long --always --tags --dirty=M 2> /dev/null` |
| 59 | if [ $? -ne 0 ]; then |
| 60 | if [ "`${GIT} ls-files -m | wc -l`" != "0" ]; then |
| 61 | MODIFIED="M" |
| 62 | fi |
| 63 | # Some older versions of git do not support all the above |
| 64 | # options. |
| 65 | VERSION=`${GIT} rev-parse --short --verify HEAD`${MODIFIED} |
| 66 | fi |
| 67 | echo GIT-${MAINLINE_BRANCH}-${VERSION} |