2006-12-11 16:38:30 +01:00
|
|
|
/* ui-shared.c: common web output functions
|
|
|
|
*
|
2014-01-08 15:10:49 +01:00
|
|
|
* Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
|
2006-12-11 16:38:30 +01:00
|
|
|
*
|
|
|
|
* Licensed under GNU General Public License v2
|
|
|
|
* (see COPYING for full license text)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cgit.h"
|
2013-04-06 12:37:59 +02:00
|
|
|
#include "ui-shared.h"
|
2008-04-12 15:53:31 +02:00
|
|
|
#include "cmd.h"
|
2008-02-23 22:45:33 +01:00
|
|
|
#include "html.h"
|
2006-12-11 16:38:30 +01:00
|
|
|
|
2015-03-08 17:32:22 +01:00
|
|
|
static const char cgit_doctype[] =
|
2006-12-11 16:38:30 +01:00
|
|
|
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
|
|
|
|
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
|
|
|
|
|
|
|
|
static char *http_date(time_t t)
|
|
|
|
{
|
2007-05-15 00:22:03 +02:00
|
|
|
static char day[][4] =
|
2006-12-11 16:38:30 +01:00
|
|
|
{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
2007-05-15 00:22:03 +02:00
|
|
|
static char month[][4] =
|
2006-12-11 16:38:30 +01:00
|
|
|
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
2009-11-02 22:10:04 +01:00
|
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
2006-12-11 16:38:30 +01:00
|
|
|
struct tm *tm = gmtime(&t);
|
|
|
|
return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday],
|
2013-03-03 16:04:29 +01:00
|
|
|
tm->tm_mday, month[tm->tm_mon], 1900 + tm->tm_year,
|
2006-12-11 16:38:30 +01:00
|
|
|
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
|
|
|
}
|
|
|
|
|
2013-04-06 12:23:52 +02:00
|
|
|
void cgit_print_error(const char *fmt, ...)
|
2006-12-11 16:38:30 +01:00
|
|
|
{
|
2013-04-06 12:23:52 +02: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 16:38:30 +01:00
|
|
|
html("<div class='error'>");
|
2013-04-06 12:23:52 +02:00
|
|
|
va_copy(cp, ap);
|
|
|
|
html_vtxtf(fmt, cp);
|
|
|
|
va_end(cp);
|
2006-12-11 16:38:30 +01:00
|
|
|
html("</div>\n");
|
|
|
|
}
|
2006-12-11 16:48:03 +01:00
|
|
|
|
2015-03-08 17:32:16 +01:00
|
|
|
const char *cgit_httpscheme(void)
|
2009-06-11 01:09:55 +02:00
|
|
|
{
|
2009-08-10 08:21:09 +02:00
|
|
|
if (ctx.env.https && !strcmp(ctx.env.https, "on"))
|
2009-06-11 01:09:55 +02:00
|
|
|
return "https://";
|
|
|
|
else
|
|
|
|
return "http://";
|
|
|
|
}
|
|
|
|
|
2015-03-08 17:32:16 +01:00
|
|
|
const char *cgit_hosturl(void)
|
2008-05-21 08:17:54 +02:00
|
|
|
{
|
2009-08-10 08:21:09 +02:00
|
|
|
if (ctx.env.http_host)
|
|
|
|
return ctx.env.http_host;
|
|
|
|
if (!ctx.env.server_name)
|
|
|
|
return NULL;
|
|
|
|
if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80)
|
|
|
|
return ctx.env.server_name;
|
2013-04-06 11:28:57 +02:00
|
|
|
return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port);
|
2008-05-21 08:17:54 +02:00
|
|
|
}
|
|
|
|
|
2015-10-09 13:15:47 +02:00
|
|
|
char *cgit_currenturl(void)
|
2015-03-03 17:18:42 +01:00
|
|
|
{
|
|
|
|
if (!ctx.qry.url)
|
2015-10-09 13:15:47 +02:00
|
|
|
return xstrdup(cgit_rooturl());
|
2015-03-08 12:34:07 +01:00
|
|
|
const char *root = cgit_rooturl();
|
|
|
|
size_t len = strlen(root);
|
|
|
|
if (len && root[len - 1] == '/')
|
|
|
|
return fmtalloc("%s%s", root, ctx.qry.url);
|
|
|
|
return fmtalloc("%s/%s", root, ctx.qry.url);
|
2015-03-03 17:18:42 +01:00
|
|
|
}
|
|
|
|
|
2015-03-08 17:32:16 +01:00
|
|
|
const char *cgit_rooturl(void)
|
2007-02-17 13:46:18 +01:00
|
|
|
{
|
2008-02-16 13:07:13 +01:00
|
|
|
if (ctx.cfg.virtual_root)
|
2013-04-01 20:03:34 +02:00
|
|
|
return ctx.cfg.virtual_root;
|
2007-02-17 13:46:18 +01:00
|
|
|
else
|
2008-02-16 13:07:13 +01:00
|
|
|
return ctx.cfg.script_name;
|
2007-02-17 13:46:18 +01:00
|
|
|
}
|
|
|
|
|
2015-03-08 17:32:16 +01:00
|
|
|
const char *cgit_loginurl(void)
|
2014-01-16 23:21:54 +01:00
|
|
|
{
|
2015-03-08 17:32:24 +01:00
|
|
|
static const char *login_url;
|
2014-01-16 23:21:54 +01:00
|
|
|
if (!login_url)
|
|
|
|
login_url = fmtalloc("%s?p=login", cgit_rooturl());
|
|
|
|
return login_url;
|
|
|
|
}
|
|
|
|
|
2006-12-11 16:48:03 +01:00
|
|
|
char *cgit_repourl(const char *reponame)
|
|
|
|
{
|
2013-04-06 11:28:57 +02:00
|
|
|
if (ctx.cfg.virtual_root)
|
|
|
|
return fmtalloc("%s%s/", ctx.cfg.virtual_root, reponame);
|
|
|
|
else
|
|
|
|
return fmtalloc("?r=%s", reponame);
|
2006-12-11 16:48:03 +01:00
|
|
|
}
|
|
|
|
|
2007-07-21 13:13:40 +02:00
|
|
|
char *cgit_fileurl(const char *reponame, const char *pagename,
|
|
|
|
const char *filename, const char *query)
|
2006-12-11 16:48:03 +01:00
|
|
|
{
|
2013-04-06 11:28:57 +02:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2007-11-03 11:15:56 +01:00
|
|
|
char *delim;
|
|
|
|
|
2008-02-16 13:07:13 +01:00
|
|
|
if (ctx.cfg.virtual_root) {
|
2013-04-06 11:28:57 +02:00
|
|
|
strbuf_addf(&sb, "%s%s/%s/%s", ctx.cfg.virtual_root, reponame,
|
|
|
|
pagename, (filename ? filename:""));
|
2007-11-03 11:15:56 +01:00
|
|
|
delim = "?";
|
2006-12-11 16:48:03 +01:00
|
|
|
} else {
|
2013-04-06 11:28:57 +02:00
|
|
|
strbuf_addf(&sb, "?url=%s/%s/%s", reponame, pagename,
|
|
|
|
(filename ? filename : ""));
|
2012-10-09 20:45:58 +02:00
|
|
|
delim = "&";
|
2006-12-11 16:48:03 +01:00
|
|
|
}
|
2007-11-03 11:15:56 +01:00
|
|
|
if (query)
|
2013-04-06 11:28:57 +02:00
|
|
|
strbuf_addf(&sb, "%s%s", delim, query);
|
|
|
|
return strbuf_detach(&sb, NULL);
|
2006-12-11 16:48:03 +01:00
|
|
|
}
|
|
|
|
|
2007-07-21 13:13:40 +02:00
|
|
|
char *cgit_pageurl(const char *reponame, const char *pagename,
|
|
|
|
const char *query)
|
|
|
|
{
|
2015-03-08 17:32:25 +01:00
|
|
|
return cgit_fileurl(reponame, pagename, NULL, query);
|
2007-07-21 13:13:40 +02:00
|
|
|
}
|
|
|
|
|
2007-07-21 15:24:07 +02: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;
|
2013-03-03 16:04:29 +01:00
|
|
|
strncpy(rvbuf, reponame, sizeof(rvbuf));
|
2013-03-04 05:21:33 +01:00
|
|
|
if (rvbuf[sizeof(rvbuf)-1])
|
2007-07-21 15:24:07 +02:00
|
|
|
die("cgit_repobasename: truncated repository name '%s'", reponame);
|
|
|
|
p = strlen(rvbuf)-1;
|
|
|
|
/* strip trailing slashes */
|
2013-03-04 05:21:33 +01:00
|
|
|
while (p && rvbuf[p] == '/') rvbuf[p--] = 0;
|
2007-07-21 15:24:07 +02:00
|
|
|
/* strip trailing .git */
|
2014-05-29 17:35:46 +02:00
|
|
|
if (p >= 3 && starts_with(&rvbuf[p-3], ".git")) {
|
2007-07-21 15:24:07 +02:00
|
|
|
p -= 3; rvbuf[p--] = 0;
|
|
|
|
}
|
|
|
|
/* strip more trailing slashes if any */
|
2013-03-04 05:21:33 +01:00
|
|
|
while ( p && rvbuf[p] == '/') rvbuf[p--] = 0;
|
2007-07-21 15:24:07 +02:00
|
|
|
/* find last slash in the remaining string */
|
|
|
|
rv = strrchr(rvbuf,'/');
|
2013-03-04 05:21:33 +01:00
|
|
|
if (rv)
|
2007-07-21 15:24:07 +02:00
|
|
|
return ++rv;
|
|
|
|
return rvbuf;
|
|
|
|
}
|
2007-07-21 13:13:40 +02:00
|
|
|
|
2015-03-03 17:23:40 +01:00
|
|
|
static void site_url(const char *page, const char *search, const char *sort, int ofs, int always_root)
|
2008-04-29 01:09:41 +02:00
|
|
|
{
|
|
|
|
char *delim = "?";
|
|
|
|
|
2015-03-03 17:23:40 +01:00
|
|
|
if (always_root || page)
|
2015-03-03 17:13:52 +01:00
|
|
|
html_attr(cgit_rooturl());
|
2015-10-09 13:15:48 +02:00
|
|
|
else {
|
|
|
|
char *currenturl = cgit_currenturl();
|
|
|
|
html_attr(currenturl);
|
|
|
|
free(currenturl);
|
|
|
|
}
|
2008-04-29 01:09:41 +02:00
|
|
|
|
|
|
|
if (page) {
|
|
|
|
htmlf("?p=%s", page);
|
2012-10-09 20:45:58 +02:00
|
|
|
delim = "&";
|
2008-04-29 01:09:41 +02:00
|
|
|
}
|
|
|
|
if (search) {
|
|
|
|
html(delim);
|
|
|
|
html("q=");
|
|
|
|
html_attr(search);
|
2012-10-09 20:45:58 +02:00
|
|
|
delim = "&";
|
2008-05-03 10:37:02 +02:00
|
|
|
}
|
2011-07-31 02:44:05 +02:00
|
|
|
if (sort) {
|
|
|
|
html(delim);
|
|
|
|
html("s=");
|
|
|
|
html_attr(sort);
|
2012-10-09 20:45:58 +02:00
|
|
|
delim = "&";
|
2011-07-31 02:44:05 +02:00
|
|
|
}
|
2008-05-03 10:37:02 +02:00
|
|
|
if (ofs) {
|
|
|
|
html(delim);
|
|
|
|
htmlf("ofs=%d", ofs);
|
2008-04-29 01:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02:00
|
|
|
static void site_link(const char *page, const char *name, const char *title,
|
2015-03-03 17:23:40 +01:00
|
|
|
const char *class, const char *search, const char *sort, int ofs, int always_root)
|
2008-04-29 01:09:41 +02:00
|
|
|
{
|
|
|
|
html("<a");
|
|
|
|
if (title) {
|
|
|
|
html(" title='");
|
|
|
|
html_attr(title);
|
|
|
|
html("'");
|
|
|
|
}
|
|
|
|
if (class) {
|
|
|
|
html(" class='");
|
|
|
|
html_attr(class);
|
|
|
|
html("'");
|
|
|
|
}
|
|
|
|
html(" href='");
|
2015-03-03 17:23:40 +01:00
|
|
|
site_url(page, search, sort, ofs, always_root);
|
2008-04-29 01:09:41 +02:00
|
|
|
html("'>");
|
|
|
|
html_txt(name);
|
|
|
|
html("</a>");
|
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02:00
|
|
|
void cgit_index_link(const char *name, const char *title, const char *class,
|
2015-03-03 17:23:40 +01:00
|
|
|
const char *pattern, const char *sort, int ofs, int always_root)
|
2008-05-03 10:37:02 +02:00
|
|
|
{
|
2015-03-03 17:23:40 +01:00
|
|
|
site_link(NULL, name, title, class, pattern, sort, ofs, always_root);
|
2008-05-03 10:37:02 +02:00
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02:00
|
|
|
static char *repolink(const char *title, const char *class, const char *page,
|
|
|
|
const char *head, const char *path)
|
2007-06-17 01:23:08 +02: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 13:07:13 +01:00
|
|
|
if (ctx.cfg.virtual_root) {
|
2008-10-05 16:54:44 +02:00
|
|
|
html_url_path(ctx.cfg.virtual_root);
|
|
|
|
html_url_path(ctx.repo->url);
|
2008-02-16 13:56:09 +01:00
|
|
|
if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
|
2007-06-17 01:23:08 +02:00
|
|
|
html("/");
|
2007-06-18 00:18:42 +02:00
|
|
|
if (page) {
|
2008-10-05 16:54:44 +02:00
|
|
|
html_url_path(page);
|
2007-06-18 00:18:42 +02:00
|
|
|
html("/");
|
|
|
|
if (path)
|
2008-10-05 16:54:44 +02:00
|
|
|
html_url_path(path);
|
2007-06-18 00:18:42 +02:00
|
|
|
}
|
2007-06-17 01:23:08 +02:00
|
|
|
} else {
|
2014-01-12 20:45:16 +01:00
|
|
|
html_url_path(ctx.cfg.script_name);
|
2007-06-17 01:23:08 +02:00
|
|
|
html("?url=");
|
2008-10-05 12:52:25 +02:00
|
|
|
html_url_arg(ctx.repo->url);
|
2008-02-16 13:56:09 +01:00
|
|
|
if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
|
2007-06-17 01:23:08 +02:00
|
|
|
html("/");
|
2007-06-18 00:18:42 +02:00
|
|
|
if (page) {
|
2008-10-05 12:52:25 +02:00
|
|
|
html_url_arg(page);
|
2007-06-18 00:18:42 +02:00
|
|
|
html("/");
|
|
|
|
if (path)
|
2008-10-05 12:52:25 +02:00
|
|
|
html_url_arg(path);
|
2007-06-18 00:18:42 +02:00
|
|
|
}
|
2007-06-17 01:23:08 +02:00
|
|
|
delim = "&";
|
|
|
|
}
|
2008-02-16 13:56:09 +01:00
|
|
|
if (head && strcmp(head, ctx.repo->defbranch)) {
|
2007-06-17 01:23:08 +02:00
|
|
|
html(delim);
|
|
|
|
html("h=");
|
2008-10-05 12:52:25 +02:00
|
|
|
html_url_arg(head);
|
2007-06-17 01:23:08 +02:00
|
|
|
delim = "&";
|
|
|
|
}
|
|
|
|
return fmt("%s", delim);
|
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02: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-17 01:23:08 +02:00
|
|
|
{
|
|
|
|
char *delim;
|
|
|
|
|
2007-06-17 13:57:51 +02:00
|
|
|
delim = repolink(title, class, page, head, path);
|
2010-02-01 17:55:37 +01:00
|
|
|
if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) {
|
2007-06-17 01:23:08 +02:00
|
|
|
html(delim);
|
|
|
|
html("id=");
|
2008-10-05 12:52:25 +02:00
|
|
|
html_url_arg(rev);
|
2007-06-17 01:23:08 +02:00
|
|
|
}
|
|
|
|
html("'>");
|
|
|
|
html_txt(name);
|
|
|
|
html("</a>");
|
|
|
|
}
|
2006-12-16 00:33:28 +01:00
|
|
|
|
2010-06-10 01:09:24 +02:00
|
|
|
void cgit_summary_link(const char *name, const char *title, const char *class,
|
|
|
|
const char *head)
|
2008-10-05 16:55:50 +02:00
|
|
|
{
|
|
|
|
reporevlink(NULL, name, title, class, head, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02:00
|
|
|
void cgit_tag_link(const char *name, const char *title, const char *class,
|
2015-01-15 23:18:14 +01:00
|
|
|
const char *tag)
|
2008-10-05 21:18:45 +02:00
|
|
|
{
|
2015-01-15 23:18:14 +01:00
|
|
|
reporevlink("tag", name, title, class, tag, NULL, NULL);
|
2008-10-05 21:18:45 +02:00
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02: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 13:57:51 +02:00
|
|
|
{
|
|
|
|
reporevlink("tree", name, title, class, head, rev, path);
|
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02: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 11:07:13 +02:00
|
|
|
{
|
|
|
|
reporevlink("plain", name, title, class, head, rev, path);
|
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02: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 16:55:28 +02:00
|
|
|
int ofs, const char *grep, const char *pattern, int showmsg,
|
|
|
|
int follow)
|
2007-06-17 13:57:51 +02:00
|
|
|
{
|
2007-06-29 20:27:41 +02:00
|
|
|
char *delim;
|
|
|
|
|
|
|
|
delim = repolink(title, class, "log", head, path);
|
2012-01-04 10:01:51 +01:00
|
|
|
if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) {
|
2007-06-29 20:27:41 +02:00
|
|
|
html(delim);
|
|
|
|
html("id=");
|
2008-10-05 12:52:25 +02:00
|
|
|
html_url_arg(rev);
|
2012-10-09 20:45:58 +02:00
|
|
|
delim = "&";
|
2007-06-29 20:27:41 +02:00
|
|
|
}
|
2007-11-03 10:42:37 +01:00
|
|
|
if (grep && pattern) {
|
|
|
|
html(delim);
|
|
|
|
html("qt=");
|
2008-10-05 12:52:25 +02:00
|
|
|
html_url_arg(grep);
|
2012-10-09 20:45:58 +02:00
|
|
|
delim = "&";
|
2007-11-03 10:42:37 +01:00
|
|
|
html(delim);
|
|
|
|
html("q=");
|
2008-10-05 12:52:25 +02:00
|
|
|
html_url_arg(pattern);
|
2007-11-03 10:42:37 +01:00
|
|
|
}
|
2007-06-29 20:27:41 +02:00
|
|
|
if (ofs > 0) {
|
|
|
|
html(delim);
|
|
|
|
html("ofs=");
|
|
|
|
htmlf("%d", ofs);
|
2012-10-09 20:45:58 +02:00
|
|
|
delim = "&";
|
2008-11-29 18:39:41 +01:00
|
|
|
}
|
|
|
|
if (showmsg) {
|
|
|
|
html(delim);
|
|
|
|
html("showmsg=1");
|
2015-08-12 16:55:28 +02:00
|
|
|
delim = "&";
|
|
|
|
}
|
|
|
|
if (follow) {
|
|
|
|
html(delim);
|
|
|
|
html("follow=1");
|
2007-06-29 20:27:41 +02:00
|
|
|
}
|
|
|
|
html("'>");
|
|
|
|
html_txt(name);
|
|
|
|
html("</a>");
|
2007-06-17 13:57:51 +02:00
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02:00
|
|
|
void cgit_commit_link(char *name, const char *title, const char *class,
|
2014-10-05 11:59:02 +02:00
|
|
|
const char *head, const char *rev, const char *path)
|
2007-06-17 14:53:02 +02:00
|
|
|
{
|
2008-02-16 13:07:13 +01:00
|
|
|
if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
|
|
|
|
name[ctx.cfg.max_msg_len] = '\0';
|
|
|
|
name[ctx.cfg.max_msg_len - 1] = '.';
|
|
|
|
name[ctx.cfg.max_msg_len - 2] = '.';
|
|
|
|
name[ctx.cfg.max_msg_len - 3] = '.';
|
2007-06-17 14:53:02 +02:00
|
|
|
}
|
2009-09-14 20:19:02 +02:00
|
|
|
|
|
|
|
char *delim;
|
|
|
|
|
2010-06-10 01:09:35 +02:00
|
|
|
delim = repolink(title, class, "commit", head, path);
|
2012-01-04 10:01:51 +01:00
|
|
|
if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) {
|
2009-09-14 20:19:02 +02:00
|
|
|
html(delim);
|
|
|
|
html("id=");
|
|
|
|
html_url_arg(rev);
|
|
|
|
delim = "&";
|
|
|
|
}
|
2014-10-05 11:59:04 +02:00
|
|
|
if (ctx.qry.difftype) {
|
2009-09-14 20:19:02 +02:00
|
|
|
html(delim);
|
2014-10-05 11:59:04 +02:00
|
|
|
htmlf("dt=%d", ctx.qry.difftype);
|
2010-06-10 20:15:51 +02:00
|
|
|
delim = "&";
|
|
|
|
}
|
|
|
|
if (ctx.qry.context > 0 && ctx.qry.context != 3) {
|
|
|
|
html(delim);
|
|
|
|
html("context=");
|
|
|
|
htmlf("%d", ctx.qry.context);
|
|
|
|
delim = "&";
|
2009-09-14 20:19:02 +02:00
|
|
|
}
|
2010-06-24 17:53:20 +02:00
|
|
|
if (ctx.qry.ignorews) {
|
|
|
|
html(delim);
|
|
|
|
html("ignorews=1");
|
|
|
|
delim = "&";
|
|
|
|
}
|
2015-08-12 16:55:28 +02:00
|
|
|
if (ctx.qry.follow) {
|
|
|
|
html(delim);
|
|
|
|
html("follow=1");
|
|
|
|
}
|
2009-09-14 20:19:02 +02:00
|
|
|
html("'>");
|
2012-10-28 18:36:08 +01:00
|
|
|
if (name[0] != '\0')
|
|
|
|
html_txt(name);
|
|
|
|
else
|
|
|
|
html_txt("(no commit message)");
|
2009-09-14 20:19:02 +02:00
|
|
|
html("</a>");
|
2007-06-17 14:53:02 +02:00
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02: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 10:47:44 +02:00
|
|
|
{
|
|
|
|
reporevlink("refs", name, title, class, head, rev, path);
|
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02: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-23 00:11:15 +02:00
|
|
|
{
|
|
|
|
reporevlink("snapshot", name, title, class, head, rev, archivename);
|
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02: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 11:59:03 +02:00
|
|
|
const char *path)
|
2007-06-17 18:12:03 +02:00
|
|
|
{
|
|
|
|
char *delim;
|
|
|
|
|
|
|
|
delim = repolink(title, class, "diff", head, path);
|
2010-02-01 17:55:37 +01:00
|
|
|
if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) {
|
2007-06-17 18:12:03 +02:00
|
|
|
html(delim);
|
|
|
|
html("id=");
|
2008-10-05 12:52:25 +02:00
|
|
|
html_url_arg(new_rev);
|
2007-06-17 18:12:03 +02:00
|
|
|
delim = "&";
|
|
|
|
}
|
|
|
|
if (old_rev) {
|
|
|
|
html(delim);
|
|
|
|
html("id2=");
|
2008-10-05 12:52:25 +02:00
|
|
|
html_url_arg(old_rev);
|
2009-09-14 20:19:02 +02:00
|
|
|
delim = "&";
|
|
|
|
}
|
2014-10-05 11:59:04 +02:00
|
|
|
if (ctx.qry.difftype) {
|
2009-09-14 20:19:02 +02:00
|
|
|
html(delim);
|
2014-10-05 11:59:04 +02:00
|
|
|
htmlf("dt=%d", ctx.qry.difftype);
|
2010-06-10 20:15:51 +02:00
|
|
|
delim = "&";
|
|
|
|
}
|
|
|
|
if (ctx.qry.context > 0 && ctx.qry.context != 3) {
|
|
|
|
html(delim);
|
|
|
|
html("context=");
|
|
|
|
htmlf("%d", ctx.qry.context);
|
|
|
|
delim = "&";
|
2007-06-17 18:12:03 +02:00
|
|
|
}
|
2010-06-24 17:53:20 +02:00
|
|
|
if (ctx.qry.ignorews) {
|
|
|
|
html(delim);
|
|
|
|
html("ignorews=1");
|
|
|
|
delim = "&";
|
|
|
|
}
|
2015-08-12 16:55:28 +02:00
|
|
|
if (ctx.qry.follow) {
|
|
|
|
html(delim);
|
|
|
|
html("follow=1");
|
|
|
|
}
|
2007-06-17 18:12:03 +02:00
|
|
|
html("'>");
|
|
|
|
html_txt(name);
|
|
|
|
html("</a>");
|
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02:00
|
|
|
void cgit_patch_link(const char *name, const char *title, const char *class,
|
2010-06-10 01:09:33 +02:00
|
|
|
const char *head, const char *rev, const char *path)
|
2007-12-10 21:47:29 +01:00
|
|
|
{
|
2010-06-10 01:09:33 +02:00
|
|
|
reporevlink("patch", name, title, class, head, rev, path);
|
2007-12-10 21:47:29 +01:00
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02:00
|
|
|
void cgit_stats_link(const char *name, const char *title, const char *class,
|
|
|
|
const char *head, const char *path)
|
2008-12-07 13:34:16 +01:00
|
|
|
{
|
|
|
|
reporevlink("stats", name, title, class, head, NULL, path);
|
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01: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 17:23:40 +01:00
|
|
|
ctx.qry.ofs, 1);
|
2014-01-15 21:53:15 +01:00
|
|
|
else if (!strcmp(ctx.qry.page, "summary"))
|
|
|
|
cgit_summary_link(name, title, class, ctx.qry.head);
|
|
|
|
else if (!strcmp(ctx.qry.page, "tag"))
|
2015-01-15 23:18:14 +01:00
|
|
|
cgit_tag_link(name, title, class, ctx.qry.has_sha1 ?
|
|
|
|
ctx.qry.sha1 : ctx.qry.head);
|
2014-01-15 21:53:15 +01:00
|
|
|
else if (!strcmp(ctx.qry.page, "tree"))
|
|
|
|
cgit_tree_link(name, title, class, ctx.qry.head,
|
|
|
|
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_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_sha1 ? ctx.qry.sha1 : NULL,
|
|
|
|
ctx.qry.path, ctx.qry.ofs,
|
|
|
|
ctx.qry.grep, ctx.qry.search,
|
2015-08-12 16:55:28 +02:00
|
|
|
ctx.qry.showmsg, ctx.qry.follow);
|
2014-01-15 21:53:15 +01:00
|
|
|
else if (!strcmp(ctx.qry.page, "commit"))
|
|
|
|
cgit_commit_link(name, title, class, ctx.qry.head,
|
|
|
|
ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL,
|
2014-10-05 11:59:02 +02:00
|
|
|
ctx.qry.path);
|
2014-01-15 21:53:15 +01:00
|
|
|
else if (!strcmp(ctx.qry.page, "patch"))
|
|
|
|
cgit_patch_link(name, title, class, ctx.qry.head,
|
|
|
|
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_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_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.sha1, ctx.qry.sha2,
|
2014-10-05 11:59:03 +02:00
|
|
|
ctx.qry.path);
|
2014-01-15 21:53:15 +01:00
|
|
|
else if (!strcmp(ctx.qry.page, "stats"))
|
|
|
|
cgit_stats_link(name, title, class, ctx.qry.head,
|
|
|
|
ctx.qry.path);
|
2013-03-06 21:51:54 +01:00
|
|
|
else {
|
|
|
|
/* Don't known how to make link for this page */
|
2014-01-15 21:53:15 +01:00
|
|
|
repolink(title, class, ctx.qry.page, ctx.qry.head, ctx.qry.path);
|
2013-03-06 21:51:54 +01:00
|
|
|
html("><!-- cgit_self_link() doesn't know how to make link for page '");
|
2014-01-15 21:53:15 +01:00
|
|
|
html_txt(ctx.qry.page);
|
2013-03-06 21:51:54 +01:00
|
|
|
html("' -->");
|
|
|
|
html_txt(name);
|
|
|
|
html("</a>");
|
|
|
|
}
|
2010-06-10 01:09:29 +02:00
|
|
|
}
|
|
|
|
|
2007-07-22 23:42:55 +02:00
|
|
|
void cgit_object_link(struct object *obj)
|
|
|
|
{
|
2008-12-01 21:58:59 +01:00
|
|
|
char *page, *shortrev, *fullrev, *name;
|
2007-07-22 23:42:55 +02:00
|
|
|
|
2008-12-01 21:58:59 +01:00
|
|
|
fullrev = sha1_to_hex(obj->sha1);
|
|
|
|
shortrev = xstrdup(fullrev);
|
|
|
|
shortrev[10] = '\0';
|
2007-07-22 23:42:55 +02:00
|
|
|
if (obj->type == OBJ_COMMIT) {
|
2013-03-03 16:04:29 +01:00
|
|
|
cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
|
2014-10-05 11:59:02 +02:00
|
|
|
ctx.qry.head, fullrev, NULL);
|
2007-07-22 23:42:55 +02:00
|
|
|
return;
|
2008-10-05 21:12:08 +02:00
|
|
|
} else if (obj->type == OBJ_TREE)
|
2007-07-22 23:42:55 +02:00
|
|
|
page = "tree";
|
2008-10-05 21:12:08 +02:00
|
|
|
else if (obj->type == OBJ_TAG)
|
2007-10-28 15:40:47 +01:00
|
|
|
page = "tag";
|
2008-10-05 21:12:08 +02:00
|
|
|
else
|
2007-07-22 23:42:55 +02:00
|
|
|
page = "blob";
|
2008-12-01 21:58:59 +01:00
|
|
|
name = fmt("%s %s...", typename(obj->type), shortrev);
|
|
|
|
reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
|
2007-07-22 23:42:55 +02:00
|
|
|
}
|
|
|
|
|
2013-03-04 08:52:33 +01:00
|
|
|
static struct string_list_item *lookup_path(struct string_list *list,
|
|
|
|
const char *path)
|
2011-06-15 10:04:13 +02: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 20:43:13 +01:00
|
|
|
len = 0;
|
2011-06-15 10:04:13 +02: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 20:41:45 +01: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 10:04:13 +02:00
|
|
|
} else {
|
2015-03-05 20:41:45 +01:00
|
|
|
html("<span");
|
|
|
|
if (class)
|
|
|
|
htmlf(" class='%s'", class);
|
|
|
|
html(">");
|
|
|
|
html_txt(path);
|
|
|
|
html("</span>");
|
2011-06-15 10:04:13 +02:00
|
|
|
}
|
2013-04-06 11:28:57 +02:00
|
|
|
html_txtf(" @ %.7s", rev);
|
2011-06-15 10:04:13 +02:00
|
|
|
if (item && tail)
|
|
|
|
path[len - 1] = tail;
|
|
|
|
}
|
|
|
|
|
2015-08-13 13:24:32 +02:00
|
|
|
static const char *fmt_date(time_t secs, const char *format, int local_time)
|
2006-12-16 00:33:28 +01:00
|
|
|
{
|
2015-08-13 13:24:32 +02:00
|
|
|
static char buf[64];
|
2006-12-16 00:33:28 +01:00
|
|
|
struct tm *time;
|
|
|
|
|
2007-12-02 22:11:35 +01:00
|
|
|
if (!secs)
|
2015-08-13 13:24:32 +02:00
|
|
|
return "";
|
2013-03-04 05:21:33 +01:00
|
|
|
if (local_time)
|
2008-08-01 14:54:38 +02:00
|
|
|
time = localtime(&secs);
|
|
|
|
else
|
|
|
|
time = gmtime(&secs);
|
2007-05-22 23:08:46 +02:00
|
|
|
strftime(buf, sizeof(buf)-1, format, time);
|
2015-08-13 13:24:32 +02:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cgit_print_date(time_t secs, const char *format, int local_time)
|
|
|
|
{
|
|
|
|
html_txt(fmt_date(secs, format, local_time));
|
2006-12-16 00:33:28 +01:00
|
|
|
}
|
|
|
|
|
2014-12-20 14:59:39 +01:00
|
|
|
static void print_rel_date(time_t t, double value,
|
|
|
|
const char *class, const char *suffix)
|
|
|
|
{
|
|
|
|
htmlf("<span class='%s' title='", class);
|
2015-08-13 13:24:33 +02:00
|
|
|
html_attr(fmt_date(t, FMT_LONGDATE, ctx.cfg.local_time));
|
2014-12-20 14:59:39 +01:00
|
|
|
htmlf("'>%.0f %s</span>", value, suffix);
|
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02:00
|
|
|
void cgit_print_age(time_t t, time_t max_relative, const char *format)
|
2007-05-22 23:08:46 +02:00
|
|
|
{
|
|
|
|
time_t now, secs;
|
|
|
|
|
2007-12-02 22:11:35 +01:00
|
|
|
if (!t)
|
|
|
|
return;
|
2007-05-22 23:08:46 +02:00
|
|
|
time(&now);
|
|
|
|
secs = now - t;
|
2014-01-17 15:41:41 +01:00
|
|
|
if (secs < 0)
|
|
|
|
secs = 0;
|
2007-05-22 23:08:46 +02:00
|
|
|
|
|
|
|
if (secs > max_relative && max_relative >= 0) {
|
2015-08-13 13:24:34 +02:00
|
|
|
html("<span title='");
|
|
|
|
html_attr(fmt_date(t, FMT_LONGDATE, ctx.cfg.local_time));
|
|
|
|
html("'>");
|
2008-08-01 14:54:38 +02:00
|
|
|
cgit_print_date(t, format, ctx.cfg.local_time);
|
2015-08-13 13:24:34 +02:00
|
|
|
html("</span>");
|
2007-05-22 23:08:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (secs < TM_HOUR * 2) {
|
2014-12-20 14:59:39 +01:00
|
|
|
print_rel_date(t, secs * 1.0 / TM_MIN, "age-mins", "min.");
|
2007-05-22 23:08:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (secs < TM_DAY * 2) {
|
2014-12-20 14:59:39 +01:00
|
|
|
print_rel_date(t, secs * 1.0 / TM_HOUR, "age-hours", "hours");
|
2007-05-22 23:08:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (secs < TM_WEEK * 2) {
|
2014-12-20 14:59:39 +01:00
|
|
|
print_rel_date(t, secs * 1.0 / TM_DAY, "age-days", "days");
|
2007-05-22 23:08:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (secs < TM_MONTH * 2) {
|
2014-12-20 14:59:39 +01:00
|
|
|
print_rel_date(t, secs * 1.0 / TM_WEEK, "age-weeks", "weeks");
|
2007-05-22 23:08:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (secs < TM_YEAR * 2) {
|
2014-12-20 14:59:39 +01:00
|
|
|
print_rel_date(t, secs * 1.0 / TM_MONTH, "age-months", "months");
|
2007-05-22 23:08:46 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-12-20 14:59:39 +01:00
|
|
|
print_rel_date(t, secs * 1.0 / TM_YEAR, "age-years", "years");
|
2007-05-22 23:08:46 +02:00
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
void cgit_print_http_headers(void)
|
2006-12-11 16:38:30 +01:00
|
|
|
{
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.env.no_http && !strcmp(ctx.env.no_http, "1"))
|
2009-01-22 23:33:56 +01:00
|
|
|
return;
|
|
|
|
|
2014-01-15 21:53:15 +01: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);
|
|
|
|
if (ctx.page.filename)
|
2008-03-24 00:51:19 +01:00
|
|
|
htmlf("Content-Disposition: inline; filename=\"%s\"\n",
|
2014-01-15 21:53:15 +01:00
|
|
|
ctx.page.filename);
|
|
|
|
if (!ctx.env.authenticated)
|
2014-01-14 21:49:31 +01:00
|
|
|
html("Cache-Control: no-cache, no-store\n");
|
2014-01-15 21:53:15 +01: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 16:38:30 +01:00
|
|
|
html("\n");
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD"))
|
2009-02-19 23:24:15 +01:00
|
|
|
exit(0);
|
2008-03-24 00:51:19 +01:00
|
|
|
}
|
|
|
|
|
2015-08-12 14:50:09 +02:00
|
|
|
void cgit_redirect(const char *url, bool permanent)
|
|
|
|
{
|
|
|
|
htmlf("Status: %d %s\n", permanent ? 301 : 302, permanent ? "Moved" : "Found");
|
2015-08-13 11:38:56 +02:00
|
|
|
htmlf("Location: %s\n\n", url);
|
2015-08-12 14:50:09 +02:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2014-08-01 23:14:19 +02: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");
|
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
void cgit_print_docstart(void)
|
2008-03-24 00:51:19 +01:00
|
|
|
{
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.cfg.embedded) {
|
|
|
|
if (ctx.cfg.header)
|
|
|
|
html_include(ctx.cfg.header);
|
2009-01-22 23:33:56 +01:00
|
|
|
return;
|
2009-08-11 10:12:35 +02:00
|
|
|
}
|
2009-01-22 23:33:56 +01:00
|
|
|
|
2013-04-01 17:11:13 +02:00
|
|
|
const char *host = cgit_hosturl();
|
2006-12-11 16:38:30 +01:00
|
|
|
html(cgit_doctype);
|
2007-11-11 13:04:28 +01:00
|
|
|
html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
|
2006-12-11 16:38:30 +01:00
|
|
|
html("<head>\n");
|
|
|
|
html("<title>");
|
2014-01-15 21:53:15 +01:00
|
|
|
html_txt(ctx.page.title);
|
2006-12-11 16:38:30 +01:00
|
|
|
html("</title>\n");
|
2007-06-18 09:42:10 +02:00
|
|
|
htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.cfg.robots && *ctx.cfg.robots)
|
|
|
|
htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots);
|
2006-12-11 16:38:30 +01:00
|
|
|
html("<link rel='stylesheet' type='text/css' href='");
|
2014-01-15 21:53:15 +01:00
|
|
|
html_attr(ctx.cfg.css);
|
2006-12-11 16:38:30 +01:00
|
|
|
html("'/>\n");
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.cfg.favicon) {
|
2008-07-19 20:40:30 +02:00
|
|
|
html("<link rel='shortcut icon' href='");
|
2014-01-15 21:53:15 +01:00
|
|
|
html_attr(ctx.cfg.favicon);
|
2008-07-19 20:40:30 +02:00
|
|
|
html("'/>\n");
|
|
|
|
}
|
2014-01-15 21:53:15 +01:00
|
|
|
if (host && ctx.repo && ctx.qry.head) {
|
2015-10-09 13:15:46 +02:00
|
|
|
char *fileurl;
|
2013-04-06 11:28:57 +02:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2014-01-15 21:53:15 +01:00
|
|
|
strbuf_addf(&sb, "h=%s", ctx.qry.head);
|
2013-04-06 11:28:57 +02:00
|
|
|
|
2009-06-11 01:18:34 +02:00
|
|
|
html("<link rel='alternate' title='Atom feed' href='");
|
|
|
|
html(cgit_httpscheme());
|
2008-05-21 08:17:54 +02:00
|
|
|
html_attr(cgit_hosturl());
|
2015-10-09 13:15:46 +02:00
|
|
|
fileurl = cgit_fileurl(ctx.repo->url, "atom", ctx.qry.vpath,
|
|
|
|
sb.buf);
|
|
|
|
html_attr(fileurl);
|
2009-03-15 05:11:54 +01:00
|
|
|
html("' type='application/atom+xml'/>\n");
|
2013-04-06 11:28:57 +02:00
|
|
|
strbuf_release(&sb);
|
2015-10-09 13:15:46 +02:00
|
|
|
free(fileurl);
|
2008-05-21 08:17:54 +02:00
|
|
|
}
|
2014-08-01 23:14:19 +02:00
|
|
|
if (ctx.repo)
|
|
|
|
cgit_add_clone_urls(print_rel_vcs_link);
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.cfg.head_include)
|
|
|
|
html_include(ctx.cfg.head_include);
|
2006-12-11 16:38:30 +01:00
|
|
|
html("</head>\n");
|
|
|
|
html("<body>\n");
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.cfg.header)
|
|
|
|
html_include(ctx.cfg.header);
|
2006-12-11 16:38:30 +01:00
|
|
|
}
|
|
|
|
|
2015-03-08 17:32:16 +01:00
|
|
|
void cgit_print_docend(void)
|
2006-12-11 16:38:30 +01:00
|
|
|
{
|
2009-08-11 10:12:35 +02: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 13:53:30 +02:00
|
|
|
if (ctx.cfg.footer)
|
|
|
|
html_include(ctx.cfg.footer);
|
|
|
|
else {
|
2014-03-19 10:11:45 +01:00
|
|
|
htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ",
|
2008-10-05 19:09:58 +02:00
|
|
|
cgit_version);
|
2008-08-01 14:54:38 +02:00
|
|
|
cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
|
2008-06-26 13:53:30 +02:00
|
|
|
html("</div>\n");
|
|
|
|
}
|
2009-08-11 10:12:35 +02:00
|
|
|
html("</div> <!-- id=cgit -->\n");
|
2008-06-26 13:53:30 +02:00
|
|
|
html("</body>\n</html>\n");
|
2007-10-30 10:47:38 +01:00
|
|
|
}
|
|
|
|
|
2015-08-14 13:47:01 +02:00
|
|
|
void cgit_print_error_page(int code, const char *msg, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2015-08-14 13:47:22 +02:00
|
|
|
ctx.page.expires = ctx.cfg.cache_dynamic_ttl;
|
2015-08-14 13:47:01 +02:00
|
|
|
ctx.page.status = code;
|
|
|
|
ctx.page.statusmsg = msg;
|
|
|
|
cgit_print_http_headers();
|
|
|
|
cgit_print_docstart();
|
|
|
|
cgit_print_pageheader();
|
|
|
|
va_start(ap, fmt);
|
|
|
|
cgit_vprint_error(fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
cgit_print_docend();
|
|
|
|
}
|
|
|
|
|
2015-08-14 13:47:11 +02: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 23:14:17 +02:00
|
|
|
static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix)
|
|
|
|
{
|
2015-02-05 10:11:42 +01:00
|
|
|
struct strbuf **url_list = strbuf_split_str(txt, ' ', 0);
|
|
|
|
int i;
|
2014-08-01 23:14:17 +02:00
|
|
|
|
2015-02-05 10:11:42 +01: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 23:14:17 +02:00
|
|
|
}
|
|
|
|
|
2015-02-05 10:11:42 +01:00
|
|
|
strbuf_list_free(url_list);
|
2014-08-01 23:14:17 +02: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 10:42:01 +02:00
|
|
|
static int print_branch_option(const char *refname, const struct object_id *oid,
|
2013-03-04 08:52:33 +01:00
|
|
|
int flags, void *cb_data)
|
2007-10-30 10:47:38 +01:00
|
|
|
{
|
|
|
|
char *name = (char *)refname;
|
2008-02-16 11:53:40 +01:00
|
|
|
html_option(name, name, ctx.qry.head);
|
2007-10-30 10:47:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-10 01:09:24 +02:00
|
|
|
void cgit_add_hidden_formfields(int incl_head, int incl_search,
|
|
|
|
const char *page)
|
2007-10-30 10:47:38 +01:00
|
|
|
{
|
2008-02-16 13:07:13 +01:00
|
|
|
if (!ctx.cfg.virtual_root) {
|
2013-04-06 11:28:57 +02:00
|
|
|
struct strbuf url = STRBUF_INIT;
|
|
|
|
|
|
|
|
strbuf_addf(&url, "%s/%s", ctx.qry.repo, page);
|
2010-06-10 01:09:27 +02:00
|
|
|
if (ctx.qry.vpath)
|
2013-04-06 11:28:57 +02:00
|
|
|
strbuf_addf(&url, "/%s", ctx.qry.vpath);
|
|
|
|
html_hidden("url", url.buf);
|
|
|
|
strbuf_release(&url);
|
2007-10-30 10:47:38 +01:00
|
|
|
}
|
|
|
|
|
2008-07-27 12:32:08 +02:00
|
|
|
if (incl_head && ctx.qry.head && ctx.repo->defbranch &&
|
|
|
|
strcmp(ctx.qry.head, ctx.repo->defbranch))
|
2008-02-16 11:53:40 +01:00
|
|
|
html_hidden("h", ctx.qry.head);
|
2007-10-30 10:47:38 +01:00
|
|
|
|
2008-02-16 11:53:40 +01:00
|
|
|
if (ctx.qry.sha1)
|
|
|
|
html_hidden("id", ctx.qry.sha1);
|
|
|
|
if (ctx.qry.sha2)
|
|
|
|
html_hidden("id2", ctx.qry.sha2);
|
2008-11-29 18:39:41 +01:00
|
|
|
if (ctx.qry.showmsg)
|
|
|
|
html_hidden("showmsg", "1");
|
2007-10-30 10:47:38 +01:00
|
|
|
|
|
|
|
if (incl_search) {
|
2008-02-16 11:53:40 +01:00
|
|
|
if (ctx.qry.grep)
|
|
|
|
html_hidden("qt", ctx.qry.grep);
|
|
|
|
if (ctx.qry.search)
|
|
|
|
html_hidden("q", ctx.qry.search);
|
2007-10-30 10:47:38 +01:00
|
|
|
}
|
2006-12-11 16:38:30 +01:00
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
static const char *hc(const char *page)
|
2008-04-12 15:53:31 +02:00
|
|
|
{
|
2014-01-15 21:53:15 +01:00
|
|
|
return strcmp(ctx.qry.page, page) ? NULL : "active";
|
2008-04-12 15:53:31 +02:00
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
static void cgit_print_path_crumbs(char *path)
|
2010-06-10 01:09:29 +02:00
|
|
|
{
|
2014-01-15 21:53:15 +01:00
|
|
|
char *old_path = ctx.qry.path;
|
2010-06-10 01:09:29 +02:00
|
|
|
char *p = path, *q, *end = path + strlen(path);
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
ctx.qry.path = NULL;
|
|
|
|
cgit_self_link("root", NULL, NULL);
|
|
|
|
ctx.qry.path = p = path;
|
2010-06-10 01:09:29 +02:00
|
|
|
while (p < end) {
|
|
|
|
if (!(q = strchr(p, '/')))
|
|
|
|
q = end;
|
|
|
|
*q = '\0';
|
|
|
|
html_txt("/");
|
2014-01-15 21:53:15 +01:00
|
|
|
cgit_self_link(p, NULL, NULL);
|
2010-06-10 01:09:29 +02:00
|
|
|
if (q < end)
|
|
|
|
*q = '/';
|
|
|
|
p = q + 1;
|
|
|
|
}
|
2014-01-15 21:53:15 +01:00
|
|
|
ctx.qry.path = old_path;
|
2010-06-10 01:09:29 +02:00
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
static void print_header(void)
|
2006-12-11 16:38:30 +01:00
|
|
|
{
|
2010-12-23 12:47:54 +01:00
|
|
|
char *logo = NULL, *logo_link = NULL;
|
|
|
|
|
2008-04-12 15:53:31 +02:00
|
|
|
html("<table id='header'>\n");
|
|
|
|
html("<tr>\n");
|
2009-06-30 03:27:51 +02:00
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.repo && ctx.repo->logo && *ctx.repo->logo)
|
|
|
|
logo = ctx.repo->logo;
|
2010-12-23 12:47:54 +01:00
|
|
|
else
|
2014-01-15 21:53:15 +01: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 12:47:54 +01:00
|
|
|
else
|
2014-01-15 21:53:15 +01:00
|
|
|
logo_link = ctx.cfg.logo_link;
|
2010-12-23 12:47:54 +01:00
|
|
|
if (logo && *logo) {
|
2009-06-30 03:27:51 +02:00
|
|
|
html("<td class='logo' rowspan='2'><a href='");
|
2010-12-23 12:47:54 +01:00
|
|
|
if (logo_link && *logo_link)
|
|
|
|
html_attr(logo_link);
|
2009-06-30 03:27:51 +02:00
|
|
|
else
|
|
|
|
html_attr(cgit_rooturl());
|
|
|
|
html("'><img src='");
|
2010-12-23 12:47:54 +01:00
|
|
|
html_attr(logo);
|
2009-06-30 03:27:51 +02:00
|
|
|
html("' alt='cgit logo'/></a></td>\n");
|
|
|
|
}
|
2008-04-13 10:57:11 +02:00
|
|
|
|
2008-04-12 15:53:31 +02:00
|
|
|
html("<td class='main'>");
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.repo) {
|
2015-03-03 17:23:40 +01:00
|
|
|
cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1);
|
2008-05-03 12:44:20 +02:00
|
|
|
html(" : ");
|
2014-01-15 21:53:15 +01:00
|
|
|
cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
|
|
|
|
if (ctx.env.authenticated) {
|
2014-01-14 21:49:31 +01:00
|
|
|
html("</td><td class='form'>");
|
|
|
|
html("<form method='get' action=''>\n");
|
2014-01-15 21:53:15 +01:00
|
|
|
cgit_add_hidden_formfields(0, 1, ctx.qry.page);
|
2014-01-14 21:49:31 +01:00
|
|
|
html("<select name='h' onchange='this.form.submit();'>\n");
|
2014-01-15 21:53:15 +01:00
|
|
|
for_each_branch_ref(print_branch_option, ctx.qry.head);
|
2015-03-18 18:08:48 +01:00
|
|
|
if (ctx.repo->enable_remote_branches)
|
|
|
|
for_each_remote_ref(print_branch_option, ctx.qry.head);
|
2014-01-14 21:49:31 +01:00
|
|
|
html("</select> ");
|
|
|
|
html("<input type='submit' name='' value='switch'/>");
|
|
|
|
html("</form>");
|
|
|
|
}
|
2008-04-12 19:59:41 +02:00
|
|
|
} else
|
2014-01-15 21:53:15 +01:00
|
|
|
html_txt(ctx.cfg.root_title);
|
2008-04-15 00:00:11 +02:00
|
|
|
html("</td></tr>\n");
|
2008-04-13 10:57:11 +02:00
|
|
|
|
2008-07-27 12:22:16 +02:00
|
|
|
html("<tr><td class='sub'>");
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.repo) {
|
|
|
|
html_txt(ctx.repo->desc);
|
2008-07-27 12:22:16 +02:00
|
|
|
html("</td><td class='sub right'>");
|
2014-01-15 21:53:15 +01:00
|
|
|
html_txt(ctx.repo->owner);
|
2008-04-15 00:00:11 +02:00
|
|
|
} else {
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.cfg.root_desc)
|
|
|
|
html_txt(ctx.cfg.root_desc);
|
|
|
|
else if (ctx.cfg.index_info)
|
|
|
|
html_include(ctx.cfg.index_info);
|
2008-04-13 10:57:11 +02:00
|
|
|
}
|
2008-04-15 00:00:11 +02:00
|
|
|
html("</td></tr></table>\n");
|
2009-07-25 12:19:31 +02:00
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:15 +01:00
|
|
|
void cgit_print_pageheader(void)
|
2009-07-25 12:19:31 +02:00
|
|
|
{
|
|
|
|
html("<div id='cgit'>");
|
2014-01-15 21:53:15 +01:00
|
|
|
if (!ctx.env.authenticated || !ctx.cfg.noheader)
|
|
|
|
print_header();
|
2008-04-12 15:53:31 +02:00
|
|
|
|
|
|
|
html("<table class='tabs'><tr><td>\n");
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.env.authenticated && ctx.repo) {
|
2014-01-17 13:53:37 +01:00
|
|
|
if (ctx.repo->readme.nr)
|
|
|
|
reporevlink("about", "about", NULL,
|
|
|
|
hc("about"), ctx.qry.head, NULL,
|
|
|
|
NULL);
|
2014-01-15 21:53:15 +01:00
|
|
|
cgit_summary_link("summary", NULL, hc("summary"),
|
|
|
|
ctx.qry.head);
|
|
|
|
cgit_refs_link("refs", NULL, hc("refs"), ctx.qry.head,
|
|
|
|
ctx.qry.sha1, NULL);
|
|
|
|
cgit_log_link("log", NULL, hc("log"), ctx.qry.head,
|
|
|
|
NULL, ctx.qry.vpath, 0, NULL, NULL,
|
2015-08-12 16:55:28 +02:00
|
|
|
ctx.qry.showmsg, ctx.qry.follow);
|
2014-01-15 21:53:15 +01:00
|
|
|
cgit_tree_link("tree", NULL, hc("tree"), ctx.qry.head,
|
|
|
|
ctx.qry.sha1, ctx.qry.vpath);
|
|
|
|
cgit_commit_link("commit", NULL, hc("commit"),
|
2014-10-05 11:59:02 +02:00
|
|
|
ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath);
|
2014-01-15 21:53:15 +01:00
|
|
|
cgit_diff_link("diff", NULL, hc("diff"), ctx.qry.head,
|
2014-10-05 11:59:03 +02:00
|
|
|
ctx.qry.sha1, ctx.qry.sha2, ctx.qry.vpath);
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.repo->max_stats)
|
|
|
|
cgit_stats_link("stats", NULL, hc("stats"),
|
|
|
|
ctx.qry.head, ctx.qry.vpath);
|
2008-04-13 10:57:11 +02:00
|
|
|
html("</td><td class='form'>");
|
|
|
|
html("<form class='right' method='get' action='");
|
2015-10-09 13:15:46 +02: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 10:57:11 +02:00
|
|
|
html("'>\n");
|
2008-12-07 15:52:35 +01:00
|
|
|
cgit_add_hidden_formfields(1, 0, "log");
|
2008-04-13 10:57:11 +02:00
|
|
|
html("<select name='qt'>\n");
|
2014-01-15 21:53:15 +01: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 10:57:11 +02:00
|
|
|
html("</select>\n");
|
2008-04-13 11:57:10 +02:00
|
|
|
html("<input class='txt' type='text' size='10' name='q' value='");
|
2014-01-15 21:53:15 +01:00
|
|
|
html_attr(ctx.qry.search);
|
2008-04-13 10:57:11 +02:00
|
|
|
html("'/>\n");
|
|
|
|
html("<input type='submit' value='search'/>\n");
|
|
|
|
html("</form>\n");
|
2014-01-15 21:53:15 +01:00
|
|
|
} else if (ctx.env.authenticated) {
|
2015-10-09 13:15:48 +02:00
|
|
|
char *currenturl = cgit_currenturl();
|
2015-03-03 17:23:40 +01:00
|
|
|
site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0, 1);
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.cfg.root_readme)
|
|
|
|
site_link("about", "about", NULL, hc("about"),
|
2015-03-03 17:23:40 +01:00
|
|
|
NULL, NULL, 0, 1);
|
2008-04-13 11:57:10 +02:00
|
|
|
html("</td><td class='form'>");
|
|
|
|
html("<form method='get' action='");
|
2015-10-09 13:15:48 +02:00
|
|
|
html_attr(currenturl);
|
2008-04-13 11:57:10 +02:00
|
|
|
html("'>\n");
|
|
|
|
html("<input type='text' name='q' size='10' value='");
|
2014-01-15 21:53:15 +01:00
|
|
|
html_attr(ctx.qry.search);
|
2008-04-13 11:57:10 +02:00
|
|
|
html("'/>\n");
|
|
|
|
html("<input type='submit' value='search'/>\n");
|
|
|
|
html("</form>");
|
2015-10-09 13:15:48 +02:00
|
|
|
free(currenturl);
|
2006-12-28 02:01:49 +01:00
|
|
|
}
|
2008-04-12 15:53:31 +02:00
|
|
|
html("</td></tr></table>\n");
|
2014-01-15 21:53:15 +01:00
|
|
|
if (ctx.env.authenticated && ctx.qry.vpath) {
|
2010-06-10 01:09:28 +02:00
|
|
|
html("<div class='path'>");
|
|
|
|
html("path: ");
|
2014-01-15 21:53:15 +01:00
|
|
|
cgit_print_path_crumbs(ctx.qry.vpath);
|
2015-08-12 16:55:28 +02: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-10 01:09:28 +02:00
|
|
|
html("</div>");
|
|
|
|
}
|
2008-04-12 15:53:31 +02:00
|
|
|
html("<div class='content'>");
|
2006-12-11 16:38:30 +01:00
|
|
|
}
|
2007-02-08 13:53:13 +01:00
|
|
|
|
2008-02-23 22:45:33 +01: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);
|
|
|
|
}
|
|
|
|
|
2008-03-24 16:00:27 +01:00
|
|
|
void cgit_print_snapshot_links(const char *repo, const char *head,
|
|
|
|
const char *hex, int snapshots)
|
|
|
|
{
|
|
|
|
const struct cgit_snapshot_format* f;
|
2013-04-06 11:28:57 +02:00
|
|
|
struct strbuf filename = STRBUF_INIT;
|
|
|
|
size_t prefixlen;
|
2009-10-16 02:03:32 +02:00
|
|
|
unsigned char sha1[20];
|
2008-03-24 16:00:27 +01:00
|
|
|
|
2009-10-16 02:03:32 +02:00
|
|
|
if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 &&
|
|
|
|
(hex[0] == 'v' || hex[0] == 'V') && isdigit(hex[1]))
|
|
|
|
hex++;
|
2013-04-06 11:28:57 +02:00
|
|
|
strbuf_addf(&filename, "%s-%s", cgit_repobasename(repo), hex);
|
|
|
|
prefixlen = filename.len;
|
2008-03-24 16:00:27 +01:00
|
|
|
for (f = cgit_snapshot_formats; f->suffix; f++) {
|
|
|
|
if (!(snapshots & f->bit))
|
|
|
|
continue;
|
2013-04-06 11:28:57 +02:00
|
|
|
strbuf_setlen(&filename, prefixlen);
|
|
|
|
strbuf_addstr(&filename, f->suffix);
|
|
|
|
cgit_snapshot_link(filename.buf, NULL, NULL, NULL, NULL,
|
|
|
|
filename.buf);
|
2008-03-24 16:00:27 +01:00
|
|
|
html("<br/>");
|
|
|
|
}
|
2013-04-06 11:28:57 +02:00
|
|
|
strbuf_release(&filename);
|
2008-03-24 16:00:27 +01:00
|
|
|
}
|