cgit

commit f69250358a74efa5d7d9c562b2cdd80fad1430f1

Author: Lars Hjemli <hjemli@gmail.com>

Add version info from git-describe

A new script, gen-version.sh, is now invoked from 'make version' to generate
the file VERSION. This file contains a version identifier generated by
git-describe and is included in the Makefile.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>

 .gitignore | 1 +
 Makefile | 29 ++++++++++++++++++-----------
 cgit.c | 3 ---
 cgit.h | 2 +-
 gen-version.sh | 4 ++++
 shared.c | 2 ++
 ui-shared.c | 2 +-


diff --git a/.gitignore b/.gitignore
index c4c9ac3ffa5af077a3a5ffd349a413df1f6e703b..566496210185cd3667c8364649d87f4f730c822b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
 # Files I don't care to see in git-status/commit
 cgit
+VERSION
 *.o
 *~




diff --git a/Makefile b/Makefile
index c2a5736971320639d4a22ef7a4ebfd8bcf614007..e69ad7e3562e66dbab48554a6f1cec0973e61baa 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,4 @@
-CGIT_VERSION = 0.5
-
 prefix = /var/www/htdocs/cgit
-
 SHA1_HEADER = <openssl/sha.h>
 CACHE_ROOT = /var/cache/cgit
 CGIT_CONFIG = /etc/cgitrc
@@ -11,6 +8,17 @@ #
 # Let the user override the above settings.
 #
 -include cgit.conf
+
+
+CGIT_VERSION = 0.5
+
+all: cgit
+
+VERSION:
+	gen-version.sh
+
+-include VERSION
+
 
 EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto
 OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \
@@ -42,12 +50,7 @@ INITGIT = ./submodules.sh -i
 endif
 
 
-#
-# basic build rules
-#
-all: cgit
-
-cgit: cgit.c cgit.h $(OBJECTS)
+cgit: cgit.c cgit.h VERSION $(OBJECTS)
 	$(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS)
 
 $(OBJECTS): cgit.h git/libgit.a
@@ -65,7 +68,7 @@ 	install cgit $(prefix)/$(CGIT_SCRIPT_NAME)
 	install cgit.css $(prefix)/cgit.css
 
 clean-cgit:
-	rm -f cgit *.o
+	rm -f cgit VERSION *.o
 
 distclean-cgit: clean-cgit
 	git clean -d -x
@@ -83,5 +86,9 @@ clean: clean-cgit clean-sub
 
 distclean: distclean-cgit distclean-sub
 
+version: clean-cgit
+	./gen-version.sh
+	make
+
 .PHONY: all install clean clean-cgit clean-sub clean-cache \
-	distclean distclean-cgit distclean-sub
+	distclean distclean-cgit distclean-sub release version




diff --git a/cgit.c b/cgit.c
index 3fc90bf8750645931bd9f4da6dcd896082c6ab9c..11dff767e7c9f57cbbb1772829dacbcf3b0b322e 100644
--- a/cgit.c
+++ b/cgit.c
@@ -8,9 +8,6 @@  */
 
 #include "cgit.h"
 
-const char cgit_version[] = CGIT_VERSION;
-
-
 static int cgit_prepare_cache(struct cacheitem *item)
 {
 	if (!cgit_repo && cgit_query_repo) {




diff --git a/cgit.h b/cgit.h
index bd2dd0d652a9e881cee0227818d46fe928fccba7..95583620d966cee311dfd620fc481b1763856894 100644
--- a/cgit.h
+++ b/cgit.h
@@ -98,7 +98,7 @@ 	int tagger_date;
 	char *msg;
 };
 
-extern const char cgit_version[];
+extern const char *cgit_version;
 
 extern struct repolist cgit_repolist;
 extern struct repoinfo *cgit_repo;




diff --git a/gen-version.sh b/gen-version.sh
new file mode 100755
index 0000000000000000000000000000000000000000..4c60f60758428c59aaf3a1f577ac59378261b8ab
--- /dev/null
+++ b/gen-version.sh
@@ -0,0 +1,4 @@
+v=$(git-describe --abbrev=4 HEAD | sed -e 's/-/./g')
+test -z "$v" && exit 1
+echo "CGIT_VERSION = $v"
+echo "CGIT_VERSION = $v" > VERSION




diff --git a/shared.c b/shared.c
index f20fb5cc423f5ab184a730a2f5e2c1bb5b4b066a..f7f43b2e8e083d4c7ba5c15fc8b5d4e36e8d2819 100644
--- a/shared.c
+++ b/shared.c
@@ -12,6 +12,8 @@ struct repolist cgit_repolist;
 struct repoinfo *cgit_repo;
 int cgit_cmd;
 
+const char *cgit_version = CGIT_VERSION;
+
 char *cgit_root_title   = "Git repository browser";
 char *cgit_css          = "/cgit.css";
 char *cgit_logo         = "/git-logo.png";




diff --git a/ui-shared.c b/ui-shared.c
index 15d825460f6d604441c0f3746e7ffa478af18cd7..110c6966877d05967c21093a32845f35efd9f9ca 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -262,7 +262,7 @@ 	html("\n");
 	html("<title>");
 	html_txt(title);
 	html("</title>\n");
-	htmlf("<meta name='generator' content='cgit v%s'/>\n", cgit_version);
+	htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
 	html("<link rel='stylesheet' type='text/css' href='");
 	html_attr(cgit_css);
 	html("'/>\n");