aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Keeping2014-08-01 22:14:17 +0100
committerJason A. Donenfeld2014-12-23 19:04:04 -0700
commitbbfa006e6eb93d56842c1d90bbba1c5484afb855 (patch)
treeb1dbf7beb06c1deae73d10998cc5cad87d736f22
parent485b09925cd54f3f55257619fa5796d274e96050 (diff)
downloadcgit-bbfa006e6eb93d56842c1d90bbba1c5484afb855.tar.gz
cgit-bbfa006e6eb93d56842c1d90bbba1c5484afb855.tar.bz2
cgit-bbfa006e6eb93d56842c1d90bbba1c5484afb855.zip
Extract clone URL printing to ui-shared.c
This will allow us to reuse the same logic to add clone URL <link/> elements to the header of all repo-specific pages in order to support the rel-vcs microformat. Signed-off-by: John Keeping <john@keeping.me.uk>
-rw-r--r--ui-shared.c37
-rw-r--r--ui-shared.h2
-rw-r--r--ui-summary.c58
3 files changed, 51 insertions, 46 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 6243d1b..4e317d0 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -727,6 +727,43 @@ void cgit_print_docend()
727 html("</body>\n</html>\n"); 727 html("</body>\n</html>\n");
728} 728}
729 729
730static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix)
731{
732 struct strbuf buf = STRBUF_INIT;
733 char *h = txt, *t, c;
734
735 while (h && *h) {
736 while (h && *h == ' ')
737 h++;
738 if (!*h)
739 break;
740 t = h;
741 while (t && *t && *t != ' ')
742 t++;
743 c = *t;
744 *t = 0;
745
746 if (suffix && *suffix) {
747 strbuf_reset(&buf);
748 strbuf_addf(&buf, "%s/%s", h, suffix);
749 h = buf.buf;
750 }
751 fn(h);
752 *t = c;
753 h = t;
754 }
755
756 strbuf_release(&buf);
757}
758
759void cgit_add_clone_urls(void (*fn)(const char *))
760{
761 if (ctx.repo->clone_url)
762 add_clone_urls(fn, expand_macros(ctx.repo->clone_url), NULL);
763 else if (ctx.cfg.clone_prefix)
764 add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url);
765}
766
730static int print_branch_option(const char *refname, const unsigned char *sha1, 767static int print_branch_option(const char *refname, const unsigned char *sha1,
731 int flags, void *cb_data) 768 int flags, void *cb_data)
732{ 769{
diff --git a/ui-shared.h b/ui-shared.h
index fc9be3b..f8cf220 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -11,6 +11,8 @@ extern char *cgit_fileurl(const char *reponame, const char *pagename,
11extern char *cgit_pageurl(const char *reponame, const char *pagename, 11extern char *cgit_pageurl(const char *reponame, const char *pagename,
12 const char *query); 12 const char *query);
13 13
14extern void cgit_add_clone_urls(void (*fn)(const char *));
15
14extern void cgit_index_link(const char *name, const char *title, 16extern void cgit_index_link(const char *name, const char *title,
15 const char *class, const char *pattern, const char *sort, int ofs); 17 const char *class, const char *pattern, const char *sort, int ofs);
16extern void cgit_summary_link(const char *name, const char *title, 18extern void cgit_summary_link(const char *name, const char *title,
diff --git a/ui-summary.c b/ui-summary.c
index 3728c3e..70ea908 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -12,62 +12,30 @@
12#include "ui-log.h" 12#include "ui-log.h"
13#include "ui-refs.h" 13#include "ui-refs.h"
14#include "ui-blob.h" 14#include "ui-blob.h"
15#include "ui-shared.h"
15#include <libgen.h> 16#include <libgen.h>
16 17
17static void print_url(char *base, char *suffix) 18static int urls;
19
20static void print_url(const char *url)
18{ 21{
19 int columns = 3; 22 int columns = 3;
20 struct strbuf basebuf = STRBUF_INIT;
21 23
22 if (ctx.repo->enable_log_filecount) 24 if (ctx.repo->enable_log_filecount)
23 columns++; 25 columns++;
24 if (ctx.repo->enable_log_linecount) 26 if (ctx.repo->enable_log_linecount)
25 columns++; 27 columns++;
26 28
27 if (!base || !*base) 29 if (urls++ == 0) {
28 return; 30 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
29 if (suffix && *suffix) { 31 htmlf("<tr><th class='left' colspan='%d'>Clone</th></tr>\n", columns);
30 strbuf_addf(&basebuf, "%s/%s", base, suffix);
31 base = basebuf.buf;
32 } 32 }
33
33 htmlf("<tr><td colspan='%d'><a href='", columns); 34 htmlf("<tr><td colspan='%d'><a href='", columns);
34 html_url_path(base); 35 html_url_path(url);
35 html("'>"); 36 html("'>");
36 html_txt(base); 37 html_txt(url);
37 html("</a></td></tr>\n"); 38 html("</a></td></tr>\n");
38 strbuf_release(&basebuf);
39}
40
41static void print_urls(char *txt, char *suffix)
42{
43 char *h = txt, *t, c;
44 int urls = 0;
45 int columns = 3;
46
47 if (ctx.repo->enable_log_filecount)
48 columns++;
49 if (ctx.repo->enable_log_linecount)
50 columns++;
51
52
53 while (h && *h) {
54 while (h && *h == ' ')
55 h++;
56 if (!*h)
57 break;
58 t = h;
59 while (t && *t && *t != ' ')
60 t++;
61 c = *t;
62 *t = 0;
63 if (urls++ == 0) {
64 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
65 htmlf("<tr><th class='left' colspan='%d'>Clone</th></tr>\n", columns);
66 }
67 print_url(h, suffix);
68 *t = c;
69 h = t;
70 }
71} 39}
72 40
73void cgit_print_summary() 41void cgit_print_summary()
@@ -88,10 +56,8 @@ void cgit_print_summary()
88 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, 56 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL,
89 NULL, NULL, 0, 0, 0); 57 NULL, NULL, 0, 0, 0);
90 } 58 }
91 if (ctx.repo->clone_url) 59 urls = 0;
92 print_urls(expand_macros(ctx.repo->clone_url), NULL); 60 cgit_add_clone_urls(print_url);
93 else if (ctx.cfg.clone_prefix)
94 print_urls(ctx.cfg.clone_prefix, ctx.repo->url);
95 html("</table>"); 61 html("</table>");
96} 62}
97 63