getver.sh 698 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env bash
  2. export LANG=C
  3. export LC_ALL=C
  4. [ -n "$TOPDIR" ] && cd $TOPDIR
  5. try_version() {
  6. [ -f version ] || return 1
  7. REV="$(cat version)"
  8. [ -n "$REV" ]
  9. }
  10. try_svn() {
  11. [ -d .svn ] || return 1
  12. REV="$(svn info | awk '/^Last Changed Rev:/ { print $4 }')"
  13. REV="${REV:+r$REV}"
  14. [ -n "$REV" ]
  15. }
  16. try_git() {
  17. git rev-parse --git-dir >/dev/null 2>&1 || return 1
  18. REV="$(git describe --tags | sed "s/v15.05.1-\([0-9]*\)-.*/\1/g")"
  19. REV="${REV:+r$((REV+49254))}"
  20. [ -n "$REV" ]
  21. }
  22. try_hg() {
  23. [ -d .hg ] || return 1
  24. REV="$(hg log -r-1 --template '{desc}' | awk '{print $2}' | sed 's/\].*//')"
  25. REV="${REV:+$REV}"
  26. [ -n "$REV" ]
  27. }
  28. try_version || try_git || try_hg || REV="unknown"
  29. echo "$REV"