[PATCH] tag-pattern support for tag filtering in summary

Will Saxon will.saxon at viterahealthcare.com
Wed Nov 28 20:50:55 CET 2012


We make heavy use of tags in our repositories, to assist with cross-repo
build tracking and to aid integration with 3rd-party applications. An
unfortunate side effect of this is that the summary and log pages for a
repo in cgit can become very wide due to the number of tags displayed.
Since many of the tags are not helpful to a user viewing the repo in
cgit, we whitelist only the ones we want to see, by pattern.

cgit.h: Added a tag_patterns string_list to cgit_config.

cgit.c: Added a new configuration option, tag_pattern. This is intended
to be a list of tag prefixes to use with prefixcmp().

ui-log.c: When displaying a tag, look through the tag_patterns. Only
display tags matching a pattern.
---
 cgit.c   |   10 ++++++++++
 cgit.h   |    1 +
 ui-log.c |   14 ++++++++++++--
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/cgit.c b/cgit.c
index a97ed69..e80ee24 100644
--- a/cgit.c
+++ b/cgit.c
@@ -26,6 +26,14 @@ void add_mimetype(const char *name, const char *value)
 	item->util = xstrdup(value);
 }
 
+void add_tag_pattern(const char *name, const char *value)
+{
+	struct string_list_item *item;
+
+	item = string_list_insert(&ctx.cfg.tag_patterns, xstrdup(name));
+	item->util = xstrdup(value);
+}
+
 struct cgit_filter *new_filter(const char *cmd, filter_type filtertype)
 {
 	struct cgit_filter *f;
@@ -275,6 +283,8 @@ void config_cb(const char *name, const char *value)
 		add_mimetype(name + 9, value);
 	else if (!strcmp(name, "include"))
 		parse_configfile(expand_macros(value), config_cb);
+	else if (!prefixcmp(name, "tag_pattern."))
+		add_tag_pattern(name + 12, value);
 }
 
 static void querystring_cb(const char *name, const char *value)
diff --git a/cgit.h b/cgit.h
index 7a99135..8693834 100644
--- a/cgit.h
+++ b/cgit.h
@@ -234,6 +234,7 @@ struct cgit_config {
 	int ssdiff;
 	int commit_sort;
 	struct string_list mimetypes;
+	struct string_list tag_patterns;
 	struct cgit_filter *about_filter;
 	struct cgit_filter *commit_filter;
 	struct cgit_filter *source_filter;
diff --git a/ui-log.c b/ui-log.c
index 2f41602..9b624dc 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -57,6 +57,8 @@ void show_commit_decorations(struct commit *commit)
 {
 	struct name_decoration *deco;
 	static char buf[1024];
+	static char tagPattern[1024];
+	int i;
 
 	buf[sizeof(buf) - 1] = 0;
 	deco = lookup_decoration(&name_decoration, &commit->object);
@@ -72,8 +74,16 @@ void show_commit_decorations(struct commit *commit)
 			cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
 		}
 		else if (!prefixcmp(deco->name, "refs/tags/")) {
-			strncpy(buf, deco->name + 10, sizeof(buf) - 1);
-			cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
+			for (i=0; i < ctx.cfg.tag_patterns.nr; i++) {
+				memset(tagPattern,0,sizeof tagPattern);
+				strncat(tagPattern,"refs/tags/",10);
+				strncat(tagPattern,ctx.cfg.tag_patterns.items[i].util,sizeof(tagPattern)-1);
+				if (!prefixcmp(deco->name, tagPattern)) {
+					strncpy(buf, deco->name + 10, sizeof(buf) - 1);
+					cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
+					break;
+				}
+			}
 		}
 		else if (!prefixcmp(deco->name, "refs/remotes/")) {
 			if (!ctx.repo->enable_remote_branches)
-- 
1.7.9





More information about the CGit mailing list