chiark / gitweb /
git-revid: new C autoversion feature
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 9 Jan 2011 14:01:47 +0000 (14:01 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 9 Jan 2011 14:01:47 +0000 (14:01 +0000)
.git-revid
.git-revid-autoversion.h [new file with mode: 0644]

index f4d77702b8ea28cd9edf37560d5b23924396555b..74037ae58d4c246dff8c4643d51c16ae8cd4a55b 100755 (executable)
@@ -1,6 +1,9 @@
 #!/bin/bash
 set -e
 set -o pipefail
+
+kind="$1"
+
 desc=`git-describe --always HEAD`
 log=`git-log -1 --pretty='format:%h %ci %s' HEAD`
 set +e
@@ -12,4 +15,25 @@ case $diffrc in
 1)     diffplus=+ ;;
 *)     exit $diffrc ;;
 esac
-printf '%.71s\n' "$desc$diffplus $log"
+
+case "$1" in
+'')    maxlen=.71
+       ;;
+C)     echo '#include "../.git-revid-autoversion.h"'
+       printf 'const char autoversion[]= \"'
+       log="${log//\\/\\\\}"
+       log="${log//\"/\\\"}"
+       maxlen=''
+       ;;
+*)     echo >&2 'bad usage for .git-revid'
+       exit 1
+       ;;
+esac
+
+printf "%${maxlen}s" "$desc$diffplus $log"
+
+case "$kind" in
+'')    printf '\n' ;;
+C)     echo '";' ;;
+*)     ;;
+esac
diff --git a/.git-revid-autoversion.h b/.git-revid-autoversion.h
new file mode 100644 (file)
index 0000000..8502ce4
--- /dev/null
@@ -0,0 +1,5 @@
+/* goes with the automatically-generated output from .git-revid */
+#ifndef AUTOVERSION_H
+#define AUTOVERSION_H
+extern const char autoversion[];
+#endif /*AUTOVERSION_H*/