aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscripts/get_source_date_epoch.sh14
1 files changed, 8 insertions, 6 deletions
diff --git a/scripts/get_source_date_epoch.sh b/scripts/get_source_date_epoch.sh
index 8a41eebae7..d122acf385 100755
--- a/scripts/get_source_date_epoch.sh
+++ b/scripts/get_source_date_epoch.sh
@@ -6,21 +6,23 @@ if [ -n "$TOPDIR" ]; then
cd "$TOPDIR" || exit 1
fi
+SOURCE="${1:-.}"
+
try_version() {
- [ -f version.date ] || return 1
- SOURCE_DATE_EPOCH="$(cat version.date)"
+ [ -f "$SOURCE/version.date" ] || return 1
+ SOURCE_DATE_EPOCH=$(cat "$SOURCE/version.date")
[ -n "$SOURCE_DATE_EPOCH" ]
}
try_git() {
- [ -e .git ] || return 1
- SOURCE_DATE_EPOCH="$(git log -1 --format=format:%ct)"
+ SOURCE_DATE_EPOCH=$(git -C "$SOURCE" log -1 --format=format:%ct \
+ "$SOURCE" 2>/dev/null)
[ -n "$SOURCE_DATE_EPOCH" ]
}
try_hg() {
- [ -d .hg ] || return 1
- SOURCE_DATE_EPOCH="$(hg log --template '{date}' -l 1 | cut -d. -f1)"
+ SOURCE_DATE_EPOCH=$(hg --cwd "$SOURCE" log --template '{date}' -l 1 \
+ "$SOURCE" 2>/dev/null | cut -d. -f1)
[ -n "$SOURCE_DATE_EPOCH" ]
}