filter: add page source to email filter

Since the email filter is called from lots of places, the script might
benefit from knowing the origin. That way it can modify its contents
and/or size depending.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2014-01-13 16:24:40 +01:00
والد e942a1622b
کامیت 786609bd36
8فایلهای تغییر یافته به همراه21 افزوده شده و 15 حذف شده

مشاهده پرونده

@ -121,9 +121,9 @@ email-filter::
Specifies a command which will be invoked to format names and email Specifies a command which will be invoked to format names and email
address of committers, authors, and taggers, as represented in various address of committers, authors, and taggers, as represented in various
places throughout the cgit interface. This command will receive an places throughout the cgit interface. This command will receive an
email address as its only command line argument, and the text to email address and an origin page string as its command line arguments,
format on STDIN. It is to write the formatted text back out onto and the text to format on STDIN. It is to write the formatted text back
STDOUT. Default value: none. See also: "FILTER API". out onto STDOUT. Default value: none. See also: "FILTER API".
embedded:: embedded::
Flag which, when set to "1", will make cgit generate a html fragment Flag which, when set to "1", will make cgit generate a html fragment
@ -620,10 +620,11 @@ commit filter::
expected on standard output. expected on standard output.
email filter:: email filter::
This filter is given a single parameter: the email address of the This filter is given two parameters: the email address of the relevent
relevent user. The filter will then receive the text string to format author and a string indicating the originating page. The filter will
on standard input and is expected to write to standard output the then receive the text string to format on standard input and is
formatted text to be included in the page. expected to write to standard output the formatted text to be included
in the page.
source filter:: source filter::
This filter is given a single parameter: the filename of the source This filter is given a single parameter: the filename of the source

مشاهده پرونده

@ -406,6 +406,9 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
switch (filtertype) { switch (filtertype) {
case EMAIL: case EMAIL:
argument_count = 2;
break;
case SOURCE: case SOURCE:
case ABOUT: case ABOUT:
argument_count = 1; argument_count = 1;

مشاهده پرونده

@ -9,7 +9,7 @@
require("crypto") require("crypto")
function filter_open(email) function filter_open(email, page)
buffer = "" buffer = ""
md5 = crypto.digest("md5", email:sub(2, -2):lower()) md5 = crypto.digest("md5", email:sub(2, -2):lower())
end end

مشاهده پرونده

@ -27,6 +27,8 @@ if email[0] == '<':
if email[-1] == '>': if email[-1] == '>':
email = email[0:-1] email = email[0:-1]
page = sys.argv[2]
md5 = hashlib.md5(email.encode()).hexdigest() md5 = hashlib.md5(email.encode()).hexdigest()
text = sys.stdin.read().strip() text = sys.stdin.read().strip()

مشاهده پرونده

@ -44,7 +44,7 @@ void cgit_print_commit(char *hex, const char *prefix)
cgit_print_diff_ctrls(); cgit_print_diff_ctrls();
html("<table summary='commit info' class='commit-info'>\n"); html("<table summary='commit info' class='commit-info'>\n");
html("<tr><th>author</th><td>"); html("<tr><th>author</th><td>");
cgit_open_filter(ctx.repo->email_filter, info->author_email); cgit_open_filter(ctx.repo->email_filter, info->author_email, "commit");
html_txt(info->author); html_txt(info->author);
if (!ctx.cfg.noplainemail) { if (!ctx.cfg.noplainemail) {
html(" "); html(" ");
@ -55,7 +55,7 @@ void cgit_print_commit(char *hex, const char *prefix)
cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time); cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
html("</td></tr>\n"); html("</td></tr>\n");
html("<tr><th>committer</th><td>"); html("<tr><th>committer</th><td>");
cgit_open_filter(ctx.repo->email_filter, info->committer_email); cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit");
html_txt(info->committer); html_txt(info->committer);
if (!ctx.cfg.noplainemail) { if (!ctx.cfg.noplainemail) {
html(" "); html(" ");

مشاهده پرونده

@ -168,7 +168,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs)
sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0); sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0);
show_commit_decorations(commit); show_commit_decorations(commit);
html("</td><td>"); html("</td><td>");
cgit_open_filter(ctx.repo->email_filter, info->author_email); cgit_open_filter(ctx.repo->email_filter, info->author_email, "log");
html_txt(info->author); html_txt(info->author);
cgit_close_filter(ctx.repo->email_filter); cgit_close_filter(ctx.repo->email_filter);

مشاهده پرونده

@ -77,7 +77,7 @@ static int print_branch(struct refinfo *ref)
if (ref->object->type == OBJ_COMMIT) { if (ref->object->type == OBJ_COMMIT) {
cgit_commit_link(info->subject, NULL, NULL, name, NULL, NULL, 0); cgit_commit_link(info->subject, NULL, NULL, name, NULL, NULL, 0);
html("</td><td>"); html("</td><td>");
cgit_open_filter(ctx.repo->email_filter, info->author_email); cgit_open_filter(ctx.repo->email_filter, info->author_email, "refs");
html_txt(info->author); html_txt(info->author);
cgit_close_filter(ctx.repo->email_filter); cgit_close_filter(ctx.repo->email_filter);
html("</td><td colspan='2'>"); html("</td><td colspan='2'>");
@ -157,12 +157,12 @@ static int print_tag(struct refinfo *ref)
html("</td><td>"); html("</td><td>");
if (info) { if (info) {
if (info->tagger) { if (info->tagger) {
cgit_open_filter(ctx.repo->email_filter, info->tagger_email); cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "refs");
html_txt(info->tagger); html_txt(info->tagger);
cgit_close_filter(ctx.repo->email_filter); cgit_close_filter(ctx.repo->email_filter);
} }
} else if (ref->object->type == OBJ_COMMIT) { } else if (ref->object->type == OBJ_COMMIT) {
cgit_open_filter(ctx.repo->email_filter, ref->commit->author_email); cgit_open_filter(ctx.repo->email_filter, ref->commit->author_email, "refs");
html_txt(ref->commit->author); html_txt(ref->commit->author);
cgit_close_filter(ctx.repo->email_filter); cgit_close_filter(ctx.repo->email_filter);
} }

مشاهده پرونده

@ -77,7 +77,7 @@ void cgit_print_tag(char *revname)
} }
if (info->tagger) { if (info->tagger) {
html("<tr><td>tagged by</td><td>"); html("<tr><td>tagged by</td><td>");
cgit_open_filter(ctx.repo->email_filter, info->tagger_email); cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "tag");
html_txt(info->tagger); html_txt(info->tagger);
if (info->tagger_email && !ctx.cfg.noplainemail) { if (info->tagger_email && !ctx.cfg.noplainemail) {
html(" "); html(" ");