diff options
author | Chris Burroughs | 2014-08-04 09:23:08 -0400 |
---|---|---|
committer | Jason A. Donenfeld | 2014-12-23 19:08:20 -0700 |
commit | 96ceb9a95a7a321209cff347fefd141a9fffc7ca (patch) | |
tree | 5077ac54da1f7992d991746492855665454147c9 | |
parent | ui-shared: add rel-vcs microformat links to HTML header (diff) | |
download | cgit-96ceb9a95a7a321209cff347fefd141a9fffc7ca.tar.gz cgit-96ceb9a95a7a321209cff347fefd141a9fffc7ca.zip |
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.
-rw-r--r-- | cgit.c | 6 | ||||
-rw-r--r-- | cgit.h | 4 | ||||
-rw-r--r-- | cgitrc.5.txt | 18 | ||||
-rw-r--r-- | filter.c | 6 | ||||
-rw-r--r-- | filters/owner-example.lua | 17 | ||||
-rw-r--r-- | shared.c | 1 | ||||
-rw-r--r-- | ui-repolist.c | 20 |
7 files changed, 64 insertions, 8 deletions
diff --git a/cgit.c b/cgit.c index 796cb7f..79019c2 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 | |||
91 | repo->source_filter = cgit_new_filter(value, SOURCE); | 91 | repo->source_filter = cgit_new_filter(value, SOURCE); |
92 | else if (!strcmp(name, "email-filter")) | 92 | else if (!strcmp(name, "email-filter")) |
93 | repo->email_filter = cgit_new_filter(value, EMAIL); | 93 | repo->email_filter = cgit_new_filter(value, EMAIL); |
94 | else if (!strcmp(name, "owner-filter")) | ||
95 | repo->owner_filter = cgit_new_filter(value, OWNER); | ||
94 | } | 96 | } |
95 | } | 97 | } |
96 | 98 | ||
@@ -194,6 +196,8 @@ static void config_cb(const char *name, const char *value) | |||
194 | ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT); | 196 | ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT); |
195 | else if (!strcmp(name, "email-filter")) | 197 | else if (!strcmp(name, "email-filter")) |
196 | ctx.cfg.email_filter = cgit_new_filter(value, EMAIL); | 198 | ctx.cfg.email_filter = cgit_new_filter(value, EMAIL); |
199 | else if (!strcmp(name, "owner-filter")) | ||
200 | ctx.cfg.owner_filter = cgit_new_filter(value, OWNER); | ||
197 | else if (!strcmp(name, "auth-filter")) | 201 | else if (!strcmp(name, "auth-filter")) |
198 | ctx.cfg.auth_filter = cgit_new_filter(value, AUTH); | 202 | ctx.cfg.auth_filter = cgit_new_filter(value, AUTH); |
199 | else if (!strcmp(name, "embedded")) | 203 | else if (!strcmp(name, "embedded")) |
@@ -800,6 +804,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo) | |||
800 | cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter="); | 804 | cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter="); |
801 | if (repo->email_filter && repo->email_filter != ctx.cfg.email_filter) | 805 | if (repo->email_filter && repo->email_filter != ctx.cfg.email_filter) |
802 | cgit_fprintf_filter(repo->email_filter, f, "repo.email-filter="); | 806 | cgit_fprintf_filter(repo->email_filter, f, "repo.email-filter="); |
807 | if (repo->owner_filter && repo->owner_filter != ctx.cfg.owner_filter) | ||
808 | cgit_fprintf_filter(repo->owner_filter, f, "repo.owner-filter="); | ||
803 | if (repo->snapshots != ctx.cfg.snapshots) { | 809 | if (repo->snapshots != ctx.cfg.snapshots) { |
804 | char *tmp = build_snapshot_setting(repo->snapshots); | 810 | char *tmp = build_snapshot_setting(repo->snapshots); |
805 | fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : ""); | 811 | fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : ""); |
diff --git a/cgit.h b/cgit.h index 0c1585d..42140ac 100644 --- a/cgit.h +++ b/cgit.h | |||
@@ -57,7 +57,7 @@ typedef enum { | |||
57 | } diff_type; | 57 | } diff_type; |
58 | 58 | ||
59 | typedef enum { | 59 | typedef enum { |
60 | ABOUT, COMMIT, SOURCE, EMAIL, AUTH | 60 | ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER |
61 | } filter_type; | 61 | } filter_type; |
62 | 62 | ||
63 | struct cgit_filter { | 63 | struct cgit_filter { |
@@ -104,6 +104,7 @@ struct cgit_repo { | |||
104 | struct cgit_filter *commit_filter; | 104 | struct cgit_filter *commit_filter; |
105 | struct cgit_filter *source_filter; | 105 | struct cgit_filter *source_filter; |
106 | struct cgit_filter *email_filter; | 106 | struct cgit_filter *email_filter; |
107 | struct cgit_filter *owner_filter; | ||
107 | struct string_list submodules; | 108 | struct string_list submodules; |
108 | }; | 109 | }; |
109 | 110 | ||
@@ -257,6 +258,7 @@ struct cgit_config { | |||
257 | struct cgit_filter *commit_filter; | 258 | struct cgit_filter *commit_filter; |
258 | struct cgit_filter *source_filter; | 259 | struct cgit_filter *source_filter; |
259 | struct cgit_filter *email_filter; | 260 | struct cgit_filter *email_filter; |
261 | struct cgit_filter *owner_filter; | ||
260 | struct cgit_filter *auth_filter; | 262 | struct cgit_filter *auth_filter; |
261 | }; | 263 | }; |
262 | 264 | ||
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 104b223..be6703f 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -247,6 +247,15 @@ logo-link:: | |||
247 | calculated url of the repository index page will be used. Default | 247 | calculated url of the repository index page will be used. Default |
248 | value: none. | 248 | value: none. |
249 | 249 | ||
250 | owner-filter:: | ||
251 | Specifies a command which will be invoked to format the Owner | ||
252 | column of the main page. The command will get the owner on STDIN, | ||
253 | and the STDOUT from the command will be included verbatim in the | ||
254 | table. This can be used to link to additional context such as an | ||
255 | owners home page. When active this filter is used instead of the | ||
256 | default owner query url. Default value: none. | ||
257 | See also: "FILTER API". | ||
258 | |||
250 | max-atom-items:: | 259 | max-atom-items:: |
251 | Specifies the number of items to display in atom feeds view. Default | 260 | Specifies the number of items to display in atom feeds view. Default |
252 | value: "10". | 261 | value: "10". |
@@ -509,6 +518,10 @@ repo.logo-link:: | |||
509 | calculated url of the repository index page will be used. Default | 518 | calculated url of the repository index page will be used. Default |
510 | value: global logo-link. | 519 | value: global logo-link. |
511 | 520 | ||
521 | repo.owner-filter:: | ||
522 | Override the default owner-filter. Default value: none. See also: | ||
523 | "enable-filter-overrides". See also: "FILTER API". | ||
524 | |||
512 | repo.module-link:: | 525 | repo.module-link:: |
513 | Text which will be used as the formatstring for a hyperlink when a | 526 | Text which will be used as the formatstring for a hyperlink when a |
514 | submodule is printed in a directory listing. The arguments for the | 527 | submodule is printed in a directory listing. The arguments for the |
@@ -641,6 +654,11 @@ email filter:: | |||
641 | expected to write to standard output the formatted text to be included | 654 | expected to write to standard output the formatted text to be included |
642 | in the page. | 655 | in the page. |
643 | 656 | ||
657 | owner filter:: | ||
658 | This filter is given no arguments. The owner text is avilable on | ||
659 | standard input and the filter is expected to write to standard | ||
660 | output. The output is included in the Owner column. | ||
661 | |||
644 | source filter:: | 662 | source filter:: |
645 | This filter is given a single parameter: the filename of the source | 663 | This filter is given a single parameter: the filename of the source |
646 | file to filter. The filter can use the filename to determine (for | 664 | 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) | |||
38 | reap_filter(ctx.cfg.commit_filter); | 38 | reap_filter(ctx.cfg.commit_filter); |
39 | reap_filter(ctx.cfg.source_filter); | 39 | reap_filter(ctx.cfg.source_filter); |
40 | reap_filter(ctx.cfg.email_filter); | 40 | reap_filter(ctx.cfg.email_filter); |
41 | reap_filter(ctx.cfg.owner_filter); | ||
41 | reap_filter(ctx.cfg.auth_filter); | 42 | reap_filter(ctx.cfg.auth_filter); |
42 | for (i = 0; i < cgit_repolist.count; ++i) { | 43 | for (i = 0; i < cgit_repolist.count; ++i) { |
43 | reap_filter(cgit_repolist.repos[i].about_filter); | 44 | reap_filter(cgit_repolist.repos[i].about_filter); |
44 | reap_filter(cgit_repolist.repos[i].commit_filter); | 45 | reap_filter(cgit_repolist.repos[i].commit_filter); |
45 | reap_filter(cgit_repolist.repos[i].source_filter); | 46 | reap_filter(cgit_repolist.repos[i].source_filter); |
46 | reap_filter(cgit_repolist.repos[i].email_filter); | 47 | reap_filter(cgit_repolist.repos[i].email_filter); |
48 | reap_filter(cgit_repolist.repos[i].owner_filter); | ||
47 | } | 49 | } |
48 | } | 50 | } |
49 | 51 | ||
@@ -425,6 +427,10 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype) | |||
425 | argument_count = 2; | 427 | argument_count = 2; |
426 | break; | 428 | break; |
427 | 429 | ||
430 | case OWNER: | ||
431 | argument_count = 0; | ||
432 | break; | ||
433 | |||
428 | case SOURCE: | 434 | case SOURCE: |
429 | case ABOUT: | 435 | case ABOUT: |
430 | argument_count = 1; | 436 | 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 @@ | |||
1 | -- This script is an example of an owner-filter. It replaces the | ||
2 | -- usual query link with one to a fictional homepage. This script may | ||
3 | -- be used with the owner-filter or repo.owner-filter settings in | ||
4 | -- cgitrc with the `lua:` prefix. | ||
5 | |||
6 | function filter_open() | ||
7 | buffer = "" | ||
8 | end | ||
9 | |||
10 | function filter_close() | ||
11 | html(string.format("<a href=\"%s\">%s</a>", "http://wiki.example.com/about/" .. buffer, buffer)) | ||
12 | return 0 | ||
13 | end | ||
14 | |||
15 | function filter_write(str) | ||
16 | buffer = buffer .. str | ||
17 | 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) | |||
72 | ret->commit_filter = ctx.cfg.commit_filter; | 72 | ret->commit_filter = ctx.cfg.commit_filter; |
73 | ret->source_filter = ctx.cfg.source_filter; | 73 | ret->source_filter = ctx.cfg.source_filter; |
74 | ret->email_filter = ctx.cfg.email_filter; | 74 | ret->email_filter = ctx.cfg.email_filter; |
75 | ret->owner_filter = ctx.cfg.owner_filter; | ||
75 | ret->clone_url = ctx.cfg.clone_url; | 76 | ret->clone_url = ctx.cfg.clone_url; |
76 | ret->submodules.strdup_strings = 1; | 77 | ret->submodules.strdup_strings = 1; |
77 | return ret; | 78 | return ret; |
diff --git a/ui-repolist.c b/ui-repolist.c index 49c991f..f929cb7 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -307,13 +307,19 @@ void cgit_print_repolist() | |||
307 | html_link_close(); | 307 | html_link_close(); |
308 | html("</td><td>"); | 308 | html("</td><td>"); |
309 | if (ctx.cfg.enable_index_owner) { | 309 | if (ctx.cfg.enable_index_owner) { |
310 | html("<a href='"); | 310 | if (ctx.repo->owner_filter) { |
311 | html_attr(cgit_rooturl()); | 311 | cgit_open_filter(ctx.repo->owner_filter); |
312 | html("?q="); | 312 | html_txt(ctx.repo->owner); |
313 | html_url_arg(ctx.repo->owner); | 313 | cgit_close_filter(ctx.repo->owner_filter); |
314 | html("'>"); | 314 | } else { |
315 | html_txt(ctx.repo->owner); | 315 | html("<a href='"); |
316 | html("</a>"); | 316 | html_attr(cgit_rooturl()); |
317 | html("?="); | ||
318 | html_url_arg(ctx.repo->owner); | ||
319 | html("'>"); | ||
320 | html_txt(ctx.repo->owner); | ||
321 | html("</a>"); | ||
322 | } | ||
317 | html("</td><td>"); | 323 | html("</td><td>"); |
318 | } | 324 | } |
319 | print_modtime(ctx.repo); | 325 | print_modtime(ctx.repo); |