+ } else
+ html_txt(ctx.cfg.root_title);
+ html("</td></tr>\n");
+
+ html("<tr><td class='sub'>");
+ if (ctx.repo) {
+ html_txt(ctx.repo->desc);
+ html("</td><td class='sub right'>");
+ html_txt(ctx.repo->owner);
+ } else {
+ if (ctx.cfg.root_desc)
+ html_txt(ctx.cfg.root_desc);
+ }
+ html("</td></tr></table>\n");
+}
+
+void cgit_print_pageheader(void)
+{
+ html("<div id='cgit'>");
+ if (!ctx.env.authenticated || !ctx.cfg.noheader)
+ print_header();
+
+ html("<table class='tabs'><tr><td>\n");
+ if (ctx.env.authenticated && ctx.repo) {
+ if (ctx.repo->readme.nr)
+ reporevlink("about", "about", NULL,
+ hc("about"), ctx.qry.head, NULL,
+ NULL);
+ cgit_summary_link("summary", NULL, hc("summary"),
+ ctx.qry.head);
+ cgit_refs_link("refs", NULL, hc("refs"), ctx.qry.head,
+ ctx.qry.oid, NULL);
+ cgit_log_link("log", NULL, hc("log"), ctx.qry.head,
+ NULL, ctx.qry.vpath, 0, NULL, NULL,
+ ctx.qry.showmsg, ctx.qry.follow);
+ if (ctx.qry.page && !strcmp(ctx.qry.page, "blame"))
+ cgit_blame_link("blame", NULL, hc("blame"), ctx.qry.head,
+ ctx.qry.oid, ctx.qry.vpath);
+ else
+ cgit_tree_link("tree", NULL, hc("tree"), ctx.qry.head,
+ ctx.qry.oid, ctx.qry.vpath);
+ cgit_commit_link("commit", NULL, hc("commit"),
+ ctx.qry.head, ctx.qry.oid, ctx.qry.vpath);
+ cgit_diff_link("diff", NULL, hc("diff"), ctx.qry.head,
+ ctx.qry.oid, ctx.qry.oid2, ctx.qry.vpath);
+ if (ctx.repo->max_stats)
+ cgit_stats_link("stats", NULL, hc("stats"),
+ ctx.qry.head, ctx.qry.vpath);
+ if (ctx.repo->homepage) {
+ html("<a href='");
+ html_attr(ctx.repo->homepage);
+ html("'>homepage</a>");
+ }
+ html("</td><td class='form'>");
+ html("<form class='right' method='get' action='");
+ if (ctx.cfg.virtual_root) {
+ char *fileurl = cgit_fileurl(ctx.qry.repo, "log",
+ ctx.qry.vpath, NULL);
+ html_url_path(fileurl);
+ free(fileurl);
+ }
+ html("'>\n");
+ cgit_add_hidden_formfields(1, 0, "log");
+ html("<select name='qt'>\n");
+ 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);
+ html("</select>\n");
+ html("<input class='txt' type='search' size='10' name='q' value='");
+ html_attr(ctx.qry.search);
+ html("'/>\n");
+ html("<input type='submit' value='search'/>\n");
+ html("</form>\n");
+ } else if (ctx.env.authenticated) {
+ char *currenturl = cgit_currenturl();
+ 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, 1);
+ html("</td><td class='form'>");
+ html("<form method='get' action='");
+ html_attr(currenturl);
+ html("'>\n");
+ html("<input type='search' name='q' size='10' value='");
+ html_attr(ctx.qry.search);
+ html("'/>\n");
+ html("<input type='submit' value='search'/>\n");
+ html("</form>");
+ free(currenturl);
+ }
+ html("</td></tr></table>\n");
+ if (ctx.env.authenticated && ctx.repo && ctx.qry.vpath) {
+ html("<div class='path'>");
+ html("path: ");
+ cgit_print_path_crumbs(ctx.qry.vpath);
+ 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(")");
+ }
+ html("</div>");
+ }
+ html("<div class='content'>");
+}
+
+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);
+}
+
+void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base,
+ const char *ref)
+{
+ struct object_id oid;
+
+ /*
+ * Prettify snapshot names by stripping leading "v" or "V" if the tag
+ * name starts with {v,V}[0-9] and the prettify mapping is injective,
+ * i.e. each stripped tag can be inverted without ambiguities.
+ */
+ if (get_oid(fmt("refs/tags/%s", ref), &oid) == 0 &&
+ (ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]) &&
+ ((get_oid(fmt("refs/tags/%s", ref + 1), &oid) == 0) +
+ (get_oid(fmt("refs/tags/v%s", ref + 1), &oid) == 0) +
+ (get_oid(fmt("refs/tags/V%s", ref + 1), &oid) == 0) == 1))
+ ref++;
+
+ strbuf_addf(filename, "%s-%s", base, ref);
+}
+
+void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref,
+ const char *separator)
+{
+ const struct cgit_snapshot_format *f;
+ struct strbuf filename = STRBUF_INIT;
+ const char *basename;
+ size_t prefixlen;
+
+ basename = cgit_snapshot_prefix(repo);
+ if (starts_with(ref, basename))
+ strbuf_addstr(&filename, ref);
+ else
+ cgit_compose_snapshot_prefix(&filename, basename, ref);
+
+ prefixlen = filename.len;
+ for (f = cgit_snapshot_formats; f->suffix; f++) {
+ if (!(repo->snapshots & cgit_snapshot_format_bit(f)))
+ continue;
+ strbuf_setlen(&filename, prefixlen);
+ strbuf_addstr(&filename, f->suffix);
+ cgit_snapshot_link(filename.buf, NULL, NULL, NULL, NULL,
+ filename.buf);
+ if (cgit_snapshot_get_sig(ref, f)) {
+ strbuf_addstr(&filename, ".asc");
+ html(" (");
+ cgit_snapshot_link("sig", NULL, NULL, NULL, NULL,
+ filename.buf);
+ html(")");
+ } 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(")");
+ }
+ html(separator);
+ }
+ strbuf_release(&filename);
+}
+
+void cgit_set_title_from_path(const char *path)
+{
+ struct strbuf sb = STRBUF_INIT;
+ const char *slash, *last_slash;
+
+ if (!path)
+ return;
+
+ 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 ");
+ }
+ strbuf_add(&sb, path, last_slash - path);
+ strbuf_addf(&sb, " - %s", ctx.page.title);
+ ctx.page.title = strbuf_detach(&sb, NULL);