aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas Gorski <jonas.gorski@gmail.com>2016-06-05 20:45:25 +0200
committerJonas Gorski <jonas.gorski@gmail.com>2016-07-09 13:41:28 +0200
commit1001b5d77c5dd7adc7bb2fcce8778364b88e5ea0 (patch)
tree93eda923c062a7dad69ba5e1b51256c0b786326d
parent575be9d18259560b40039ee0e4bf6d6ce109fca6 (diff)
downloadupstream-1001b5d77c5dd7adc7bb2fcce8778364b88e5ea0.tar.gz
upstream-1001b5d77c5dd7adc7bb2fcce8778364b88e5ea0.tar.bz2
upstream-1001b5d77c5dd7adc7bb2fcce8778364b88e5ea0.zip
scripts/getver.sh: allow conversion between git hash and revision
Add code allowing easy conversion between git commit ids and revisions. Example: $ ./scripts/getver.sh r792 $ ./scripts/getver.sh r123 b7fc892eb56b52d25bc00578af9d1ee058dcf6b3 $ ./scrpts/getver.sh b7fc892eb56b52d25bc00578af9d1ee058dcf6b3 r123 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
-rwxr-xr-xscripts/getver.sh20
1 files changed, 18 insertions, 2 deletions
diff --git a/scripts/getver.sh b/scripts/getver.sh
index 340ed6862c..a60b91ede1 100755
--- a/scripts/getver.sh
+++ b/scripts/getver.sh
@@ -3,6 +3,8 @@ export LANG=C
export LC_ALL=C
[ -n "$TOPDIR" ] && cd $TOPDIR
+GET_REV=$1
+
try_version() {
[ -f version ] || return 1
REV="$(cat version)"
@@ -11,8 +13,22 @@ try_version() {
try_git() {
git rev-parse --git-dir >/dev/null 2>&1 || return 1
- REV="$(git rev-list reboot..HEAD --count)"
- REV="${REV:+r$REV}"
+
+ [ -n "$GET_REV" ] || GET_REV="HEAD"
+
+ case "$GET_REV" in
+ r*)
+ GET_REV="$(echo $GET_REV | tr -d 'r')"
+ BASE_REV="$(git rev-list reboot..HEAD --count)"
+ REV="$(git rev-parse HEAD~$((BASE_REV - GET_REV)))"
+ ;;
+ *)
+
+ REV="$(git rev-list reboot..$GET_REV --count)"
+ REV="${REV:+r$REV}"
+ ;;
+ esac
+
[ -n "$REV" ]
}