source: trunk/scripts/getver.sh @ 28604

Last change on this file since 28604 was 28604, checked in by jow, 5 years ago

[scripts] getver.sh: cope with varying "git log" line formats to reliably extract the git-svn rev (#10268)

  • Property svn:executable set to *
File size: 686 bytes
Line 
1#!/usr/bin/env bash
2export LANG=C
3export LC_ALL=C
4[ -n "$TOPDIR" ] && cd $TOPDIR
5
6try_version() {
7        [ -f version ] || return 1
8        REV="$(cat version)"
9        [ -n "$REV" ]
10}
11
12try_svn() {
13        [ -d .svn ] || return 1
14        REV="$(svn info | awk '/^Last Changed Rev:/ { print $4 }')"
15        REV="${REV:+r$REV}"
16        [ -n "$REV" ]
17}
18
19try_git() {
20        [ -d .git ] || return 1
21        REV="$(git log | grep -m 1 git-svn-id | awk '{ gsub(/.*@/, "", $0); print $1 }')"
22        REV="${REV:+r$REV}"
23        [ -n "$REV" ]
24}
25
26try_hg() {
27        [ -d .hg ] || return 1
28        REV="$(hg log -r-1 --template '{desc}' | awk '{print $2}' | sed 's/\].*//')"
29        REV="${REV:+$REV}"
30        [ -n "$REV" ]
31}
32
33try_version || try_svn || try_git || try_hg || REV="unknown"
34echo "$REV"
Note: See TracBrowser for help on using the repository browser.