From 57ea1aa2a5eab7f6aba702b3366fe4dcc72124f6 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Tue, 19 Jan 2016 19:33:01 +0000 Subject: ui-shared: remove "format" from cgit_print_age() We never use any format other than FMT_SHORTDATE, so move that into the function. Signed-off-by: John Keeping --- ui-shared.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index 54bbde7..76aac60 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -635,7 +635,7 @@ static void print_rel_date(time_t t, double value, htmlf("'>%.0f %s", value, suffix); } -void cgit_print_age(time_t t, time_t max_relative, const char *format) +void cgit_print_age(time_t t, time_t max_relative) { time_t now, secs; @@ -650,7 +650,7 @@ void cgit_print_age(time_t t, time_t max_relative, const char *format) html(""); - cgit_print_date(t, format, ctx.cfg.local_time); + cgit_print_date(t, FMT_SHORTDATE, ctx.cfg.local_time); html(""); return; } -- cgit v1.2.3 From 360af46fac6fe79ec1868141a6c34b4c6b732ba0 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Tue, 19 Jan 2016 19:33:03 +0000 Subject: ui-shared: add cgit_date_mode() This returns the correct mode value for use with Git's show_date() based on the current CGit configuration and will be used in the following patches. Signed-off-by: John Keeping --- ui-shared.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index 76aac60..923d102 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -627,6 +627,15 @@ void cgit_print_date(time_t secs, const char *format, int local_time) html_txt(fmt_date(secs, format, local_time)); } +const struct date_mode *cgit_date_mode(const char *format) +{ + static struct date_mode mode; + mode.type = DATE_STRFTIME; + mode.strftime_fmt = format; + mode.local = ctx.cfg.local_time; + return &mode; +} + static void print_rel_date(time_t t, double value, const char *class, const char *suffix) { -- cgit v1.2.3 From f2a901d2e1db5217d6890b26c6dc1ec119505d02 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Tue, 19 Jan 2016 19:33:05 +0000 Subject: ui: show ages in the originator's timezone This affects the tooltip showing the full time and the case when a date is sufficiently old to be shown in full rather than as an offset. Signed-off-by: John Keeping --- ui-shared.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index 923d102..3ce86fe 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -636,15 +636,15 @@ const struct date_mode *cgit_date_mode(const char *format) return &mode; } -static void print_rel_date(time_t t, double value, +static void print_rel_date(time_t t, int tz, double value, const char *class, const char *suffix) { htmlf("%.0f %s", value, suffix); } -void cgit_print_age(time_t t, time_t max_relative) +void cgit_print_age(time_t t, int tz, time_t max_relative) { time_t now, secs; @@ -657,34 +657,34 @@ void cgit_print_age(time_t t, time_t max_relative) if (secs > max_relative && max_relative >= 0) { html(""); - cgit_print_date(t, FMT_SHORTDATE, ctx.cfg.local_time); + html_txt(show_date(t, tz, cgit_date_mode(FMT_SHORTDATE))); html(""); return; } if (secs < TM_HOUR * 2) { - print_rel_date(t, secs * 1.0 / TM_MIN, "age-mins", "min."); + print_rel_date(t, tz, secs * 1.0 / TM_MIN, "age-mins", "min."); return; } if (secs < TM_DAY * 2) { - print_rel_date(t, secs * 1.0 / TM_HOUR, "age-hours", "hours"); + print_rel_date(t, tz, secs * 1.0 / TM_HOUR, "age-hours", "hours"); return; } if (secs < TM_WEEK * 2) { - print_rel_date(t, secs * 1.0 / TM_DAY, "age-days", "days"); + print_rel_date(t, tz, secs * 1.0 / TM_DAY, "age-days", "days"); return; } if (secs < TM_MONTH * 2) { - print_rel_date(t, secs * 1.0 / TM_WEEK, "age-weeks", "weeks"); + print_rel_date(t, tz, secs * 1.0 / TM_WEEK, "age-weeks", "weeks"); return; } if (secs < TM_YEAR * 2) { - print_rel_date(t, secs * 1.0 / TM_MONTH, "age-months", "months"); + print_rel_date(t, tz, secs * 1.0 / TM_MONTH, "age-months", "months"); return; } - print_rel_date(t, secs * 1.0 / TM_YEAR, "age-years", "years"); + print_rel_date(t, tz, secs * 1.0 / TM_YEAR, "age-years", "years"); } void cgit_print_http_headers(void) -- cgit v1.2.3 From e68c86e8c54a6f03e7405dff3d38995c6c42e4fa Mon Sep 17 00:00:00 2001 From: John Keeping Date: Tue, 19 Jan 2016 19:33:06 +0000 Subject: ui-shared: use show_date for footer timestamp Signed-off-by: John Keeping --- ui-shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index 3ce86fe..eaa45fb 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -801,7 +801,7 @@ void cgit_print_docend(void) else { htmlf("\n"); } html(" \n"); -- cgit v1.2.3 From 17c74eefa4390d42a244b12885dc63ac4a764e44 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Tue, 19 Jan 2016 19:33:08 +0000 Subject: ui-shared: remove cgit_print_date() There are no longer any users of this function. Signed-off-by: John Keeping --- ui-shared.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index eaa45fb..d1f9249 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -607,26 +607,6 @@ void cgit_submodule_link(const char *class, char *path, const char *rev) path[len - 1] = tail; } -static const char *fmt_date(time_t secs, const char *format, int local_time) -{ - static char buf[64]; - struct tm *time; - - if (!secs) - return ""; - if (local_time) - time = localtime(&secs); - else - time = gmtime(&secs); - strftime(buf, sizeof(buf)-1, format, time); - return buf; -} - -void cgit_print_date(time_t secs, const char *format, int local_time) -{ - html_txt(fmt_date(secs, format, local_time)); -} - const struct date_mode *cgit_date_mode(const char *format) { static struct date_mode mode; -- cgit v1.2.3 From 9c15f3c6954e43c5ffd36230e666eccf112803f2 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Mon, 8 Feb 2016 15:05:54 +0000 Subject: Avoid DATE_STRFTIME for long/short dates Git's DATE_STRFTIME ignores the timezone argument and just uses the local timezone regardless of whether the "local" flag is set. Since our existing FMT_LONGDATE and FMT_SHORTDATE are pretty-much perfect matches to DATE_ISO8601 and DATE_SHORT, switch to taking a date_mode_type directly in cgit_date_mode(). Signed-off-by: John Keeping --- ui-shared.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index d1f9249..03dcc08 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -607,11 +607,10 @@ void cgit_submodule_link(const char *class, char *path, const char *rev) path[len - 1] = tail; } -const struct date_mode *cgit_date_mode(const char *format) +const struct date_mode *cgit_date_mode(enum date_mode_type type) { static struct date_mode mode; - mode.type = DATE_STRFTIME; - mode.strftime_fmt = format; + mode.type = type; mode.local = ctx.cfg.local_time; return &mode; } @@ -620,7 +619,7 @@ static void print_rel_date(time_t t, int tz, double value, const char *class, const char *suffix) { htmlf("%.0f %s", value, suffix); } @@ -637,9 +636,9 @@ void cgit_print_age(time_t t, int tz, time_t max_relative) if (secs > max_relative && max_relative >= 0) { html(""); - html_txt(show_date(t, tz, cgit_date_mode(FMT_SHORTDATE))); + html_txt(show_date(t, tz, cgit_date_mode(DATE_SHORT))); html(""); return; } @@ -781,7 +780,7 @@ void cgit_print_docend(void) else { htmlf("\n"); } html(" \n"); -- cgit v1.2.3 From 5f2664f13c90f083b827d8fafa6cfc01c0c4f513 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 22 Feb 2016 16:04:15 +0100 Subject: ui-shared: add homepage to tabs Signed-off-by: Jason A. Donenfeld --- ui-shared.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index 03dcc08..2c91e75 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -997,6 +997,11 @@ void cgit_print_pageheader(void) if (ctx.repo->max_stats) cgit_stats_link("stats", NULL, hc("stats"), ctx.qry.head, ctx.qry.vpath); + if (ctx.repo->homepage) { + html("homepage"); + } html(""); html("
homepage) { html("homepage"); + html("'>homepage"); } html(""); html(" Date: Wed, 11 May 2016 17:50:09 +0000 Subject: ui-shared: Simplify cgit_print_error_page() logic --- ui-shared.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index 9a38aa9..bf92747 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -792,13 +792,11 @@ void cgit_print_error_page(int code, const char *msg, const char *fmt, ...) ctx.page.expires = ctx.cfg.cache_dynamic_ttl; ctx.page.status = code; ctx.page.statusmsg = msg; - cgit_print_http_headers(); - cgit_print_docstart(); - cgit_print_pageheader(); + cgit_print_layout_start(); va_start(ap, fmt); cgit_vprint_error(fmt, ap); va_end(ap); - cgit_print_docend(); + cgit_print_layout_end(); } void cgit_print_layout_start(void) -- cgit v1.2.3 From 8d05b398bb1f4effcb59dddc62a3ea1f021f8631 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Wed, 11 May 2016 18:04:14 +0000 Subject: ui-shared: HTML-ize DOCTYPE and Get rid of the XHTML headers, bringing cgit slowly to the modern age of HTML. --- ui-shared.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index bf92747..1529ff1 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -12,8 +12,7 @@ #include "html.h" static const char cgit_doctype[] = -"\n"; +"\n"; static char *http_date(time_t t) { @@ -723,7 +722,7 @@ void cgit_print_docstart(void) char *host = cgit_hosturl(); html(cgit_doctype); - html("\n"); + html("\n"); html("\n"); html(""); html_txt(ctx.page.title); -- cgit v1.2.3 From 9afda36ed72083febca5e1a249b7f9f09205fe16 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi <wub@partyvan.eu> Date: Wed, 11 May 2016 18:04:18 +0000 Subject: ui-shared: Remove a name attribute with an empty value The name attribute is optional in an input element, but it must not be an empty value. See: https://html.spec.whatwg.org/#attr-fe-name See: https://html.spec.whatwg.org/#the-input-element --- ui-shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index 1529ff1..770b685 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -944,7 +944,7 @@ static void print_header(void) if (ctx.repo->enable_remote_branches) for_each_remote_ref(print_branch_option, ctx.qry.head); html("</select> "); - html("<input type='submit' name='' value='switch'/>"); + html("<input type='submit' value='switch'/>"); html("</form>"); } } else -- cgit v1.2.3 From c34e28835bc06ea9f76f440909f59a697910e9e8 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 12 May 2016 21:29:40 +0200 Subject: forms: action should not be empty Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index 770b685..2c88b72 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -937,7 +937,7 @@ static void print_header(void) cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); if (ctx.env.authenticated) { html("</td><td class='form'>"); - html("<form method='get' action=''>\n"); + html("<form method='get'>\n"); cgit_add_hidden_formfields(0, 1, ctx.qry.page); html("<select name='h' onchange='this.form.submit();'>\n"); for_each_branch_ref(print_branch_option, ctx.qry.head); -- cgit v1.2.3 From d88ec849c4f7af41a8a41af1a4f79a2b4d41717a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Wed, 24 Feb 2016 18:01:42 +0100 Subject: Hosted on HTTPS now --- ui-shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index 2c88b72..562fa0e 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -776,7 +776,7 @@ void cgit_print_docend(void) if (ctx.cfg.footer) html_include(ctx.cfg.footer); else { - htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ", + htmlf("<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit %s</a> at ", cgit_version); html_txt(show_date(time(NULL), 0, cgit_date_mode(DATE_ISO8601))); html("</div>\n"); -- cgit v1.2.3 From 9984e7ab49c59e49a0d7e62c3435e7133f7a53ec Mon Sep 17 00:00:00 2001 From: Lukas Fleischer <lfleischer@lfos.de> Date: Tue, 24 May 2016 18:15:18 +0200 Subject: Avoid ambiguities when prettifying snapshot names When composing snapshot file names for a tag with a prefix of the form v[0-9] (resp. V[0-9]), the leading "v" (resp. "V") is stripped. This leads to conflicts if a tag with the stripped name already exists or if there are tags only differing in the capitalization of the leading "v". Make sure we do not strip the "v" in these cases. Reported-by: Juuso Lapinlampi <wub@partyvan.eu> Signed-off-by: Lukas Fleischer <lfleischer@lfos.de> --- ui-shared.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index 562fa0e..b1a6c46 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1069,18 +1069,34 @@ void cgit_print_filemode(unsigned short mode) html_fileperm(mode); } +void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, + const char *ref) +{ + unsigned char sha1[20]; + + /* + * Prettify snapshot names by stripping leading "v" or "V" if the tag + * name starts with {v,V}[0-9] and the prettify mapping is injective, + * i.e. each stripped tag can be inverted without ambiguities. + */ + if (get_sha1(fmt("refs/tags/%s", ref), sha1) == 0 && + (ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]) && + ((get_sha1(fmt("refs/tags/%s", ref + 1), sha1) == 0) + + (get_sha1(fmt("refs/tags/v%s", ref + 1), sha1) == 0) + + (get_sha1(fmt("refs/tags/V%s", ref + 1), sha1) == 0) == 1)) + ref++; + + strbuf_addf(filename, "%s-%s", base, ref); +} + void cgit_print_snapshot_links(const char *repo, const char *head, const char *hex, int snapshots) { const struct cgit_snapshot_format* f; struct strbuf filename = STRBUF_INIT; size_t prefixlen; - unsigned char sha1[20]; - if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 && - (hex[0] == 'v' || hex[0] == 'V') && isdigit(hex[1])) - hex++; - strbuf_addf(&filename, "%s-%s", cgit_repobasename(repo), hex); + cgit_compose_snapshot_prefix(&filename, cgit_repobasename(repo), hex); prefixlen = filename.len; for (f = cgit_snapshot_formats; f->suffix; f++) { if (!(snapshots & f->bit)) -- cgit v1.2.3 From 590ba455d694deaf2ec206510cf7f047ac365a96 Mon Sep 17 00:00:00 2001 From: Eric Wong <normalperson@yhbt.net> Date: Wed, 6 Jul 2016 07:08:01 +0000 Subject: ui-shared: fix segfault when defbranch is NULL Not sure if there's a better fix for this. defbranch is NULL here on my setup when a crawler hit an invalid URL, causing strcmp to segfault. Signed-off-by: Eric Wong <normalperson@yhbt.net> --- ui-shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index b1a6c46..e39d004 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -253,7 +253,7 @@ static char *repolink(const char *title, const char *class, const char *page, } delim = "&"; } - if (head && strcmp(head, ctx.repo->defbranch)) { + if (head && ctx.repo->defbranch && strcmp(head, ctx.repo->defbranch)) { html(delim); html("h="); html_url_arg(head); -- cgit v1.2.3