X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/dd0f27eb36e737261b57d6ebcbd9fe20e559470d..820df9c66073b1345397642b46f1885b40b620e3:/ui-shared.c diff --git a/ui-shared.c b/ui-shared.c index e4bb98f..7ab2ab1 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -7,6 +7,9 @@ */ #include "cgit.h" +#include "ui-shared.h" +#include "cmd.h" +#include "html.h" const char cgit_doctype[] = "tm_wday], - tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, + tm->tm_mday, month[tm->tm_mon], 1900 + tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec); } -static long ttl_seconds(long ttl) +void cgit_print_error(const char *fmt, ...) { - if (ttl<0) - return 60 * 60 * 24 * 365; - else - return ttl * 60; + va_list ap; + va_start(ap, fmt); + cgit_vprint_error(fmt, ap); + va_end(ap); } -void cgit_print_error(char *msg) +void cgit_vprint_error(const char *fmt, va_list ap) { + va_list cp; html("
| "); - html_txt(cgit_root_title); - html(" | ");
- html(" | ||||
| ");
- if (cgit_query_repo) {
- html_txt(cgit_repo->name);
- html(" (");
- html_txt(cgit_query_head);
- html(") : ");
- reporevlink(NULL, "summary", NULL, NULL, cgit_query_head,
- NULL, NULL);
- html(" ");
- cgit_log_link("log", NULL, NULL, cgit_query_head,
- cgit_query_sha1, cgit_query_path, 0);
- html(" ");
- cgit_tree_link("tree", NULL, NULL, cgit_query_head,
- cgit_query_sha1, NULL);
- html(" ");
- cgit_commit_link("commit", NULL, NULL, cgit_query_head,
- cgit_query_sha1);
- html(" ");
- cgit_diff_link("diff", NULL, NULL, cgit_query_head,
- cgit_query_sha1, cgit_query_sha2,
- cgit_query_path);
+ char *name = (char *)refname;
+ html_option(name, name, ctx.qry.head);
+ return 0;
+}
+
+void cgit_add_hidden_formfields(int incl_head, int incl_search,
+ const char *page)
+{
+ if (!ctx.cfg.virtual_root) {
+ struct strbuf url = STRBUF_INIT;
+
+ strbuf_addf(&url, "%s/%s", ctx.qry.repo, page);
+ if (ctx.qry.vpath)
+ strbuf_addf(&url, "/%s", ctx.qry.vpath);
+ html_hidden("url", url.buf);
+ strbuf_release(&url);
+ }
+
+ if (incl_head && ctx.qry.head && ctx.repo->defbranch &&
+ strcmp(ctx.qry.head, ctx.repo->defbranch))
+ html_hidden("h", ctx.qry.head);
+
+ if (ctx.qry.sha1)
+ html_hidden("id", ctx.qry.sha1);
+ if (ctx.qry.sha2)
+ html_hidden("id2", ctx.qry.sha2);
+ if (ctx.qry.showmsg)
+ html_hidden("showmsg", "1");
+
+ if (incl_search) {
+ if (ctx.qry.grep)
+ html_hidden("qt", ctx.qry.grep);
+ if (ctx.qry.search)
+ html_hidden("q", ctx.qry.search);
+ }
+}
+
+static const char *hc(struct cgit_context *ctx, const char *page)
+{
+ return strcmp(ctx->qry.page, page) ? NULL : "active";
+}
+
+static void cgit_print_path_crumbs(struct cgit_context *ctx, char *path)
+{
+ char *old_path = ctx->qry.path;
+ char *p = path, *q, *end = path + strlen(path);
+
+ ctx->qry.path = NULL;
+ cgit_self_link("root", NULL, NULL, ctx);
+ ctx->qry.path = p = path;
+ while (p < end) {
+ if (!(q = strchr(p, '/')))
+ q = end;
+ *q = '\0';
+ html_txt("/");
+ cgit_self_link(p, NULL, NULL, ctx);
+ if (q < end)
+ *q = '/';
+ p = q + 1;
+ }
+ ctx->qry.path = old_path;
+}
+
+static void print_header(struct cgit_context *ctx)
+{
+ char *logo = NULL, *logo_link = NULL;
+
+ html(" ");
+ if (!ctx->cfg.noheader)
+ print_header(ctx);
+
+ html("
");
+ html("path: ");
+ cgit_print_path_crumbs(ctx, ctx->qry.vpath);
+ html(" ");
+ }
+ html("");
}
-/* vim:set sw=8: */
+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_print_snapshot_links(const char *repo, const char *head,
+ const char *hex, int snapshots)
+{
+ const struct cgit_snapshot_format* f;
+ struct strbuf filename = STRBUF_INIT;
+ size_t prefixlen;
+ unsigned char sha1[20];
+
+ if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 &&
+ (hex[0] == 'v' || hex[0] == 'V') && isdigit(hex[1]))
+ hex++;
+ strbuf_addf(&filename, "%s-%s", cgit_repobasename(repo), hex);
+ prefixlen = filename.len;
+ for (f = cgit_snapshot_formats; f->suffix; f++) {
+ if (!(snapshots & f->bit))
+ continue;
+ strbuf_setlen(&filename, prefixlen);
+ strbuf_addstr(&filename, f->suffix);
+ cgit_snapshot_link(filename.buf, NULL, NULL, NULL, NULL,
+ filename.buf);
+ html(" "); + } + strbuf_release(&filename); +} | |||||