mirror of
https://git.zx2c4.com/cgit
synced 2024-11-22 00:18:41 +00:00
filter: add support for email filter
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
800380dde7
commit
a5e1553726
6
cgit.c
6
cgit.c
@ -89,6 +89,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
|
|||||||
repo->commit_filter = cgit_new_filter(value, COMMIT);
|
repo->commit_filter = cgit_new_filter(value, COMMIT);
|
||||||
else if (!strcmp(name, "source-filter"))
|
else if (!strcmp(name, "source-filter"))
|
||||||
repo->source_filter = cgit_new_filter(value, SOURCE);
|
repo->source_filter = cgit_new_filter(value, SOURCE);
|
||||||
|
else if (!strcmp(name, "email-filter"))
|
||||||
|
repo->email_filter = cgit_new_filter(value, EMAIL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,6 +190,8 @@ static void config_cb(const char *name, const char *value)
|
|||||||
ctx.cfg.about_filter = cgit_new_filter(value, ABOUT);
|
ctx.cfg.about_filter = cgit_new_filter(value, ABOUT);
|
||||||
else if (!strcmp(name, "commit-filter"))
|
else if (!strcmp(name, "commit-filter"))
|
||||||
ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT);
|
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, "embedded"))
|
else if (!strcmp(name, "embedded"))
|
||||||
ctx.cfg.embedded = atoi(value);
|
ctx.cfg.embedded = atoi(value);
|
||||||
else if (!strcmp(name, "max-atom-items"))
|
else if (!strcmp(name, "max-atom-items"))
|
||||||
@ -711,6 +715,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
|
|||||||
cgit_fprintf_filter(repo->commit_filter, f, "repo.commit-filter=");
|
cgit_fprintf_filter(repo->commit_filter, f, "repo.commit-filter=");
|
||||||
if (repo->source_filter && repo->source_filter != ctx.cfg.source_filter)
|
if (repo->source_filter && repo->source_filter != ctx.cfg.source_filter)
|
||||||
cgit_fprintf_filter(repo->source_filter, f, "repo.source-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->snapshots != ctx.cfg.snapshots) {
|
if (repo->snapshots != ctx.cfg.snapshots) {
|
||||||
char *tmp = build_snapshot_setting(repo->snapshots);
|
char *tmp = build_snapshot_setting(repo->snapshots);
|
||||||
fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
|
fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
|
||||||
|
4
cgit.h
4
cgit.h
@ -53,7 +53,7 @@ typedef void (*filepair_fn)(struct diff_filepair *pair);
|
|||||||
typedef void (*linediff_fn)(char *line, int len);
|
typedef void (*linediff_fn)(char *line, int len);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ABOUT, COMMIT, SOURCE
|
ABOUT, COMMIT, SOURCE, EMAIL
|
||||||
} filter_type;
|
} filter_type;
|
||||||
|
|
||||||
struct cgit_filter {
|
struct cgit_filter {
|
||||||
@ -99,6 +99,7 @@ struct cgit_repo {
|
|||||||
struct cgit_filter *about_filter;
|
struct cgit_filter *about_filter;
|
||||||
struct cgit_filter *commit_filter;
|
struct cgit_filter *commit_filter;
|
||||||
struct cgit_filter *source_filter;
|
struct cgit_filter *source_filter;
|
||||||
|
struct cgit_filter *email_filter;
|
||||||
struct string_list submodules;
|
struct string_list submodules;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -250,6 +251,7 @@ struct cgit_config {
|
|||||||
struct cgit_filter *about_filter;
|
struct cgit_filter *about_filter;
|
||||||
struct cgit_filter *commit_filter;
|
struct cgit_filter *commit_filter;
|
||||||
struct cgit_filter *source_filter;
|
struct cgit_filter *source_filter;
|
||||||
|
struct cgit_filter *email_filter;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cgit_page {
|
struct cgit_page {
|
||||||
|
18
cgitrc.5.txt
18
cgitrc.5.txt
@ -117,6 +117,14 @@ css::
|
|||||||
Url which specifies the css document to include in all cgit pages.
|
Url which specifies the css document to include in all cgit pages.
|
||||||
Default value: "/cgit.css".
|
Default value: "/cgit.css".
|
||||||
|
|
||||||
|
email-filter::
|
||||||
|
Specifies a command which will be invoked to format names and email
|
||||||
|
address of committers, authors, and taggers, as represented in various
|
||||||
|
places throughout the cgit interface. This command will receive an
|
||||||
|
email address as its only command line argument, and the text to
|
||||||
|
format on STDIN. It is to write the formatted text back 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
|
||||||
suitable for embedding in other html pages. Default value: none. See
|
suitable for embedding in other html pages. Default value: none. See
|
||||||
@ -457,6 +465,10 @@ repo.defbranch::
|
|||||||
repo.desc::
|
repo.desc::
|
||||||
The value to show as repository description. Default value: none.
|
The value to show as repository description. Default value: none.
|
||||||
|
|
||||||
|
repo.email-filter::
|
||||||
|
Override the default email-filter. Default value: none. See also:
|
||||||
|
"enable-filter-overrides". See also: "FILTER API".
|
||||||
|
|
||||||
repo.enable-commit-graph::
|
repo.enable-commit-graph::
|
||||||
A flag which can be used to disable the global setting
|
A flag which can be used to disable the global setting
|
||||||
`enable-commit-graph'. Default value: none.
|
`enable-commit-graph'. Default value: none.
|
||||||
@ -607,6 +619,12 @@ commit filter::
|
|||||||
be filtered is available on standard input and the filtered text is
|
be filtered is available on standard input and the filtered text is
|
||||||
expected on standard output.
|
expected on standard output.
|
||||||
|
|
||||||
|
email filter::
|
||||||
|
This filter is given a single parameter: the email address of the
|
||||||
|
relevent user. The filter will then receive the text string to format
|
||||||
|
on standard input and is 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
|
||||||
file to filter. The filter can use the filename to determine (for
|
file to filter. The filter can use the filename to determine (for
|
||||||
|
3
filter.c
3
filter.c
@ -37,10 +37,12 @@ void cgit_cleanup_filters(void)
|
|||||||
reap_filter(ctx.cfg.about_filter);
|
reap_filter(ctx.cfg.about_filter);
|
||||||
reap_filter(ctx.cfg.commit_filter);
|
reap_filter(ctx.cfg.commit_filter);
|
||||||
reap_filter(ctx.cfg.source_filter);
|
reap_filter(ctx.cfg.source_filter);
|
||||||
|
reap_filter(ctx.cfg.email_filter);
|
||||||
for (i = 0; i < cgit_repolist.count; ++i) {
|
for (i = 0; i < cgit_repolist.count; ++i) {
|
||||||
reap_filter(cgit_repolist.repos[i].about_filter);
|
reap_filter(cgit_repolist.repos[i].about_filter);
|
||||||
reap_filter(cgit_repolist.repos[i].commit_filter);
|
reap_filter(cgit_repolist.repos[i].commit_filter);
|
||||||
reap_filter(cgit_repolist.repos[i].source_filter);
|
reap_filter(cgit_repolist.repos[i].source_filter);
|
||||||
|
reap_filter(cgit_repolist.repos[i].email_filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,6 +405,7 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
|
|||||||
colon = NULL;
|
colon = NULL;
|
||||||
|
|
||||||
switch (filtertype) {
|
switch (filtertype) {
|
||||||
|
case EMAIL:
|
||||||
case SOURCE:
|
case SOURCE:
|
||||||
case ABOUT:
|
case ABOUT:
|
||||||
argument_count = 1;
|
argument_count = 1;
|
||||||
|
1
shared.c
1
shared.c
@ -71,6 +71,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
|
|||||||
ret->about_filter = ctx.cfg.about_filter;
|
ret->about_filter = ctx.cfg.about_filter;
|
||||||
ret->commit_filter = ctx.cfg.commit_filter;
|
ret->commit_filter = ctx.cfg.commit_filter;
|
||||||
ret->source_filter = ctx.cfg.source_filter;
|
ret->source_filter = ctx.cfg.source_filter;
|
||||||
|
ret->email_filter = ctx.cfg.email_filter;
|
||||||
ret->clone_url = ctx.cfg.clone_url;
|
ret->clone_url = ctx.cfg.clone_url;
|
||||||
ret->submodules.strdup_strings = 1;
|
ret->submodules.strdup_strings = 1;
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -44,20 +44,24 @@ 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);
|
||||||
html_txt(info->author);
|
html_txt(info->author);
|
||||||
if (!ctx.cfg.noplainemail) {
|
if (!ctx.cfg.noplainemail) {
|
||||||
html(" ");
|
html(" ");
|
||||||
html_txt(info->author_email);
|
html_txt(info->author_email);
|
||||||
}
|
}
|
||||||
|
cgit_close_filter(ctx.repo->email_filter);
|
||||||
html("</td><td class='right'>");
|
html("</td><td class='right'>");
|
||||||
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);
|
||||||
html_txt(info->committer);
|
html_txt(info->committer);
|
||||||
if (!ctx.cfg.noplainemail) {
|
if (!ctx.cfg.noplainemail) {
|
||||||
html(" ");
|
html(" ");
|
||||||
html_txt(info->committer_email);
|
html_txt(info->committer_email);
|
||||||
}
|
}
|
||||||
|
cgit_close_filter(ctx.repo->email_filter);
|
||||||
html("</td><td class='right'>");
|
html("</td><td class='right'>");
|
||||||
cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
|
cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
|
||||||
html("</td></tr>\n");
|
html("</td></tr>\n");
|
||||||
|
2
ui-log.c
2
ui-log.c
@ -168,7 +168,9 @@ 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);
|
||||||
html_txt(info->author);
|
html_txt(info->author);
|
||||||
|
cgit_close_filter(ctx.repo->email_filter);
|
||||||
|
|
||||||
if (revs->graph) {
|
if (revs->graph) {
|
||||||
html("</td><td>");
|
html("</td><td>");
|
||||||
|
@ -77,7 +77,9 @@ 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);
|
||||||
html_txt(info->author);
|
html_txt(info->author);
|
||||||
|
cgit_close_filter(ctx.repo->email_filter);
|
||||||
html("</td><td colspan='2'>");
|
html("</td><td colspan='2'>");
|
||||||
cgit_print_age(info->commit->date, -1, NULL);
|
cgit_print_age(info->commit->date, -1, NULL);
|
||||||
} else {
|
} else {
|
||||||
@ -154,10 +156,15 @@ static int print_tag(struct refinfo *ref)
|
|||||||
cgit_object_link(obj);
|
cgit_object_link(obj);
|
||||||
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);
|
||||||
html_txt(info->tagger);
|
html_txt(info->tagger);
|
||||||
|
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);
|
||||||
html_txt(ref->commit->author);
|
html_txt(ref->commit->author);
|
||||||
|
cgit_close_filter(ctx.repo->email_filter);
|
||||||
}
|
}
|
||||||
html("</td><td colspan='2'>");
|
html("</td><td colspan='2'>");
|
||||||
if (info) {
|
if (info) {
|
||||||
|
2
ui-tag.c
2
ui-tag.c
@ -77,11 +77,13 @@ 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);
|
||||||
html_txt(info->tagger);
|
html_txt(info->tagger);
|
||||||
if (info->tagger_email && !ctx.cfg.noplainemail) {
|
if (info->tagger_email && !ctx.cfg.noplainemail) {
|
||||||
html(" ");
|
html(" ");
|
||||||
html_txt(info->tagger_email);
|
html_txt(info->tagger_email);
|
||||||
}
|
}
|
||||||
|
cgit_close_filter(ctx.repo->email_filter);
|
||||||
html("</td></tr>\n");
|
html("</td></tr>\n");
|
||||||
}
|
}
|
||||||
html("<tr><td>tagged object</td><td class='sha1'>");
|
html("<tr><td>tagged object</td><td class='sha1'>");
|
||||||
|
Loading…
Reference in New Issue
Block a user