From fa871b31f6c3309d3c3d0b4bebcd5b5b62706f0a Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 29 Aug 2026 15:50:14 -1000 Subject: Point clone rows at a url a browser can follow --- source/ui-empty.c | 8 +------ source/ui-shared.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ source/ui-shared.h | 1 + source/ui-summary.c | 8 +------ 4 files changed, 72 insertions(+), 14 deletions(-) (limited to 'source') diff --git a/source/ui-empty.c b/source/ui-empty.c index a65f49b..dd8dc64 100644 --- a/source/ui-empty.c +++ b/source/ui-empty.c @@ -13,13 +13,7 @@ static void print_clone_url(const char *url) { - html(""); - html_txt(url); - html("\n"); + cgit_print_clone_row(url, 0); } /* diff --git a/source/ui-shared.c b/source/ui-shared.c index 85712bf..5cf9428 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -317,8 +317,26 @@ static void print_rel_date(time_t t, int tz, double count, const char *class, htmlf("'>%.0f %s", count, suffix); } +/* + * Whether a clone url opens with a URI scheme. The scp form git@host:path + * has none, and a link element's href must hold a URI, so that form stays + * out of the document head. + */ +static int has_uri_scheme(const char *url) +{ + const char *p = url; + + if (!isalpha((unsigned char)*p)) + return 0; + while (isalnum((unsigned char)*p) || *p == '+' || *p == '-' || *p == '.') + p++; + return *p == ':'; +} + static void print_rel_vcs_link(const char *url) { + if (!has_uri_scheme(url)) + return; html("url); + } + + if (colspan) + htmlf("", colspan); + else + html(""); + html(""); + html_txt(url); + html("\n"); + free(fallback); +} + void cgit_add_hidden_formfields(int incl_head, int incl_search, const char *page) { diff --git a/source/ui-shared.h b/source/ui-shared.h index c266951..c421178 100644 --- a/source/ui-shared.h +++ b/source/ui-shared.h @@ -24,6 +24,7 @@ extern char *cgit_currenturl(void); extern char *cgit_currentfullurl(void); extern const char *cgit_loginurl(void); extern char *cgit_repourl(const char *reponame); +extern void cgit_print_clone_row(const char *url, int colspan); extern char *cgit_fileurl(const char *reponame, const char *pagename, const char *filename, const char *query); extern char *cgit_pageurl(const char *reponame, const char *pagename, diff --git a/source/ui-summary.c b/source/ui-summary.c index 3658bc5..dacf0f7 100644 --- a/source/ui-summary.c +++ b/source/ui-summary.c @@ -48,13 +48,7 @@ static void print_clone_url(const char *url) htmlf("Clone\n", columns); } - htmlf(""); - html_txt(url); - html("\n"); + cgit_print_clone_row(url, columns); } /* -- cgit v2.8.0