List for cgit developers and users
 help / color / mirror / Atom feed
From: john at keeping.me.uk (John Keeping)
Subject: [RFC] Relocate repos when using scan-path
Date: Sat, 18 May 2013 17:06:37 +0100	[thread overview]
Message-ID: <20130518160636.GE27005@serenity.lan> (raw)
In-Reply-To: <CAHmME9poL0rYs7exUHbRTwUqcP-sUN7WD2fVDL5nGWE3jgpmZw@mail.gmail.com>

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



  reply	other threads:[~2013-05-18 16:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-13 13:56 bluewind
2013-05-18 15:10 ` john
2013-05-18 15:25   ` Jason
2013-05-18 15:27   ` bluewind
2013-05-18 15:46     ` Jason
2013-05-18 16:06       ` john [this message]
2013-05-18 16:20         ` Jason
2013-05-18 16:48           ` john
2013-05-19 11:54         ` bluewind

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130518160636.GE27005@serenity.lan \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).