aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Green <andy@warmcat.com>2018-06-19 10:32:25 +0800
committerAndy Green <andy@warmcat.com>2018-06-29 07:53:21 +0800
commit1592728359c15e1a2f481414ae4ccd8d6feb3251 (patch)
treebb332432660af3c15daf9eeb36a4a3b1fae4f874
parentmd2html: add asset postfix arg (diff)
downloadcgit-1592728359c15e1a2f481414ae4ccd8d6feb3251.tar.xz
cgit-1592728359c15e1a2f481414ae4ccd8d6feb3251.zip
ui-shared: add helper for generating non-urlencoded links
We are going to have to produce plain links in the next patch. But depending on config, the links are not simple. Reproduce the logic in repolink() to generate correctly- formatted links in a strbuf, without urlencoding, in a reusable helper cgit_repo_create_url(). Signed-off-by: Andy Green <andy@warmcat.com>
-rw-r--r--ui-shared.c32
-rw-r--r--ui-shared.h3
2 files changed, 35 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 15887cc..2327570 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -226,6 +226,38 @@ void cgit_index_link(const char *name, const char *title, const char *class,
site_link(NULL, name, title, class, pattern, sort, ofs, always_root);
}
+const char *cgit_repo_create_url(struct strbuf *sb, struct strbuf *sb_post,
+ const char *page, const char *head,
+ const char *path)
+{
+ const char *delim = "?";
+
+ if (ctx.cfg.virtual_root) {
+ strbuf_addf(sb, "%s%s", ctx.cfg.virtual_root, ctx.repo->url);
+ } else {
+ strbuf_addstr(sb, ctx.cfg.script_name);
+ sb = sb_post;
+ strbuf_addf(sb, "?url=%s", ctx.repo->url);
+ delim = "&";
+ }
+
+ if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
+ strbuf_addch(sb, '/');
+
+ if (page) {
+ strbuf_addf(sb, "%s/", page);
+ if (path)
+ strbuf_addstr(sb, path);
+ }
+
+ if (head && ctx.repo->defbranch && strcmp(head, ctx.repo->defbranch)) {
+ strbuf_addf(sb_post, "%sh=%s", delim, head);
+ delim = "&";
+ }
+
+ return delim;
+}
+
static char *repolink(const char *title, const char *class, const char *page,
const char *head, const char *path)
{
diff --git a/ui-shared.h b/ui-shared.h
index 1bc9b61..8d32a3d 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -59,6 +59,9 @@ extern void cgit_object_link(struct object *obj);
extern void cgit_submodule_link(const char *class, char *path,
const char *rev);
+extern const char *cgit_repo_create_url(struct strbuf *sb, struct strbuf *sb_post,
+ const char *page, const char *head,
+ const char *path);
extern void cgit_print_layout_start(void);
extern void cgit_print_layout_end(void);