Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Print each person through one helper
The log, refs and tag pages no longer open a filter of their own, so they stop including filter.h.
-rw-r--r--source/ui-commit.c19
-rw-r--r--source/ui-log.c5
-rw-r--r--source/ui-refs.c22
-rw-r--r--source/ui-shared.c12
-rw-r--r--source/ui-shared.h7
-rw-r--r--source/ui-tag.c9
6 files changed, 30 insertions, 44 deletions
diff --git a/source/ui-commit.c b/source/ui-commit.c
index 4882f3a..8e88faf 100644
--- a/source/ui-commit.c
+++ b/source/ui-commit.c
@@ -30,13 +30,7 @@ static void print_ident_row(const char *role, const char *name, const char *emai
timestamp_t date, int tz)
{
htmlf("<tr><th scope='row'>%s</th><td>", role);
- cgit_open_filter(ctx.repo->email_filter, email ? email : "", "commit");
- html_txt(name);
- if (ctx.cfg.enable_plain_email) {
- html(" ");
- html_txt(email);
- }
- cgit_close_filter(ctx.repo->email_filter);
+ cgit_print_person(name, email, "commit", 1);
html("</td><td class='right'><time datetime='");
html_attr(show_date(date, tz, cgit_date_mode(DATE_ISO8601_STRICT)));
html("'>");
@@ -104,6 +98,7 @@ static void print_trailer_value(const char *key, const char *value)
struct string_list *map;
struct strbuf email = STRBUF_INIT;
const char *name, *mail, *rest;
+ char *who;
size_t name_len, mail_len;
if (!split_ident_line(&ident, value, strlen(value)) &&
@@ -118,13 +113,9 @@ static void print_trailer_value(const char *key, const char *value)
strbuf_addch(&email, '<');
strbuf_add(&email, mail, mail_len);
strbuf_addch(&email, '>');
- cgit_open_filter(ctx.repo->email_filter, email.buf, "commit");
- html_ntxt(name, name_len);
- if (ctx.cfg.enable_plain_email) {
- html(" ");
- html_txt(email.buf);
- }
- cgit_close_filter(ctx.repo->email_filter);
+ who = xmemdupz(name, name_len);
+ cgit_print_person(who, email.buf, "commit", 1);
+ free(who);
strbuf_release(&email);
rest = ident.mail_end + 1;
while (isspace((unsigned char)*rest))
diff --git a/source/ui-log.c b/source/ui-log.c
index 128c01f..2211aa0 100644
--- a/source/ui-log.c
+++ b/source/ui-log.c
@@ -11,7 +11,6 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "cgit.h"
-#include "filter.h"
#include "html.h"
#include "parsing.h"
#include "shared.h"
@@ -256,9 +255,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs, int colum
oid_to_hex(&commit->object.oid), ctx.qry.vpath);
cgit_print_commit_decorations(commit);
html("</td><td class='col-author'>");
- cgit_open_filter(ctx.repo->email_filter, info->author_email ? info->author_email : "", "log");
- html_txt(info->author);
- cgit_close_filter(ctx.repo->email_filter);
+ cgit_print_person(info->author, info->author_email, "log", 0);
if (revs->graph) {
html("</td><td>");
diff --git a/source/ui-refs.c b/source/ui-refs.c
index 9bf5d2d..69a2cc1 100644
--- a/source/ui-refs.c
+++ b/source/ui-refs.c
@@ -10,7 +10,6 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "cgit.h"
-#include "filter.h"
#include "html.h"
#include "parsing.h"
#include "ui-refs.h"
@@ -188,12 +187,7 @@ static void print_branch(struct refinfo *ref, int columns)
if (ref->object->type == OBJ_COMMIT) {
cgit_commit_link(info->subject, NULL, NULL, name, NULL, NULL);
html("</td><td class='col-author'>");
- // A filter must not be handed a NULL argument.
- cgit_open_filter(
- ctx.repo->email_filter, info->author_email ? info->author_email : "", "refs"
- );
- html_txt(info->author);
- cgit_close_filter(ctx.repo->email_filter);
+ cgit_print_person(info->author, info->author_email, "refs", 0);
htmlf("</td><td%s>", age_colspan(columns));
cgit_print_age(info->committer_date, info->committer_tz, -1);
} else {
@@ -249,18 +243,10 @@ static void print_tag(struct refinfo *ref, int columns)
cgit_object_link(obj, 0);
html("</td><td class='col-author'>");
if (info) {
- if (info->tagger) {
- cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "refs");
- html_txt(info->tagger);
- cgit_close_filter(ctx.repo->email_filter);
- }
+ if (info->tagger)
+ cgit_print_person(info->tagger, info->tagger_email, "refs", 0);
} else if (ref->object->type == OBJ_COMMIT) {
- cgit_open_filter(
- ctx.repo->email_filter, ref->commit->author_email ? ref->commit->author_email : "",
- "refs"
- );
- html_txt(ref->commit->author);
- cgit_close_filter(ctx.repo->email_filter);
+ cgit_print_person(ref->commit->author, ref->commit->author_email, "refs", 0);
}
htmlf("</td><td%s>", age_colspan(columns));
if (info) {
diff --git a/source/ui-shared.c b/source/ui-shared.c
index fc4e559..8c5e4e5 100644
--- a/source/ui-shared.c
+++ b/source/ui-shared.c
@@ -11,6 +11,7 @@
#include "cache.h"
#include "cgit.h"
+#include "filter.h"
#include "html.h"
#include "shared.h"
#include "submodule-config.h"
@@ -1307,6 +1308,17 @@ void cgit_print_age(time_t t, int tz, time_t max_relative)
print_rel_date(t, tz, secs * 1.0 / SECONDS_PER_YEAR, "age-years", "years");
}
+void cgit_print_person(const char *name, const char *email, const char *origin, int show_email)
+{
+ cgit_open_filter(ctx.repo->email_filter, email ? email : "", origin);
+ html_txt(name);
+ if (show_email && email && ctx.cfg.enable_plain_email) {
+ html(" ");
+ html_txt(email);
+ }
+ cgit_close_filter(ctx.repo->email_filter);
+}
+
/*
* Whether a content type carries text a charset applies to, which is every
* text type and the XML types of RFC 7303, the atom feed among them.
diff --git a/source/ui-shared.h b/source/ui-shared.h
index 87f9c60..6b58ab3 100644
--- a/source/ui-shared.h
+++ b/source/ui-shared.h
@@ -107,6 +107,13 @@ extern struct date_mode cgit_date_mode(enum date_mode_type type);
* relative dates off gets the date either way.
*/
extern void cgit_print_age(time_t t, int tz, time_t max_relative);
+
+/*
+ * Print name through the email filter, followed by the address when
+ * show_email is set and enable-plain-email is on. A missing address reaches
+ * the filter as an empty string, since a filter must not be handed NULL.
+ */
+extern void cgit_print_person(const char *name, const char *email, const char *origin, int show_email);
extern void cgit_print_http_headers(void);
/*
* Answer with a redirect to url, followed by query when one is given. Both
diff --git a/source/ui-tag.c b/source/ui-tag.c
index 04cbb8b..66ddf66 100644
--- a/source/ui-tag.c
+++ b/source/ui-tag.c
@@ -10,7 +10,6 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "cgit.h"
-#include "filter.h"
#include "html.h"
#include "parsing.h"
#include "ui-shared.h"
@@ -37,13 +36,7 @@ static void print_date_row(struct taginfo *info)
static void print_tagger_row(struct taginfo *info)
{
html("<tr><th scope='row'>tagged by</th><td>");
- cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "tag");
- html_txt(info->tagger);
- if (ctx.cfg.enable_plain_email) {
- html(" ");
- html_txt(info->tagger_email);
- }
- cgit_close_filter(ctx.repo->email_filter);
+ cgit_print_person(info->tagger, info->tagger_email, "tag", 1);
html("</td></tr>\n");
}