aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jason A. Donenfeld <Jason@zx2c4.com>2014-01-13 12:04:52 (JST)
committerGravatar Jason A. Donenfeld <Jason@zx2c4.com>2014-01-14 10:00:07 (JST)
commita5e15537268410e268c7b26aa69d03b347c326c8 (patch)
tree77f42b7f03788d4741bfd60b49719fbc649181ff
parent800380dde797ae35d738a644acdae2fabb9a0d44 (diff)
downloadcgit-a5e15537268410e268c7b26aa69d03b347c326c8.zip
cgit-a5e15537268410e268c7b26aa69d03b347c326c8.tar.gz
filter: add support for email filter
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--cgit.c6
-rw-r--r--cgit.h4
-rw-r--r--cgitrc.5.txt18
-rw-r--r--filter.c3
-rw-r--r--shared.c1
-rw-r--r--ui-commit.c4
-rw-r--r--ui-log.c2
-rw-r--r--ui-refs.c9
-rw-r--r--ui-tag.c2
9 files changed, 47 insertions, 2 deletions
diff --git a/cgit.c b/cgit.c
index 725fd65..f3fe56b 100644
--- a/cgit.c
+++ b/cgit.c
@@ -89,6 +89,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
89 repo->commit_filter = cgit_new_filter(value, COMMIT); 89 repo->commit_filter = cgit_new_filter(value, COMMIT);
90 else if (!strcmp(name, "source-filter")) 90 else if (!strcmp(name, "source-filter"))
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"))
93 repo->email_filter = cgit_new_filter(value, EMAIL);
92 } 94 }
93} 95}
94 96
@@ -188,6 +190,8 @@ static void config_cb(const char *name, const char *value)
188 ctx.cfg.about_filter = cgit_new_filter(value, ABOUT); 190 ctx.cfg.about_filter = cgit_new_filter(value, ABOUT);
189 else if (!strcmp(name, "commit-filter")) 191 else if (!strcmp(name, "commit-filter"))
190 ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT); 192 ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT);
193 else if (!strcmp(name, "email-filter"))
194 ctx.cfg.email_filter = cgit_new_filter(value, EMAIL);
191 else if (!strcmp(name, "embedded")) 195 else if (!strcmp(name, "embedded"))
192 ctx.cfg.embedded = atoi(value); 196 ctx.cfg.embedded = atoi(value);
193 else if (!strcmp(name, "max-atom-items")) 197 else if (!strcmp(name, "max-atom-items"))
@@ -711,6 +715,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
711 cgit_fprintf_filter(repo->commit_filter, f, "repo.commit-filter="); 715 cgit_fprintf_filter(repo->commit_filter, f, "repo.commit-filter=");
712 if (repo->source_filter && repo->source_filter != ctx.cfg.source_filter) 716 if (repo->source_filter && repo->source_filter != ctx.cfg.source_filter)
713 cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter="); 717 cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter=");
718 if (repo->email_filter && repo->email_filter != ctx.cfg.email_filter)
719 cgit_fprintf_filter(repo->email_filter, f, "repo.email-filter=");
714 if (repo->snapshots != ctx.cfg.snapshots) { 720 if (repo->snapshots != ctx.cfg.snapshots) {
715 char *tmp = build_snapshot_setting(repo->snapshots); 721 char *tmp = build_snapshot_setting(repo->snapshots);
716 fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : ""); 722 fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
diff --git a/cgit.h b/cgit.h
index 519d2af..e200a06 100644
--- a/cgit.h
+++ b/cgit.h
@@ -53,7 +53,7 @@ typedef void (*filepair_fn)(struct diff_filepair *pair);
53typedef void (*linediff_fn)(char *line, int len); 53typedef void (*linediff_fn)(char *line, int len);
54 54
55typedef enum { 55typedef enum {
56 ABOUT, COMMIT, SOURCE 56 ABOUT, COMMIT, SOURCE, EMAIL
57} filter_type; 57} filter_type;
58 58
59struct cgit_filter { 59struct cgit_filter {
@@ -99,6 +99,7 @@ struct cgit_repo {
99 struct cgit_filter *about_filter; 99 struct cgit_filter *about_filter;
100 struct cgit_filter *commit_filter; 100 struct cgit_filter *commit_filter;
101 struct cgit_filter *source_filter; 101 struct cgit_filter *source_filter;
102 struct cgit_filter *email_filter;
102 struct string_list submodules; 103 struct string_list submodules;
103}; 104};
104 105
@@ -250,6 +251,7 @@ struct cgit_config {
250 struct cgit_filter *about_filter; 251 struct cgit_filter *about_filter;
251 struct cgit_filter *commit_filter; 252 struct cgit_filter *commit_filter;
252 struct cgit_filter *source_filter; 253 struct cgit_filter *source_filter;
254 struct cgit_filter *email_filter;
253}; 255};
254 256
255struct cgit_page { 257struct cgit_page {
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 78f33c8..b7dc5a4 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -117,6 +117,14 @@ css::
117 Url which specifies the css document to include in all cgit pages. 117 Url which specifies the css document to include in all cgit pages.
118 Default value: "/cgit.css". 118 Default value: "/cgit.css".
119 119
120email-filter::
121 Specifies a command which will be invoked to format names and email
122 address of committers, authors, and taggers, as represented in various
123 places throughout the cgit interface. This command will receive an
124 email address as its only command line argument, and the text to
125 format on STDIN. It is to write the formatted text back out onto
126 STDOUT. Default value: none. See also: "FILTER API".
127
120embedded:: 128embedded::
121 Flag which, when set to "1", will make cgit generate a html fragment 129 Flag which, when set to "1", will make cgit generate a html fragment
122 suitable for embedding in other html pages. Default value: none. See 130 suitable for embedding in other html pages. Default value: none. See
@@ -457,6 +465,10 @@ repo.defbranch::
457repo.desc:: 465repo.desc::
458 The value to show as repository description. Default value: none. 466 The value to show as repository description. Default value: none.
459 467
468repo.email-filter::
469 Override the default email-filter. Default value: none. See also:
470 "enable-filter-overrides". See also: "FILTER API".
471
460repo.enable-commit-graph:: 472repo.enable-commit-graph::
461 A flag which can be used to disable the global setting 473 A flag which can be used to disable the global setting
462 `enable-commit-graph'. Default value: none. 474 `enable-commit-graph'. Default value: none.
@@ -607,6 +619,12 @@ commit filter::
607 be filtered is available on standard input and the filtered text is 619 be filtered is available on standard input and the filtered text is
608 expected on standard output. 620 expected on standard output.
609 621
622email filter::
623 This filter is given a single parameter: the email address of the
624 relevent user. The filter will then receive the text string to format
625 on standard input and is expected to write to standard output the
626 formatted text to be included in the page.
627
610source filter:: 628source filter::
611 This filter is given a single parameter: the filename of the source 629 This filter is given a single parameter: the filename of the source
612 file to filter. The filter can use the filename to determine (for 630 file to filter. The filter can use the filename to determine (for
diff --git a/filter.c b/filter.c
index 7983737..08ce7a5 100644
--- a/filter.c
+++ b/filter.c
@@ -37,10 +37,12 @@ void cgit_cleanup_filters(void)
37 reap_filter(ctx.cfg.about_filter); 37 reap_filter(ctx.cfg.about_filter);
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 for (i = 0; i < cgit_repolist.count; ++i) { 41 for (i = 0; i < cgit_repolist.count; ++i) {
41 reap_filter(cgit_repolist.repos[i].about_filter); 42 reap_filter(cgit_repolist.repos[i].about_filter);
42 reap_filter(cgit_repolist.repos[i].commit_filter); 43 reap_filter(cgit_repolist.repos[i].commit_filter);
43 reap_filter(cgit_repolist.repos[i].source_filter); 44 reap_filter(cgit_repolist.repos[i].source_filter);
45 reap_filter(cgit_repolist.repos[i].email_filter);
44 } 46 }
45} 47}
46 48
@@ -403,6 +405,7 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
403 colon = NULL; 405 colon = NULL;
404 406
405 switch (filtertype) { 407 switch (filtertype) {
408 case EMAIL:
406 case SOURCE: 409 case SOURCE:
407 case ABOUT: 410 case ABOUT:
408 argument_count = 1; 411 argument_count = 1;
diff --git a/shared.c b/shared.c
index 4626148..7e88bbd 100644
--- a/shared.c
+++ b/shared.c
@@ -71,6 +71,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
71 ret->about_filter = ctx.cfg.about_filter; 71 ret->about_filter = ctx.cfg.about_filter;
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->clone_url = ctx.cfg.clone_url; 75 ret->clone_url = ctx.cfg.clone_url;
75 ret->submodules.strdup_strings = 1; 76 ret->submodules.strdup_strings = 1;
76 return ret; 77 return ret;
diff --git a/ui-commit.c b/ui-commit.c
index 5ac79c0..bd14ef0 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -44,20 +44,24 @@ void cgit_print_commit(char *hex, const char *prefix)
44 cgit_print_diff_ctrls(); 44 cgit_print_diff_ctrls();
45 html("<table summary='commit info' class='commit-info'>\n"); 45 html("<table summary='commit info' class='commit-info'>\n");
46 html("<tr><th>author</th><td>"); 46 html("<tr><th>author</th><td>");
47 cgit_open_filter(ctx.repo->email_filter, info->author_email);
47 html_txt(info->author); 48 html_txt(info->author);
48 if (!ctx.cfg.noplainemail) { 49 if (!ctx.cfg.noplainemail) {
49 html(" "); 50 html(" ");
50 html_txt(info->author_email); 51 html_txt(info->author_email);
51 } 52 }
53 cgit_close_filter(ctx.repo->email_filter);
52 html("</td><td class='right'>"); 54 html("</td><td class='right'>");
53 cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time); 55 cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
54 html("</td></tr>\n"); 56 html("</td></tr>\n");
55 html("<tr><th>committer</th><td>"); 57 html("<tr><th>committer</th><td>");
58 cgit_open_filter(ctx.repo->email_filter, info->committer_email);
56 html_txt(info->committer); 59 html_txt(info->committer);
57 if (!ctx.cfg.noplainemail) { 60 if (!ctx.cfg.noplainemail) {
58 html(" "); 61 html(" ");
59 html_txt(info->committer_email); 62 html_txt(info->committer_email);
60 } 63 }
64 cgit_close_filter(ctx.repo->email_filter);
61 html("</td><td class='right'>"); 65 html("</td><td class='right'>");
62 cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time); 66 cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
63 html("</td></tr>\n"); 67 html("</td></tr>\n");
diff --git a/ui-log.c b/ui-log.c
index 584336a..957d887 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -168,7 +168,9 @@ static void print_commit(struct commit *commit, struct rev_info *revs)
168 sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0); 168 sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0);
169 show_commit_decorations(commit); 169 show_commit_decorations(commit);
170 html("</td><td>"); 170 html("</td><td>");
171 cgit_open_filter(ctx.repo->email_filter, info->author_email);
171 html_txt(info->author); 172 html_txt(info->author);
173 cgit_close_filter(ctx.repo->email_filter);
172 174
173 if (revs->graph) { 175 if (revs->graph) {
174 html("</td><td>"); 176 html("</td><td>");
diff --git a/ui-refs.c b/ui-refs.c
index c97b0c6..d125459 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -77,7 +77,9 @@ static int print_branch(struct refinfo *ref)
77 if (ref->object->type == OBJ_COMMIT) { 77 if (ref->object->type == OBJ_COMMIT) {
78 cgit_commit_link(info->subject, NULL, NULL, name, NULL, NULL, 0); 78 cgit_commit_link(info->subject, NULL, NULL, name, NULL, NULL, 0);
79 html("</td><td>"); 79 html("</td><td>");
80 cgit_open_filter(ctx.repo->email_filter, info->author_email);
80 html_txt(info->author); 81 html_txt(info->author);
82 cgit_close_filter(ctx.repo->email_filter);
81 html("</td><td colspan='2'>"); 83 html("</td><td colspan='2'>");
82 cgit_print_age(info->commit->date, -1, NULL); 84 cgit_print_age(info->commit->date, -1, NULL);
83 } else { 85 } else {
@@ -154,10 +156,15 @@ static int print_tag(struct refinfo *ref)
154 cgit_object_link(obj); 156 cgit_object_link(obj);
155 html("</td><td>"); 157 html("</td><td>");
156 if (info) { 158 if (info) {
157 if (info->tagger) 159 if (info->tagger) {
160 cgit_open_filter(ctx.repo->email_filter, info->tagger_email);
158 html_txt(info->tagger); 161 html_txt(info->tagger);
162 cgit_close_filter(ctx.repo->email_filter);
163 }
159 } else if (ref->object->type == OBJ_COMMIT) { 164 } else if (ref->object->type == OBJ_COMMIT) {
165 cgit_open_filter(ctx.repo->email_filter, ref->commit->author_email);
160 html_txt(ref->commit->author); 166 html_txt(ref->commit->author);
167 cgit_close_filter(ctx.repo->email_filter);
161 } 168 }
162 html("</td><td colspan='2'>"); 169 html("</td><td colspan='2'>");
163 if (info) { 170 if (info) {
diff --git a/ui-tag.c b/ui-tag.c
index ec9c757..adbdb90 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -77,11 +77,13 @@ void cgit_print_tag(char *revname)
77 } 77 }
78 if (info->tagger) { 78 if (info->tagger) {
79 html("<tr><td>tagged by</td><td>"); 79 html("<tr><td>tagged by</td><td>");
80 cgit_open_filter(ctx.repo->email_filter, info->tagger_email);
80 html_txt(info->tagger); 81 html_txt(info->tagger);
81 if (info->tagger_email && !ctx.cfg.noplainemail) { 82 if (info->tagger_email && !ctx.cfg.noplainemail) {
82 html(" "); 83 html(" ");
83 html_txt(info->tagger_email); 84 html_txt(info->tagger_email);
84 } 85 }
86 cgit_close_filter(ctx.repo->email_filter);
85 html("</td></tr>\n"); 87 html("</td></tr>\n");
86 } 88 }
87 html("<tr><td>tagged object</td><td class='sha1'>"); 89 html("<tr><td>tagged object</td><td class='sha1'>");