Skip to content

Commit 9415696

Browse files
committed
Time-traveled get-scala-revision to 3-way merge base.
1 parent b16cbcd commit 9415696

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

tools/get-scala-revision

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,35 @@
22
#
33
# Usage: get-scala-revision [dir]
44
# Figures out current scala revision of a git clone.
5-
#
65
# If no dir is given, current working dir is used.
6+
#
7+
# Example build version string:
8+
# v2.10.0-M1-0098-g6f1c486d0b-2012-02-01
9+
#
10+
11+
[[ $# -eq 0 ]] || cd "$1"
12+
13+
ensure_tag () {
14+
# v2.10.0-M1
15+
fallback=58cb15c40d
16+
[[ -n $(git tag -l v2.10.0-M1) ]] || {
17+
git tag -a -m "generated by get-scala-revision" v2.10.0-M1 $fallback
18+
}
19+
}
20+
ensure_tag
721

8-
# not like releases come out so often that we are duty-bound
9-
# to recalculate this every time.
10-
# git merge-base v2.8.2 v2.9.1 master
11-
devbase="df13e31bbb"
22+
# the closest tag, obtained separately because we have to
23+
# reconstruct the string around the padded distance.
24+
tag=$(git describe --match 'v2*' --abbrev=0)
1225

13-
# reimplementing git describe hopefully in a way which works
14-
# without any particular tags, branches, or recent versions of git.
15-
# this is supposed to generate
16-
# dev-NNNN-g<sha>
17-
# where NNNN is the number of commits since devbase, which
18-
# is the merge-base of the most recent release and master.
19-
# Presently hardcoded to reduce uncertainty, v2.8.2/v2.9.1/master.
20-
commits=$(git --no-pager log --pretty=oneline $devbase..HEAD | wc -l)
21-
sha=$(git rev-list -n 1 HEAD)
22-
datestr=$(date "+%Y-%m-%d")
26+
# the full string - padding correctness depends on abbrev=10.
27+
described=$(git describe --match 'v2*' --abbrev=10)
28+
suffix="${described##${tag}-}"
29+
counter=$(echo $suffix | cut -d - -f 1)
30+
hash=$(echo $suffix | cut -d - -f 2)
2331

24-
printf "rdev-%s-%s-g%s\n" $commits $datestr ${sha:0:7}
32+
# 016 is rocket-surgically-calibrated to pad the distance from the
33+
# tag to the current commit into a 4-digit number - since maven
34+
# will be treating this as a string, the ide depends on
35+
# 10 being greater than 9 (thus 0010 and 00009.)
36+
printf "%s-%04d-%10s-%s\n" "$tag" "$counter" "$hash" $(date "+%Y-%m-%d")

0 commit comments

Comments
 (0)