This repository was archived by the owner on Jul 30, 2021. It is now read-only.
Commit 8f601b5
build/git-version: Only call 'git' once (#951)
Simplify the logic from 04848d1 (Add release build process,
2016-05-27, #47) to:
* Move from Bash to a generic POSIX shell. This makes the script more
portable (it will work on POSIX systems without Bash). It does mean
we need to drop the 'set' (which is not in POSIX [1]), but that's
not a major problem because:
* We can use &&-chaining instead of 'set -e'.
* We do only have the one locally-defined variable, so we don't need
'set -u'.
* The simpler logic has no pipes, so 'set -o pipefail' would no
longer matter.
* Replace the previous multiple Git calls with a single call to 'git
describe'.
* Use --dirty so we can drop the previous diff call.
* Drop --tags, because we don't want to use lightweight
(non-annotated) tags. We want to use annotated tags, because we
want to use signed release tags. There's no code check for tag
signatures here, but RELEASING.md requests 'tag -s vX.Y.Z', which
will create signed, annotated tags.
* Git's SHA-1 hashes are 40 hex digits, but I've used --abbrev=100
to get unabbreviated hashes even in the face of future hash
transitions [2]. This is a bit of a hack compared to the previous
approach, because at some point Git may have >100-char hashes.
But if that happens, it will be far enough in the future that I
think the simplification we get here is worth it (and this
constant is easy to bump if we need to).
* The new call always returns the most recent tag, and (for commits
which are not exact tag matches) also includes the abbreviated
commit. To isolate the hash (and possible dirty-mark) for commits
that are not exact tags, I use POSIX's ${parameter##[word]}
prefix-pattern removal [3]. Exact tags are unlikely to include
'-g' (unless it is in the tag itself), so for them the
prefix-removal is a no-op. Again, this is a bit of a hack, since
a tag might include '-g', but I think that's unlikely enough (as
mentioned above, RELEASING.md requests vX.Y.Z for tags) that the
simplification we get here is worth it.
[1]: http://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html
[2]: https://github.com/git/git/blob/v2.16.3/Documentation/technical/hash-function-transition.txt
[3]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_021 parent 101f003 commit 8f601b5
1 file changed
+3
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
3 | 2 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
| 3 | + | |
| 4 | + | |
0 commit comments