| 1 | #!/bin/sh |
| 2 | # Print additional version information for non-release trees. |
| 3 | |
| 4 | usage() { |
| 5 | echo "Usage: $0 [srctree]" >&2 |
| 6 | exit 1 |
| 7 | } |
| 8 | |
| 9 | cd "${1:-.}" || usage |
| 10 | |
| 11 | # Check for git and a git repo. |
| 12 | if head=`git rev-parse --verify HEAD 2>/dev/null`; then |
| 13 | # Do we have an untagged version? |
| 14 | if git name-rev --tags HEAD | grep -E '^HEAD[[:space:]]+(.*~[0-9]*|undefined)$' > /dev/null; then |
| 15 | git describe | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}' |
| 16 | fi |
| 17 | |
| 18 | # Are there uncommitted changes? |
| 19 | git update-index --refresh --unmerged > /dev/null |
| 20 | if git diff-index --name-only HEAD | grep -v "^scripts/package" \ |
| 21 | | read dummy; then |
| 22 | printf '%s' -dirty |
| 23 | fi |
| 24 | |
| 25 | # All done with git |
| 26 | exit |
| 27 | fi |
| 28 | |
| 29 | # Check for mercurial and a mercurial repo. |
| 30 | if hgid=`hg id 2>/dev/null`; then |
| 31 | tag=`printf '%s' "$hgid" | cut -d' ' -f2` |
| 32 | |
| 33 | # Do we have an untagged version? |
| 34 | if [ -z "$tag" -o "$tag" = tip ]; then |
| 35 | id=`printf '%s' "$hgid" | sed 's/[+ ].*//'` |
| 36 | printf '%s%s' -hg "$id" |
| 37 | fi |
| 38 | |
| 39 | # Are there uncommitted changes? |
| 40 | # These are represented by + after the changeset id. |
| 41 | case "$hgid" in |
| 42 | *+|*+\ *) printf '%s' -dirty ;; |
| 43 | esac |
| 44 | |
| 45 | # All done with mercurial |
| 46 | exit |
| 47 | fi |
| 48 | |
| 49 | # Check for svn and a svn repo. |
| 50 | if rev=`svn info 2>/dev/null | grep '^Revision'`; then |
| 51 | rev=`echo $rev | awk '{print $NF}'` |
| 52 | changes=`svn status 2>/dev/null | grep '^[AMD]' | wc -l` |
| 53 | |
| 54 | # Are there uncommitted changes? |
| 55 | if [ $changes != 0 ]; then |
| 56 | printf -- '-svn%s%s%s' "$rev" -dirty "$changes" |
| 57 | else |
| 58 | printf -- '-svn%s' "$rev" |
| 59 | fi |
| 60 | |
| 61 | # All done with svn |
| 62 | exit |
| 63 | fi |