diff options
Diffstat (limited to 'source/ui-shared.c')
-rw-r--r--source/ui-shared.c87
1 file changed, 60 insertions, 27 deletions
diff --git a/source/ui-shared.c b/source/ui-shared.c
index fd9cd20..94a749e 100644
--- a/source/ui-shared.c
+++ b/source/ui-shared.c
@@ -138,6 +138,47 @@ static void site_link(const char *page, const char *name, const char *title,
}
/*
+ * Write the url naming the repository, the page and the path, and return
+ * whether the url has opened its query string already.
+ */
+static int write_page_url(const char *page, const char *path)
+{
+ if (ctx.cfg.virtual_root) {
+ html_url_path(ctx.cfg.virtual_root);
+ html_url_path(ctx.repo->url);
+ if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
+ html("/");
+ if (page) {
+ html_url_path(page);
+ html("/");
+ if (path)
+ html_url_path(path);
+ }
+ return 0;
+ }
+ html_url_path(ctx.cfg.script_name);
+ html("?url=");
+ html_url_arg(ctx.repo->url);
+ if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
+ html("/");
+ if (page) {
+ html_url_arg(page);
+ html("/");
+ if (path)
+ html_url_arg(path);
+ }
+ return 1;
+}
+
+/*
+ * Whether head needs naming in a url, which the default branch does not.
+ */
+static int head_is_named(const char *head)
+{
+ return head && ctx.repo->defbranch && strcmp(head, ctx.repo->defbranch);
+}
+
+/*
* Open an anchor and write the part of its href naming the repository, the
* page and the path, leaving the href quote open for the caller to add its own
* arguments and close. The return is the delimiter to put before the first of
@@ -146,7 +187,7 @@ static void site_link(const char *page, const char *name, const char *title,
static const char *repolink(const char *title, const char *class, const char *page,
const char *head, const char *path)
{
- const char *delim = "?";
+ const char *delim;
html("<a");
if (title) {
@@ -156,32 +197,8 @@ static const char *repolink(const char *title, const char *class, const char *pa
}
link_class(class);
html(" href='");
- if (ctx.cfg.virtual_root) {
- html_url_path(ctx.cfg.virtual_root);
- html_url_path(ctx.repo->url);
- if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
- html("/");
- if (page) {
- html_url_path(page);
- html("/");
- if (path)
- html_url_path(path);
- }
- } else {
- html_url_path(ctx.cfg.script_name);
- html("?url=");
- html_url_arg(ctx.repo->url);
- if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
- html("/");
- if (page) {
- html_url_arg(page);
- html("/");
- if (path)
- html_url_arg(path);
- }
- delim = "&amp;";
- }
- if (head && ctx.repo->defbranch && strcmp(head, ctx.repo->defbranch)) {
+ delim = write_page_url(page, path) ? "&amp;" : "?";
+ if (head_is_named(head)) {
html(delim);
html("h=");
html_url_arg(head);
@@ -911,6 +928,22 @@ char *cgit_pageurl(const char *reponame, const char *pagename, const char *query
return cgit_fileurl(reponame, pagename, NULL, query);
}
+void cgit_tree_url(const char *head, struct strbuf *base, struct strbuf *query)
+{
+ int query_open;
+
+ html_capture_begin(base);
+ query_open = write_page_url("tree", NULL);
+ html_capture_end();
+ if (!head_is_named(head))
+ return;
+ html_capture_begin(query);
+ html(query_open ? "&" : "?");
+ html("h=");
+ html_url_arg(head);
+ html_capture_end();
+}
+
const char *cgit_snapshot_prefix(const struct cgit_repo *repo)
{
if (repo->snapshot_prefix)