getver.sh 686 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. [ -d .git ] || return 1
  18. REV="$(git log | grep -m 1 git-svn-id | awk '{ gsub(/.*@/, "", $0); print $1 }')"
  19. REV="${REV:+r$REV}"
  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_svn || try_git || try_hg || REV="unknown"
  29. echo "$REV"