summaryrefslogtreecommitdiffstats
path: root/GIT-VERSION-GEN
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-12-06 14:24:39 +0100
committerJunio C Hamano <gitster@pobox.com>2024-12-06 23:52:08 +0100
commit0c8d33951400f7d7175e1dad51e970fb70849f2b (patch)
treef3d40e1e433824b1c1b211e3943642c553240966 /GIT-VERSION-GEN
parentMakefile: refactor GIT-VERSION-GEN to be reusable (diff)
downloadgit-0c8d33951400f7d7175e1dad51e970fb70849f2b.tar.xz
git-0c8d33951400f7d7175e1dad51e970fb70849f2b.zip
Makefile: propagate Git version via generated header
We set up a couple of preprocessor macros when compiling Git that propagate the version that Git was built from to `git version` et al. The way this is set up makes it harder than necessary to reuse the infrastructure across the different build systems. Refactor this such that we generate a "version-def.h" header via `GIT-VERSION-GEN` instead. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'GIT-VERSION-GEN')
-rwxr-xr-xGIT-VERSION-GEN7
1 files changed, 7 insertions, 0 deletions
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 7afc7aad14..c18f24e515 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -52,6 +52,11 @@ else
fi
GIT_VERSION=$(expr "$VN" : v*'\(.*\)')
+GIT_BUILT_FROM_COMMIT=$(git -C "$SOURCE_DIR" rev-parse -q --verify HEAD 2>/dev/null)
+if test -z "$GIT_USER_AGENT"
+then
+ GIT_USER_AGENT="git/$GIT_VERSION"
+fi
read GIT_MAJOR_VERSION GIT_MINOR_VERSION GIT_MICRO_VERSION trailing <<EOF
$(echo "$GIT_VERSION" 0 0 0 | tr '.a-zA-Z-' ' ')
@@ -61,6 +66,8 @@ sed -e "s|@GIT_VERSION@|$GIT_VERSION|" \
-e "s|@GIT_MAJOR_VERSION@|$GIT_MAJOR_VERSION|" \
-e "s|@GIT_MINOR_VERSION@|$GIT_MINOR_VERSION|" \
-e "s|@GIT_MICRO_VERSION@|$GIT_MICRO_VERSION|" \
+ -e "s|@GIT_BUILT_FROM_COMMIT@|$GIT_BUILT_FROM_COMMIT|" \
+ -e "s|@GIT_USER_AGENT@|$GIT_USER_AGENT|" \
"$INPUT" >"$OUTPUT"+
if ! test -f "$OUTPUT" || ! cmp "$OUTPUT"+ "$OUTPUT" >/dev/null