get_source_date_epoch.sh 696 B

12345678910111213141516171819202122232425262728293031
  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.date ] || return 1
  7. SOURCE_DATE_EPOCH="$(cat version.date)"
  8. [ -n "$SOURCE_DATE_EPOCH" ]
  9. }
  10. try_svn() {
  11. [ -d .svn ] || return 1
  12. SOURCE_DATE_EPOCH="$(./scripts/portable_date.sh "$(LC_ALL=C svn info | sed -ne 's/^Last Changed Date: //p')" +%s)"
  13. [ -n "$SOURCE_DATE_EPOCH" ]
  14. }
  15. try_git() {
  16. [ -e .git ] || return 1
  17. SOURCE_DATE_EPOCH="$(git log -1 --format=format:%ct)"
  18. [ -n "$SOURCE_DATE_EPOCH" ]
  19. }
  20. try_hg() {
  21. [ -d .hg ] || return 1
  22. SOURCE_DATE_EPOCH=""
  23. [ -n "$SOURCE_DATE_EPOCH" ]
  24. }
  25. try_version || try_svn || try_git || try_hg || SOURCE_DATE_EPOCH=""
  26. echo "$SOURCE_DATE_EPOCH"