[PATCH 2/2] Add feature: obtain repo section from git config

Jamie Couture jamie.couture at gmail.com
Sat Jun 4 01:21:02 CEST 2011


From: Jamie Couture <jamie.couture at gmail.com>

---
 cgit.c       |    2 ++
 cgit.h       |    1 +
 cgitrc.5.txt |    8 ++++++++
 scan-tree.c  |   10 ++++++++++
 4 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/cgit.c b/cgit.c
index f4dd6ef..6a51bec 100644
--- a/cgit.c
+++ b/cgit.c
@@ -207,6 +207,8 @@ void config_cb(const char *name, const char *value)
 		ctx.cfg.scan_hidden_path = atoi(value);
 	else if (!strcmp(name, "section-from-path"))
 		ctx.cfg.section_from_path = atoi(value);
+	else if (!strcmp(name, "section-from-repo-config"))
+		ctx.cfg.section_from_repo_config = atoi(value);
 	else if (!strcmp(name, "source-filter"))
 		ctx.cfg.source_filter = new_filter(value, 1);
 	else if (!strcmp(name, "summary-log"))
diff --git a/cgit.h b/cgit.h
index b5f00fc..14e8243 100644
--- a/cgit.h
+++ b/cgit.h
@@ -214,6 +214,7 @@ struct cgit_config {
 	int remove_suffix;
 	int scan_hidden_path;
 	int section_from_path;
+	int section_from_repo_config;
 	int snapshots;
 	int summary_branches;
 	int summary_log;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index c3698a6..a78d226 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -301,6 +301,14 @@ section-from-path::
 	If negative, cgit will discard the specified number of path elements
 	above the repo directory. Default value: 0.
 
+section-from-repo-config::
+	If set to "1" obtain the section name from git config. The expected config
+	section.key that is used is "cgit.section".
+	Ex: $ git config cgit.section mysection
+	An alternative to section-from-path, and will not check git config if
+	section-from-path is set. See also: scan-path.  This must be defined prior
+	to scan-path.
+
 side-by-side-diffs::
 	If set to "1" shows side-by-side diffs instead of unidiffs per
 	default. Default value: "0".
diff --git a/scan-tree.c b/scan-tree.c
index 3f579ec..3bbc4bc 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -61,6 +61,13 @@ static int git_owner_config(const char *key, const char *value, void *cb)
 	return 0;
 }
 
+static int git_section_config(const char *key, const char *value, void *cb)
+{
+	if (!strcmp(key, "cgit.section"))
+		repo->section = xstrdup(value);
+	return 0;
+}
+
 static char *xstrrchr(char *s, char *from, int c)
 {
 	while (from >= s && *from != c)
@@ -149,6 +156,9 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
 			}
 		}
 	}
+	else if (ctx.cfg.section_from_repo_config) {
+		git_config_from_file(git_section_config, fmt("%s/config", path), NULL);
+	}
 
 	p = fmt("%s/cgitrc", path);
 	if (!stat(p, &st)) {
-- 
1.7.5.4





More information about the CGit mailing list