Skip to content

Commit

Permalink
scripts/getver.sh: allow conversion between git hash and revision
Browse files Browse the repository at this point in the history
Add code allowing easy conversion between git commit ids and revisions.

Example:

$ ./scripts/getver.sh
r792
$ ./scripts/getver.sh r123
b7fc892
$ ./scrpts/getver.sh b7fc892
r123

Signed-off-by: Jonas Gorski <[email protected]>
  • Loading branch information
KanjiMonster committed Jul 9, 2016
1 parent 575be9d commit 1001b5d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions scripts/getver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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" ]
}

Expand Down

0 comments on commit 1001b5d

Please sign in to comment.