From f0ff15f80775e3e80c48a0b055c2ba12f93d04c8 Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Wed, 2 Mar 2016 20:24:55 -0500 Subject: [PATCH] HEAD independent version script --- README.md | 8 ++++---- bin/version.sh | 12 +++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b84aec36644be..e32024dd7f8b9 100644 --- a/README.md +++ b/README.md @@ -180,13 +180,13 @@ Currently, the `@compat` macro supports the following syntaxes: ## Developer tips -If you're adding additional compatibility code to this package, the [`bin/version.sh` script is useful for extracting the version number from a git commit SHA. For example, from the git repository of `julia`, run something like this: +If you're adding additional compatibility code to this package, the [`bin/version.sh`](https://github.com/JuliaLang/Compat.jl/blob/master/bin/version.sh) script is useful for extracting the version number from a git commit SHA. For example, from the git repository of `julia`, run something like this: ```sh bash $ /path/to/Compat/bin/version.sh a378b60fe483130d0d30206deb8ba662e93944da 0.5.0-dev+2023 ``` -This prints a number `XXXX`, and you can then test whether Julia -is at least this version by `VERSION >= v"0.Y.0-dev+XXXX"` (assuming -it is a commit from the 0.Y development cycle). +This prints a version number corresponding to the specified commit of the form +`X.Y.Z-aaa+NNNN`, and you can then test whether Julia +is at least this version by `VERSION >= v"X.Y.Z-aaa+NNNN"`. diff --git a/bin/version.sh b/bin/version.sh index 99e9e31cf396e..ae6e542c30739 100755 --- a/bin/version.sh +++ b/bin/version.sh @@ -1,5 +1,11 @@ #!/bin/bash -last_tag=$(git describe --tags --abbrev=0) -ver=$(cat VERSION) -nb=$(git rev-list $1 ^$last_tag | wc -l | sed -e 's/[^[:digit:]]//g') + +# Need to be run from a julia repo clone +# First argument (Optional) is a ref to the commit + +gitref=${1:-HEAD} + +last_tag=$(git describe --tags --abbrev=0 "$gitref") +ver=$(git show "$gitref:VERSION") +nb=$(git rev-list --count "$gitref" "^$last_tag") echo "$ver+$nb"