List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH] filter: add support for owner-filter
@ 2014-08-01 17:54 chris.burroughs
  2014-08-01 18:18 ` john
  0 siblings, 1 reply; 8+ messages in thread
From: chris.burroughs @ 2014-08-01 17:54 UTC (permalink / raw)


Followup and attempt at implementation of an owner filter as described
in http://lists.zx2c4.com/pipermail/cgit/2014-July/002163.html.  There
are two parts I am unsure of:
 * Is there an advantage (performance?) to passing the owner as an
   argument instead of using CGIT_REPO_OWNER?
 * I passed along the cgit_rooturl so that a filter could re-implement
   what the C code is doing.  This seemed a good test of if the filter
   was flexible enough, but passing it along as an argument feels a
   bit wonky.  Maybe this would be better as an environmental variable
   to all filters?

---
 cgit.c                    |    6 ++++++
 cgit.h                    |    4 +++-
 cgitrc.5.txt              |   18 ++++++++++++++++++
 filter.c                  |    6 ++++++
 filters/owner-example.lua |   24 ++++++++++++++++++++++++
 shared.c                  |    1 +
 ui-repolist.c             |    2 ++
 7 files changed, 60 insertions(+), 1 deletion(-)
 create mode 100644 filters/owner-example.lua

diff --git a/cgit.c b/cgit.c
index 20f6e27..d29e7f5 100644
--- a/cgit.c
+++ b/cgit.c
@@ -91,6 +91,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
 			repo->source_filter = cgit_new_filter(value, SOURCE);
 		else if (!strcmp(name, "email-filter"))
 			repo->email_filter = cgit_new_filter(value, EMAIL);
+		else if (!strcmp(name, "owner-filter"))
+			repo->owner_filter = cgit_new_filter(value, OWNER);
 	}
 }
 
@@ -194,6 +196,8 @@ static void config_cb(const char *name, const char *value)
 		ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT);
 	else if (!strcmp(name, "email-filter"))
 		ctx.cfg.email_filter = cgit_new_filter(value, EMAIL);
+	else if (!strcmp(name, "owner-filter"))
+		ctx.cfg.owner_filter = cgit_new_filter(value, OWNER);
 	else if (!strcmp(name, "auth-filter"))
 		ctx.cfg.auth_filter = cgit_new_filter(value, AUTH);
 	else if (!strcmp(name, "embedded"))
@@ -802,6 +806,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
 		cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter=");
 	if (repo->email_filter && repo->email_filter != ctx.cfg.email_filter)
 		cgit_fprintf_filter(repo->email_filter, f, "repo.email-filter=");
+	if (repo->owner_filter && repo->owner_filter != ctx.cfg.owner_filter)
+		cgit_fprintf_filter(repo->owner_filter, f, "repo.owner-filter=");
 	if (repo->snapshots != ctx.cfg.snapshots) {
 		char *tmp = build_snapshot_setting(repo->snapshots);
 		fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
diff --git a/cgit.h b/cgit.h
index 0badc64..0078ac1 100644
--- a/cgit.h
+++ b/cgit.h
@@ -53,7 +53,7 @@ typedef void (*filepair_fn)(struct diff_filepair *pair);
 typedef void (*linediff_fn)(char *line, int len);
 
 typedef enum {
-	ABOUT, COMMIT, SOURCE, EMAIL, AUTH
+	ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
 } filter_type;
 
 struct cgit_filter {
@@ -100,6 +100,7 @@ struct cgit_repo {
 	struct cgit_filter *commit_filter;
 	struct cgit_filter *source_filter;
 	struct cgit_filter *email_filter;
+	struct cgit_filter *owner_filter;
 	struct string_list submodules;
 };
 
@@ -253,6 +254,7 @@ struct cgit_config {
 	struct cgit_filter *commit_filter;
 	struct cgit_filter *source_filter;
 	struct cgit_filter *email_filter;
+	struct cgit_filter *owner_filter;
 	struct cgit_filter *auth_filter;
 };
 
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index b7570db..7ed2c80 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -247,6 +247,14 @@ logo-link::
 	calculated url of the repository index page will be used. Default
 	value: none.
 
+owner-filter::
+	Specifies a command which will be invoked to format the Owner column
+	of the main page.  The command will get the default html on its STDIN,
+	and the STDOUT from the command will be included verbatim in the
+	table.  This can be used to link to additional context such as an
+	owners home page. Default value: none.
+	See also: "FILTER API".
+
 max-atom-items::
 	Specifies the number of items to display in atom feeds view. Default
 	value: "10".
@@ -509,6 +517,10 @@ repo.logo-link::
 	calculated url of the repository index page will be used. Default
 	value: global logo-link.
 
+repo.owner-filter::
+	Override the default owner-filter. Default value: none. See also:
+	"enable-filter-overrides". See also: "FILTER API".
+
 repo.module-link::
 	Text which will be used as the formatstring for a hyperlink when a
 	submodule is printed in a directory listing. The arguments for the
@@ -641,6 +653,12 @@ email filter::
 	expected to write to standard output the formatted text to be included
 	in the page.
 
+owner filter::
+	This filter is given two parameters: the repository owner and the cgit
+	root url.  The filter will then receive the default html to argument
+	on standard input and is expected to write to standard output the
+	formatted text to be included in the column.
+
 source filter::
 	This filter is given a single parameter: the filename of the source
 	file to filter. The filter can use the filename to determine (for
diff --git a/filter.c b/filter.c
index 270f009..35502b5 100644
--- a/filter.c
+++ b/filter.c
@@ -38,12 +38,14 @@ void cgit_cleanup_filters(void)
 	reap_filter(ctx.cfg.commit_filter);
 	reap_filter(ctx.cfg.source_filter);
 	reap_filter(ctx.cfg.email_filter);
+	reap_filter(ctx.cfg.owner_filter);
 	reap_filter(ctx.cfg.auth_filter);
 	for (i = 0; i < cgit_repolist.count; ++i) {
 		reap_filter(cgit_repolist.repos[i].about_filter);
 		reap_filter(cgit_repolist.repos[i].commit_filter);
 		reap_filter(cgit_repolist.repos[i].source_filter);
 		reap_filter(cgit_repolist.repos[i].email_filter);
+		reap_filter(cgit_repolist.repos[i].owner_filter);
 	}
 }
 
@@ -425,6 +427,10 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
 			argument_count = 2;
 			break;
 
+		case OWNER:
+			argument_count = 2;
+			break;
+
 		case SOURCE:
 		case ABOUT:
 			argument_count = 1;
diff --git a/filters/owner-example.lua b/filters/owner-example.lua
new file mode 100644
index 0000000..79b1d49
--- /dev/null
+++ b/filters/owner-example.lua
@@ -0,0 +1,24 @@
+-- This script is an example of an owner-filter.  It adds an
+-- additional link to a fictional home page.  This script may be used
+-- with the owner-filter or repo.owner-filter settings in cgitrc with
+-- the `lua:` prefix.  `cgit_root_url` is provided so that it's
+-- possible to replicate the default behavior with a filter instead of
+-- echoing the buffer.
+--
+
+function filter_open(cgit_repo_owner, cgit_root_url)
+   buffer = ""
+   owner = cgit_repo_owner
+   root_url = cgit_root_url
+end
+
+function filter_close()
+   html(buffer)
+   html(string.format(" <a href=\"%s\">%s</a>", "http://wiki.example.com/about/" .. owner, "Home"))
+   return 0
+end
+
+function filter_write(str)
+	buffer = buffer .. str
+end
+
diff --git a/shared.c b/shared.c
index 8ed14c0..6e91857 100644
--- a/shared.c
+++ b/shared.c
@@ -72,6 +72,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
 	ret->commit_filter = ctx.cfg.commit_filter;
 	ret->source_filter = ctx.cfg.source_filter;
 	ret->email_filter = ctx.cfg.email_filter;
+	ret->owner_filter = ctx.cfg.owner_filter;
 	ret->clone_url = ctx.cfg.clone_url;
 	ret->submodules.strdup_strings = 1;
 	return ret;
diff --git a/ui-repolist.c b/ui-repolist.c
index c2bcce1..8997d08 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -306,6 +306,7 @@ void cgit_print_repolist()
 		html_link_close();
 		html("</td><td>");
 		if (ctx.cfg.enable_index_owner) {
+			cgit_open_filter(ctx.repo->owner_filter, ctx.repo->owner, cgit_rooturl());
 			html("<a href='");
 			html_attr(cgit_rooturl());
 			html("?q=");
@@ -313,6 +314,7 @@ void cgit_print_repolist()
 			html("'>");
 			html_txt(ctx.repo->owner);
 			html("</a>");
+			cgit_close_filter(ctx.repo->owner_filter);
 			html("</td><td>");
 		}
 		print_modtime(ctx.repo);
-- 
1.7.10.4


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] filter: add support for owner-filter
  2014-08-01 17:54 [PATCH] filter: add support for owner-filter chris.burroughs
@ 2014-08-01 18:18 ` john
  2014-08-01 19:44   ` chris.burroughs
  0 siblings, 1 reply; 8+ messages in thread
From: john @ 2014-08-01 18:18 UTC (permalink / raw)


On Fri, Aug 01, 2014 at 01:54:46PM -0400, Chris Burroughs wrote:
> Followup and attempt at implementation of an owner filter as described
> in http://lists.zx2c4.com/pipermail/cgit/2014-July/002163.html.  There
> are two parts I am unsure of:
>  * Is there an advantage (performance?) to passing the owner as an
>    argument instead of using CGIT_REPO_OWNER?

I suspect argument parsing is quicker than a lookup in the environment,
particularly with Lua filters, but without benchmarking I wouldn't like
to say.

>  * I passed along the cgit_rooturl so that a filter could re-implement
>    what the C code is doing.  This seemed a good test of if the filter
>    was flexible enough, but passing it along as an argument feels a
>    bit wonky.  Maybe this would be better as an environmental variable
>    to all filters?

Possibly, but see below...

> ---
>  cgit.c                    |    6 ++++++
>  cgit.h                    |    4 +++-
>  cgitrc.5.txt              |   18 ++++++++++++++++++
>  filter.c                  |    6 ++++++
>  filters/owner-example.lua |   24 ++++++++++++++++++++++++
>  shared.c                  |    1 +
>  ui-repolist.c             |    2 ++
>  7 files changed, 60 insertions(+), 1 deletion(-)
>  create mode 100644 filters/owner-example.lua
> 
> diff --git a/cgit.c b/cgit.c
> index 20f6e27..d29e7f5 100644
> --- a/cgit.c
> +++ b/cgit.c
> @@ -91,6 +91,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
>  			repo->source_filter = cgit_new_filter(value, SOURCE);
>  		else if (!strcmp(name, "email-filter"))
>  			repo->email_filter = cgit_new_filter(value, EMAIL);
> +		else if (!strcmp(name, "owner-filter"))
> +			repo->owner_filter = cgit_new_filter(value, OWNER);
>  	}
>  }
>  
> @@ -194,6 +196,8 @@ static void config_cb(const char *name, const char *value)
>  		ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT);
>  	else if (!strcmp(name, "email-filter"))
>  		ctx.cfg.email_filter = cgit_new_filter(value, EMAIL);
> +	else if (!strcmp(name, "owner-filter"))
> +		ctx.cfg.owner_filter = cgit_new_filter(value, OWNER);
>  	else if (!strcmp(name, "auth-filter"))
>  		ctx.cfg.auth_filter = cgit_new_filter(value, AUTH);
>  	else if (!strcmp(name, "embedded"))
> @@ -802,6 +806,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
>  		cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter=");
>  	if (repo->email_filter && repo->email_filter != ctx.cfg.email_filter)
>  		cgit_fprintf_filter(repo->email_filter, f, "repo.email-filter=");
> +	if (repo->owner_filter && repo->owner_filter != ctx.cfg.owner_filter)
> +		cgit_fprintf_filter(repo->owner_filter, f, "repo.owner-filter=");
>  	if (repo->snapshots != ctx.cfg.snapshots) {
>  		char *tmp = build_snapshot_setting(repo->snapshots);
>  		fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
> diff --git a/cgit.h b/cgit.h
> index 0badc64..0078ac1 100644
> --- a/cgit.h
> +++ b/cgit.h
> @@ -53,7 +53,7 @@ typedef void (*filepair_fn)(struct diff_filepair *pair);
>  typedef void (*linediff_fn)(char *line, int len);
>  
>  typedef enum {
> -	ABOUT, COMMIT, SOURCE, EMAIL, AUTH
> +	ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
>  } filter_type;
>  
>  struct cgit_filter {
> @@ -100,6 +100,7 @@ struct cgit_repo {
>  	struct cgit_filter *commit_filter;
>  	struct cgit_filter *source_filter;
>  	struct cgit_filter *email_filter;
> +	struct cgit_filter *owner_filter;
>  	struct string_list submodules;
>  };
>  
> @@ -253,6 +254,7 @@ struct cgit_config {
>  	struct cgit_filter *commit_filter;
>  	struct cgit_filter *source_filter;
>  	struct cgit_filter *email_filter;
> +	struct cgit_filter *owner_filter;
>  	struct cgit_filter *auth_filter;
>  };
>  
> diff --git a/cgitrc.5.txt b/cgitrc.5.txt
> index b7570db..7ed2c80 100644
> --- a/cgitrc.5.txt
> +++ b/cgitrc.5.txt
> @@ -247,6 +247,14 @@ logo-link::
>  	calculated url of the repository index page will be used. Default
>  	value: none.
>  
> +owner-filter::
> +	Specifies a command which will be invoked to format the Owner column
> +	of the main page.  The command will get the default html on its STDIN,
> +	and the STDOUT from the command will be included verbatim in the
> +	table.  This can be used to link to additional context such as an
> +	owners home page. Default value: none.
> +	See also: "FILTER API".
> +
>  max-atom-items::
>  	Specifies the number of items to display in atom feeds view. Default
>  	value: "10".
> @@ -509,6 +517,10 @@ repo.logo-link::
>  	calculated url of the repository index page will be used. Default
>  	value: global logo-link.
>  
> +repo.owner-filter::
> +	Override the default owner-filter. Default value: none. See also:
> +	"enable-filter-overrides". See also: "FILTER API".
> +
>  repo.module-link::
>  	Text which will be used as the formatstring for a hyperlink when a
>  	submodule is printed in a directory listing. The arguments for the
> @@ -641,6 +653,12 @@ email filter::
>  	expected to write to standard output the formatted text to be included
>  	in the page.
>  
> +owner filter::
> +	This filter is given two parameters: the repository owner and the cgit
> +	root url.  The filter will then receive the default html to argument
> +	on standard input and is expected to write to standard output the
> +	formatted text to be included in the column.
> +
>  source filter::
>  	This filter is given a single parameter: the filename of the source
>  	file to filter. The filter can use the filename to determine (for
> diff --git a/filter.c b/filter.c
> index 270f009..35502b5 100644
> --- a/filter.c
> +++ b/filter.c
> @@ -38,12 +38,14 @@ void cgit_cleanup_filters(void)
>  	reap_filter(ctx.cfg.commit_filter);
>  	reap_filter(ctx.cfg.source_filter);
>  	reap_filter(ctx.cfg.email_filter);
> +	reap_filter(ctx.cfg.owner_filter);
>  	reap_filter(ctx.cfg.auth_filter);
>  	for (i = 0; i < cgit_repolist.count; ++i) {
>  		reap_filter(cgit_repolist.repos[i].about_filter);
>  		reap_filter(cgit_repolist.repos[i].commit_filter);
>  		reap_filter(cgit_repolist.repos[i].source_filter);
>  		reap_filter(cgit_repolist.repos[i].email_filter);
> +		reap_filter(cgit_repolist.repos[i].owner_filter);
>  	}
>  }
>  
> @@ -425,6 +427,10 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
>  			argument_count = 2;
>  			break;
>  
> +		case OWNER:
> +			argument_count = 2;
> +			break;
> +
>  		case SOURCE:
>  		case ABOUT:
>  			argument_count = 1;
> diff --git a/filters/owner-example.lua b/filters/owner-example.lua
> new file mode 100644
> index 0000000..79b1d49
> --- /dev/null
> +++ b/filters/owner-example.lua
> @@ -0,0 +1,24 @@
> +-- This script is an example of an owner-filter.  It adds an
> +-- additional link to a fictional home page.  This script may be used
> +-- with the owner-filter or repo.owner-filter settings in cgitrc with
> +-- the `lua:` prefix.  `cgit_root_url` is provided so that it's
> +-- possible to replicate the default behavior with a filter instead of
> +-- echoing the buffer.
> +--
> +
> +function filter_open(cgit_repo_owner, cgit_root_url)
> +   buffer = ""
> +   owner = cgit_repo_owner
> +   root_url = cgit_root_url
> +end
> +
> +function filter_close()
> +   html(buffer)
> +   html(string.format(" <a href=\"%s\">%s</a>", "http://wiki.example.com/about/" .. owner, "Home"))
> +   return 0
> +end
> +
> +function filter_write(str)
> +	buffer = buffer .. str
> +end

This isn't really acting as a filter, you're taking the argument from
the function call and then just appending something based on that from
the default generated by the C code.  I think the email filter has to
take the email address as an argument because it may not be present in
the input to the filter (depending on the value of "noplainemail")...

> diff --git a/shared.c b/shared.c
> index 8ed14c0..6e91857 100644
> --- a/shared.c
> +++ b/shared.c
> @@ -72,6 +72,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
>  	ret->commit_filter = ctx.cfg.commit_filter;
>  	ret->source_filter = ctx.cfg.source_filter;
>  	ret->email_filter = ctx.cfg.email_filter;
> +	ret->owner_filter = ctx.cfg.owner_filter;
>  	ret->clone_url = ctx.cfg.clone_url;
>  	ret->submodules.strdup_strings = 1;
>  	return ret;
> diff --git a/ui-repolist.c b/ui-repolist.c
> index c2bcce1..8997d08 100644
> --- a/ui-repolist.c
> +++ b/ui-repolist.c
> @@ -306,6 +306,7 @@ void cgit_print_repolist()
>  		html_link_close();
>  		html("</td><td>");
>  		if (ctx.cfg.enable_index_owner) {
> +			cgit_open_filter(ctx.repo->owner_filter, ctx.repo->owner, cgit_rooturl());
>  			html("<a href='");
>  			html_attr(cgit_rooturl());
>  			html("?q=");
> @@ -313,6 +314,7 @@ void cgit_print_repolist()
>  			html("'>");
>  			html_txt(ctx.repo->owner);
>  			html("</a>");
> +			cgit_close_filter(ctx.repo->owner_filter);

Perhaps this would be better as:

	if (ctx.cfg.enable_index_owner) {
		if (ctx.repo->owner_filter) {
			cgit_open_filter(ctx.repo->owner_filter);
			html_txt(ctx.repo->owner);
			cgit_close_filter(ctx.repo->owner_filter);
		} else {
			html("<a href='");
			html_attr(cgit_rooturl());
			html("?=");
			html_url_arg(ctx.repo->owner);
			html("'>");
			html_txt(ctx.repo->owner);
			html("</a>");
		}
		html("</td><td>");
	}

so that the filter really is a filter acting on the owner.  Then the Lua
implementation becomes:

-- >8 --
function filter_open()
   buffer = ""
end

function filter_close()
   html(string.format("<a href=\"%s\">%s</a>",
           "http://wiki.example.com/about/" .. buffer, buffer))
   return 0
end

function filter_write(str)
    buffer = buffer .. str
end
-- 8< --

What do you think?

>  			html("</td><td>");
>  		}
>  		print_modtime(ctx.repo);


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] filter: add support for owner-filter
  2014-08-01 18:18 ` john
@ 2014-08-01 19:44   ` chris.burroughs
  2014-08-01 20:01     ` chris.burroughs
  0 siblings, 1 reply; 8+ messages in thread
From: chris.burroughs @ 2014-08-01 19:44 UTC (permalink / raw)


On 08/01/2014 02:18 PM, John Keeping wrote:
> On Fri, Aug 01, 2014 at 01:54:46PM -0400, Chris Burroughs wrote:
> This isn't really acting as a filter, you're taking the argument from
> the function call and then just appending something based on that from
> the default generated by the C code.  I think the email filter has to
> take the email address as an argument because it may not be present in
> the input to the filter (depending on the value of "noplainemail")...
>


>
> Perhaps this would be better as:
>
> 	if (ctx.cfg.enable_index_owner) {
> 		if (ctx.repo->owner_filter) {
> 			cgit_open_filter(ctx.repo->owner_filter);
> 			html_txt(ctx.repo->owner);
> 			cgit_close_filter(ctx.repo->owner_filter);
> 		} else {
> 			html("<a href='");
> 			html_attr(cgit_rooturl());
> 			html("?=");
> 			html_url_arg(ctx.repo->owner);
> 			html("'>");
> 			html_txt(ctx.repo->owner);
> 			html("</a>");
> 		}
> 		html("</td><td>");
> 	}
>

Yes, much!


> so that the filter really is a filter acting on the owner.  Then the Lua
> implementation becomes:
>
> -- >8 --
> function filter_open()
>     buffer = ""
> end
>
> function filter_close()
>     html(string.format("<a href=\"%s\">%s</a>",
>             "http://wiki.example.com/about/" .. buffer, buffer))
>     return 0
> end
>
> function filter_write(str)
>      buffer = buffer .. str
> end
> -- 8< --
>
> What do you think?
>

I think using STDIN for "the thing to filter" consistently is much 
better.  I was thrown off by the way the email filter also takes the 
address as an argument.  cgit_root might be useful but if that's true I 
much prefer adding it to the environment later instead of shoe-horning 
it into the filter_open api.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] filter: add support for owner-filter
  2014-08-01 19:44   ` chris.burroughs
@ 2014-08-01 20:01     ` chris.burroughs
  2014-08-01 20:43       ` john
  2014-12-24  2:01       ` [PATCH] filter: add support for owner-filter Jason
  0 siblings, 2 replies; 8+ messages in thread
From: chris.burroughs @ 2014-08-01 20:01 UTC (permalink / raw)


revised patch

---
 cgit.c                    |    6 ++++++
 cgit.h                    |    4 +++-
 cgitrc.5.txt              |   18 ++++++++++++++++++
 filter.c                  |    6 ++++++
 filters/owner-example.lua |   19 +++++++++++++++++++
 shared.c                  |    1 +
 ui-repolist.c             |   20 +++++++++++++-------
 7 files changed, 66 insertions(+), 8 deletions(-)
 create mode 100644 filters/owner-example.lua

diff --git a/cgit.c b/cgit.c
index 20f6e27..d29e7f5 100644
--- a/cgit.c
+++ b/cgit.c
@@ -91,6 +91,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
 			repo->source_filter = cgit_new_filter(value, SOURCE);
 		else if (!strcmp(name, "email-filter"))
 			repo->email_filter = cgit_new_filter(value, EMAIL);
+		else if (!strcmp(name, "owner-filter"))
+			repo->owner_filter = cgit_new_filter(value, OWNER);
 	}
 }
 
@@ -194,6 +196,8 @@ static void config_cb(const char *name, const char *value)
 		ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT);
 	else if (!strcmp(name, "email-filter"))
 		ctx.cfg.email_filter = cgit_new_filter(value, EMAIL);
+	else if (!strcmp(name, "owner-filter"))
+		ctx.cfg.owner_filter = cgit_new_filter(value, OWNER);
 	else if (!strcmp(name, "auth-filter"))
 		ctx.cfg.auth_filter = cgit_new_filter(value, AUTH);
 	else if (!strcmp(name, "embedded"))
@@ -802,6 +806,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
 		cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter=");
 	if (repo->email_filter && repo->email_filter != ctx.cfg.email_filter)
 		cgit_fprintf_filter(repo->email_filter, f, "repo.email-filter=");
+	if (repo->owner_filter && repo->owner_filter != ctx.cfg.owner_filter)
+		cgit_fprintf_filter(repo->owner_filter, f, "repo.owner-filter=");
 	if (repo->snapshots != ctx.cfg.snapshots) {
 		char *tmp = build_snapshot_setting(repo->snapshots);
 		fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
diff --git a/cgit.h b/cgit.h
index 0badc64..0078ac1 100644
--- a/cgit.h
+++ b/cgit.h
@@ -53,7 +53,7 @@ typedef void (*filepair_fn)(struct diff_filepair *pair);
 typedef void (*linediff_fn)(char *line, int len);
 
 typedef enum {
-	ABOUT, COMMIT, SOURCE, EMAIL, AUTH
+	ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
 } filter_type;
 
 struct cgit_filter {
@@ -100,6 +100,7 @@ struct cgit_repo {
 	struct cgit_filter *commit_filter;
 	struct cgit_filter *source_filter;
 	struct cgit_filter *email_filter;
+	struct cgit_filter *owner_filter;
 	struct string_list submodules;
 };
 
@@ -253,6 +254,7 @@ struct cgit_config {
 	struct cgit_filter *commit_filter;
 	struct cgit_filter *source_filter;
 	struct cgit_filter *email_filter;
+	struct cgit_filter *owner_filter;
 	struct cgit_filter *auth_filter;
 };
 
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index b7570db..d774ed3 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -247,6 +247,15 @@ logo-link::
 	calculated url of the repository index page will be used. Default
 	value: none.
 
+owner-filter::
+	Specifies a command which will be invoked to format the Owner
+	column of the main page.  The command will get the owner on STDIN,
+	and the STDOUT from the command will be included verbatim in the
+	table.  This can be used to link to additional context such as an
+	owners home page.  When active this filter is used instead of the
+	default owner query url.  Default value: none.
+	See also: "FILTER API".
+
 max-atom-items::
 	Specifies the number of items to display in atom feeds view. Default
 	value: "10".
@@ -509,6 +518,10 @@ repo.logo-link::
 	calculated url of the repository index page will be used. Default
 	value: global logo-link.
 
+repo.owner-filter::
+	Override the default owner-filter. Default value: none. See also:
+	"enable-filter-overrides". See also: "FILTER API".
+
 repo.module-link::
 	Text which will be used as the formatstring for a hyperlink when a
 	submodule is printed in a directory listing. The arguments for the
@@ -641,6 +654,11 @@ email filter::
 	expected to write to standard output the formatted text to be included
 	in the page.
 
+owner filter::
+	This filter is given no arguments.  The owner text is avilable on
+	standard input and the filter is expected to write to standard
+	output.  The output is included in the Owner column.
+
 source filter::
 	This filter is given a single parameter: the filename of the source
 	file to filter. The filter can use the filename to determine (for
diff --git a/filter.c b/filter.c
index 270f009..9f433db 100644
--- a/filter.c
+++ b/filter.c
@@ -38,12 +38,14 @@ void cgit_cleanup_filters(void)
 	reap_filter(ctx.cfg.commit_filter);
 	reap_filter(ctx.cfg.source_filter);
 	reap_filter(ctx.cfg.email_filter);
+	reap_filter(ctx.cfg.owner_filter);
 	reap_filter(ctx.cfg.auth_filter);
 	for (i = 0; i < cgit_repolist.count; ++i) {
 		reap_filter(cgit_repolist.repos[i].about_filter);
 		reap_filter(cgit_repolist.repos[i].commit_filter);
 		reap_filter(cgit_repolist.repos[i].source_filter);
 		reap_filter(cgit_repolist.repos[i].email_filter);
+		reap_filter(cgit_repolist.repos[i].owner_filter);
 	}
 }
 
@@ -425,6 +427,10 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
 			argument_count = 2;
 			break;
 
+		case OWNER:
+			argument_count = 0;
+			break;
+
 		case SOURCE:
 		case ABOUT:
 			argument_count = 1;
diff --git a/filters/owner-example.lua b/filters/owner-example.lua
new file mode 100644
index 0000000..df7de04
--- /dev/null
+++ b/filters/owner-example.lua
@@ -0,0 +1,19 @@
+-- This script is an example of an owner-filter.  It replaces the
+-- usual query link with one to a fictional homepage.  This script may
+-- be used with the owner-filter or repo.owner-filter settings in
+-- cgitrc with the `lua:` prefix.
+
+function filter_open()
+   buffer = ""
+
+end
+
+function filter_close()
+   html(string.format("<a href=\"%s\">%s</a>", "http://wiki.example.com/about/" .. buffer, buffer))
+   return 0
+end
+
+function filter_write(str)
+	buffer = buffer .. str
+end
+
diff --git a/shared.c b/shared.c
index 8ed14c0..6e91857 100644
--- a/shared.c
+++ b/shared.c
@@ -72,6 +72,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
 	ret->commit_filter = ctx.cfg.commit_filter;
 	ret->source_filter = ctx.cfg.source_filter;
 	ret->email_filter = ctx.cfg.email_filter;
+	ret->owner_filter = ctx.cfg.owner_filter;
 	ret->clone_url = ctx.cfg.clone_url;
 	ret->submodules.strdup_strings = 1;
 	return ret;
diff --git a/ui-repolist.c b/ui-repolist.c
index c2bcce1..1e64cf2 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -306,13 +306,19 @@ void cgit_print_repolist()
 		html_link_close();
 		html("</td><td>");
 		if (ctx.cfg.enable_index_owner) {
-			html("<a href='");
-			html_attr(cgit_rooturl());
-			html("?q=");
-			html_url_arg(ctx.repo->owner);
-			html("'>");
-			html_txt(ctx.repo->owner);
-			html("</a>");
+			if (ctx.repo->owner_filter) {
+				cgit_open_filter(ctx.repo->owner_filter);
+				html_txt(ctx.repo->owner);
+				cgit_close_filter(ctx.repo->owner_filter);
+			} else {
+				html("<a href='");
+				html_attr(cgit_rooturl());
+				html("?=");
+				html_url_arg(ctx.repo->owner);
+				html("'>");
+				html_txt(ctx.repo->owner);
+				html("</a>");
+			}
 			html("</td><td>");
 		}
 		print_modtime(ctx.repo);
-- 
1.7.10.4



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] filter: add support for owner-filter
  2014-08-01 20:01     ` chris.burroughs
@ 2014-08-01 20:43       ` john
  2014-08-04 13:23         ` [PATCH v3] repolist: add owner-filter chris.burroughs
  2014-12-24  2:01       ` [PATCH] filter: add support for owner-filter Jason
  1 sibling, 1 reply; 8+ messages in thread
From: john @ 2014-08-01 20:43 UTC (permalink / raw)


On Fri, Aug 01, 2014 at 04:01:53PM -0400, Chris Burroughs wrote:
> revised patch

This type of comment should go below the "---" line below, since it's
not intended to be part of the commit message in the permanent history.
Also "filter" in the subject doesn't really identify a code area.  How
about something like this:

	repolist: add owner-filter

	This allows custom links to be used for repository owners by
	configuring a filter to be applied in the "Owner" column in the
	repository list.

More below...

> ---
>  cgit.c                    |    6 ++++++
>  cgit.h                    |    4 +++-
>  cgitrc.5.txt              |   18 ++++++++++++++++++
>  filter.c                  |    6 ++++++
>  filters/owner-example.lua |   19 +++++++++++++++++++
>  shared.c                  |    1 +
>  ui-repolist.c             |   20 +++++++++++++-------
>  7 files changed, 66 insertions(+), 8 deletions(-)
>  create mode 100644 filters/owner-example.lua
> 
> diff --git a/cgit.c b/cgit.c
> index 20f6e27..d29e7f5 100644
> --- a/cgit.c
> +++ b/cgit.c
> @@ -91,6 +91,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
>  			repo->source_filter = cgit_new_filter(value, SOURCE);
>  		else if (!strcmp(name, "email-filter"))
>  			repo->email_filter = cgit_new_filter(value, EMAIL);
> +		else if (!strcmp(name, "owner-filter"))
> +			repo->owner_filter = cgit_new_filter(value, OWNER);
>  	}
>  }
>  
> @@ -194,6 +196,8 @@ static void config_cb(const char *name, const char *value)
>  		ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT);
>  	else if (!strcmp(name, "email-filter"))
>  		ctx.cfg.email_filter = cgit_new_filter(value, EMAIL);
> +	else if (!strcmp(name, "owner-filter"))
> +		ctx.cfg.owner_filter = cgit_new_filter(value, OWNER);
>  	else if (!strcmp(name, "auth-filter"))
>  		ctx.cfg.auth_filter = cgit_new_filter(value, AUTH);
>  	else if (!strcmp(name, "embedded"))
> @@ -802,6 +806,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
>  		cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter=");
>  	if (repo->email_filter && repo->email_filter != ctx.cfg.email_filter)
>  		cgit_fprintf_filter(repo->email_filter, f, "repo.email-filter=");
> +	if (repo->owner_filter && repo->owner_filter != ctx.cfg.owner_filter)
> +		cgit_fprintf_filter(repo->owner_filter, f, "repo.owner-filter=");
>  	if (repo->snapshots != ctx.cfg.snapshots) {
>  		char *tmp = build_snapshot_setting(repo->snapshots);
>  		fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
> diff --git a/cgit.h b/cgit.h
> index 0badc64..0078ac1 100644
> --- a/cgit.h
> +++ b/cgit.h
> @@ -53,7 +53,7 @@ typedef void (*filepair_fn)(struct diff_filepair *pair);
>  typedef void (*linediff_fn)(char *line, int len);
>  
>  typedef enum {
> -	ABOUT, COMMIT, SOURCE, EMAIL, AUTH
> +	ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
>  } filter_type;
>  
>  struct cgit_filter {
> @@ -100,6 +100,7 @@ struct cgit_repo {
>  	struct cgit_filter *commit_filter;
>  	struct cgit_filter *source_filter;
>  	struct cgit_filter *email_filter;
> +	struct cgit_filter *owner_filter;
>  	struct string_list submodules;
>  };
>  
> @@ -253,6 +254,7 @@ struct cgit_config {
>  	struct cgit_filter *commit_filter;
>  	struct cgit_filter *source_filter;
>  	struct cgit_filter *email_filter;
> +	struct cgit_filter *owner_filter;
>  	struct cgit_filter *auth_filter;
>  };
>  
> diff --git a/cgitrc.5.txt b/cgitrc.5.txt
> index b7570db..d774ed3 100644
> --- a/cgitrc.5.txt
> +++ b/cgitrc.5.txt
> @@ -247,6 +247,15 @@ logo-link::
>  	calculated url of the repository index page will be used. Default
>  	value: none.
>  
> +owner-filter::
> +	Specifies a command which will be invoked to format the Owner
> +	column of the main page.  The command will get the owner on STDIN,
> +	and the STDOUT from the command will be included verbatim in the
> +	table.  This can be used to link to additional context such as an
> +	owners home page.  When active this filter is used instead of the
> +	default owner query url.  Default value: none.
> +	See also: "FILTER API".
> +
>  max-atom-items::
>  	Specifies the number of items to display in atom feeds view. Default
>  	value: "10".
> @@ -509,6 +518,10 @@ repo.logo-link::
>  	calculated url of the repository index page will be used. Default
>  	value: global logo-link.
>  
> +repo.owner-filter::
> +	Override the default owner-filter. Default value: none. See also:
> +	"enable-filter-overrides". See also: "FILTER API".
> +
>  repo.module-link::
>  	Text which will be used as the formatstring for a hyperlink when a
>  	submodule is printed in a directory listing. The arguments for the
> @@ -641,6 +654,11 @@ email filter::
>  	expected to write to standard output the formatted text to be included
>  	in the page.
>  
> +owner filter::
> +	This filter is given no arguments.  The owner text is avilable on
> +	standard input and the filter is expected to write to standard
> +	output.  The output is included in the Owner column.
> +
>  source filter::
>  	This filter is given a single parameter: the filename of the source
>  	file to filter. The filter can use the filename to determine (for
> diff --git a/filter.c b/filter.c
> index 270f009..9f433db 100644
> --- a/filter.c
> +++ b/filter.c
> @@ -38,12 +38,14 @@ void cgit_cleanup_filters(void)
>  	reap_filter(ctx.cfg.commit_filter);
>  	reap_filter(ctx.cfg.source_filter);
>  	reap_filter(ctx.cfg.email_filter);
> +	reap_filter(ctx.cfg.owner_filter);
>  	reap_filter(ctx.cfg.auth_filter);
>  	for (i = 0; i < cgit_repolist.count; ++i) {
>  		reap_filter(cgit_repolist.repos[i].about_filter);
>  		reap_filter(cgit_repolist.repos[i].commit_filter);
>  		reap_filter(cgit_repolist.repos[i].source_filter);
>  		reap_filter(cgit_repolist.repos[i].email_filter);
> +		reap_filter(cgit_repolist.repos[i].owner_filter);
>  	}
>  }
>  
> @@ -425,6 +427,10 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
>  			argument_count = 2;
>  			break;
>  
> +		case OWNER:
> +			argument_count = 0;
> +			break;
> +
>  		case SOURCE:
>  		case ABOUT:
>  			argument_count = 1;
> diff --git a/filters/owner-example.lua b/filters/owner-example.lua
> new file mode 100644
> index 0000000..df7de04
> --- /dev/null
> +++ b/filters/owner-example.lua
> @@ -0,0 +1,19 @@
> +-- This script is an example of an owner-filter.  It replaces the
> +-- usual query link with one to a fictional homepage.  This script may
> +-- be used with the owner-filter or repo.owner-filter settings in
> +-- cgitrc with the `lua:` prefix.
> +
> +function filter_open()
> +   buffer = ""
> +
> +end
> +
> +function filter_close()
> +   html(string.format("<a href=\"%s\">%s</a>", "http://wiki.example.com/about/" .. buffer, buffer))
> +   return 0
> +end
> +
> +function filter_write(str)
> +	buffer = buffer .. str
> +end
> +

There's an extra blank line at the end of this file and the indentation
in the Lua file is inconsistent.  Our other Lua files use hard tabs, so
filter_write() above is correct.

The C changes look good.

> diff --git a/shared.c b/shared.c
> index 8ed14c0..6e91857 100644
> --- a/shared.c
> +++ b/shared.c
> @@ -72,6 +72,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
>  	ret->commit_filter = ctx.cfg.commit_filter;
>  	ret->source_filter = ctx.cfg.source_filter;
>  	ret->email_filter = ctx.cfg.email_filter;
> +	ret->owner_filter = ctx.cfg.owner_filter;
>  	ret->clone_url = ctx.cfg.clone_url;
>  	ret->submodules.strdup_strings = 1;
>  	return ret;
> diff --git a/ui-repolist.c b/ui-repolist.c
> index c2bcce1..1e64cf2 100644
> --- a/ui-repolist.c
> +++ b/ui-repolist.c
> @@ -306,13 +306,19 @@ void cgit_print_repolist()
>  		html_link_close();
>  		html("</td><td>");
>  		if (ctx.cfg.enable_index_owner) {
> -			html("<a href='");
> -			html_attr(cgit_rooturl());
> -			html("?q=");
> -			html_url_arg(ctx.repo->owner);
> -			html("'>");
> -			html_txt(ctx.repo->owner);
> -			html("</a>");
> +			if (ctx.repo->owner_filter) {
> +				cgit_open_filter(ctx.repo->owner_filter);
> +				html_txt(ctx.repo->owner);
> +				cgit_close_filter(ctx.repo->owner_filter);
> +			} else {
> +				html("<a href='");
> +				html_attr(cgit_rooturl());
> +				html("?=");
> +				html_url_arg(ctx.repo->owner);
> +				html("'>");
> +				html_txt(ctx.repo->owner);
> +				html("</a>");
> +			}
>  			html("</td><td>");
>  		}
>  		print_modtime(ctx.repo);
> -- 
> 1.7.10.4
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3] repolist: add owner-filter
  2014-08-01 20:43       ` john
@ 2014-08-04 13:23         ` chris.burroughs
  2014-12-24  2:09           ` Jason
  0 siblings, 1 reply; 8+ messages in thread
From: chris.burroughs @ 2014-08-04 13:23 UTC (permalink / raw)


This allows custom links to be used for repository owners by
configuring a filter to be applied in the "Owner" column in the
repository list.
---
I think I have it all right now.  Thank you for the multiple rounds of
review

 cgit.c                    |    6 ++++++
 cgit.h                    |    4 +++-
 cgitrc.5.txt              |   18 ++++++++++++++++++
 filter.c                  |    6 ++++++
 filters/owner-example.lua |   17 +++++++++++++++++
 shared.c                  |    1 +
 ui-repolist.c             |   20 +++++++++++++-------
 7 files changed, 64 insertions(+), 8 deletions(-)
 create mode 100644 filters/owner-example.lua

diff --git a/cgit.c b/cgit.c
index 20f6e27..d29e7f5 100644
--- a/cgit.c
+++ b/cgit.c
@@ -91,6 +91,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
 			repo->source_filter = cgit_new_filter(value, SOURCE);
 		else if (!strcmp(name, "email-filter"))
 			repo->email_filter = cgit_new_filter(value, EMAIL);
+		else if (!strcmp(name, "owner-filter"))
+			repo->owner_filter = cgit_new_filter(value, OWNER);
 	}
 }
 
@@ -194,6 +196,8 @@ static void config_cb(const char *name, const char *value)
 		ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT);
 	else if (!strcmp(name, "email-filter"))
 		ctx.cfg.email_filter = cgit_new_filter(value, EMAIL);
+	else if (!strcmp(name, "owner-filter"))
+		ctx.cfg.owner_filter = cgit_new_filter(value, OWNER);
 	else if (!strcmp(name, "auth-filter"))
 		ctx.cfg.auth_filter = cgit_new_filter(value, AUTH);
 	else if (!strcmp(name, "embedded"))
@@ -802,6 +806,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
 		cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter=");
 	if (repo->email_filter && repo->email_filter != ctx.cfg.email_filter)
 		cgit_fprintf_filter(repo->email_filter, f, "repo.email-filter=");
+	if (repo->owner_filter && repo->owner_filter != ctx.cfg.owner_filter)
+		cgit_fprintf_filter(repo->owner_filter, f, "repo.owner-filter=");
 	if (repo->snapshots != ctx.cfg.snapshots) {
 		char *tmp = build_snapshot_setting(repo->snapshots);
 		fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
diff --git a/cgit.h b/cgit.h
index 0badc64..0078ac1 100644
--- a/cgit.h
+++ b/cgit.h
@@ -53,7 +53,7 @@ typedef void (*filepair_fn)(struct diff_filepair *pair);
 typedef void (*linediff_fn)(char *line, int len);
 
 typedef enum {
-	ABOUT, COMMIT, SOURCE, EMAIL, AUTH
+	ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
 } filter_type;
 
 struct cgit_filter {
@@ -100,6 +100,7 @@ struct cgit_repo {
 	struct cgit_filter *commit_filter;
 	struct cgit_filter *source_filter;
 	struct cgit_filter *email_filter;
+	struct cgit_filter *owner_filter;
 	struct string_list submodules;
 };
 
@@ -253,6 +254,7 @@ struct cgit_config {
 	struct cgit_filter *commit_filter;
 	struct cgit_filter *source_filter;
 	struct cgit_filter *email_filter;
+	struct cgit_filter *owner_filter;
 	struct cgit_filter *auth_filter;
 };
 
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index b7570db..d774ed3 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -247,6 +247,15 @@ logo-link::
 	calculated url of the repository index page will be used. Default
 	value: none.
 
+owner-filter::
+	Specifies a command which will be invoked to format the Owner
+	column of the main page.  The command will get the owner on STDIN,
+	and the STDOUT from the command will be included verbatim in the
+	table.  This can be used to link to additional context such as an
+	owners home page.  When active this filter is used instead of the
+	default owner query url.  Default value: none.
+	See also: "FILTER API".
+
 max-atom-items::
 	Specifies the number of items to display in atom feeds view. Default
 	value: "10".
@@ -509,6 +518,10 @@ repo.logo-link::
 	calculated url of the repository index page will be used. Default
 	value: global logo-link.
 
+repo.owner-filter::
+	Override the default owner-filter. Default value: none. See also:
+	"enable-filter-overrides". See also: "FILTER API".
+
 repo.module-link::
 	Text which will be used as the formatstring for a hyperlink when a
 	submodule is printed in a directory listing. The arguments for the
@@ -641,6 +654,11 @@ email filter::
 	expected to write to standard output the formatted text to be included
 	in the page.
 
+owner filter::
+	This filter is given no arguments.  The owner text is avilable on
+	standard input and the filter is expected to write to standard
+	output.  The output is included in the Owner column.
+
 source filter::
 	This filter is given a single parameter: the filename of the source
 	file to filter. The filter can use the filename to determine (for
diff --git a/filter.c b/filter.c
index 270f009..9f433db 100644
--- a/filter.c
+++ b/filter.c
@@ -38,12 +38,14 @@ void cgit_cleanup_filters(void)
 	reap_filter(ctx.cfg.commit_filter);
 	reap_filter(ctx.cfg.source_filter);
 	reap_filter(ctx.cfg.email_filter);
+	reap_filter(ctx.cfg.owner_filter);
 	reap_filter(ctx.cfg.auth_filter);
 	for (i = 0; i < cgit_repolist.count; ++i) {
 		reap_filter(cgit_repolist.repos[i].about_filter);
 		reap_filter(cgit_repolist.repos[i].commit_filter);
 		reap_filter(cgit_repolist.repos[i].source_filter);
 		reap_filter(cgit_repolist.repos[i].email_filter);
+		reap_filter(cgit_repolist.repos[i].owner_filter);
 	}
 }
 
@@ -425,6 +427,10 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
 			argument_count = 2;
 			break;
 
+		case OWNER:
+			argument_count = 0;
+			break;
+
 		case SOURCE:
 		case ABOUT:
 			argument_count = 1;
diff --git a/filters/owner-example.lua b/filters/owner-example.lua
new file mode 100644
index 0000000..50fc25a
--- /dev/null
+++ b/filters/owner-example.lua
@@ -0,0 +1,17 @@
+-- This script is an example of an owner-filter.  It replaces the
+-- usual query link with one to a fictional homepage.  This script may
+-- be used with the owner-filter or repo.owner-filter settings in
+-- cgitrc with the `lua:` prefix.
+
+function filter_open()
+	buffer = ""
+end
+
+function filter_close()
+	html(string.format("<a href=\"%s\">%s</a>", "http://wiki.example.com/about/" .. buffer, buffer))
+	return 0
+end
+
+function filter_write(str)
+	buffer = buffer .. str
+end
diff --git a/shared.c b/shared.c
index 8ed14c0..6e91857 100644
--- a/shared.c
+++ b/shared.c
@@ -72,6 +72,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
 	ret->commit_filter = ctx.cfg.commit_filter;
 	ret->source_filter = ctx.cfg.source_filter;
 	ret->email_filter = ctx.cfg.email_filter;
+	ret->owner_filter = ctx.cfg.owner_filter;
 	ret->clone_url = ctx.cfg.clone_url;
 	ret->submodules.strdup_strings = 1;
 	return ret;
diff --git a/ui-repolist.c b/ui-repolist.c
index c2bcce1..1e64cf2 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -306,13 +306,19 @@ void cgit_print_repolist()
 		html_link_close();
 		html("</td><td>");
 		if (ctx.cfg.enable_index_owner) {
-			html("<a href='");
-			html_attr(cgit_rooturl());
-			html("?q=");
-			html_url_arg(ctx.repo->owner);
-			html("'>");
-			html_txt(ctx.repo->owner);
-			html("</a>");
+			if (ctx.repo->owner_filter) {
+				cgit_open_filter(ctx.repo->owner_filter);
+				html_txt(ctx.repo->owner);
+				cgit_close_filter(ctx.repo->owner_filter);
+			} else {
+				html("<a href='");
+				html_attr(cgit_rooturl());
+				html("?=");
+				html_url_arg(ctx.repo->owner);
+				html("'>");
+				html_txt(ctx.repo->owner);
+				html("</a>");
+			}
 			html("</td><td>");
 		}
 		print_modtime(ctx.repo);
-- 
1.7.10.4



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] filter: add support for owner-filter
  2014-08-01 20:01     ` chris.burroughs
  2014-08-01 20:43       ` john
@ 2014-12-24  2:01       ` Jason
  1 sibling, 0 replies; 8+ messages in thread
From: Jason @ 2014-12-24  2:01 UTC (permalink / raw)


Hi Chris,

I like this patch, and I intend to merge it. Would you take care of John's
nitpicks, and rebase this against the current master, and I'll merge?

Sorry for the delay.

Thanks,
Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20141223/b708e455/attachment.html>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3] repolist: add owner-filter
  2014-08-04 13:23         ` [PATCH v3] repolist: add owner-filter chris.burroughs
@ 2014-12-24  2:09           ` Jason
  0 siblings, 0 replies; 8+ messages in thread
From: Jason @ 2014-12-24  2:09 UTC (permalink / raw)


Sorry I didn't see this a few minutes ago. Rebased it myself against
master, and merged. Thanks for your work on this. Looking forward to
log-filter next!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20141223/bcfc071f/attachment.html>


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-12-24  2:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-01 17:54 [PATCH] filter: add support for owner-filter chris.burroughs
2014-08-01 18:18 ` john
2014-08-01 19:44   ` chris.burroughs
2014-08-01 20:01     ` chris.burroughs
2014-08-01 20:43       ` john
2014-08-04 13:23         ` [PATCH v3] repolist: add owner-filter chris.burroughs
2014-12-24  2:09           ` Jason
2014-12-24  2:01       ` [PATCH] filter: add support for owner-filter Jason

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).