summaryrefslogtreecommitdiff
path: root/git_version.sh
diff options
context:
space:
mode:
authorLuc Verhaegen <libv@skynet.be>2006-08-15 04:24:04 +0200
committerLuc Verhaegen <libv@skynet.be>2006-08-15 04:24:04 +0200
commit038ab4a78b281623fb25ea7783ccc21b407c3462 (patch)
tree13f9621614c654b1b4295b442b40bdd74733f4f0 /git_version.sh
parent8c17a22472a6b2183ce284f6cba34a0d452ad81a (diff)
Add git based versioning.
Add git_version.sh, which gathers the following information: * wether git is used. * what SHA-ID the latest commit has. * the name of the branch we're in. * whether there are local changes. This information is piped to git_version.h, which is included in src/via_driver.c to print extra version information in VIAProbe. This is not a foolproof solution as the file doesn't get rebuilt all the time, only when it's not present, like after make clean.
Diffstat (limited to 'git_version.sh')
-rwxr-xr-xgit_version.sh60
1 files changed, 60 insertions, 0 deletions
diff --git a/git_version.sh b/git_version.sh
new file mode 100755
index 0000000..ea597e6
--- /dev/null
+++ b/git_version.sh
@@ -0,0 +1,60 @@
+#! /bin/sh
+#
+# Generate some basic versioning information which can be piped to a header.
+#
+echo "/*"
+echo " * Basic versioning gathered from the git repository."
+echo " */"
+echo ""
+# this might not correspond with the final filename, but will be close enough.
+echo "#ifndef HAVE_GIT_VERSION_H"
+echo "#define HAVE_GIT_VERSION_H 1"
+echo ""
+
+git_tools=`which git-whatchanged`
+if test "$git_tools" != ""; then
+ if [ -e .git/index ]; then
+ echo "/* This is a git repository */"
+ echo "#define GIT_USED 1"
+ echo ""
+
+ # SHA-ID
+ git_shaid=`git-whatchanged | head -n1 | sed s/^diff-tree\ // | sed s/\ \(from\ \[0-9a-f\]*\.\.\.\)$//`
+ echo "/* Git SHA ID of last commit */"
+ echo "#define GIT_SHAID \"$git_shaid\""
+ echo ""
+
+ # Branch -- use git-status instead of git-branch
+ git_branch=`git-status | grep "# On branch" | sed s/#\ On\ branch\ //`
+ if test "$git_branch" = ""; then
+ git_branch="master"
+ fi
+ echo "/* Branch this tree is on */"
+ echo "#define GIT_BRANCH \"$git_branch\""
+ echo ""
+
+ # Any uncommitted changes we should know about?
+ git_uncommitted=`git-status | grep "Changed but not updated"`
+ if test "$git_uncommitted" = ""; then
+ git_uncommitted=`git-status | grep "Updated but not checked in"`
+ fi
+
+ if test "$git_uncommitted" != ""; then
+ echo "/* Local changes might be breaking things */"
+ echo "#define GIT_UNCOMMITTED 1"
+ else
+ echo "/* SHA-ID uniquely defines the state of this code */"
+ echo "#undef GIT_UNCOMMITTED"
+ fi
+ else
+ echo "/* This is not a git repository */"
+ echo "#undef GIT_USED"
+ fi
+else
+ echo "/* git is not installed */"
+ echo "#undef GIT_USED"
+fi
+
+echo ""
+echo "#endif /* HAVE_GIT_VERSION_H */"
+