cgit

commit db8b8cb9467625cb8d9ecb67863aa67590e59cc0

Author: Lars Hjemli <hjemli@gmail.com>

Merge branch 'lh/about'

Conflicts:
	cgit.h

 cgit.c | 4 ++++
 cgit.h | 2 ++
 cgitrc.5.txt | 10 ++++++++++
 cmd.c | 2 +-
 shared.c | 1 +
 ui-repolist.c | 9 +++++++--
 ui-summary.c | 28 ++++++++++++++++++++++------
 ui-summary.h | 2 +-


diff --git a/cgit.c b/cgit.c
index dbec1962763145d3c88f89b3ba947dd9ca11bbd5..7b228af83046faef92602b0a74a6e1e6e58fea47 100644
--- a/cgit.c
+++ b/cgit.c
@@ -100,6 +100,8 @@ 	else if (!strcmp(name, "cache-static-ttl"))
 		ctx.cfg.cache_static_ttl = atoi(value);
 	else if (!strcmp(name, "cache-dynamic-ttl"))
 		ctx.cfg.cache_dynamic_ttl = atoi(value);
+	else if (!strcmp(name, "about-filter"))
+		ctx.cfg.about_filter = new_filter(value, 0);
 	else if (!strcmp(name, "commit-filter"))
 		ctx.cfg.commit_filter = new_filter(value, 0);
 	else if (!strcmp(name, "embedded"))
@@ -158,6 +160,8 @@ 	else if (ctx.repo && !strcmp(name, "repo.max-stats"))
 		ctx.repo->max_stats = cgit_find_stats_period(value, NULL);
 	else if (ctx.repo && !strcmp(name, "repo.module-link"))
 		ctx.repo->module_link= xstrdup(value);
+	else if (ctx.repo && !strcmp(name, "repo.about-filter"))
+		ctx.repo->about_filter = new_filter(value, 0);
 	else if (ctx.repo && !strcmp(name, "repo.commit-filter"))
 		ctx.repo->commit_filter = new_filter(value, 0);
 	else if (ctx.repo && !strcmp(name, "repo.source-filter"))




diff --git a/cgit.h b/cgit.h
index b8557ace3912b4b62c59eb709fc37dea2f1f506c..4c854eaa8320771466460f18ff0839c73cc2dafc 100644
--- a/cgit.h
+++ b/cgit.h
@@ -74,6 +74,7 @@ 	int enable_log_filecount;
 	int enable_log_linecount;
 	int max_stats;
 	time_t mtime;
+	struct cgit_filter *about_filter;
 	struct cgit_filter *commit_filter;
 	struct cgit_filter *source_filter;
 };
@@ -188,6 +189,7 @@ 	int summary_branches;
 	int summary_log;
 	int summary_tags;
 	struct string_list mimetypes;
+	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 dc63637b4bb7b17f9a5aeb7088e94db343189d72..4d656fee5323fb35f0846ec086d7dfbd016d21c3 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -16,6 +16,13 @@
 
 GLOBAL SETTINGS
 ---------------
+about-filter::
+	Specifies a command which will be invoked to format the content of
+	about pages (both top-level and for each repository). The command will
+	get the content of the about-file on its STDIN, and the STDOUT from the
+	command will be included verbatim on the about page. Default value:
+	none.
+
 agefile::
 	Specifies a path, relative to each repository path, which can be used
 	to specify the date and time of the youngest commit in the repository.
@@ -242,6 +249,9 @@ 	same kind of virtual urls, so this option will probably be deprecated.
 
 REPOSITORY SETTINGS
 -------------------
+repo.about-filter::
+	Override the default about-filter. Default value: <about-filter>.
+
 repo.clone-url::
 	A list of space-separated urls which can be used to clone this repo.
 	Default value: none.




diff --git a/cmd.c b/cmd.c
index cf97da75a17f733b0627066921dbabf424165a6c..766f90397b89d2407574f3e2bf7056df68b43add 100644
--- a/cmd.c
+++ b/cmd.c
@@ -39,7 +39,7 @@
 static void about_fn(struct cgit_context *ctx)
 {
 	if (ctx->repo)
-		cgit_print_repo_readme();
+		cgit_print_repo_readme(ctx->qry.path);
 	else
 		cgit_print_site_readme();
 }




diff --git a/shared.c b/shared.c
index 783604beba81510f4e155c6de8edced39c8ac3df..911a55a9a4476482b6333bd82d9abb515787021c 100644
--- a/shared.c
+++ b/shared.c
@@ -62,6 +62,7 @@ 	ret->max_stats = ctx.cfg.max_stats;
 	ret->module_link = ctx.cfg.module_link;
 	ret->readme = NULL;
 	ret->mtime = -1;
+	ret->about_filter = ctx.cfg.about_filter;
 	ret->commit_filter = ctx.cfg.commit_filter;
 	ret->source_filter = ctx.cfg.source_filter;
 	return ret;




diff --git a/ui-repolist.c b/ui-repolist.c
index 2c13d5041b2a4931358b241b6316db3d96a9a6b5..25f076fd3198cac33bca32dcceea423e4d9af30c 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -273,6 +273,11 @@ }
 
 void cgit_print_site_readme()
 {
-	if (ctx.cfg.root_readme)
-		html_include(ctx.cfg.root_readme);
+	if (!ctx.cfg.root_readme)
+		return;
+	if (ctx.cfg.about_filter)
+		cgit_open_filter(ctx.cfg.about_filter);
+	html_include(ctx.cfg.root_readme);
+	if (ctx.cfg.about_filter)
+		cgit_close_filter(ctx.cfg.about_filter);
 }




diff --git a/ui-summary.c b/ui-summary.c
index ede4a629765e4d58314d6c78e408159ef3dfddab..a2c018e3087b8b70866a55f2de4a110a81dddc90 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -66,11 +66,27 @@ 		print_urls(ctx.cfg.clone_prefix, ctx.repo->url);
 	html("</table>");
 }
 
-void cgit_print_repo_readme()
+void cgit_print_repo_readme(char *path)
 {
-	if (ctx.repo->readme) {
-		html("<div id='summary'>");
-		html_include(ctx.repo->readme);
-		html("</div>");
-	}
+	char *slash, *tmp;
+
+	if (!ctx.repo->readme)
+		return;
+
+	if (path) {
+		slash = strrchr(ctx.repo->readme, '/');
+		if (!slash)
+			return;
+		tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1);
+		strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1);
+		strcpy(tmp + (slash - ctx.repo->readme + 1), path);
+	} else
+		tmp = ctx.repo->readme;
+	html("<div id='summary'>");
+	if (ctx.repo->about_filter)
+		cgit_open_filter(ctx.repo->about_filter);
+	html_include(tmp);
+	if (ctx.repo->about_filter)
+		cgit_close_filter(ctx.repo->about_filter);
+	html("</div>");
 }




diff --git a/ui-summary.h b/ui-summary.h
index 3e130394915d6b7d77785a311fab4f528bd0ed9b..c01f56012dcdcd64f39f6935c20eb5d18efb1b33 100644
--- a/ui-summary.h
+++ b/ui-summary.h
@@ -2,6 +2,6 @@ #ifndef UI_SUMMARY_H
 #define UI_SUMMARY_H
 
 extern void cgit_print_summary();
-extern void cgit_print_repo_readme();
+extern void cgit_print_repo_readme(char *path);
 
 #endif /* UI_SUMMARY_H */