Re: [PATCH 3/8] Skip forbidden characters.
On Tue, Jul 01, 2014 at 09:40:28AM +0200, zwin...@kit.edu wrote: > From: Sebastian Buchwald Why do we want to do this? Does it not break anything that uses whitespace="pre" (explicitly or implicitly)? > --- > html.c | 9 ++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/html.c b/html.c > index 91047ad..6037eec 100644 > --- a/html.c > +++ b/html.c > @@ -129,7 +129,8 @@ void html_txt(const char *txt) > const char *t = txt; > while (t && *t) { > int c = *t; > - if (c == '<' || c == '>' || c == '&') { > + if ((c < 0x20 && c != '\t' && c != '\n' && c != '\r') > + || (c == '<' || c == '>' || c == '&')) { > html_raw(txt, t - txt); > if (c == '>') > html(">"); > @@ -150,7 +151,8 @@ void html_ntxt(int len, const char *txt) > const char *t = txt; > while (t && *t && len--) { > int c = *t; > - if (c == '<' || c == '>' || c == '&') { > + if ((c < 0x20 && c != '\t' && c != '\n' && c != '\r') > + || (c == '<' || c == '>' || c == '&')) { > html_raw(txt, t - txt); > if (c == '>') > html(">"); > @@ -186,7 +188,8 @@ void html_attr(const char *txt) > const char *t = txt; > while (t && *t) { > int c = *t; > - if (c == '<' || c == '>' || c == '\'' || c == '\"' || c == '&') > { > + if (c == '<' || c == '>' || c == '\'' || c == '\"' || c == '&' > + || (c < 0x20 && c != '\t' && c != '\n' && c != > '\r')) { > html_raw(txt, t - txt); > if (c == '>') > html(">"); ___ CGit mailing list CGit@lists.zx2c4.com http://lists.zx2c4.com/mailman/listinfo/cgit
[PATCH 1/8] Can add diffs to Atom feed entries
From: Andreas Zwinkau Off by default. Set enable-atom-diff flag for repos to enable. Uses HTML5's "scoped CSS" feature to colorize diff deletes and inserts. Mainstream pre-HTML5 engines either ignore this or apply the style document-wide, which should not break anything. As cgit was not prepared to produce multiple diffs per run, so this also reset some counters during the diff. Additionally, the cgit_self_link had to be extended, as it is called during the diffing. --- cgit.c | 7 +++ cgit.h | 2 ++ cgitrc.5.txt| 4 cmd.c | 2 +- shared.c| 1 + tests/t0112-atom.sh | 24 ui-atom.c | 22 +++--- ui-atom.h | 2 +- ui-diff.c | 4 ui-shared.c | 4 10 files changed, 67 insertions(+), 5 deletions(-) create mode 100755 tests/t0112-atom.sh diff --git a/cgit.c b/cgit.c index f488ebf..0b5d9e1 100644 --- a/cgit.c +++ b/cgit.c @@ -45,6 +45,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va repo->defbranch = xstrdup(value); else if (!strcmp(name, "snapshots")) repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); + else if (!strcmp(name, "enable-atom-diff")) + repo->enable_atom_diff = atoi(value); else if (!strcmp(name, "enable-commit-graph")) repo->enable_commit_graph = atoi(value); else if (!strcmp(name, "enable-log-filecount")) @@ -144,6 +146,8 @@ static void config_cb(const char *name, const char *value) ctx.cfg.noheader = atoi(value); else if (!strcmp(name, "snapshots")) ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); + else if (!strcmp(name, "enable-atom-diff")) + ctx.cfg.enable_atom_diff = atoi(value); else if (!strcmp(name, "enable-filter-overrides")) ctx.cfg.enable_filter_overrides = atoi(value); else if (!strcmp(name, "enable-http-clone")) @@ -346,6 +350,7 @@ static void prepare_context(void) ctx.cfg.logo = "/cgit.png"; ctx.cfg.favicon = "/favicon.ico"; ctx.cfg.local_time = 0; + ctx.cfg.enable_atom_diff = 0; ctx.cfg.enable_http_clone = 1; ctx.cfg.enable_index_owner = 1; ctx.cfg.enable_tree_linenumbers = 1; @@ -788,6 +793,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.section=%s\n", repo->section); if (repo->clone_url) fprintf(f, "repo.clone-url=%s\n", repo->clone_url); + fprintf(f, "repo.enable-atom-diff=%d\n", + repo->enable_atom_diff); fprintf(f, "repo.enable-commit-graph=%d\n", repo->enable_commit_graph); fprintf(f, "repo.enable-log-filecount=%d\n", diff --git a/cgit.h b/cgit.h index 0badc64..3db220e 100644 --- a/cgit.h +++ b/cgit.h @@ -87,6 +87,7 @@ struct cgit_repo { char *logo; char *logo_link; int snapshots; + int enable_atom_diff; int enable_commit_graph; int enable_log_filecount; int enable_log_linecount; @@ -213,6 +214,7 @@ struct cgit_config { int cache_snapshot_ttl; int case_sensitive_sort; int embedded; + int enable_atom_diff; int enable_filter_overrides; int enable_http_clone; int enable_index_links; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index b7570db..b729294 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -141,6 +141,10 @@ embedded:: suitable for embedding in other html pages. Default value: none. See also: "noheader". +enable-atom-diff:: + Flag which, when set to "1", will make cgit include a html-escaped diff + within the atom feed commit entries. Default value: "0". + enable-commit-graph:: Flag which, when set to "1", will make cgit print an ASCII-art commit history graph to the left of the commit messages in the repository diff --git a/cmd.c b/cmd.c index 188cd56..3d9f245 100644 --- a/cmd.c +++ b/cmd.c @@ -33,7 +33,7 @@ static void HEAD_fn(void) static void atom_fn(void) { - cgit_print_atom(ctx.qry.head, ctx.qry.path, ctx.cfg.max_atom_items); + cgit_print_atom(ctx.qry.head, ctx.qry.path, ctx.cfg.max_atom_items, ctx.repo->enable_atom_diff); } static void about_fn(void) diff --git a/shared.c b/shared.c index 8ed14c0..6bd82f9 100644 --- a/shared.c +++ b/shared.c @@ -57,6 +57,7 @@ struct cgit_repo *cgit_add_repo(const char *url) ret->owner = NULL; ret->section = ctx.cfg.section; ret->snapshots = ctx.cfg.snapshots; + ret->enable_atom_diff = ctx.cfg.enable_atom_diff; ret->enable_commit_graph = ctx.cfg.enable_commit_graph; ret->enable_log_filecount = ctx.cfg.enable_log_filecount; ret->enable_log_linecount = ctx.cfg.enable_log_linecount; diff --git a/tests/t0112-atom.sh b/tests/t0112-at
[PATCH 7/8] add to atom feed
From: Matthias Braun FEED Validator recommends it. --- ui-atom.c | 11 +++ 1 file changed, 11 insertions(+) diff --git a/ui-atom.c b/ui-atom.c index 4d9ba00..6da3e36 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -150,6 +150,17 @@ void cgit_print_atom(char *tip, char *path, int max_count, int enable_atom_diff) html_attr(cgit_repourl(ctx.repo->url)); html("'/>\n"); + html("\n"); + html(""); html(cgit_httpscheme()); html_txt(host); -- 1.9.1 ___ CGit mailing list CGit@lists.zx2c4.com http://lists.zx2c4.com/mailman/listinfo/cgit
[PATCH 8/8] fix html error in diff output for binary files
From: Matthias Braun --- ui-diff.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ui-diff.c b/ui-diff.c index b80..b7bf777 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -108,6 +108,7 @@ static void print_fileinfo(struct fileinfo *info) if (info->binary) { htmlf("bin%ld -> %ld bytes", info->old_size, info->new_size); + html("\n"); return; } htmlf("%d", info->added + info->removed); -- 1.9.1 ___ CGit mailing list CGit@lists.zx2c4.com http://lists.zx2c4.com/mailman/listinfo/cgit
[PATCH 5/8] display updated, use urn/url for atom:id
From: Matthias Braun --- ui-atom.c | 33 +++-- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/ui-atom.c b/ui-atom.c index fdc5cb3..aa6a188 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -12,15 +12,13 @@ #include "ui-shared.h" #include "ui-diff.h" -static void add_entry(struct commit *commit, const char *host, int enable_atom_diff) +static void add_entry(struct commit *commit, struct commitinfo *info, char *host, int enable_atom_diff) { char delim = '&'; char *hex; char *hex_parent; char *mail, *t, *t2; - struct commitinfo *info; - info = cgit_parse_commit(commit); hex = sha1_to_hex(commit->object.sha1); if (commit->parents) { hex_parent = sha1_to_hex(commit->parents->item->object.sha1); @@ -68,8 +66,15 @@ static void add_entry(struct commit *commit, const char *host, int enable_atom_d delim = '?'; htmlf("%cid=%s", delim, hex); html("'/>\n"); + + html(""); + html(cgit_httpscheme()); + html_attr(host); + html_attr(cgit_repourl(ctx.repo->url)); + htmlf("/commit/?id=%s\n", hex); + } else { + htmlf("urn:tag:%s\n", hex); } - htmlf("%s\n", hex); html("\n"); html_txt(info->msg); html("\n"); @@ -90,7 +95,6 @@ static void add_entry(struct commit *commit, const char *host, int enable_atom_d html("\n"); html("\n"); html("\n"); - cgit_free_commitinfo(info); } @@ -101,6 +105,7 @@ void cgit_print_atom(char *tip, char *path, int max_count, int enable_atom_diff) struct commit *commit; struct rev_info rev; int argc = 2; + int had_global_updated = 0; if (ctx.qry.show_all) argv[1] = "--all"; @@ -147,9 +152,25 @@ void cgit_print_atom(char *tip, char *path, int max_count, int enable_atom_diff) html_attr(host); html_attr(cgit_repourl(ctx.repo->url)); html("'/>\n"); + + html(""); + html(cgit_httpscheme()); + html_txt(host); + html_txt(cgit_repourl(ctx.repo->url)); + html("\n"); } + while ((commit = get_revision(&rev)) != NULL) { - add_entry(commit, host, enable_atom_diff); + struct commitinfo *info = cgit_parse_commit(commit); + if (!had_global_updated) { + html(""); + cgit_print_date(info->committer_date, FMT_ATOMDATE, 0); + html("\n"); + had_global_updated = 1; + } + add_entry(commit, info, host, enable_atom_diff); + + cgit_free_commitinfo(info); free(commit->buffer); commit->buffer = NULL; free_commit_list(commit->parents); -- 1.9.1 ___ CGit mailing list CGit@lists.zx2c4.com http://lists.zx2c4.com/mailman/listinfo/cgit
[PATCH 6/8] only one content tag allowed, so remove the text one
From: Matthias Braun --- ui-atom.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/ui-atom.c b/ui-atom.c index aa6a188..4d9ba00 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -75,9 +75,6 @@ static void add_entry(struct commit *commit, struct commitinfo *info, char *host } else { htmlf("urn:tag:%s\n", hex); } - html("\n"); - html_txt(info->msg); - html("\n"); html("\n"); html("\n"); html("\n"); -- 1.9.1 ___ CGit mailing list CGit@lists.zx2c4.com http://lists.zx2c4.com/mailman/listinfo/cgit
[PATCH 4/8] add xml-header to atom-feed
From: Matthias Braun --- ui-atom.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ui-atom.c b/ui-atom.c index 6a6a98b..fdc5cb3 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -125,6 +125,7 @@ void cgit_print_atom(char *tip, char *path, int max_count, int enable_atom_diff) ctx.page.mimetype = "text/xml"; ctx.page.charset = "utf-8"; cgit_print_http_headers(); + html("\n"); html("\n"); html(""); html_txt(ctx.repo->name); -- 1.9.1 ___ CGit mailing list CGit@lists.zx2c4.com http://lists.zx2c4.com/mailman/listinfo/cgit
[PATCH 3/8] Skip forbidden characters.
From: Sebastian Buchwald --- html.c | 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/html.c b/html.c index 91047ad..6037eec 100644 --- a/html.c +++ b/html.c @@ -129,7 +129,8 @@ void html_txt(const char *txt) const char *t = txt; while (t && *t) { int c = *t; - if (c == '<' || c == '>' || c == '&') { + if ((c < 0x20 && c != '\t' && c != '\n' && c != '\r') + || (c == '<' || c == '>' || c == '&')) { html_raw(txt, t - txt); if (c == '>') html(">"); @@ -150,7 +151,8 @@ void html_ntxt(int len, const char *txt) const char *t = txt; while (t && *t && len--) { int c = *t; - if (c == '<' || c == '>' || c == '&') { + if ((c < 0x20 && c != '\t' && c != '\n' && c != '\r') + || (c == '<' || c == '>' || c == '&')) { html_raw(txt, t - txt); if (c == '>') html(">"); @@ -186,7 +188,8 @@ void html_attr(const char *txt) const char *t = txt; while (t && *t) { int c = *t; - if (c == '<' || c == '>' || c == '\'' || c == '\"' || c == '&') { + if (c == '<' || c == '>' || c == '\'' || c == '\"' || c == '&' + || (c < 0x20 && c != '\t' && c != '\n' && c != '\r')) { html_raw(txt, t - txt); if (c == '>') html(">"); -- 1.9.1 ___ CGit mailing list CGit@lists.zx2c4.com http://lists.zx2c4.com/mailman/listinfo/cgit
[PATCH 2/8] Improved readability.
From: Sebastian Buchwald --- html.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html.c b/html.c index f0ee2d6..91047ad 100644 --- a/html.c +++ b/html.c @@ -193,7 +193,7 @@ void html_attr(const char *txt) else if (c == '<') html("<"); else if (c == '\'') - html("'"); + html("'"); else if (c == '"') html("""); else if (c == '&') -- 1.9.1 ___ CGit mailing list CGit@lists.zx2c4.com http://lists.zx2c4.com/mailman/listinfo/cgit