source: git-version.sh@ 6ca780c

11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since 6ca780c was 6ca780c, checked in by Xi Ruoyao <xry111@…>, 3 years ago

git-version: simplify the versioning scheme

Now the version for trunk head is simply rx.y-z. x.y is the last
release, and z is the number of commits after x.y.

For other commits, the version is rx.y-z-g{sha}. An abbreviated sha
hash is added to distinguish commits with same x, y, and z on different
branches.

If there are uncommited changes, a "+" is appended to the version,
indicating the version is "unclean".

To make it works correctly, a tag "rx.y" have to be created on the last
commit on trunk of x.y release.

  • Property mode set to 100755
File size: 1.4 KB
Line 
1#!/bin/sh
2
3if ! git status > /dev/null; then
4 # Either it's not a git repository, or git is unavaliable.
5 # Just workaround.
6 echo "<!ENTITY version \"unknown\">" > version.ent
7 echo "<!ENTITY versiond \"unknown-systemd\">" >> version.ent
8 echo "<!ENTITY releasedate \"unknown\">" >> version.ent
9 echo "<!ENTITY copyrightdate \"1999-2021\">" >> version.ent
10 exit 0
11fi
12
13export LC_ALL=en_US.utf8
14export TZ=US/Pacific
15
16commit_date=$(git show -s --format=format:"%cd" --date=local)
17
18year=$(date --date "$commit_date" "+%Y")
19month=$(date --date "$commit_date" "+%B")
20month_digit=$(date --date "$commit_date" "+%m")
21day=$(date --date "$commit_date" "+%d" | sed 's/^0//')
22
23case $day in
24 "1" | "21" | "31" ) suffix="st";;
25 "2" | "22" ) suffix="nd";;
26 "3" | "23" ) suffix="rd";;
27 * ) suffix="th";;
28esac
29
30full_date="$month $day$suffix, $year"
31
32sha="$(git describe --abbrev=1)"
33if git describe --all --match trunk > /dev/null 2> /dev/null; then
34 sha=$(echo "$sha" | sed 's/-g[^-]*$//')
35fi
36version="$sha"
37versiond="$sha-systemd"
38
39if [ "$(git diff HEAD | wc -l)" != "0" ]; then
40 version="$version+"
41 versiond="$versiond+"
42fi
43
44echo "<!ENTITY version \"$version\">" > version.ent
45echo "<!ENTITY versiond \"$versiond\">" >> version.ent
46echo "<!ENTITY releasedate \"$full_date\">" >> version.ent
47echo "<!ENTITY copyrightdate \"1999-$year\">" >> version.ent
Note: See TracBrowser for help on using the repository browser.