List for cgit developers and users
 help / color / mirror / Atom feed
Subject: [PATCH 1/2] Read "cgit.*" settings from gitconfig.
Date: Sun,  7 Oct 2012 23:23:46 +0200	[thread overview]
Message-ID: <1349645027-22007-2-git-send-email-necoro@necoro.net> (raw)
In-Reply-To: <1349645027-22007-1-git-send-email-necoro@necoro.net>

Allow to override cgit settings directly using git config -- this
is especially useful for gitolite, as it works without having to export
multiple options by hand.

The gitconfig section is "cgit", in contrast to the normal "repo" key used
throughout normal cgit. This is to avoid possible future name clashes.

Patch based on: http://hjemli.net/pipermail/cgit/2011-November/000428.html
---
 cgit.c      |    3 +++
 cgit.h      |    1 +
 scan-tree.c |   19 +++++++++++++++----
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/cgit.c b/cgit.c
index 1ec02e7..910bf1d 100644
--- a/cgit.c
+++ b/cgit.c
@@ -183,6 +183,8 @@ void config_cb(const char *name, const char *value)
 		ctx.cfg.enable_subject_links = atoi(value);
 	else if (!strcmp(name, "enable-tree-linenumbers"))
 		ctx.cfg.enable_tree_linenumbers = atoi(value);
+	else if (!strcmp(name, "enable-git-config"))
+		ctx.cfg.enable_git_config = atoi(value);
 	else if (!strcmp(name, "max-stats"))
 		ctx.cfg.max_stats = cgit_find_stats_period(value, NULL);
 	else if (!strcmp(name, "cache-size"))
@@ -348,6 +350,7 @@ static void prepare_context(struct cgit_context *ctx)
 	ctx->cfg.enable_gitweb_section = 1;
 	ctx->cfg.enable_http_clone = 1;
 	ctx->cfg.enable_tree_linenumbers = 1;
+	ctx->cfg.enable_git_config = 0;
 	ctx->cfg.max_repo_count = 50;
 	ctx->cfg.max_commit_count = 50;
 	ctx->cfg.max_lock_attempts = 5;
diff --git a/cgit.h b/cgit.h
index 79ba7ad..4ac6f80 100644
--- a/cgit.h
+++ b/cgit.h
@@ -211,6 +211,7 @@ struct cgit_config {
 	int enable_remote_branches;
 	int enable_subject_links;
 	int enable_tree_linenumbers;
+	int enable_git_config;
 	int local_time;
 	int max_atom_items;
 	int max_repo_count;
diff --git a/scan-tree.c b/scan-tree.c
index 6d1941e..7e711d5 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -67,7 +67,14 @@ static int gitweb_config(const char *key, const char *value, void *cb)
 	return 0;
 }
 
+static int cgit_repo_config(const char *key, const char *value, void *cb)
+{
+	if (!prefixcmp(key, "cgit.")) {
+		config_fn(repo, key + 5, value);
+	}
 
+	return 0;
+}
 
 static char *xstrrchr(char *s, char *from, int c)
 {
@@ -166,10 +173,14 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
 		}
 	}
 
-	p = fmt("%s/cgitrc", path);
-	if (!stat(p, &st)) {
-		config_fn = fn;
-		parse_configfile(xstrdup(p), &repo_config);
+	config_fn = fn;
+	if (ctx.cfg.enable_git_config) {
+		git_config_from_file(cgit_repo_config, fmt("%s/config", path), NULL);
+	} else {
+		p = fmt("%s/cgitrc", path);
+		if (!stat(p, &st)) {
+			parse_configfile(xstrdup(p), &repo_config);
+		}
 	}
 
 	free(rel);
-- 
1.7.8.6





  reply	other threads:[~2012-10-07 21:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-07 21:23 [PATCH 0/2] Git-Config Parsing during scan-path 
2012-10-07 21:23 `  [this message]
2012-10-08 15:14   ` [PATCH 1/2] Read "cgit.*" settings from gitconfig jamie.couture
2012-10-08 15:19     ` Jason
2012-10-08 15:24       ` 
2012-10-08 15:25         ` Jason
2012-10-07 21:23 ` [PATCH 2/2] Documentation for the gitconfig sourcing 
2012-10-08 21:27 ` [PATCH 0/2] Git-Config Parsing during scan-path Jason
2012-10-09  9:30   ` 
2012-10-09 11:40     ` Jason
2012-10-09 12:07       ` 
2012-10-09 12:22         ` Jason
2012-10-09 11:02   ` jamie.couture

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=1349645027-22007-2-git-send-email-necoro@necoro.net \
    --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).