123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- #!/bin/sh
- scriptversion=2016-05-08.18;
- me=$0
- version="git-version-gen $scriptversion
- Copyright 2011 Free Software Foundation, Inc.
- There is NO warranty. You may redistribute this software
- under the terms of the GNU General Public License.
- For more information about these matters, see the files named COPYING."
- usage="\
- Usage: $me [OPTION]... \$srcdir/.tarball-version [TAG-NORMALIZATION-SED-SCRIPT]
- Print a version string.
- Options:
- --prefix PREFIX prefix of git tags (default 'v')
- --fallback VERSION
- fallback version to use if \"git --version\" fails
- --help display this help and exit
- --version output version information and exit
- Running without arguments will suffice in most cases."
- prefix=v
- fallback=
- while test $# -gt 0; do
- case $1 in
- --help) echo "$usage"; exit 0;;
- --version) echo "$version"; exit 0;;
- --prefix) shift; prefix=${1?};;
- --fallback) shift; fallback=${1?};;
- -*)
- echo "$0: Unknown option '$1'." >&2
- echo "$0: Try '--help' for more information." >&2
- exit 1;;
- *)
- if test "x$tarball_version_file" = x; then
- tarball_version_file="$1"
- elif test "x$tag_sed_script" = x; then
- tag_sed_script="$1"
- else
- echo "$0: extra non-option argument '$1'." >&2
- exit 1
- fi;;
- esac
- shift
- done
- if test "x$tarball_version_file" = x; then
- echo "$usage"
- exit 1
- fi
- tag_sed_script="${tag_sed_script:-s/x/x/}"
- nl='
- '
- v=
- v_from_git=
- if test -f $tarball_version_file
- then
- v=`cat $tarball_version_file` || v=
- case $v in
- *$nl*) v= ;;
- [0-9]*) ;;
- *) v= ;;
- esac
- test "x$v" = x \
- && echo "$0: WARNING: $tarball_version_file is missing or damaged" 1>&2
- fi
- if test "x$v" != x
- then
- :
- elif test "`git log -1 --pretty=format:x . 2>&1`" = x \
- && v=`git describe --abbrev=4 --match="$prefix*" HEAD 2>/dev/null \
- || git describe --abbrev=4 HEAD 2>/dev/null` \
- && v=`printf '%s\n' "$v" | sed "$tag_sed_script"` \
- && case $v in
- $prefix[0-9]*) ;;
- *) (exit 1) ;;
- esac
- then
-
-
-
-
- case $v in
- *-*-*) : git describe is okay three part flavor ;;
- *-*)
- : git describe is older two part flavor
-
-
-
- vtag=`echo "$v" | sed 's/-.*//'`
- commit_list=`git rev-list "$vtag"..HEAD 2>/dev/null` \
- || { commit_list=failed;
- echo "$0: WARNING: git rev-list failed" 1>&2; }
- numcommits=`echo "$commit_list" | wc -l`
- v=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`;
- test "$commit_list" = failed && v=UNKNOWN
- ;;
- esac
-
-
- v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`;
- v_from_git=1
- elif test "x$fallback" = x || git --version >/dev/null 2>&1; then
- v=UNKNOWN
- else
- v=$fallback
- fi
- v=`echo "$v" |sed "s/^$prefix//"`
- if test "x$v_from_git" != x; then
-
- git update-index --refresh > /dev/null 2>&1
- dirty=`exec 2>/dev/null;git diff-index --name-only HEAD` || dirty=
- case "$dirty" in
- '') ;;
- *)
- case $v in
- *-dirty) ;;
- *) v="$v-dirty" ;;
- esac ;;
- esac
- fi
- printf %s "$v"
|