History

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.

John Keeping committed 12 years ago

Commit bbfa0061 parent 485b0993 files · +51 −46Browse files

Unified · Split

3 files
  1. ui-shared.c +37 −0
  2. ui-shared.h +2 −0
  3. ui-summary.c +12 −46
ui-shared.c+37−0
@@ -727,6 +727,43 @@ void cgit_print_docend() · 726 unmodified lines
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{
ui-shared.h+2−0
@@ -11,6 +11,8 @@ extern char *cgit_fileurl(const char *reponame, const char *pagename, · 10 unmodified lines
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,
ui-summary.c+12−46
@@ -12,62 +12,30 @@ · 11 unmodified lines
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() · 14 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t