repo_shell
+version.c
*.swp
.svn
-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)
--- /dev/null
+# 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))
#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"
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 */
}
};
static int handler(void* user, const char* section, const char* name,
- const char* value)
+ const char* value)
{
cfg_t* pconfig = (cfg_t*)user;
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");
--- /dev/null
+const char version[] = "__appVersion__";
--- /dev/null
+#ifndef VERSION_H
+#define VERSION_H
+
+extern const char version[];
+
+#endif /* end of include guard: VERSION_H */