]> oss.titaniummirror.com Git - repo_shell.git/commitdiff
Add version option, derived from repository tags 0.1
authorR. Steve McKown <rsmckown@gmail.com>
Mon, 24 Sep 2012 01:26:45 +0000 (19:26 -0600)
committerR. Steve McKown <rsmckown@gmail.com>
Mon, 24 Sep 2012 01:26:45 +0000 (19:26 -0600)
.gitignore
Makefile
mkversion.mk [new file with mode: 0644]
repo_shell.c
version.c.in [new file with mode: 0644]
version.h [new file with mode: 0644]

index baba52a44c01572a0949f279db7f65e3aa398bea..f4255f98bebedef006fb6d5eb1430a20e9166903 100644 (file)
@@ -1,3 +1,4 @@
 repo_shell
+version.c
 *.swp
 .svn
index b2e6998fc5fc9da221370c8bea799fddd51340df..dc3b5f843748e741739279838a459b6c8717e6f5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,2 +1,24 @@
-repo_shell: repo_shell.c inih/ini.c
+PROGRAM := repo_shell
+# Git derives its version "prefix" from tags
+
+# Add TMI's mkversion to render files xxx.in -> xxx, updating __appVersion__
+# Massage the version coming back because setup.py build to exe only wants
+# versions of the form a.b.c.d.  We'll use this to our advantage to cause
+# setup.py to error if the VERSION is either dirty, or if git, not a tag.
+include mkversion.mk
+#$(warning VERSION $(VERSION))
+INFILES := $(shell ls *.in 2>/dev/null)
+INFILES := $(INFILES:%.in=%)
+#$(warning INFILES $(INFILES))
+
+repo_shell: repo_shell.c inih/ini.c version.c
        $(CC) -I inih $^ -o $@
+
+$(INFILES):%: %.in
+       @sed -e 's|__appVersion__|$(VERSION)|g' < $^ > $@-tmp
+       @diff -q $@-tmp $@ >/dev/null 2>&1 && rm -f $@-tmp || mv $@-tmp $@
+
+clean:
+       @rm -rf $(PROGRAM) $(INFILES)
+
+.PHONY: all clean $(INFILES)
diff --git a/mkversion.mk b/mkversion.mk
new file mode 100644 (file)
index 0000000..0a4f124
--- /dev/null
@@ -0,0 +1,55 @@
+# mkversion.mk
+#
+# Determine the repository checkout id.  Assume that there are no local
+# changes in the workspace.  Support svn, git svn, and git.
+#
+# Usage example:
+#
+# VERSION_FILE := "version.h"
+# $(VERSION_FILE):%.h: %.in
+#      sed -e 's|__appVersion__|$(VERSION)|g' < $^ > $@
+#
+# Contents of version.h:
+#
+# #ifndef VERSION_H
+# #define VERSION_H
+#
+# #define VERSION      "__appVersion__"
+#
+# #endif
+
+ifeq (.svn,$(shell ls -d .svn 2>/dev/null))
+    VERSION := $(shell svnversion . 2>/dev/null | sed -e 's|M$$|-dirty|')
+    ifneq (,$(VERSION))
+       VERSION := r$(VERSION)
+    endif
+    VERFROM := svn
+endif
+ifeq (.git,$(shell ls -d .git))
+    VERSION := $(shell git svn info 2>/dev/null | grep "Revision: " | \
+           sed -e s'/^[^0-9]*\([0-9]*\).*$$/r\1/')
+    ifneq (,$(VERSION))
+       # git-svn
+       ifeq (,$(shell git log -n1 2>/dev/null | grep "git-svn-id: "))
+           VERSION := $(VERSION)-dirty
+       else
+           ifneq (,$(shell git diff-index --name-only HEAD 2>/dev/null))
+               VERSION := $(VERSION)-dirty
+           endif
+       endif
+       VERFROM := svn
+    else
+       # git
+       VERSION := $(shell git describe --tags --always 2>/dev/null)
+       ifneq (,$(VERSION))
+           ifneq (,$(shell git diff-index --name-only HEAD 2>/dev/null))
+               VERSION := $(VERSION)-dirty
+           endif
+       endif
+       VERFROM := git
+    endif
+endif
+ifeq (,$(VERSION))
+    VERSION := unknown
+endif
+#$(warning VERSION $(VERSION))
index e11bf5403f105366544085cfbc71aa18b8dbe42b..b51c0add25039ca49e31b232a50a9f3add431fa8 100644 (file)
@@ -8,6 +8,7 @@
 #include <pwd.h>
 #include <string.h>
 #include "ini.h"
+#include "version.h"
 
 #define CFG_FILE "/etc/repo_shell.cfg"
 #define GIT_ACL_FILE "git_acl.cfg"
@@ -164,8 +165,8 @@ static int git_acl(const char *user, const char *repo)
        len = strlen(pw->pw_dir) + strlen(GIT_ACL_FILE) + 2;
        file = xmalloc(sizeof(char) * len);
        sprintf(file, "%s/%s", pw->pw_dir, GIT_ACL_FILE);
-        fprintf(stderr, "[someday check %s]\n", file);
-        free(file);
+       fprintf(stderr, "[someday check %s]\n", file);
+       free(file);
        return 2; /* assume read/write for now */
 }
 
@@ -303,7 +304,7 @@ static struct commands {
 };
 
 static int handler(void* user, const char* section, const char* name,
-                   const char* value)
+               const char* value)
 {
        cfg_t* pconfig = (cfg_t*)user;
 
@@ -339,6 +340,11 @@ int main(int argc, char **argv)
                die("opening /dev/null failed");
        close (devnull_fd);
 
+       if (argc == 2 && (!strcmp(argv[1], "-v") ||
+                       !strcmp(argv[1], "--version"))) {
+               fprintf(stderr, "%s\n", version);
+               return 0;
+        }
        if (argc < 3)
                die("invalid arguments");
 
diff --git a/version.c.in b/version.c.in
new file mode 100644 (file)
index 0000000..c38856b
--- /dev/null
@@ -0,0 +1 @@
+const char version[] = "__appVersion__";
diff --git a/version.h b/version.h
new file mode 100644 (file)
index 0000000..f22f7cf
--- /dev/null
+++ b/version.h
@@ -0,0 +1,6 @@
+#ifndef VERSION_H
+#define VERSION_H
+
+extern const char version[];
+
+#endif /* end of include guard: VERSION_H */