2006-12-11 15:38:30 +00:00
|
|
|
/* ui-shared.c: common web output functions
|
|
|
|
*
|
2017-10-02 04:39:09 +00:00
|
|
|
* Copyright (C) 2006-2017 cgit Development Team <cgit@lists.zx2c4.com>
|
2006-12-11 15:38:30 +00:00
|
|
|
*
|
|
|
|
* Licensed under GNU General Public License v2
|
|
|
|
* (see COPYING for full license text)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cgit.h"
|
2013-04-06 10:37:59 +00:00
|
|
|
#include "ui-shared.h"
|
2008-04-12 13:53:31 +00:00
|
|
|
#include "cmd.h"
|
2008-02-23 21:45:33 +00:00
|
|
|
#include "html.h"
|
2018-06-04 20:27:46 +00:00
|
|
|
#include "version.h"
|
2006-12-11 15:38:30 +00:00
|
|
|
|
2015-03-08 16:32:22 +00:00
|
|
|
static const char cgit_doctype[] =
|
2016-05-11 18:04:14 +00:00
|
|
|
"<!DOCTYPE html>\n";
|
2006-12-11 15:38:30 +00:00
|
|
|
|
|
|
|
static char *http_date(time_t t)
|
|
|
|
{
|
2007-05-14 22:22:03 +00:00
|
|
|
static char day[][4] =
|
2006-12-11 15:38:30 +00:00
|
|
|
{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
2007-05-14 22:22:03 +00:00
|
|
|
static char month[][4] =
|
2006-12-11 15:38:30 +00:00
|
|
|
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
2009-11-02 21:10:04 +00:00
|
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
2020-12-28 22:27:13 +00:00
|
|
|
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);
|
2006-12-11 15:38:30 +00:00
|
|
|
}
|
|
|
|
|
2013-04-06 10:23:52 +00:00
|
|
|
void cgit_print_error(const char *fmt, ...)
|
2006-12-11 15:38:30 +00:00
|
|
|
{
|
2013-04-06 10:23:52 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
cgit_vprint_error(fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cgit_vprint_error(const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
va_list cp;
|
2006-12-11 15:38:30 +00:00
|
|
|
html("<div class='error'>");
|
2013-04-06 10:23:52 +00:00
|
|
|
va_copy(cp, ap);
|
|
|
|
html_vtxtf(fmt, cp);
|
|
|
|
va_end(cp);
|
2006-12-11 15:38:30 +00:00
|
|
|
html("</div>\n");
|
|
|
|
}
|
2006-12-11 15:48:03 +00:00
|
|
|
|
2015-03-08 16:32:16 +00:00
|
|
|
const char *cgit_httpscheme(void)
|
2009-06-10 23:09:55 +00:00
|
|
|
{
|
2009-08-10 06:21:09 +00:00
|
|
|
if (ctx.env.https && !strcmp(ctx.env.https, "on"))
|
2009-06-10 23:09:55 +00:00
|
|
|
return "https://";
|
|
|
|
else
|
|
|
|
return "http://";
|
|
|
|
}
|
|
|
|
|
2015-10-09 11:15:50 +00:00
|
|
|
char *cgit_hosturl(void)
|
2008-05-21 06:17:54 +00:00
|
|
|
{
|
2009-08-10 06:21:09 +00:00
|
|
|
if (ctx.env.http_host)
|
2015-10-09 11:15:50 +00:00
|
|
|
return xstrdup(ctx.env.http_host);
|
2009-08-10 06:21:09 +00:00
|
|
|
if (!ctx.env.server_name)
|
|
|
|
return NULL;
|
|
|
|
if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80)
|
2015-10-09 11:15:50 +00:00
|
|
|
return xstrdup(ctx.env.server_name);
|
2013-04-06 09:28:57 +00:00
|
|
|
return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port);
|
2008-05-21 06:17:54 +00:00
|
|
|
}
|
|
|
|
|
2015-10-09 11:15:47 +00:00
|
|
|
char *cgit_currenturl(void)
|
2015-03-03 16:18:42 +00:00
|
|
|
{
|
2015-03-08 11:34:07 +00:00
|
|
|
const char *root = cgit_rooturl();
|
2016-08-07 15:13:30 +00:00
|
|
|
|
|
|
|
if (!ctx.qry.url)
|
|
|
|
return xstrdup(root);
|
2018-11-21 02:16:11 +00:00
|
|
|
if (root[0] && root[strlen(root) - 1] == '/')
|
2015-03-08 11:34:07 +00:00
|
|
|
return fmtalloc("%s%s", root, ctx.qry.url);
|
|
|
|
return fmtalloc("%s/%s", root, ctx.qry.url);
|
2015-03-03 16:18:42 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 02:16:11 +00:00
|
|
|
char *cgit_currentfullurl(void)
|
|
|
|
{
|
|
|
|
const char *root = cgit_rooturl();
|
|
|
|
const char *orig_query = ctx.env.query_string ? ctx.env.query_string : "";
|
|
|
|
size_t len = strlen(orig_query);
|
|
|
|
char *query = xmalloc(len + 2), *start_url, *ret;
|
|
|
|
|
|
|
|
/* Remove all url=... parts from query string */
|
|
|
|
memcpy(query + 1, orig_query, len + 1);
|
|
|
|
query[0] = '?';
|
|
|
|
start_url = query;
|
|
|
|
while ((start_url = strstr(start_url, "url=")) != NULL) {
|
|
|
|
if (start_url[-1] == '?' || start_url[-1] == '&') {
|
|
|
|
const char *end_url = strchr(start_url, '&');
|
|
|
|
if (end_url)
|
|
|
|
memmove(start_url, end_url + 1, strlen(end_url));
|
|
|
|
else
|
|
|
|
start_url[0] = '\0';
|
|
|
|
} else
|
|
|
|
++start_url;
|
|
|
|
}
|
|
|
|
if (!query[1])
|
|
|
|
query[0] = '\0';
|
|
|
|
|
|
|
|
if (!ctx.qry.url)
|
|
|
|
ret = fmtalloc("%s%s", root, query);
|
|
|
|
else if (root[0] && root[strlen(root) - 1] == '/')
|
|
|
|
ret = fmtalloc("%s%s%s", root, ctx.qry.url, query);
|
|
|
|
else
|
|
|
|
ret = fmtalloc("%s/%s%s", root, ctx.qry.url, query);
|
|
|
|
free(query);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-03-08 16:32:16 +00:00
|
|
|
const char *cgit_rooturl(void)
|
2007-02-17 12:46:18 +00:00
|
|
|
{
|
2008-02-16 12:07:13 +00:00
|
|
|
if (ctx.cfg.virtual_root)
|
2013-04-01 18:03:34 +00:00
|
|
|
return ctx.cfg.virtual_root;
|
2007-02-17 12:46:18 +00:00
|
|
|
else
|
2008-02-16 12:07:13 +00:00
|
|
|
return ctx.cfg.script_name;
|
2007-02-17 12:46:18 +00:00
|
|
|
}
|
|
|
|
|
2015-03-08 16:32:16 +00:00
|
|
|
const char *cgit_loginurl(void)
|
2014-01-16 22:21:54 +00:00
|
|
|
{
|
2015-03-08 16:32:24 +00:00
|
|
|
static const char *login_url;
|
2014-01-16 22:21:54 +00:00
|
|
|
if (!login_url)
|
|
|
|
login_url = fmtalloc("%s?p=login", cgit_rooturl());
|
|
|
|
return login_url;
|
|
|
|
}
|
|
|
|
|
2006-12-11 15:48:03 +00:00
|
|
|
char *cgit_repourl(const char *reponame)
|
|
|
|
{
|
2013-04-06 09:28:57 +00:00
|
|
|
if (ctx.cfg.virtual_root)
|
|
|
|
return fmtalloc("%s%s/", ctx.cfg.virtual_root, reponame);
|
|
|
|
else
|
|
|
|
return fmtalloc("?r=%s", reponame);
|
2006-12-11 15:48:03 +00:00
|
|
|
}
|
|
|
|
|
2007-07-21 11:13:40 +00:00
|
|
|
char *cgit_fileurl(const char *reponame, const char *pagename,
|
|
|
|
const char *filename, const char *query)
|
2006-12-11 15:48:03 +00:00
|
|
|
{
|
2013-04-06 09:28:57 +00:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2007-11-03 10:15:56 +00:00
|
|
|
char *delim;
|
|
|
|
|
2008-02-16 12:07:13 +00:00
|
|
|
if (ctx.cfg.virtual_root) {
|
2013-04-06 09:28:57 +00:00
|
|
|
strbuf_addf(&sb, "%s%s/%s/%s", ctx.cfg.virtual_root, reponame,
|
|
|
|
pagename, (filename ? filename:""));
|
2007-11-03 10:15:56 +00:00
|
|
|
delim = "?";
|
2006-12-11 15:48:03 +00:00
|
|
|
} else {
|
2013-04-06 09:28:57 +00:00
|
|
|
strbuf_addf(&sb, "?url=%s/%s/%s", reponame, pagename,
|
|
|
|
(filename ? filename : ""));
|
2012-10-09 18:45:58 +00:00
|
|
|
delim = "&";
|
2006-12-11 15:48:03 +00:00
|
|
|
}
|
2007-11-03 10:15:56 +00:00
|
|
|
if (query)
|
2013-04-06 09:28:57 +00:00
|
|
|
strbuf_addf(&sb, "%s%s", delim, query);
|
|
|
|
return strbuf_detach(&sb, NULL);
|
2006-12-11 15:48:03 +00:00
|
|
|
}
|
|
|
|
|
2007-07-21 11:13:40 +00:00
|
|
|
char *cgit_pageurl(const char *reponame, const char *pagename,
|
|
|
|
const char *query)
|
|
|
|
{
|
2015-03-08 16:32:25 +00:00
|
|
|
return cgit_fileurl(reponame, pagename, NULL, query);
|
2007-07-21 11:13:40 +00:00
|
|
|
}
|
|
|
|
|
2007-07-21 13:24:07 +00:00
|
|
|
const char *cgit_repobasename(const char *reponame)
|
|
|
|
{
|
|
|
|
/* I assume we don't need to store more than one repo basename */
|
|
|
|
static char rvbuf[1024];
|
|
|
|
int p;
|
|
|
|
const char *rv;
|
2018-07-04 01:13:31 +00:00
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = strlcpy(rvbuf, reponame, sizeof(rvbuf));
|
|
|
|
if (len >= sizeof(rvbuf))
|
2007-07-21 13:24:07 +00:00
|
|
|
die("cgit_repobasename: truncated repository name '%s'", reponame);
|
2018-07-04 01:13:31 +00:00
|
|
|
p = len - 1;
|
2007-07-21 13:24:07 +00:00
|
|
|
/* strip trailing slashes */
|
2018-07-04 01:13:31 +00:00
|
|
|
while (p && rvbuf[p] == '/')
|
|
|
|
rvbuf[p--] = '\0';
|
2007-07-21 13:24:07 +00:00
|
|
|
/* strip trailing .git */
|
2014-05-29 15:35:46 +00:00
|
|
|
if (p >= 3 && starts_with(&rvbuf[p-3], ".git")) {
|
2018-07-04 01:13:31 +00:00
|
|
|
p -= 3;
|
|
|
|
rvbuf[p--] = '\0';
|
2007-07-21 13:24:07 +00:00
|
|
|
}
|
|
|
|
/* strip more trailing slashes if any */
|
2018-07-04 01:13:31 +00:00
|
|
|
while (p && rvbuf[p] == '/')
|
|
|
|
rvbuf[p--] = '\0';
|
2007-07-21 13:24:07 +00:00
|
|
|
/* find last slash in the remaining string */
|
2018-07-04 01:13:31 +00:00
|
|
|
rv = strrchr(rvbuf, '/');
|
2013-03-04 04:21:33 +00:00
|
|
|
if (rv)
|
2007-07-21 13:24:07 +00:00
|
|
|
return ++rv;
|
|
|
|
return rvbuf;
|
|
|
|
}
|
2007-07-21 11:13:40 +00:00
|
|
|
|
2018-03-31 13:20:01 +00:00
|
|
|
const char *cgit_snapshot_prefix(const struct cgit_repo *repo)
|
|
|
|
{
|
|
|
|
if (repo->snapshot_prefix)
|
|
|
|
return repo->snapshot_prefix;
|
|
|
|
|
|
|
|
return cgit_repobasename(repo->url);
|
|
|
|
}
|
|
|
|
|
2015-03-03 16:23:40 +00:00
|
|
|
static void site_url(const char *page, const char *search, const char *sort, int ofs, int always_root)
|
2008-04-28 23:09:41 +00:00
|
|
|
{
|
|
|
|
char *delim = "?";
|
|
|
|
|
2015-03-03 16:23:40 +00:00
|
|
|
if (always_root || page)
|
2015-03-03 16:13:52 +00:00
|
|
|
html_attr(cgit_rooturl());
|
2015-10-09 11:15:48 +00:00
|
|
|
else {
|
|
|
|
char *currenturl = cgit_currenturl();
|
|
|
|
html_attr(currenturl);
|
|
|
|
free(currenturl);
|
|
|
|
}
|
2008-04-28 23:09:41 +00:00
|
|
|
|
|
|
|
if (page) {
|
|
|
|
htmlf("?p=%s", page);
|
2012-10-09 18:45:58 +00:00
|
|
|
delim = "&";
|
2008-04-28 23:09:41 +00:00
|
|
|
}
|
|
|
|
if (search) {
|
|
|
|
html(delim);
|
|
|
|
html("q=");
|
|
|
|
html_attr(search);
|
2012-10-09 18:45:58 +00:00
|
|
|
delim = "&";
|
2008-05-03 08:37:02 +00:00
|
|
|
}
|
2011-07-31 00:44:05 +00:00
|
|
|
if (sort) {
|
|
|
|
html(delim);
|
|
|
|
html("s=");
|
|
|
|
html_attr(sort);
|
2012-10-09 18:45:58 +00:00
|
|
|
delim = "&";
|
2011-07-31 00:44:05 +00:00
|
|
|
}
|
2008-05-03 08:37:02 +00:00
|
|
|
if (ofs) {
|
|
|
|
html(delim);
|
|
|
|
htmlf("ofs=%d", ofs);
|
2008-04-28 23:09:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
static void site_link(const char *page, const char *name, const char *title,
|
2015-03-03 16:23:40 +00:00
|
|
|
const char *class, const char *search, const char *sort, int ofs, int always_root)
|
2008-04-28 23:09:41 +00:00
|
|
|
{
|
|
|
|
html("<a");
|
|
|
|
if (title) {
|
|
|
|
html(" title='");
|
|
|
|
html_attr(title);
|
|
|
|
html("'");
|
|
|
|
}
|
|
|
|
if (class) {
|
|
|
|
html(" class='");
|
|
|
|
html_attr(class);
|
|
|
|
html("'");
|
|
|
|
}
|
|
|
|
html(" href='");
|
2015-03-03 16:23:40 +00:00
|
|
|
site_url(page, search, sort, ofs, always_root);
|
2008-04-28 23:09:41 +00:00
|
|
|
html("'>");
|
|
|
|
html_txt(name);
|
|
|
|
html("</a>");
|
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
void cgit_index_link(const char *name, const char *title, const char *class,
|
2015-03-03 16:23:40 +00:00
|
|
|
const char *pattern, const char *sort, int ofs, int always_root)
|
2008-05-03 08:37:02 +00:00
|
|
|
{
|
2015-03-03 16:23:40 +00:00
|
|
|
site_link(NULL, name, title, class, pattern, sort, ofs, always_root);
|
2008-05-03 08:37:02 +00:00
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
static char *repolink(const char *title, const char *class, const char *page,
|
|
|
|
const char *head, const char *path)
|
2007-06-16 23:23:08 +00:00
|
|
|
{
|
|
|
|
char *delim = "?";
|
|
|
|
|
|
|
|
html("<a");
|
|
|
|
if (title) {
|
|
|
|
html(" title='");
|
|
|
|
html_attr(title);
|
|
|
|
html("'");
|
|
|
|
}
|
|
|
|
if (class) {
|
|
|
|
html(" class='");
|
|
|
|
html_attr(class);
|
|
|
|
html("'");
|
|
|
|
}
|
|
|
|
html(" href='");
|
2008-02-16 12:07:13 +00:00
|
|
|
if (ctx.cfg.virtual_root) {
|
2008-10-05 14:54:44 +00:00
|
|
|
html_url_path(ctx.cfg.virtual_root);
|
|
|
|
html_url_path(ctx.repo->url);
|
2008-02-16 12:56:09 +00:00
|
|
|
if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
|
2007-06-16 23:23:08 +00:00
|
|
|
html("/");
|
2007-06-17 22:18:42 +00:00
|
|
|
if (page) {
|
2008-10-05 14:54:44 +00:00
|
|
|
html_url_path(page);
|
2007-06-17 22:18:42 +00:00
|
|
|
html("/");
|
|
|
|
if (path)
|
2008-10-05 14:54:44 +00:00
|
|
|
html_url_path(path);
|
2007-06-17 22:18:42 +00:00
|
|
|
}
|
2007-06-16 23:23:08 +00:00
|
|
|
} else {
|
2014-01-12 19:45:16 +00:00
|
|
|
html_url_path(ctx.cfg.script_name);
|
2007-06-16 23:23:08 +00:00
|
|
|
html("?url=");
|
2008-10-05 10:52:25 +00:00
|
|
|
html_url_arg(ctx.repo->url);
|
2008-02-16 12:56:09 +00:00
|
|
|
if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
|
2007-06-16 23:23:08 +00:00
|
|
|
html("/");
|
2007-06-17 22:18:42 +00:00
|
|
|
if (page) {
|
2008-10-05 10:52:25 +00:00
|
|
|
html_url_arg(page);
|
2007-06-17 22:18:42 +00:00
|
|
|
html("/");
|
|
|
|
if (path)
|
2008-10-05 10:52:25 +00:00
|
|
|
html_url_arg(path);
|
2007-06-17 22:18:42 +00:00
|
|
|
}
|
2007-06-16 23:23:08 +00:00
|
|
|
delim = "&";
|
|
|
|
}
|
2016-07-06 07:08:01 +00:00
|
|
|
if (head && ctx.repo->defbranch && strcmp(head, ctx.repo->defbranch)) {
|
2007-06-16 23:23:08 +00:00
|
|
|
html(delim);
|
|
|
|
html("h=");
|
2008-10-05 10:52:25 +00:00
|
|
|
html_url_arg(head);
|
2007-06-16 23:23:08 +00:00
|
|
|
delim = "&";
|
|
|
|
}
|
|
|
|
return fmt("%s", delim);
|
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
static void reporevlink(const char *page, const char *name, const char *title,
|
|
|
|
const char *class, const char *head, const char *rev,
|
|
|
|
const char *path)
|
2007-06-16 23:23:08 +00:00
|
|
|
{
|
|
|
|
char *delim;
|
|
|
|
|
2007-06-17 11:57:51 +00:00
|
|
|
delim = repolink(title, class, page, head, path);
|
2010-02-01 16:55:37 +00:00
|
|
|
if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) {
|
2007-06-16 23:23:08 +00:00
|
|
|
html(delim);
|
|
|
|
html("id=");
|
2008-10-05 10:52:25 +00:00
|
|
|
html_url_arg(rev);
|
2007-06-16 23:23:08 +00:00
|
|
|
}
|
|
|
|
html("'>");
|
|
|
|
html_txt(name);
|
|
|
|
html("</a>");
|
|
|
|
}
|
2006-12-15 23:33:28 +00:00
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
void cgit_summary_link(const char *name, const char *title, const char *class,
|
|
|
|
const char *head)
|
2008-10-05 14:55:50 +00:00
|
|
|
{
|
|
|
|
reporevlink(NULL, name, title, class, head, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
void cgit_tag_link(const char *name, const char *title, const char *class,
|
2015-01-15 22:18:14 +00:00
|
|
|
const char *tag)
|
2008-10-05 19:18:45 +00:00
|
|
|
{
|
2015-01-15 22:18:14 +00:00
|
|
|
reporevlink("tag", name, title, class, tag, NULL, NULL);
|
2008-10-05 19:18:45 +00:00
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
void cgit_tree_link(const char *name, const char *title, const char *class,
|
|
|
|
const char *head, const char *rev, const char *path)
|
2007-06-17 11:57:51 +00:00
|
|
|
{
|
|
|
|
reporevlink("tree", name, title, class, head, rev, path);
|
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
void cgit_plain_link(const char *name, const char *title, const char *class,
|
|
|
|
const char *head, const char *rev, const char *path)
|
2008-08-06 09:07:13 +00:00
|
|
|
{
|
|
|
|
reporevlink("plain", name, title, class, head, rev, path);
|
|
|
|
}
|
|
|
|
|
2017-10-02 04:39:09 +00:00
|
|
|
void cgit_blame_link(const char *name, const char *title, const char *class,
|
|
|
|
const char *head, const char *rev, const char *path)
|
|
|
|
{
|
|
|
|
reporevlink("blame", name, title, class, head, rev, path);
|
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
void cgit_log_link(const char *name, const char *title, const char *class,
|
|
|
|
const char *head, const char *rev, const char *path,
|
2015-08-12 14:55:28 +00:00
|
|
|
int ofs, const char *grep, const char *pattern, int showmsg,
|
|
|
|
int follow)
|
2007-06-17 11:57:51 +00:00
|
|
|
{
|
2007-06-29 18:27:41 +00:00
|
|
|
char *delim;
|
|
|
|
|
|
|
|
delim = repolink(title, class, "log", head, path);
|
2012-01-04 09:01:51 +00:00
|
|
|
if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) {
|
2007-06-29 18:27:41 +00:00
|
|
|
html(delim);
|
|
|
|
html("id=");
|
2008-10-05 10:52:25 +00:00
|
|
|
html_url_arg(rev);
|
2012-10-09 18:45:58 +00:00
|
|
|
delim = "&";
|
2007-06-29 18:27:41 +00:00
|
|
|
}
|
2007-11-03 09:42:37 +00:00
|
|
|
if (grep && pattern) {
|
|
|
|
html(delim);
|
|
|
|
html("qt=");
|
2008-10-05 10:52:25 +00:00
|
|
|
html_url_arg(grep);
|
2012-10-09 18:45:58 +00:00
|
|
|
delim = "&";
|
2007-11-03 09:42:37 +00:00
|
|
|
html(delim);
|
|
|
|
html("q=");
|
2008-10-05 10:52:25 +00:00
|
|
|
html_url_arg(pattern);
|
2007-11-03 09:42:37 +00:00
|
|
|
}
|
2007-06-29 18:27:41 +00:00
|
|
|
if (ofs > 0) {
|
|
|
|
html(delim);
|
|
|
|
html("ofs=");
|
|
|
|
htmlf("%d", ofs);
|
2012-10-09 18:45:58 +00:00
|
|
|
delim = "&";
|
2008-11-29 17:39:41 +00:00
|
|
|
}
|
|
|
|
if (showmsg) {
|
|
|
|
html(delim);
|
|
|
|
html("showmsg=1");
|
2015-08-12 14:55:28 +00:00
|
|
|
delim = "&";
|
|
|
|
}
|
|
|
|
if (follow) {
|
|
|
|
html(delim);
|
|
|
|
html("follow=1");
|
2007-06-29 18:27:41 +00:00
|
|
|
}
|
|
|
|
html("'>");
|
|
|
|
html_txt(name);
|
|
|
|
html("</a>");
|
2007-06-17 11:57:51 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 04:39:07 +00:00
|
|
|
void cgit_commit_link(const char *name, const char *title, const char *class,
|
2014-10-05 09:59:02 +00:00
|
|
|
const char *head, const char *rev, const char *path)
|
2007-06-17 12:53:02 +00:00
|
|
|
{
|
2016-08-07 15:13:30 +00:00
|
|
|
char *delim;
|
|
|
|
|
2010-06-09 23:09:35 +00:00
|
|
|
delim = repolink(title, class, "commit", head, path);
|
2012-01-04 09:01:51 +00:00
|
|
|
if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) {
|
2009-09-14 18:19:02 +00:00
|
|
|
html(delim);
|
|
|
|
html("id=");
|
|
|
|
html_url_arg(rev);
|
|
|
|
delim = "&";
|
|
|
|
}
|
2014-10-05 09:59:04 +00:00
|
|
|
if (ctx.qry.difftype) {
|
2009-09-14 18:19:02 +00:00
|
|
|
html(delim);
|
2014-10-05 09:59:04 +00:00
|
|
|
htmlf("dt=%d", ctx.qry.difftype);
|
2010-06-10 18:15:51 +00:00
|
|
|
delim = "&";
|
|
|
|
}
|
|
|
|
if (ctx.qry.context > 0 && ctx.qry.context != 3) {
|
|
|
|
html(delim);
|
|
|
|
html("context=");
|
|
|
|
htmlf("%d", ctx.qry.context);
|
|
|
|
delim = "&";
|
2009-09-14 18:19:02 +00:00
|
|
|
}
|
2010-06-24 15:53:20 +00:00
|
|
|
if (ctx.qry.ignorews) {
|
|
|
|
html(delim);
|
|
|
|
html("ignorews=1");
|
|
|
|
delim = "&";
|
|
|
|
}
|
2015-08-12 14:55:28 +00:00
|
|
|
if (ctx.qry.follow) {
|
|
|
|
html(delim);
|
|
|
|
html("follow=1");
|
|
|
|
}
|
2009-09-14 18:19:02 +00:00
|
|
|
html("'>");
|
2017-10-02 04:39:07 +00:00
|
|
|
if (name[0] != '\0') {
|
|
|
|
if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
|
|
|
|
html_ntxt(name, ctx.cfg.max_msg_len - 3);
|
|
|
|
html("...");
|
|
|
|
} else
|
|
|
|
html_txt(name);
|
|
|
|
} else
|
2012-10-28 17:36:08 +00:00
|
|
|
html_txt("(no commit message)");
|
2009-09-14 18:19:02 +00:00
|
|
|
html("</a>");
|
2007-06-17 12:53:02 +00:00
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
void cgit_refs_link(const char *name, const char *title, const char *class,
|
|
|
|
const char *head, const char *rev, const char *path)
|
2007-10-27 08:47:44 +00:00
|
|
|
{
|
|
|
|
reporevlink("refs", name, title, class, head, rev, path);
|
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
void cgit_snapshot_link(const char *name, const char *title, const char *class,
|
|
|
|
const char *head, const char *rev,
|
|
|
|
const char *archivename)
|
2007-07-22 22:11:15 +00:00
|
|
|
{
|
|
|
|
reporevlink("snapshot", name, title, class, head, rev, archivename);
|
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
void cgit_diff_link(const char *name, const char *title, const char *class,
|
|
|
|
const char *head, const char *new_rev, const char *old_rev,
|
2014-10-05 09:59:03 +00:00
|
|
|
const char *path)
|
2007-06-17 16:12:03 +00:00
|
|
|
{
|
|
|
|
char *delim;
|
|
|
|
|
|
|
|
delim = repolink(title, class, "diff", head, path);
|
2010-02-01 16:55:37 +00:00
|
|
|
if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) {
|
2007-06-17 16:12:03 +00:00
|
|
|
html(delim);
|
|
|
|
html("id=");
|
2008-10-05 10:52:25 +00:00
|
|
|
html_url_arg(new_rev);
|
2007-06-17 16:12:03 +00:00
|
|
|
delim = "&";
|
|
|
|
}
|
|
|
|
if (old_rev) {
|
|
|
|
html(delim);
|
|
|
|
html("id2=");
|
2008-10-05 10:52:25 +00:00
|
|
|
html_url_arg(old_rev);
|
2009-09-14 18:19:02 +00:00
|
|
|
delim = "&";
|
|
|
|
}
|
2014-10-05 09:59:04 +00:00
|
|
|
if (ctx.qry.difftype) {
|
2009-09-14 18:19:02 +00:00
|
|
|
html(delim);
|
2014-10-05 09:59:04 +00:00
|
|
|
htmlf("dt=%d", ctx.qry.difftype);
|
2010-06-10 18:15:51 +00:00
|
|
|
delim = "&";
|
|
|
|
}
|
|
|
|
if (ctx.qry.context > 0 && ctx.qry.context != 3) {
|
|
|
|
html(delim);
|
|
|
|
html("context=");
|
|
|
|
htmlf("%d", ctx.qry.context);
|
|
|
|
delim = "&";
|
2007-06-17 16:12:03 +00:00
|
|
|
}
|
2010-06-24 15:53:20 +00:00
|
|
|
if (ctx.qry.ignorews) {
|
|
|
|
html(delim);
|
|
|
|
html("ignorews=1");
|
|
|
|
delim = "&";
|
|
|
|
}
|
2015-08-12 14:55:28 +00:00
|
|
|
if (ctx.qry.follow) {
|
|
|
|
html(delim);
|
|
|
|
html("follow=1");
|
|
|
|
}
|
2007-06-17 16:12:03 +00:00
|
|
|
html("'>");
|
|
|
|
html_txt(name);
|
|
|
|
html("</a>");
|
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
void cgit_patch_link(const char *name, const char *title, const char *class,
|
2010-06-09 23:09:33 +00:00
|
|
|
const char *head, const char *rev, const char *path)
|
2007-12-10 20:47:29 +00:00
|
|
|
{
|
2010-06-09 23:09:33 +00:00
|
|
|
reporevlink("patch", name, title, class, head, rev, path);
|
2007-12-10 20:47:29 +00:00
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
void cgit_stats_link(const char *name, const char *title, const char *class,
|
|
|
|
const char *head, const char *path)
|
2008-12-07 12:34:16 +00:00
|
|
|
{
|
|
|
|
reporevlink("stats", name, title, class, head, NULL, path);
|
|
|
|
}
|
|
|
|
|
2014-01-15 20:53:15 +00:00
|
|
|
static void cgit_self_link(char *name, const char *title, const char *class)
|
|
|
|
{
|
|
|
|
if (!strcmp(ctx.qry.page, "repolist"))
|
|
|
|
cgit_index_link(name, title, class, ctx.qry.search, ctx.qry.sort,
|
2015-03-03 16:23:40 +00:00
|
|
|
ctx.qry.ofs, 1);
|
2014-01-15 20:53:15 +00:00
|
|
|
else if (!strcmp(ctx.qry.page, "summary"))
|
|
|
|
cgit_summary_link(name, title, class, ctx.qry.head);
|
|
|
|
else if (!strcmp(ctx.qry.page, "tag"))
|
2020-10-20 21:32:45 +00:00
|
|
|
cgit_tag_link(name, title, class, ctx.qry.has_oid ?
|
|
|
|
ctx.qry.oid : ctx.qry.head);
|
2014-01-15 20:53:15 +00:00
|
|
|
else if (!strcmp(ctx.qry.page, "tree"))
|
|
|
|
cgit_tree_link(name, title, class, ctx.qry.head,
|
2020-10-20 21:32:45 +00:00
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
2014-01-15 20:53:15 +00:00
|
|
|
ctx.qry.path);
|
|
|
|
else if (!strcmp(ctx.qry.page, "plain"))
|
|
|
|
cgit_plain_link(name, title, class, ctx.qry.head,
|
2020-10-20 21:32:45 +00:00
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
2014-01-15 20:53:15 +00:00
|
|
|
ctx.qry.path);
|
2017-10-02 04:39:09 +00:00
|
|
|
else if (!strcmp(ctx.qry.page, "blame"))
|
|
|
|
cgit_blame_link(name, title, class, ctx.qry.head,
|
2020-10-20 21:32:45 +00:00
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
2017-10-02 04:39:09 +00:00
|
|
|
ctx.qry.path);
|
2014-01-15 20:53:15 +00:00
|
|
|
else if (!strcmp(ctx.qry.page, "log"))
|
|
|
|
cgit_log_link(name, title, class, ctx.qry.head,
|
2020-10-20 21:32:45 +00:00
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
2014-01-15 20:53:15 +00:00
|
|
|
ctx.qry.path, ctx.qry.ofs,
|
|
|
|
ctx.qry.grep, ctx.qry.search,
|
2015-08-12 14:55:28 +00:00
|
|
|
ctx.qry.showmsg, ctx.qry.follow);
|
2014-01-15 20:53:15 +00:00
|
|
|
else if (!strcmp(ctx.qry.page, "commit"))
|
|
|
|
cgit_commit_link(name, title, class, ctx.qry.head,
|
2020-10-20 21:32:45 +00:00
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
2014-10-05 09:59:02 +00:00
|
|
|
ctx.qry.path);
|
2014-01-15 20:53:15 +00:00
|
|
|
else if (!strcmp(ctx.qry.page, "patch"))
|
|
|
|
cgit_patch_link(name, title, class, ctx.qry.head,
|
2020-10-20 21:32:45 +00:00
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
2014-01-15 20:53:15 +00:00
|
|
|
ctx.qry.path);
|
|
|
|
else if (!strcmp(ctx.qry.page, "refs"))
|
|
|
|
cgit_refs_link(name, title, class, ctx.qry.head,
|
2020-10-20 21:32:45 +00:00
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
2014-01-15 20:53:15 +00:00
|
|
|
ctx.qry.path);
|
|
|
|
else if (!strcmp(ctx.qry.page, "snapshot"))
|
|
|
|
cgit_snapshot_link(name, title, class, ctx.qry.head,
|
2020-10-20 21:32:45 +00:00
|
|
|
ctx.qry.has_oid ? ctx.qry.oid : NULL,
|
2014-01-15 20:53:15 +00:00
|
|
|
ctx.qry.path);
|
|
|
|
else if (!strcmp(ctx.qry.page, "diff"))
|
|
|
|
cgit_diff_link(name, title, class, ctx.qry.head,
|
2020-10-20 21:32:45 +00:00
|
|
|
ctx.qry.oid, ctx.qry.oid2,
|
2014-10-05 09:59:03 +00:00
|
|
|
ctx.qry.path);
|
2014-01-15 20:53:15 +00:00
|
|
|
else if (!strcmp(ctx.qry.page, "stats"))
|
|
|
|
cgit_stats_link(name, title, class, ctx.qry.head,
|
|
|
|
ctx.qry.path);
|
2013-03-06 20:51:54 +00:00
|
|
|
else {
|
|
|
|
/* Don't known how to make link for this page */
|
2014-01-15 20:53:15 +00:00
|
|
|
repolink(title, class, ctx.qry.page, ctx.qry.head, ctx.qry.path);
|
2013-03-06 20:51:54 +00:00
|
|
|
html("><!-- cgit_self_link() doesn't know how to make link for page '");
|
2014-01-15 20:53:15 +00:00
|
|
|
html_txt(ctx.qry.page);
|
2013-03-06 20:51:54 +00:00
|
|
|
html("' -->");
|
|
|
|
html_txt(name);
|
|
|
|
html("</a>");
|
|
|
|
}
|
2010-06-09 23:09:29 +00:00
|
|
|
}
|
|
|
|
|
2007-07-22 21:42:55 +00:00
|
|
|
void cgit_object_link(struct object *obj)
|
|
|
|
{
|
2008-12-01 20:58:59 +00:00
|
|
|
char *page, *shortrev, *fullrev, *name;
|
2007-07-22 21:42:55 +00:00
|
|
|
|
2016-01-05 06:38:53 +00:00
|
|
|
fullrev = oid_to_hex(&obj->oid);
|
2008-12-01 20:58:59 +00:00
|
|
|
shortrev = xstrdup(fullrev);
|
|
|
|
shortrev[10] = '\0';
|
2007-07-22 21:42:55 +00:00
|
|
|
if (obj->type == OBJ_COMMIT) {
|
2013-03-03 15:04:29 +00:00
|
|
|
cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
|
2014-10-05 09:59:02 +00:00
|
|
|
ctx.qry.head, fullrev, NULL);
|
2007-07-22 21:42:55 +00:00
|
|
|
return;
|
2008-10-05 19:12:08 +00:00
|
|
|
} else if (obj->type == OBJ_TREE)
|
2007-07-22 21:42:55 +00:00
|
|
|
page = "tree";
|
2008-10-05 19:12:08 +00:00
|
|
|
else if (obj->type == OBJ_TAG)
|
2007-10-28 14:40:47 +00:00
|
|
|
page = "tag";
|
2008-10-05 19:12:08 +00:00
|
|
|
else
|
2007-07-22 21:42:55 +00:00
|
|
|
page = "blob";
|
2018-05-30 08:28:12 +00:00
|
|
|
name = fmt("%s %s...", type_name(obj->type), shortrev);
|
2008-12-01 20:58:59 +00:00
|
|
|
reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
|
2007-07-22 21:42:55 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static struct string_list_item *lookup_path(struct string_list *list,
|
|
|
|
const char *path)
|
2011-06-15 08:04:13 +00:00
|
|
|
{
|
|
|
|
struct string_list_item *item;
|
|
|
|
|
|
|
|
while (path && path[0]) {
|
|
|
|
if ((item = string_list_lookup(list, path)))
|
|
|
|
return item;
|
|
|
|
if (!(path = strchr(path, '/')))
|
|
|
|
break;
|
|
|
|
path++;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cgit_submodule_link(const char *class, char *path, const char *rev)
|
|
|
|
{
|
|
|
|
struct string_list *list;
|
|
|
|
struct string_list_item *item;
|
|
|
|
char tail, *dir;
|
|
|
|
size_t len;
|
|
|
|
|
2013-03-20 19:43:13 +00:00
|
|
|
len = 0;
|
2011-06-15 08:04:13 +00:00
|
|
|
tail = 0;
|
|
|
|
list = &ctx.repo->submodules;
|
|
|
|
item = lookup_path(list, path);
|
|
|
|
if (!item) {
|
|
|
|
len = strlen(path);
|
|
|
|
tail = path[len - 1];
|
|
|
|
if (tail == '/') {
|
|
|
|
path[len - 1] = 0;
|
|
|
|
item = lookup_path(list, path);
|
|
|
|
}
|
|
|
|
}
|
2015-03-05 19:41:45 +00:00
|
|
|
if (item || ctx.repo->module_link) {
|
|
|
|
html("<a ");
|
|
|
|
if (class)
|
|
|
|
htmlf("class='%s' ", class);
|
|
|
|
html("href='");
|
|
|
|
if (item) {
|
|
|
|
html_attrf(item->util, rev);
|
|
|
|
} else {
|
|
|
|
dir = strrchr(path, '/');
|
|
|
|
if (dir)
|
|
|
|
dir++;
|
|
|
|
else
|
|
|
|
dir = path;
|
|
|
|
html_attrf(ctx.repo->module_link, dir, rev);
|
|
|
|
}
|
|
|
|
html("'>");
|
|
|
|
html_txt(path);
|
|
|
|
html("</a>");
|
2011-06-15 08:04:13 +00:00
|
|
|
} else {
|
2015-03-05 19:41:45 +00:00
|
|
|
html("<span");
|
|
|
|
if (class)
|
|
|
|
htmlf(" class='%s'", class);
|
|
|
|
html(">");
|
|
|
|
html_txt(path);
|
|
|
|
html("</span>");
|
2011-06-15 08:04:13 +00:00
|
|
|
}
|
2013-04-06 09:28:57 +00:00
|
|
|
html_txtf(" @ %.7s", rev);
|
2011-06-15 08:04:13 +00:00
|
|
|
if (item && tail)
|
|
|
|
path[len - 1] = tail;
|
|
|
|
}
|
|
|
|
|
2016-02-08 15:05:54 +00:00
|
|
|
const struct date_mode *cgit_date_mode(enum date_mode_type type)
|
2016-01-19 19:33:03 +00:00
|
|
|
{
|
|
|
|
static struct date_mode mode;
|
2016-02-08 15:05:54 +00:00
|
|
|
mode.type = type;
|
2016-01-19 19:33:03 +00:00
|
|
|
mode.local = ctx.cfg.local_time;
|
|
|
|
return &mode;
|
|
|
|
}
|
|
|
|
|
2016-01-19 19:33:05 +00:00
|
|
|
static void print_rel_date(time_t t, int tz, double value,
|
2014-12-20 13:59:39 +00:00
|
|
|
const char *class, const char *suffix)
|
|
|
|
{
|
js: add dynamic age update
This patch updates the emitted "ages" dynamically on the client side.
After updating on completion of the document load, it sets a timer
to update according to the smallest age it found. If there are any
ages listed in minutes, then it will update again in 10s. When the
most recent age is in hours, it updates every 5m. If days, then
every 30m and so on.
This keeps the cost of the dynamic updates at worst once per 10s.
The updates are done entirely on the client side without contact
with the server.
To make this work reliably, since parsing datetimes is unreliable in
browser js, the unix time is added as an attribute to all age spans.
To make that reliable cross-platform, the unix time is treated as a
uint64_t when it is formatted for printing.
The rules for display conversion of the age is aligned with the
existing server-side rules in ui-shared.h.
If the client or server-side time are not synchronized by ntpd etc,
ages shown on the client will not relate to the original ages computed
at the server. The client updates the ages immediately when the
DOM has finished loading, so in the case the times at the server and
client are not aligned, this patch changes what the user sees on the
page to reflect patch age compared to client time.
If the server and client clocks are aligned, this patch makes no
difference to what is seen on the page.
Signed-off-by: Andy Green <andy@warmcat.com>
Signed-off-by: Christian Hesse <mail@eworm.de>
2018-06-24 07:05:20 +00:00
|
|
|
htmlf("<span class='%s' data-ut='%" PRIu64 "' title='", class, (uint64_t)t);
|
2016-02-08 15:05:54 +00:00
|
|
|
html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601)));
|
2014-12-20 13:59:39 +00:00
|
|
|
htmlf("'>%.0f %s</span>", value, suffix);
|
|
|
|
}
|
|
|
|
|
2016-01-19 19:33:05 +00:00
|
|
|
void cgit_print_age(time_t t, int tz, time_t max_relative)
|
2007-05-22 21:08:46 +00:00
|
|
|
{
|
|
|
|
time_t now, secs;
|
|
|
|
|
2007-12-02 21:11:35 +00:00
|
|
|
if (!t)
|
|
|
|
return;
|
2007-05-22 21:08:46 +00:00
|
|
|
time(&now);
|
|
|
|
secs = now - t;
|
2014-01-17 14:41:41 +00:00
|
|
|
if (secs < 0)
|
|
|
|
secs = 0;
|
2007-05-22 21:08:46 +00:00
|
|
|
|
|
|
|
if (secs > max_relative && max_relative >= 0) {
|
2015-08-13 11:24:34 +00:00
|
|
|
html("<span title='");
|
2016-02-08 15:05:54 +00:00
|
|
|
html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601)));
|
2015-08-13 11:24:34 +00:00
|
|
|
html("'>");
|
2016-02-08 15:05:54 +00:00
|
|
|
html_txt(show_date(t, tz, cgit_date_mode(DATE_SHORT)));
|
2015-08-13 11:24:34 +00:00
|
|
|
html("</span>");
|
2007-05-22 21:08:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (secs < TM_HOUR * 2) {
|
2016-01-19 19:33:05 +00:00
|
|
|
print_rel_date(t, tz, secs * 1.0 / TM_MIN, "age-mins", "min.");
|
2007-05-22 21:08:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (secs < TM_DAY * 2) {
|
2016-01-19 19:33:05 +00:00
|
|
|
print_rel_date(t, tz, secs * 1.0 / TM_HOUR, "age-hours", "hours");
|
2007-05-22 21:08:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (secs < TM_WEEK * 2) {
|
2016-01-19 19:33:05 +00:00
|
|
|
print_rel_date(t, tz, secs * 1.0 / TM_DAY, "age-days", "days");
|
2007-05-22 21:08:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (secs < TM_MONTH * 2) {
|
2016-01-19 19:33:05 +00:00
|
|
|
print_rel_date(t, tz, secs * 1.0 / TM_WEEK, "age-weeks", "weeks");
|
2007-05-22 21:08:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (secs < TM_YEAR * 2) {
|
2016-01-19 19:33:05 +00:00
|
|
|
print_rel_date(t, tz, secs * 1.0 / TM_MONTH, "age-months", "months");
|
2007-05-22 21:08:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-01-19 19:33:05 +00:00
|
|
|
print_rel_date(t, tz, secs * 1.0 / TM_YEAR, "age-years", "years");
|
2007-05-22 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
2014-01-15 20:53:15 +00:00
|
|
|
void cgit_print_http_headers(void)
|
2006-12-11 15:38:30 +00:00
|
|
|
{
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.env.no_http && !strcmp(ctx.env.no_http, "1"))
|
2009-01-22 22:33:56 +00:00
|
|
|
return;
|
|
|
|
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.page.status)
|
|
|
|
htmlf("Status: %d %s\n", ctx.page.status, ctx.page.statusmsg);
|
|
|
|
if (ctx.page.mimetype && ctx.page.charset)
|
|
|
|
htmlf("Content-Type: %s; charset=%s\n", ctx.page.mimetype,
|
|
|
|
ctx.page.charset);
|
|
|
|
else if (ctx.page.mimetype)
|
|
|
|
htmlf("Content-Type: %s\n", ctx.page.mimetype);
|
|
|
|
if (ctx.page.size)
|
|
|
|
htmlf("Content-Length: %zd\n", ctx.page.size);
|
2016-01-14 13:28:37 +00:00
|
|
|
if (ctx.page.filename) {
|
|
|
|
html("Content-Disposition: inline; filename=\"");
|
|
|
|
html_header_arg_in_quotes(ctx.page.filename);
|
|
|
|
html("\"\n");
|
|
|
|
}
|
2014-01-15 20:53:15 +00:00
|
|
|
if (!ctx.env.authenticated)
|
2014-01-14 20:49:31 +00:00
|
|
|
html("Cache-Control: no-cache, no-store\n");
|
2014-01-15 20:53:15 +00:00
|
|
|
htmlf("Last-Modified: %s\n", http_date(ctx.page.modified));
|
|
|
|
htmlf("Expires: %s\n", http_date(ctx.page.expires));
|
|
|
|
if (ctx.page.etag)
|
|
|
|
htmlf("ETag: \"%s\"\n", ctx.page.etag);
|
2006-12-11 15:38:30 +00:00
|
|
|
html("\n");
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD"))
|
2009-02-19 22:24:15 +00:00
|
|
|
exit(0);
|
2008-03-23 23:51:19 +00:00
|
|
|
}
|
|
|
|
|
2015-08-12 12:50:09 +00:00
|
|
|
void cgit_redirect(const char *url, bool permanent)
|
|
|
|
{
|
|
|
|
htmlf("Status: %d %s\n", permanent ? 301 : 302, permanent ? "Moved" : "Found");
|
2016-01-14 13:13:39 +00:00
|
|
|
html("Location: ");
|
|
|
|
html_url_path(url);
|
|
|
|
html("\n\n");
|
2015-08-12 12:50:09 +00:00
|
|
|
}
|
|
|
|
|
2014-08-01 21:14:19 +00:00
|
|
|
static void print_rel_vcs_link(const char *url)
|
|
|
|
{
|
|
|
|
html("<link rel='vcs-git' href='");
|
|
|
|
html_attr(url);
|
|
|
|
html("' title='");
|
|
|
|
html_attr(ctx.repo->name);
|
|
|
|
html(" Git repository'/>\n");
|
|
|
|
}
|
|
|
|
|
2018-07-03 03:33:59 +00:00
|
|
|
static int emit_css_link(struct string_list_item *s, void *arg)
|
|
|
|
{
|
2023-01-07 09:32:07 +00:00
|
|
|
/* Do not emit anything if css= is specified. */
|
|
|
|
if (s && *s->string == '\0')
|
|
|
|
return 0;
|
|
|
|
|
2018-07-03 03:33:59 +00:00
|
|
|
html("<link rel='stylesheet' type='text/css' href='");
|
|
|
|
if (s)
|
|
|
|
html_attr(s->string);
|
|
|
|
else
|
|
|
|
html_attr((const char *)arg);
|
|
|
|
html("'/>\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-23 10:25:53 +00:00
|
|
|
static int emit_js_link(struct string_list_item *s, void *arg)
|
|
|
|
{
|
2023-01-07 09:32:07 +00:00
|
|
|
/* Do not emit anything if js= is specified. */
|
|
|
|
if (s && *s->string == '\0')
|
|
|
|
return 0;
|
|
|
|
|
2018-06-23 10:25:53 +00:00
|
|
|
html("<script type='text/javascript' src='");
|
|
|
|
if (s)
|
|
|
|
html_attr(s->string);
|
|
|
|
else
|
|
|
|
html_attr((const char *)arg);
|
|
|
|
html("'></script>\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-15 20:53:15 +00:00
|
|
|
void cgit_print_docstart(void)
|
2008-03-23 23:51:19 +00:00
|
|
|
{
|
2016-08-07 15:13:30 +00:00
|
|
|
char *host = cgit_hosturl();
|
|
|
|
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.cfg.embedded) {
|
|
|
|
if (ctx.cfg.header)
|
|
|
|
html_include(ctx.cfg.header);
|
2009-01-22 22:33:56 +00:00
|
|
|
return;
|
2009-08-11 08:12:35 +00:00
|
|
|
}
|
2009-01-22 22:33:56 +00:00
|
|
|
|
2006-12-11 15:38:30 +00:00
|
|
|
html(cgit_doctype);
|
2016-05-11 18:04:14 +00:00
|
|
|
html("<html lang='en'>\n");
|
2006-12-11 15:38:30 +00:00
|
|
|
html("<head>\n");
|
|
|
|
html("<title>");
|
2014-01-15 20:53:15 +00:00
|
|
|
html_txt(ctx.page.title);
|
2006-12-11 15:38:30 +00:00
|
|
|
html("</title>\n");
|
2007-06-18 07:42:10 +00:00
|
|
|
htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.cfg.robots && *ctx.cfg.robots)
|
|
|
|
htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots);
|
2018-07-03 03:33:59 +00:00
|
|
|
|
|
|
|
if (ctx.cfg.css.items)
|
|
|
|
for_each_string_list(&ctx.cfg.css, emit_css_link, NULL);
|
|
|
|
else
|
|
|
|
emit_css_link(NULL, "/cgit.css");
|
|
|
|
|
2018-06-23 10:25:53 +00:00
|
|
|
if (ctx.cfg.js.items)
|
|
|
|
for_each_string_list(&ctx.cfg.js, emit_js_link, NULL);
|
|
|
|
else
|
|
|
|
emit_js_link(NULL, "/cgit.js");
|
|
|
|
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.cfg.favicon) {
|
2008-07-19 18:40:30 +00:00
|
|
|
html("<link rel='shortcut icon' href='");
|
2014-01-15 20:53:15 +00:00
|
|
|
html_attr(ctx.cfg.favicon);
|
2008-07-19 18:40:30 +00:00
|
|
|
html("'/>\n");
|
|
|
|
}
|
2014-01-15 20:53:15 +00:00
|
|
|
if (host && ctx.repo && ctx.qry.head) {
|
2015-10-09 11:15:46 +00:00
|
|
|
char *fileurl;
|
2013-04-06 09:28:57 +00:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2014-01-15 20:53:15 +00:00
|
|
|
strbuf_addf(&sb, "h=%s", ctx.qry.head);
|
2013-04-06 09:28:57 +00:00
|
|
|
|
2009-06-10 23:18:34 +00:00
|
|
|
html("<link rel='alternate' title='Atom feed' href='");
|
|
|
|
html(cgit_httpscheme());
|
2015-10-09 11:15:51 +00:00
|
|
|
html_attr(host);
|
2015-10-09 11:15:46 +00:00
|
|
|
fileurl = cgit_fileurl(ctx.repo->url, "atom", ctx.qry.vpath,
|
|
|
|
sb.buf);
|
|
|
|
html_attr(fileurl);
|
2009-03-15 04:11:54 +00:00
|
|
|
html("' type='application/atom+xml'/>\n");
|
2013-04-06 09:28:57 +00:00
|
|
|
strbuf_release(&sb);
|
2015-10-09 11:15:46 +00:00
|
|
|
free(fileurl);
|
2008-05-21 06:17:54 +00:00
|
|
|
}
|
2014-08-01 21:14:19 +00:00
|
|
|
if (ctx.repo)
|
|
|
|
cgit_add_clone_urls(print_rel_vcs_link);
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.cfg.head_include)
|
|
|
|
html_include(ctx.cfg.head_include);
|
2018-02-12 22:10:06 +00:00
|
|
|
if (ctx.repo && ctx.repo->extra_head_content)
|
|
|
|
html(ctx.repo->extra_head_content);
|
2006-12-11 15:38:30 +00:00
|
|
|
html("</head>\n");
|
|
|
|
html("<body>\n");
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.cfg.header)
|
|
|
|
html_include(ctx.cfg.header);
|
2015-10-09 11:15:51 +00:00
|
|
|
free(host);
|
2006-12-11 15:38:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-08 16:32:16 +00:00
|
|
|
void cgit_print_docend(void)
|
2006-12-11 15:38:30 +00:00
|
|
|
{
|
2009-08-11 08:12:35 +00:00
|
|
|
html("</div> <!-- class=content -->\n");
|
|
|
|
if (ctx.cfg.embedded) {
|
|
|
|
html("</div> <!-- id=cgit -->\n");
|
|
|
|
if (ctx.cfg.footer)
|
|
|
|
html_include(ctx.cfg.footer);
|
|
|
|
return;
|
|
|
|
}
|
2008-06-26 11:53:30 +00:00
|
|
|
if (ctx.cfg.footer)
|
|
|
|
html_include(ctx.cfg.footer);
|
|
|
|
else {
|
2018-06-04 20:27:46 +00:00
|
|
|
htmlf("<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit %s</a> "
|
|
|
|
"(<a href='https://git-scm.com/'>git %s</a>) at ", cgit_version, git_version_string);
|
2016-02-08 15:05:54 +00:00
|
|
|
html_txt(show_date(time(NULL), 0, cgit_date_mode(DATE_ISO8601)));
|
2008-06-26 11:53:30 +00:00
|
|
|
html("</div>\n");
|
|
|
|
}
|
2009-08-11 08:12:35 +00:00
|
|
|
html("</div> <!-- id=cgit -->\n");
|
2008-06-26 11:53:30 +00:00
|
|
|
html("</body>\n</html>\n");
|
2007-10-30 09:47:38 +00:00
|
|
|
}
|
|
|
|
|
2015-08-14 11:47:01 +00:00
|
|
|
void cgit_print_error_page(int code, const char *msg, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2015-08-14 11:47:22 +00:00
|
|
|
ctx.page.expires = ctx.cfg.cache_dynamic_ttl;
|
2015-08-14 11:47:01 +00:00
|
|
|
ctx.page.status = code;
|
|
|
|
ctx.page.statusmsg = msg;
|
2016-05-11 17:50:09 +00:00
|
|
|
cgit_print_layout_start();
|
2015-08-14 11:47:01 +00:00
|
|
|
va_start(ap, fmt);
|
|
|
|
cgit_vprint_error(fmt, ap);
|
|
|
|
va_end(ap);
|
2016-05-11 17:50:09 +00:00
|
|
|
cgit_print_layout_end();
|
2015-08-14 11:47:01 +00:00
|
|
|
}
|
|
|
|
|
2015-08-14 11:47:11 +00:00
|
|
|
void cgit_print_layout_start(void)
|
|
|
|
{
|
|
|
|
cgit_print_http_headers();
|
|
|
|
cgit_print_docstart();
|
|
|
|
cgit_print_pageheader();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cgit_print_layout_end(void)
|
|
|
|
{
|
|
|
|
cgit_print_docend();
|
|
|
|
}
|
|
|
|
|
2014-08-01 21:14:17 +00:00
|
|
|
static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix)
|
|
|
|
{
|
2015-02-05 09:11:42 +00:00
|
|
|
struct strbuf **url_list = strbuf_split_str(txt, ' ', 0);
|
|
|
|
int i;
|
2014-08-01 21:14:17 +00:00
|
|
|
|
2015-02-05 09:11:42 +00:00
|
|
|
for (i = 0; url_list[i]; i++) {
|
|
|
|
strbuf_rtrim(url_list[i]);
|
|
|
|
if (url_list[i]->len == 0)
|
|
|
|
continue;
|
|
|
|
if (suffix && *suffix)
|
|
|
|
strbuf_addf(url_list[i], "/%s", suffix);
|
|
|
|
fn(url_list[i]->buf);
|
2014-08-01 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
2015-02-05 09:11:42 +00:00
|
|
|
strbuf_list_free(url_list);
|
2014-08-01 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cgit_add_clone_urls(void (*fn)(const char *))
|
|
|
|
{
|
|
|
|
if (ctx.repo->clone_url)
|
|
|
|
add_clone_urls(fn, expand_macros(ctx.repo->clone_url), NULL);
|
|
|
|
else if (ctx.cfg.clone_prefix)
|
|
|
|
add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url);
|
|
|
|
}
|
|
|
|
|
2015-07-28 08:42:01 +00:00
|
|
|
static int print_branch_option(const char *refname, const struct object_id *oid,
|
2013-03-04 07:52:33 +00:00
|
|
|
int flags, void *cb_data)
|
2007-10-30 09:47:38 +00:00
|
|
|
{
|
|
|
|
char *name = (char *)refname;
|
2008-02-16 10:53:40 +00:00
|
|
|
html_option(name, name, ctx.qry.head);
|
2007-10-30 09:47:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-09 23:09:24 +00:00
|
|
|
void cgit_add_hidden_formfields(int incl_head, int incl_search,
|
|
|
|
const char *page)
|
2007-10-30 09:47:38 +00:00
|
|
|
{
|
2008-02-16 12:07:13 +00:00
|
|
|
if (!ctx.cfg.virtual_root) {
|
2013-04-06 09:28:57 +00:00
|
|
|
struct strbuf url = STRBUF_INIT;
|
|
|
|
|
|
|
|
strbuf_addf(&url, "%s/%s", ctx.qry.repo, page);
|
2010-06-09 23:09:27 +00:00
|
|
|
if (ctx.qry.vpath)
|
2013-04-06 09:28:57 +00:00
|
|
|
strbuf_addf(&url, "/%s", ctx.qry.vpath);
|
|
|
|
html_hidden("url", url.buf);
|
|
|
|
strbuf_release(&url);
|
2007-10-30 09:47:38 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 10:32:08 +00:00
|
|
|
if (incl_head && ctx.qry.head && ctx.repo->defbranch &&
|
|
|
|
strcmp(ctx.qry.head, ctx.repo->defbranch))
|
2008-02-16 10:53:40 +00:00
|
|
|
html_hidden("h", ctx.qry.head);
|
2007-10-30 09:47:38 +00:00
|
|
|
|
2020-10-20 21:32:45 +00:00
|
|
|
if (ctx.qry.oid)
|
|
|
|
html_hidden("id", ctx.qry.oid);
|
|
|
|
if (ctx.qry.oid2)
|
|
|
|
html_hidden("id2", ctx.qry.oid2);
|
2008-11-29 17:39:41 +00:00
|
|
|
if (ctx.qry.showmsg)
|
|
|
|
html_hidden("showmsg", "1");
|
2007-10-30 09:47:38 +00:00
|
|
|
|
|
|
|
if (incl_search) {
|
2008-02-16 10:53:40 +00:00
|
|
|
if (ctx.qry.grep)
|
|
|
|
html_hidden("qt", ctx.qry.grep);
|
|
|
|
if (ctx.qry.search)
|
|
|
|
html_hidden("q", ctx.qry.search);
|
2007-10-30 09:47:38 +00:00
|
|
|
}
|
2006-12-11 15:38:30 +00:00
|
|
|
}
|
|
|
|
|
2014-01-15 20:53:15 +00:00
|
|
|
static const char *hc(const char *page)
|
2008-04-12 13:53:31 +00:00
|
|
|
{
|
2015-12-13 00:27:13 +00:00
|
|
|
if (!ctx.qry.page)
|
|
|
|
return NULL;
|
|
|
|
|
2014-01-15 20:53:15 +00:00
|
|
|
return strcmp(ctx.qry.page, page) ? NULL : "active";
|
2008-04-12 13:53:31 +00:00
|
|
|
}
|
|
|
|
|
2014-01-15 20:53:15 +00:00
|
|
|
static void cgit_print_path_crumbs(char *path)
|
2010-06-09 23:09:29 +00:00
|
|
|
{
|
2014-01-15 20:53:15 +00:00
|
|
|
char *old_path = ctx.qry.path;
|
2010-06-09 23:09:29 +00:00
|
|
|
char *p = path, *q, *end = path + strlen(path);
|
2019-05-20 19:45:12 +00:00
|
|
|
int levels = 0;
|
2010-06-09 23:09:29 +00:00
|
|
|
|
2014-01-15 20:53:15 +00:00
|
|
|
ctx.qry.path = NULL;
|
|
|
|
cgit_self_link("root", NULL, NULL);
|
|
|
|
ctx.qry.path = p = path;
|
2010-06-09 23:09:29 +00:00
|
|
|
while (p < end) {
|
2019-05-20 19:45:12 +00:00
|
|
|
if (!(q = strchr(p, '/')) || levels > 15)
|
2010-06-09 23:09:29 +00:00
|
|
|
q = end;
|
|
|
|
*q = '\0';
|
|
|
|
html_txt("/");
|
2014-01-15 20:53:15 +00:00
|
|
|
cgit_self_link(p, NULL, NULL);
|
2010-06-09 23:09:29 +00:00
|
|
|
if (q < end)
|
|
|
|
*q = '/';
|
|
|
|
p = q + 1;
|
2019-05-20 19:45:12 +00:00
|
|
|
++levels;
|
2010-06-09 23:09:29 +00:00
|
|
|
}
|
2014-01-15 20:53:15 +00:00
|
|
|
ctx.qry.path = old_path;
|
2010-06-09 23:09:29 +00:00
|
|
|
}
|
|
|
|
|
2014-01-15 20:53:15 +00:00
|
|
|
static void print_header(void)
|
2006-12-11 15:38:30 +00:00
|
|
|
{
|
2010-12-23 11:47:54 +00:00
|
|
|
char *logo = NULL, *logo_link = NULL;
|
|
|
|
|
2008-04-12 13:53:31 +00:00
|
|
|
html("<table id='header'>\n");
|
|
|
|
html("<tr>\n");
|
2009-06-30 01:27:51 +00:00
|
|
|
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.repo && ctx.repo->logo && *ctx.repo->logo)
|
|
|
|
logo = ctx.repo->logo;
|
2010-12-23 11:47:54 +00:00
|
|
|
else
|
2014-01-15 20:53:15 +00:00
|
|
|
logo = ctx.cfg.logo;
|
|
|
|
if (ctx.repo && ctx.repo->logo_link && *ctx.repo->logo_link)
|
|
|
|
logo_link = ctx.repo->logo_link;
|
2010-12-23 11:47:54 +00:00
|
|
|
else
|
2014-01-15 20:53:15 +00:00
|
|
|
logo_link = ctx.cfg.logo_link;
|
2010-12-23 11:47:54 +00:00
|
|
|
if (logo && *logo) {
|
2009-06-30 01:27:51 +00:00
|
|
|
html("<td class='logo' rowspan='2'><a href='");
|
2010-12-23 11:47:54 +00:00
|
|
|
if (logo_link && *logo_link)
|
|
|
|
html_attr(logo_link);
|
2009-06-30 01:27:51 +00:00
|
|
|
else
|
|
|
|
html_attr(cgit_rooturl());
|
|
|
|
html("'><img src='");
|
2010-12-23 11:47:54 +00:00
|
|
|
html_attr(logo);
|
2009-06-30 01:27:51 +00:00
|
|
|
html("' alt='cgit logo'/></a></td>\n");
|
|
|
|
}
|
2008-04-13 08:57:11 +00:00
|
|
|
|
2008-04-12 13:53:31 +00:00
|
|
|
html("<td class='main'>");
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.repo) {
|
2015-03-03 16:23:40 +00:00
|
|
|
cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1);
|
2008-05-03 10:44:20 +00:00
|
|
|
html(" : ");
|
2019-03-15 20:17:05 +00:00
|
|
|
cgit_summary_link(ctx.repo->name, NULL, NULL, NULL);
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.env.authenticated) {
|
2014-01-14 20:49:31 +00:00
|
|
|
html("</td><td class='form'>");
|
2016-05-12 19:29:40 +00:00
|
|
|
html("<form method='get'>\n");
|
2014-01-15 20:53:15 +00:00
|
|
|
cgit_add_hidden_formfields(0, 1, ctx.qry.page);
|
2014-01-14 20:49:31 +00:00
|
|
|
html("<select name='h' onchange='this.form.submit();'>\n");
|
2014-01-15 20:53:15 +00:00
|
|
|
for_each_branch_ref(print_branch_option, ctx.qry.head);
|
2015-03-18 17:08:48 +00:00
|
|
|
if (ctx.repo->enable_remote_branches)
|
|
|
|
for_each_remote_ref(print_branch_option, ctx.qry.head);
|
2014-01-14 20:49:31 +00:00
|
|
|
html("</select> ");
|
2016-05-11 18:04:18 +00:00
|
|
|
html("<input type='submit' value='switch'/>");
|
2014-01-14 20:49:31 +00:00
|
|
|
html("</form>");
|
|
|
|
}
|
2008-04-12 17:59:41 +00:00
|
|
|
} else
|
2014-01-15 20:53:15 +00:00
|
|
|
html_txt(ctx.cfg.root_title);
|
2008-04-14 22:00:11 +00:00
|
|
|
html("</td></tr>\n");
|
2008-04-13 08:57:11 +00:00
|
|
|
|
2008-07-27 10:22:16 +00:00
|
|
|
html("<tr><td class='sub'>");
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.repo) {
|
|
|
|
html_txt(ctx.repo->desc);
|
2008-07-27 10:22:16 +00:00
|
|
|
html("</td><td class='sub right'>");
|
2021-02-04 22:10:14 +00:00
|
|
|
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);
|
|
|
|
}
|
2008-04-14 22:00:11 +00:00
|
|
|
} else {
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.cfg.root_desc)
|
|
|
|
html_txt(ctx.cfg.root_desc);
|
2008-04-13 08:57:11 +00:00
|
|
|
}
|
2008-04-14 22:00:11 +00:00
|
|
|
html("</td></tr></table>\n");
|
2009-07-25 10:19:31 +00:00
|
|
|
}
|
|
|
|
|
2014-01-15 20:53:15 +00:00
|
|
|
void cgit_print_pageheader(void)
|
2009-07-25 10:19:31 +00:00
|
|
|
{
|
|
|
|
html("<div id='cgit'>");
|
2014-01-15 20:53:15 +00:00
|
|
|
if (!ctx.env.authenticated || !ctx.cfg.noheader)
|
|
|
|
print_header();
|
2008-04-12 13:53:31 +00:00
|
|
|
|
|
|
|
html("<table class='tabs'><tr><td>\n");
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.env.authenticated && ctx.repo) {
|
2014-01-17 12:53:37 +00:00
|
|
|
if (ctx.repo->readme.nr)
|
|
|
|
reporevlink("about", "about", NULL,
|
|
|
|
hc("about"), ctx.qry.head, NULL,
|
|
|
|
NULL);
|
2014-01-15 20:53:15 +00:00
|
|
|
cgit_summary_link("summary", NULL, hc("summary"),
|
|
|
|
ctx.qry.head);
|
|
|
|
cgit_refs_link("refs", NULL, hc("refs"), ctx.qry.head,
|
2020-10-20 21:32:45 +00:00
|
|
|
ctx.qry.oid, NULL);
|
2014-01-15 20:53:15 +00:00
|
|
|
cgit_log_link("log", NULL, hc("log"), ctx.qry.head,
|
|
|
|
NULL, ctx.qry.vpath, 0, NULL, NULL,
|
2015-08-12 14:55:28 +00:00
|
|
|
ctx.qry.showmsg, ctx.qry.follow);
|
2017-10-02 04:39:09 +00:00
|
|
|
if (ctx.qry.page && !strcmp(ctx.qry.page, "blame"))
|
|
|
|
cgit_blame_link("blame", NULL, hc("blame"), ctx.qry.head,
|
2020-10-20 21:32:45 +00:00
|
|
|
ctx.qry.oid, ctx.qry.vpath);
|
2017-10-02 04:39:09 +00:00
|
|
|
else
|
|
|
|
cgit_tree_link("tree", NULL, hc("tree"), ctx.qry.head,
|
2020-10-20 21:32:45 +00:00
|
|
|
ctx.qry.oid, ctx.qry.vpath);
|
2014-01-15 20:53:15 +00:00
|
|
|
cgit_commit_link("commit", NULL, hc("commit"),
|
2020-10-20 21:32:45 +00:00
|
|
|
ctx.qry.head, ctx.qry.oid, ctx.qry.vpath);
|
2014-01-15 20:53:15 +00:00
|
|
|
cgit_diff_link("diff", NULL, hc("diff"), ctx.qry.head,
|
2020-10-20 21:32:45 +00:00
|
|
|
ctx.qry.oid, ctx.qry.oid2, ctx.qry.vpath);
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.repo->max_stats)
|
|
|
|
cgit_stats_link("stats", NULL, hc("stats"),
|
|
|
|
ctx.qry.head, ctx.qry.vpath);
|
2016-02-22 15:04:15 +00:00
|
|
|
if (ctx.repo->homepage) {
|
|
|
|
html("<a href='");
|
|
|
|
html_attr(ctx.repo->homepage);
|
2016-02-23 14:35:32 +00:00
|
|
|
html("'>homepage</a>");
|
2016-02-22 15:04:15 +00:00
|
|
|
}
|
2008-04-13 08:57:11 +00:00
|
|
|
html("</td><td class='form'>");
|
|
|
|
html("<form class='right' method='get' action='");
|
2015-10-09 11:15:46 +00:00
|
|
|
if (ctx.cfg.virtual_root) {
|
|
|
|
char *fileurl = cgit_fileurl(ctx.qry.repo, "log",
|
|
|
|
ctx.qry.vpath, NULL);
|
|
|
|
html_url_path(fileurl);
|
|
|
|
free(fileurl);
|
|
|
|
}
|
2008-04-13 08:57:11 +00:00
|
|
|
html("'>\n");
|
2008-12-07 14:52:35 +00:00
|
|
|
cgit_add_hidden_formfields(1, 0, "log");
|
2008-04-13 08:57:11 +00:00
|
|
|
html("<select name='qt'>\n");
|
2014-01-15 20:53:15 +00:00
|
|
|
html_option("grep", "log msg", ctx.qry.grep);
|
|
|
|
html_option("author", "author", ctx.qry.grep);
|
|
|
|
html_option("committer", "committer", ctx.qry.grep);
|
|
|
|
html_option("range", "range", ctx.qry.grep);
|
2008-04-13 08:57:11 +00:00
|
|
|
html("</select>\n");
|
2017-10-14 19:02:16 +00:00
|
|
|
html("<input class='txt' type='search' size='10' name='q' value='");
|
2014-01-15 20:53:15 +00:00
|
|
|
html_attr(ctx.qry.search);
|
2008-04-13 08:57:11 +00:00
|
|
|
html("'/>\n");
|
|
|
|
html("<input type='submit' value='search'/>\n");
|
|
|
|
html("</form>\n");
|
2014-01-15 20:53:15 +00:00
|
|
|
} else if (ctx.env.authenticated) {
|
2015-10-09 11:15:48 +00:00
|
|
|
char *currenturl = cgit_currenturl();
|
2015-03-03 16:23:40 +00:00
|
|
|
site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0, 1);
|
2014-01-15 20:53:15 +00:00
|
|
|
if (ctx.cfg.root_readme)
|
|
|
|
site_link("about", "about", NULL, hc("about"),
|
2015-03-03 16:23:40 +00:00
|
|
|
NULL, NULL, 0, 1);
|
2008-04-13 09:57:10 +00:00
|
|
|
html("</td><td class='form'>");
|
|
|
|
html("<form method='get' action='");
|
2015-10-09 11:15:48 +00:00
|
|
|
html_attr(currenturl);
|
2008-04-13 09:57:10 +00:00
|
|
|
html("'>\n");
|
2017-10-14 19:02:16 +00:00
|
|
|
html("<input type='search' name='q' size='10' value='");
|
2014-01-15 20:53:15 +00:00
|
|
|
html_attr(ctx.qry.search);
|
2008-04-13 09:57:10 +00:00
|
|
|
html("'/>\n");
|
|
|
|
html("<input type='submit' value='search'/>\n");
|
|
|
|
html("</form>");
|
2015-10-09 11:15:48 +00:00
|
|
|
free(currenturl);
|
2006-12-28 01:01:49 +00:00
|
|
|
}
|
2008-04-12 13:53:31 +00:00
|
|
|
html("</td></tr></table>\n");
|
2017-02-19 12:27:48 +00:00
|
|
|
if (ctx.env.authenticated && ctx.repo && ctx.qry.vpath) {
|
2010-06-09 23:09:28 +00:00
|
|
|
html("<div class='path'>");
|
|
|
|
html("path: ");
|
2014-01-15 20:53:15 +00:00
|
|
|
cgit_print_path_crumbs(ctx.qry.vpath);
|
2015-08-12 14:55:28 +00:00
|
|
|
if (ctx.cfg.enable_follow_links && !strcmp(ctx.qry.page, "log")) {
|
|
|
|
html(" (");
|
|
|
|
ctx.qry.follow = !ctx.qry.follow;
|
|
|
|
cgit_self_link(ctx.qry.follow ? "follow" : "unfollow",
|
|
|
|
NULL, NULL);
|
|
|
|
ctx.qry.follow = !ctx.qry.follow;
|
|
|
|
html(")");
|
|
|
|
}
|
2010-06-09 23:09:28 +00:00
|
|
|
html("</div>");
|
|
|
|
}
|
2008-04-12 13:53:31 +00:00
|
|
|
html("<div class='content'>");
|
2006-12-11 15:38:30 +00:00
|
|
|
}
|
2007-02-08 12:53:13 +00:00
|
|
|
|
2008-02-23 21:45:33 +00:00
|
|
|
void cgit_print_filemode(unsigned short mode)
|
|
|
|
{
|
|
|
|
if (S_ISDIR(mode))
|
|
|
|
html("d");
|
|
|
|
else if (S_ISLNK(mode))
|
|
|
|
html("l");
|
|
|
|
else if (S_ISGITLINK(mode))
|
|
|
|
html("m");
|
|
|
|
else
|
|
|
|
html("-");
|
|
|
|
html_fileperm(mode >> 6);
|
|
|
|
html_fileperm(mode >> 3);
|
|
|
|
html_fileperm(mode);
|
|
|
|
}
|
|
|
|
|
2016-05-24 16:15:18 +00:00
|
|
|
void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base,
|
|
|
|
const char *ref)
|
|
|
|
{
|
2016-09-29 20:10:21 +00:00
|
|
|
struct object_id oid;
|
2016-05-24 16:15:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-09-29 20:10:21 +00:00
|
|
|
if (get_oid(fmt("refs/tags/%s", ref), &oid) == 0 &&
|
2016-05-24 16:15:18 +00:00
|
|
|
(ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]) &&
|
2016-09-29 20:10:21 +00:00
|
|
|
((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))
|
2016-05-24 16:15:18 +00:00
|
|
|
ref++;
|
|
|
|
|
|
|
|
strbuf_addf(filename, "%s-%s", base, ref);
|
|
|
|
}
|
|
|
|
|
2018-03-31 14:08:59 +00:00
|
|
|
void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref,
|
|
|
|
const char *separator)
|
2008-03-24 15:00:27 +00:00
|
|
|
{
|
2018-06-07 19:31:28 +00:00
|
|
|
const struct cgit_snapshot_format *f;
|
2013-04-06 09:28:57 +00:00
|
|
|
struct strbuf filename = STRBUF_INIT;
|
2018-03-31 14:06:01 +00:00
|
|
|
const char *basename;
|
2013-04-06 09:28:57 +00:00
|
|
|
size_t prefixlen;
|
2008-03-24 15:00:27 +00:00
|
|
|
|
2018-03-31 14:06:01 +00:00
|
|
|
basename = cgit_snapshot_prefix(repo);
|
|
|
|
if (starts_with(ref, basename))
|
|
|
|
strbuf_addstr(&filename, ref);
|
|
|
|
else
|
|
|
|
cgit_compose_snapshot_prefix(&filename, basename, ref);
|
|
|
|
|
2013-04-06 09:28:57 +00:00
|
|
|
prefixlen = filename.len;
|
2008-03-24 15:00:27 +00:00
|
|
|
for (f = cgit_snapshot_formats; f->suffix; f++) {
|
2018-06-11 06:26:59 +00:00
|
|
|
if (!(repo->snapshots & cgit_snapshot_format_bit(f)))
|
2008-03-24 15:00:27 +00:00
|
|
|
continue;
|
2013-04-06 09:28:57 +00:00
|
|
|
strbuf_setlen(&filename, prefixlen);
|
|
|
|
strbuf_addstr(&filename, f->suffix);
|
|
|
|
cgit_snapshot_link(filename.buf, NULL, NULL, NULL, NULL,
|
|
|
|
filename.buf);
|
2018-03-31 15:15:48 +00:00
|
|
|
if (cgit_snapshot_get_sig(ref, f)) {
|
|
|
|
strbuf_addstr(&filename, ".asc");
|
|
|
|
html(" (");
|
|
|
|
cgit_snapshot_link("sig", NULL, NULL, NULL, NULL,
|
|
|
|
filename.buf);
|
|
|
|
html(")");
|
2018-06-07 19:31:28 +00:00
|
|
|
} else if (starts_with(f->suffix, ".tar") && cgit_snapshot_get_sig(ref, &cgit_snapshot_formats[0])) {
|
|
|
|
strbuf_setlen(&filename, strlen(filename.buf) - strlen(f->suffix));
|
|
|
|
strbuf_addstr(&filename, ".tar.asc");
|
|
|
|
html(" (");
|
|
|
|
cgit_snapshot_link("sig", NULL, NULL, NULL, NULL,
|
|
|
|
filename.buf);
|
|
|
|
html(")");
|
2018-03-31 15:15:48 +00:00
|
|
|
}
|
2018-03-31 14:08:59 +00:00
|
|
|
html(separator);
|
2008-03-24 15:00:27 +00:00
|
|
|
}
|
2013-04-06 09:28:57 +00:00
|
|
|
strbuf_release(&filename);
|
2008-03-24 15:00:27 +00:00
|
|
|
}
|
2017-10-02 04:39:06 +00:00
|
|
|
|
|
|
|
void cgit_set_title_from_path(const char *path)
|
|
|
|
{
|
2019-01-02 06:52:12 +00:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
const char *slash, *last_slash;
|
2017-10-02 04:39:06 +00:00
|
|
|
|
|
|
|
if (!path)
|
|
|
|
return;
|
|
|
|
|
2019-01-02 06:52:12 +00:00
|
|
|
for (last_slash = path + strlen(path); (slash = memrchr(path, '/', last_slash - path)) != NULL; last_slash = slash) {
|
|
|
|
strbuf_add(&sb, slash + 1, last_slash - slash - 1);
|
|
|
|
strbuf_addstr(&sb, " \xc2\xab ");
|
2017-10-02 04:39:06 +00:00
|
|
|
}
|
2019-01-02 06:52:12 +00:00
|
|
|
strbuf_add(&sb, path, last_slash - path);
|
|
|
|
strbuf_addf(&sb, " - %s", ctx.page.title);
|
|
|
|
ctx.page.title = strbuf_detach(&sb, NULL);
|
2017-10-02 04:39:06 +00:00
|
|
|
}
|