]> git.cameronkatri.com Git - cgit.git/commitdiff
repolist: add owner-filter
authorChris Burroughs <chris.burroughs@gmail.com>
Mon, 4 Aug 2014 13:23:08 +0000 (09:23 -0400)
committerJason A. Donenfeld <Jason@zx2c4.com>
Wed, 24 Dec 2014 02:08:20 +0000 (19:08 -0700)
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.

cgit.c
cgit.h
cgitrc.5.txt
filter.c
filters/owner-example.lua [new file with mode: 0644]
shared.c
ui-repolist.c

diff --git a/cgit.c b/cgit.c
index 796cb7fa9127ff2c9576e9567bc421fba9e498cb..79019c268027343e7944ceab6db35477219e861f 100644 (file)
--- 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);
                        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);
                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"))
        else if (!strcmp(name, "auth-filter"))
                ctx.cfg.auth_filter = cgit_new_filter(value, AUTH);
        else if (!strcmp(name, "embedded"))
@@ -800,6 +804,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=");
                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 : "");
        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 0c1585d34cdd4872f0ad5fc3d1cac8e01388ef02..42140ac4acdb8d59942a5e0abcfb9f7bbbb3bf4b 100644 (file)
--- a/cgit.h
+++ b/cgit.h
@@ -57,7 +57,7 @@ typedef enum {
 } diff_type;
 
 typedef enum {
 } diff_type;
 
 typedef enum {
-       ABOUT, COMMIT, SOURCE, EMAIL, AUTH
+       ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
 } filter_type;
 
 struct cgit_filter {
 } filter_type;
 
 struct cgit_filter {
@@ -104,6 +104,7 @@ struct cgit_repo {
        struct cgit_filter *commit_filter;
        struct cgit_filter *source_filter;
        struct cgit_filter *email_filter;
        struct cgit_filter *commit_filter;
        struct cgit_filter *source_filter;
        struct cgit_filter *email_filter;
+       struct cgit_filter *owner_filter;
        struct string_list submodules;
 };
 
        struct string_list submodules;
 };
 
@@ -257,6 +258,7 @@ struct cgit_config {
        struct cgit_filter *commit_filter;
        struct cgit_filter *source_filter;
        struct cgit_filter *email_filter;
        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;
 };
 
        struct cgit_filter *auth_filter;
 };
 
index 104b223b9b9e64c62c5c6d2c8e7c35db8fbb1960..be6703fdb1e0bfce51907c4420dab4ce3d47cff1 100644 (file)
@@ -247,6 +247,15 @@ logo-link::
        calculated url of the repository index page will be used. Default
        value: none.
 
        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".
 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.
 
        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
 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.
 
        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
 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
index 270f0098612862e3980d8c89a2991200b2925329..9f433dbc178df40259245ba7b8b18702920e33fd 100644 (file)
--- 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.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(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;
 
                        argument_count = 2;
                        break;
 
+               case OWNER:
+                       argument_count = 0;
+                       break;
+
                case SOURCE:
                case ABOUT:
                        argument_count = 1;
                case SOURCE:
                case ABOUT:
                        argument_count = 1;
diff --git a/filters/owner-example.lua b/filters/owner-example.lua
new file mode 100644 (file)
index 0000000..50fc25a
--- /dev/null
@@ -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
index 8ed14c0bdbcbf378dd2adc439e21f5895b6e4ac9..6e91857066a03faf40ea1153bc8868ee9b29f404 100644 (file)
--- 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->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;
        ret->clone_url = ctx.cfg.clone_url;
        ret->submodules.strdup_strings = 1;
        return ret;
index 49c991f616a74a5fdf24f4c0c65d959c88275378..f929cb79ec05ded2e92deb90e50743dde88d6681 100644 (file)
@@ -307,13 +307,19 @@ void cgit_print_repolist()
                html_link_close();
                html("</td><td>");
                if (ctx.cfg.enable_index_owner) {
                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);
                        html("</td><td>");
                }
                print_modtime(ctx.repo);