[RFC] Relocate repos when using scan-path

John Keeping john at keeping.me.uk
Sat May 18 18:06:37 CEST 2013


On Sat, May 18, 2013 at 05:46:35PM +0200, Jason A. Donenfeld wrote:
> On Sat, May 18, 2013 at 5:27 PM, Florian Pritz <bluewind at xinu.at> wrote:
> > The point is that I want to keep already cloned repositories (as in "git
> > clone git://foo" via git-daemon) working and mod_rewrite won't help with
> > that even though it would probably work fine with the http clones.
> 
> Make a directory elsewhere on the file system.
> Symlink everything you need into it.
> Point git-daemon at that.

That might still break SSH; for a proper solution I think we need
something like this (untested).

It might be good to force USE_WILDCARD=YesPlease in the makefile on top
of this patch, which will replace fnmatch with Git's wildmatch, adding
support for "**" to match any number of directory levels.

-- >8 --
Subject: [PATCH] Add scan-exclude option to filter out repositories

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 cgit.c       |  4 ++++
 cgit.h       |  1 +
 cgitrc.5.txt |  7 +++++++
 scan-tree.c  | 15 +++++++++++++++
 4 files changed, 27 insertions(+)

diff --git a/cgit.c b/cgit.c
index 6f44ef2..c621439 100644
--- a/cgit.c
+++ b/cgit.c
@@ -229,6 +229,8 @@ static void config_cb(const char *name, const char *value)
 		ctx.cfg.max_commit_count = atoi(value);
 	else if (!strcmp(name, "project-list"))
 		ctx.cfg.project_list = xstrdup(expand_macros(value));
+	else if (!strcmp(name, "scan-exclude"))
+		string_list_append(&ctx.cfg.scan_exclude, expand_macros(value));
 	else if (!strcmp(name, "scan-path"))
 		if (!ctx.cfg.nocache && ctx.cfg.cache_size)
 			process_cached_repolist(expand_macros(value));
@@ -405,6 +407,8 @@ static void prepare_context(struct cgit_context *ctx)
 	ctx->page.expires = ctx->page.modified;
 	ctx->page.etag = NULL;
 	memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list));
+	memset(&ctx->cfg.scan_exclude, 0, sizeof(struct string_list));
+	ctx->cfg.scan_exclude.strdup_strings = 1;
 	if (ctx->env.script_name)
 		ctx->cfg.script_name = xstrdup(ctx->env.script_name);
 	if (ctx->env.query_string)
diff --git a/cgit.h b/cgit.h
index 850b792..ee6a545 100644
--- a/cgit.h
+++ b/cgit.h
@@ -238,6 +238,7 @@ struct cgit_config {
 	int branch_sort;
 	int commit_sort;
 	struct string_list mimetypes;
+	struct string_list scan_exclude;
 	struct cgit_filter *about_filter;
 	struct cgit_filter *commit_filter;
 	struct cgit_filter *source_filter;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 9b803b3..71db425 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -329,6 +329,13 @@ root-title::
 	Text printed as heading on the repository index page. Default value:
 	"Git Repository Browser".
 
+scan-exclude::
+	Specified a pattern to be used to exclude repositories found by
+	"scan-path". This option may be specified more than once, with each
+	pattern being compared to discovered repositories with fnmatch(3).
+	Any matches will cause the repository to be omitted from CGit's index.
+	This must be defined prior to scan-path. See also: scan-path.
+
 scan-hidden-path::
 	If set to "1" and scan-path is enabled, scan-path will recurse into
 	directories whose name starts with a period ('.'). Otherwise,
diff --git a/scan-tree.c b/scan-tree.c
index a1ec8fb..6ab49e5 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -75,6 +75,18 @@ static char *xstrrchr(char *s, char *from, int c)
 	return from < s ? NULL : from;
 }
 
+static int exclude_repo(const char *path)
+{
+	int i;
+	struct string_list *exclude = &ctx.cfg.scan_exclude;
+
+	for (i = 0; i < exclude->nr; i++)
+		if (!fnmatch(exclude->items[i].string, path, FNM_PATHNAME))
+			return 1;
+
+	return 0;
+}
+
 static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
 {
 	struct stat st;
@@ -91,6 +103,9 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
 		return;
 	}
 
+	if (exclude_repo(path->buf))
+		return;
+
 	strbuf_addch(path, '/');
 	pathlen = path->len;
 
-- 
1.8.3.rc2.285.gfc18c2c



More information about the CGit mailing list