mkrevision.sh 668 B

123456789101112131415161718192021222324252627
  1. #!/bin/sh
  2. TOPDIR="${0%mkrevision.sh}"
  3. [ -d "$TOPDIR/../build" ] || {
  4. echo "Please execute as ./build/mkrevision.sh" >&2
  5. exit 1
  6. }
  7. (
  8. cd "$TOPDIR"
  9. if svn info >/dev/null 2>/dev/null; then
  10. revision="svn-r$(LC_ALL=C svn info | sed -ne 's/^Revision: //p')"
  11. elif git log -1 >/dev/null 2>/dev/null; then
  12. revision="svn-r$(LC_ALL=C git log -1 | sed -ne 's/.*git-svn-id: .*@\([0-9]\+\) .*/\1/p')"
  13. if [ "$revision" = "svn-r" ]; then
  14. set -- $(git log -1 --format="%ct %h")
  15. secs="$(($1 % 86400))"
  16. yday="$(date --utc --date="@$1" "+%y.%j")"
  17. revision="$(printf 'git-%s.%05d-%s' "$yday" "$secs" "$2")"
  18. fi
  19. else
  20. revision="unknown"
  21. fi
  22. echo "$revision"
  23. )