From 6ca780c12dc8d1257a6a6ab0665f11d00de99fe3 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Sat, 1 May 2021 20:57:42 +0800 Subject: [PATCH] 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. --- git-version.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/git-version.sh b/git-version.sh index 0512a26aa..8fe051501 100755 --- a/git-version.sh +++ b/git-version.sh @@ -14,7 +14,6 @@ export LC_ALL=en_US.utf8 export TZ=US/Pacific commit_date=$(git show -s --format=format:"%cd" --date=local) -short_date=$(date --date "$commit_date" "+%Y%m%d") year=$(date --date "$commit_date" "+%Y") month=$(date --date "$commit_date" "+%B") @@ -30,13 +29,16 @@ esac full_date="$month $day$suffix, $year" -sha="g$(git describe --always)" -version="GIT-$short_date-$sha" -versiond="GIT-$short_date-$sha-systemd" +sha="$(git describe --abbrev=1)" +if git describe --all --match trunk > /dev/null 2> /dev/null; then + sha=$(echo "$sha" | sed 's/-g[^-]*$//') +fi +version="$sha" +versiond="$sha-systemd" if [ "$(git diff HEAD | wc -l)" != "0" ]; then - version="$version-MODIFIED" - versiond="$versiond-MODIFIED" + version="$version+" + versiond="$versiond+" fi echo "" > version.ent