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"