From cd55bcfa008a8cfe221ef7f71632096ea4e8d348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Holz?= Date: Fri, 10 Oct 2025 15:39:46 +0200 Subject: [PATCH] Kernel: Use `git describe` to generate git hash Instead of manually creating the git hash string, we can simply use `git describe` with appropriate options: - `--exclude '*'` to exclude any git tags - `--always` to make `git describe` print a uniquely abbreviated commit hash if no tag is matching - `--dirty=-modified` to add a "-modified" suffix if the working tree has local modifications This should also guarantee now that the abbreviated commit hash is always unique. Previously, we always abbreviated the commit hash to 7 characters. --- Kernel/generate-version-file.sh | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/Kernel/generate-version-file.sh b/Kernel/generate-version-file.sh index 98d02b7ae54..12aa65bdc21 100755 --- a/Kernel/generate-version-file.sh +++ b/Kernel/generate-version-file.sh @@ -4,20 +4,7 @@ set -e OUTPUT_FILE=$1 -if command -v git >/dev/null; then - if git status >/dev/null 2>&1; then - GIT_HASH=$( (git log --pretty=format:'%h' -n 1 | cut -c1-7) || true ) - # There is at least one modified file as reported by git. - if git status --porcelain=v2 | head | grep -Ei '^1' >/dev/null; then - GIT_HASH="${GIT_HASH}-modified" - fi - else - GIT_HASH=unknown - fi -else - GIT_HASH=unknown -fi - +GIT_HASH=$(git describe --exclude '*' --always --dirty=-modified 2>/dev/null || echo "unknown") cat << EOF > "$OUTPUT_FILE" /*