#include "cmd.h"
#include "html.h"
-const char cgit_doctype[] =
+static const char cgit_doctype[] =
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
html("</div>\n");
}
-const char *cgit_httpscheme()
+const char *cgit_httpscheme(void)
{
if (ctx.env.https && !strcmp(ctx.env.https, "on"))
return "https://";
return "http://";
}
-const char *cgit_hosturl()
+const char *cgit_hosturl(void)
{
if (ctx.env.http_host)
return ctx.env.http_host;
return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port);
}
-const char *cgit_rooturl()
+const char *cgit_currenturl(void)
+{
+ if (!ctx.qry.url)
+ return cgit_rooturl();
+ 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);
+}
+
+const char *cgit_rooturl(void)
{
if (ctx.cfg.virtual_root)
return ctx.cfg.virtual_root;
return ctx.cfg.script_name;
}
-const char *cgit_loginurl()
+const char *cgit_loginurl(void)
{
- static const char *login_url = 0;
+ static const char *login_url;
if (!login_url)
login_url = fmtalloc("%s?p=login", cgit_rooturl());
return login_url;
char *cgit_pageurl(const char *reponame, const char *pagename,
const char *query)
{
- return cgit_fileurl(reponame, pagename, 0, query);
+ return cgit_fileurl(reponame, pagename, NULL, query);
}
const char *cgit_repobasename(const char *reponame)
return rvbuf;
}
-static void site_url(const char *page, const char *search, const char *sort, int ofs)
+static void site_url(const char *page, const char *search, const char *sort, int ofs, int always_root)
{
char *delim = "?";
- if (ctx.cfg.virtual_root)
- html_attr(ctx.cfg.virtual_root);
+ if (always_root || page)
+ html_attr(cgit_rooturl());
else
- html_url_path(ctx.cfg.script_name);
+ html_attr(cgit_currenturl());
if (page) {
htmlf("?p=%s", page);
}
static void site_link(const char *page, const char *name, const char *title,
- const char *class, const char *search, const char *sort, int ofs)
+ const char *class, const char *search, const char *sort, int ofs, int always_root)
{
html("<a");
if (title) {
html("'");
}
html(" href='");
- site_url(page, search, sort, ofs);
+ site_url(page, search, sort, ofs, always_root);
html("'>");
html_txt(name);
html("</a>");
}
void cgit_index_link(const char *name, const char *title, const char *class,
- const char *pattern, const char *sort, int ofs)
+ const char *pattern, const char *sort, int ofs, int always_root)
{
- site_link(NULL, name, title, class, pattern, sort, ofs);
+ site_link(NULL, name, title, class, pattern, sort, ofs, always_root);
}
static char *repolink(const char *title, const char *class, const char *page,
{
if (!strcmp(ctx.qry.page, "repolist"))
cgit_index_link(name, title, class, ctx.qry.search, ctx.qry.sort,
- ctx.qry.ofs);
+ ctx.qry.ofs, 1);
else if (!strcmp(ctx.qry.page, "summary"))
cgit_summary_link(name, title, class, ctx.qry.head);
else if (!strcmp(ctx.qry.page, "tag"))
item = lookup_path(list, path);
}
}
- html("<a ");
- if (class)
- htmlf("class='%s' ", class);
- html("href='");
- if (item) {
- html_attrf(item->util, rev);
- } else if (ctx.repo->module_link) {
- dir = strrchr(path, '/');
- if (dir)
- dir++;
- else
- dir = path;
- html_attrf(ctx.repo->module_link, dir, rev);
+ 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>");
} else {
- html("#");
+ html("<span");
+ if (class)
+ htmlf(" class='%s'", class);
+ html(">");
+ html_txt(path);
+ html("</span>");
}
- html("'>");
- html_txt(path);
- html("</a>");
html_txtf(" @ %.7s", rev);
if (item && tail)
path[len - 1] = tail;
html_include(ctx.cfg.header);
}
-void cgit_print_docend()
+void cgit_print_docend(void)
{
html("</div> <!-- class=content -->\n");
if (ctx.cfg.embedded) {
static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix)
{
- struct strbuf buf = STRBUF_INIT;
- char *h = txt, *t, c;
+ struct strbuf **url_list = strbuf_split_str(txt, ' ', 0);
+ int i;
- while (h && *h) {
- while (h && *h == ' ')
- h++;
- if (!*h)
- break;
- t = h;
- while (t && *t && *t != ' ')
- t++;
- c = *t;
- *t = 0;
-
- if (suffix && *suffix) {
- strbuf_reset(&buf);
- strbuf_addf(&buf, "%s/%s", h, suffix);
- h = buf.buf;
- }
- fn(h);
- *t = c;
- h = t;
+ 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);
}
- strbuf_release(&buf);
+ strbuf_list_free(url_list);
}
void cgit_add_clone_urls(void (*fn)(const char *))
add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url);
}
-static int print_branch_option(const char *refname, const unsigned char *sha1,
+static int print_branch_option(const char *refname, const struct object_id *oid,
int flags, void *cb_data)
{
char *name = (char *)refname;
html("<td class='main'>");
if (ctx.repo) {
- cgit_index_link("index", NULL, NULL, NULL, NULL, 0);
+ cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1);
html(" : ");
cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
if (ctx.env.authenticated) {
cgit_add_hidden_formfields(0, 1, ctx.qry.page);
html("<select name='h' onchange='this.form.submit();'>\n");
for_each_branch_ref(print_branch_option, ctx.qry.head);
+ if (ctx.repo->enable_remote_branches)
+ for_each_remote_ref(print_branch_option, ctx.qry.head);
html("</select> ");
html("<input type='submit' name='' value='switch'/>");
html("</form>");
html("<input type='submit' value='search'/>\n");
html("</form>\n");
} else if (ctx.env.authenticated) {
- site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0);
+ site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0, 1);
if (ctx.cfg.root_readme)
site_link("about", "about", NULL, hc("about"),
- NULL, NULL, 0);
+ NULL, NULL, 0, 1);
html("</td><td class='form'>");
html("<form method='get' action='");
- html_attr(cgit_rooturl());
+ html_attr(cgit_currenturl());
html("'>\n");
html("<input type='text' name='q' size='10' value='");
html_attr(ctx.qry.search);