|
|
|
@ -6,8 +6,6 @@
|
|
|
|
|
* (see COPYING for full license text)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define USE_THE_REPOSITORY_VARIABLE
|
|
|
|
|
|
|
|
|
|
#include "cgit.h"
|
|
|
|
|
#include "ui-shared.h"
|
|
|
|
|
#include "cmd.h"
|
|
|
|
@ -24,11 +22,10 @@ static char *http_date(time_t t)
|
|
|
|
|
static char month[][4] =
|
|
|
|
|
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
|
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
|
|
|
|
struct tm tm;
|
|
|
|
|
gmtime_r(&t, &tm);
|
|
|
|
|
return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm.tm_wday],
|
|
|
|
|
tm.tm_mday, month[tm.tm_mon], 1900 + tm.tm_year,
|
|
|
|
|
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
|
|
|
|
struct tm *tm = gmtime(&t);
|
|
|
|
|
return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday],
|
|
|
|
|
tm->tm_mday, month[tm->tm_mon], 1900 + tm->tm_year,
|
|
|
|
|
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cgit_print_error(const char *fmt, ...)
|
|
|
|
@ -524,45 +521,45 @@ static void cgit_self_link(char *name, const char *title, const char *class)
|
|
|
|
|
else if (!strcmp(ctx.qry.page, "summary"))
|
|
|
|
|
cgit_summary_link(name, title, class, ctx.qry.head);
|
|
|
|
|
else if (!strcmp(ctx.qry.page, "tag"))
|
|
|
|
|
cgit_tag_link(name, title, class, ctx.qry.has_oid ?
|
|
|
|
|
ctx.qry.oid : ctx.qry.head);
|
|
|
|
|
cgit_tag_link(name, title, class, ctx.qry.has_sha1 ?
|
|
|
|
|
ctx.qry.sha1 : ctx.qry.head);
|
|
|
|
|
else if (!strcmp(ctx.qry.page, "tree"))
|
|
|
|
|
cgit_tree_link(name, title, class, ctx.qry.head,
|
|
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
|
|
|
|
ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
|
|
|
|
|
ctx.qry.path);
|
|
|
|
|
else if (!strcmp(ctx.qry.page, "plain"))
|
|
|
|
|
cgit_plain_link(name, title, class, ctx.qry.head,
|
|
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
|
|
|
|
ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
|
|
|
|
|
ctx.qry.path);
|
|
|
|
|
else if (!strcmp(ctx.qry.page, "blame"))
|
|
|
|
|
cgit_blame_link(name, title, class, ctx.qry.head,
|
|
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
|
|
|
|
ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
|
|
|
|
|
ctx.qry.path);
|
|
|
|
|
else if (!strcmp(ctx.qry.page, "log"))
|
|
|
|
|
cgit_log_link(name, title, class, ctx.qry.head,
|
|
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
|
|
|
|
ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
|
|
|
|
|
ctx.qry.path, ctx.qry.ofs,
|
|
|
|
|
ctx.qry.grep, ctx.qry.search,
|
|
|
|
|
ctx.qry.showmsg, ctx.qry.follow);
|
|
|
|
|
else if (!strcmp(ctx.qry.page, "commit"))
|
|
|
|
|
cgit_commit_link(name, title, class, ctx.qry.head,
|
|
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
|
|
|
|
ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
|
|
|
|
|
ctx.qry.path);
|
|
|
|
|
else if (!strcmp(ctx.qry.page, "patch"))
|
|
|
|
|
cgit_patch_link(name, title, class, ctx.qry.head,
|
|
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
|
|
|
|
ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
|
|
|
|
|
ctx.qry.path);
|
|
|
|
|
else if (!strcmp(ctx.qry.page, "refs"))
|
|
|
|
|
cgit_refs_link(name, title, class, ctx.qry.head,
|
|
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
|
|
|
|
ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
|
|
|
|
|
ctx.qry.path);
|
|
|
|
|
else if (!strcmp(ctx.qry.page, "snapshot"))
|
|
|
|
|
cgit_snapshot_link(name, title, class, ctx.qry.head,
|
|
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
|
|
|
|
ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
|
|
|
|
|
ctx.qry.path);
|
|
|
|
|
else if (!strcmp(ctx.qry.page, "diff"))
|
|
|
|
|
cgit_diff_link(name, title, class, ctx.qry.head,
|
|
|
|
|
ctx.qry.oid, ctx.qry.oid2,
|
|
|
|
|
ctx.qry.sha1, ctx.qry.sha2,
|
|
|
|
|
ctx.qry.path);
|
|
|
|
|
else if (!strcmp(ctx.qry.page, "stats"))
|
|
|
|
|
cgit_stats_link(name, title, class, ctx.qry.head,
|
|
|
|
@ -664,18 +661,18 @@ void cgit_submodule_link(const char *class, char *path, const char *rev)
|
|
|
|
|
path[len - 1] = tail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const struct date_mode cgit_date_mode(enum date_mode_type type)
|
|
|
|
|
const struct date_mode *cgit_date_mode(enum date_mode_type type)
|
|
|
|
|
{
|
|
|
|
|
static struct date_mode mode;
|
|
|
|
|
mode.type = type;
|
|
|
|
|
mode.local = ctx.cfg.local_time;
|
|
|
|
|
return mode;
|
|
|
|
|
return &mode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void print_rel_date(time_t t, int tz, double value,
|
|
|
|
|
const char *class, const char *suffix)
|
|
|
|
|
{
|
|
|
|
|
htmlf("<span class='%s' data-ut='%" PRIu64 "' title='", class, (uint64_t)t);
|
|
|
|
|
htmlf("<span class='%s' title='", class);
|
|
|
|
|
html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601)));
|
|
|
|
|
htmlf("'>%.0f %s</span>", value, suffix);
|
|
|
|
|
}
|
|
|
|
@ -770,38 +767,6 @@ static void print_rel_vcs_link(const char *url)
|
|
|
|
|
html(" Git repository'/>\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int emit_css_link(struct string_list_item *s, void *arg)
|
|
|
|
|
{
|
|
|
|
|
/* Do not emit anything if css= is specified. */
|
|
|
|
|
if (s && *s->string == '\0')
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
html("<link rel='stylesheet' type='text/css' href='");
|
|
|
|
|
if (s)
|
|
|
|
|
html_attr(s->string);
|
|
|
|
|
else
|
|
|
|
|
html_attr((const char *)arg);
|
|
|
|
|
html("'/>\n");
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int emit_js_link(struct string_list_item *s, void *arg)
|
|
|
|
|
{
|
|
|
|
|
/* Do not emit anything if js= is specified. */
|
|
|
|
|
if (s && *s->string == '\0')
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
html("<script type='text/javascript' src='");
|
|
|
|
|
if (s)
|
|
|
|
|
html_attr(s->string);
|
|
|
|
|
else
|
|
|
|
|
html_attr((const char *)arg);
|
|
|
|
|
html("'></script>\n");
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cgit_print_docstart(void)
|
|
|
|
|
{
|
|
|
|
|
char *host = cgit_hosturl();
|
|
|
|
@ -821,17 +786,9 @@ void cgit_print_docstart(void)
|
|
|
|
|
htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
|
|
|
|
|
if (ctx.cfg.robots && *ctx.cfg.robots)
|
|
|
|
|
htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots);
|
|
|
|
|
|
|
|
|
|
if (ctx.cfg.css.items)
|
|
|
|
|
for_each_string_list(&ctx.cfg.css, emit_css_link, NULL);
|
|
|
|
|
else
|
|
|
|
|
emit_css_link(NULL, "/cgit.css");
|
|
|
|
|
|
|
|
|
|
if (ctx.cfg.js.items)
|
|
|
|
|
for_each_string_list(&ctx.cfg.js, emit_js_link, NULL);
|
|
|
|
|
else
|
|
|
|
|
emit_js_link(NULL, "/cgit.js");
|
|
|
|
|
|
|
|
|
|
html("<link rel='stylesheet' type='text/css' href='");
|
|
|
|
|
html_attr(ctx.cfg.css);
|
|
|
|
|
html("'/>\n");
|
|
|
|
|
if (ctx.cfg.favicon) {
|
|
|
|
|
html("<link rel='shortcut icon' href='");
|
|
|
|
|
html_attr(ctx.cfg.favicon);
|
|
|
|
@ -961,10 +918,10 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search,
|
|
|
|
|
strcmp(ctx.qry.head, ctx.repo->defbranch))
|
|
|
|
|
html_hidden("h", ctx.qry.head);
|
|
|
|
|
|
|
|
|
|
if (ctx.qry.oid)
|
|
|
|
|
html_hidden("id", ctx.qry.oid);
|
|
|
|
|
if (ctx.qry.oid2)
|
|
|
|
|
html_hidden("id2", ctx.qry.oid2);
|
|
|
|
|
if (ctx.qry.sha1)
|
|
|
|
|
html_hidden("id", ctx.qry.sha1);
|
|
|
|
|
if (ctx.qry.sha2)
|
|
|
|
|
html_hidden("id2", ctx.qry.sha2);
|
|
|
|
|
if (ctx.qry.showmsg)
|
|
|
|
|
html_hidden("showmsg", "1");
|
|
|
|
|
|
|
|
|
@ -1037,17 +994,15 @@ static void print_header(void)
|
|
|
|
|
if (ctx.repo) {
|
|
|
|
|
cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1);
|
|
|
|
|
html(" : ");
|
|
|
|
|
cgit_summary_link(ctx.repo->name, NULL, NULL, NULL);
|
|
|
|
|
cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
|
|
|
|
|
if (ctx.env.authenticated) {
|
|
|
|
|
html("</td><td class='form'>");
|
|
|
|
|
html("<form method='get'>\n");
|
|
|
|
|
cgit_add_hidden_formfields(0, 1, ctx.qry.page);
|
|
|
|
|
html("<select name='h' onchange='this.form.submit();'>\n");
|
|
|
|
|
refs_for_each_branch_ref(get_main_ref_store(the_repository),
|
|
|
|
|
print_branch_option, ctx.qry.head);
|
|
|
|
|
for_each_branch_ref(print_branch_option, ctx.qry.head);
|
|
|
|
|
if (ctx.repo->enable_remote_branches)
|
|
|
|
|
refs_for_each_remote_ref(get_main_ref_store(the_repository),
|
|
|
|
|
print_branch_option, ctx.qry.head);
|
|
|
|
|
for_each_remote_ref(print_branch_option, ctx.qry.head);
|
|
|
|
|
html("</select> ");
|
|
|
|
|
html("<input type='submit' value='switch'/>");
|
|
|
|
|
html("</form>");
|
|
|
|
@ -1060,13 +1015,7 @@ static void print_header(void)
|
|
|
|
|
if (ctx.repo) {
|
|
|
|
|
html_txt(ctx.repo->desc);
|
|
|
|
|
html("</td><td class='sub right'>");
|
|
|
|
|
if (ctx.repo->owner_filter) {
|
|
|
|
|
cgit_open_filter(ctx.repo->owner_filter);
|
|
|
|
|
html_txt(ctx.repo->owner);
|
|
|
|
|
cgit_close_filter(ctx.repo->owner_filter);
|
|
|
|
|
} else {
|
|
|
|
|
html_txt(ctx.repo->owner);
|
|
|
|
|
}
|
|
|
|
|
html_txt(ctx.repo->owner);
|
|
|
|
|
} else {
|
|
|
|
|
if (ctx.cfg.root_desc)
|
|
|
|
|
html_txt(ctx.cfg.root_desc);
|
|
|
|
@ -1089,20 +1038,20 @@ void cgit_print_pageheader(void)
|
|
|
|
|
cgit_summary_link("summary", NULL, hc("summary"),
|
|
|
|
|
ctx.qry.head);
|
|
|
|
|
cgit_refs_link("refs", NULL, hc("refs"), ctx.qry.head,
|
|
|
|
|
ctx.qry.oid, NULL);
|
|
|
|
|
ctx.qry.sha1, NULL);
|
|
|
|
|
cgit_log_link("log", NULL, hc("log"), ctx.qry.head,
|
|
|
|
|
NULL, ctx.qry.vpath, 0, NULL, NULL,
|
|
|
|
|
ctx.qry.showmsg, ctx.qry.follow);
|
|
|
|
|
if (ctx.qry.page && !strcmp(ctx.qry.page, "blame"))
|
|
|
|
|
cgit_blame_link("blame", NULL, hc("blame"), ctx.qry.head,
|
|
|
|
|
ctx.qry.oid, ctx.qry.vpath);
|
|
|
|
|
ctx.qry.sha1, ctx.qry.vpath);
|
|
|
|
|
else
|
|
|
|
|
cgit_tree_link("tree", NULL, hc("tree"), ctx.qry.head,
|
|
|
|
|
ctx.qry.oid, ctx.qry.vpath);
|
|
|
|
|
ctx.qry.sha1, ctx.qry.vpath);
|
|
|
|
|
cgit_commit_link("commit", NULL, hc("commit"),
|
|
|
|
|
ctx.qry.head, ctx.qry.oid, ctx.qry.vpath);
|
|
|
|
|
ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath);
|
|
|
|
|
cgit_diff_link("diff", NULL, hc("diff"), ctx.qry.head,
|
|
|
|
|
ctx.qry.oid, ctx.qry.oid2, ctx.qry.vpath);
|
|
|
|
|
ctx.qry.sha1, ctx.qry.sha2, ctx.qry.vpath);
|
|
|
|
|
if (ctx.repo->max_stats)
|
|
|
|
|
cgit_stats_link("stats", NULL, hc("stats"),
|
|
|
|
|
ctx.qry.head, ctx.qry.vpath);
|
|
|
|
@ -1192,11 +1141,11 @@ void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base,
|
|
|
|
|
* name starts with {v,V}[0-9] and the prettify mapping is injective,
|
|
|
|
|
* i.e. each stripped tag can be inverted without ambiguities.
|
|
|
|
|
*/
|
|
|
|
|
if (repo_get_oid(the_repository, fmt("refs/tags/%s", ref), &oid) == 0 &&
|
|
|
|
|
if (get_oid(fmt("refs/tags/%s", ref), &oid) == 0 &&
|
|
|
|
|
(ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]) &&
|
|
|
|
|
((repo_get_oid(the_repository, fmt("refs/tags/%s", ref + 1), &oid) == 0) +
|
|
|
|
|
(repo_get_oid(the_repository, fmt("refs/tags/v%s", ref + 1), &oid) == 0) +
|
|
|
|
|
(repo_get_oid(the_repository, fmt("refs/tags/V%s", ref + 1), &oid) == 0) == 1))
|
|
|
|
|
((get_oid(fmt("refs/tags/%s", ref + 1), &oid) == 0) +
|
|
|
|
|
(get_oid(fmt("refs/tags/v%s", ref + 1), &oid) == 0) +
|
|
|
|
|
(get_oid(fmt("refs/tags/V%s", ref + 1), &oid) == 0) == 1))
|
|
|
|
|
ref++;
|
|
|
|
|
|
|
|
|
|
strbuf_addf(filename, "%s-%s", base, ref);
|
|
|
|
|