[PATCH 4/4] repolist: add a git link on front page
Sebastian Andrzej Siewior
sebastian at breakpoint.cc
Sat Jan 18 21:25:00 CET 2014
If links are enabled there will be an additinal "git" links next to
"summary log tree" _if_ the config has clone-prefix set or the
repository has clone_url set. In case the clone-prefix contains multiple
enties then only the first one will be considered.
The intention is to present the git:// link for a given repo early to the user.
Signed-off-by: Sebastian Andrzej Siewior <sebastian at breakpoint.cc>
---
ui-repolist.c | 1 +
ui-shared.c | 35 +++++++++++++++++++++++++++++++++++
ui-shared.h | 1 +
3 files changed, 37 insertions(+)
diff --git a/ui-repolist.c b/ui-repolist.c
index 477a949..b6d56ed 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -323,6 +323,7 @@ void cgit_print_repolist()
cgit_log_link("log", NULL, "button", NULL, NULL, NULL,
0, NULL, NULL, ctx.qry.showmsg);
cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
+ cgit_git_link();
html("</td>");
}
html("</tr>\n");
diff --git a/ui-shared.c b/ui-shared.c
index 1ede2b0..5f80de9 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -284,6 +284,41 @@ void cgit_tree_link(const char *name, const char *title, const char *class,
reporevlink("tree", name, title, class, head, rev, path);
}
+void cgit_git_link(void)
+{
+ char *url = NULL;
+
+ if (ctx.repo->clone_url)
+ url = strdup(ctx.repo->clone_url);
+ else if (ctx.cfg.clone_prefix) {
+ char *second;
+ char *p;
+ int len;
+
+ p = ctx.cfg.clone_prefix;
+ while (*p == ' ')
+ p++;
+ second = strchr(p, ' ');
+ if (second)
+ *second = '\0';
+ len = snprintf(NULL, 0, "%s/%s", p, ctx.repo->url);
+ if (len < 0)
+ return;
+ len++;
+ url = xmalloc(len);
+ snprintf(url, len, "%s/%s", p, ctx.repo->url);
+ if (second)
+ *second = ' ';
+ }
+ if (!url)
+ return;
+ html("<a class='button'");
+ html(" href='");
+ html_url_path(url);
+ html("'>git</a>");
+ free(url);
+}
+
void cgit_plain_link(const char *name, const char *title, const char *class,
const char *head, const char *rev, const char *path)
{
diff --git a/ui-shared.h b/ui-shared.h
index 3e7a91b..2d5d9cd 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -21,6 +21,7 @@ extern void cgit_tag_link(const char *name, const char *title,
extern void cgit_tree_link(const char *name, const char *title,
const char *class, const char *head,
const char *rev, const char *path);
+extern void cgit_git_link(void);
extern void cgit_plain_link(const char *name, const char *title,
const char *class, const char *head,
const char *rev, const char *path);
--
1.8.5.2
More information about the CGit
mailing list