summaryrefslogtreecommitdiffabout
path: root/ui-summary.c
Unidiff
Diffstat (limited to 'ui-summary.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-summary.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/ui-summary.c b/ui-summary.c
index a2c018e..02f191e 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -1,92 +1,110 @@
1/* ui-summary.c: functions for generating repo summary page 1/* ui-summary.c: functions for generating repo summary page
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com>
4 * 5 *
5 * Licensed under GNU General Public License v2 6 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 7 * (see COPYING for full license text)
7 */ 8 */
8 9
9#include "cgit.h" 10#include "cgit.h"
10#include "html.h" 11#include "html.h"
11#include "ui-log.h" 12#include "ui-log.h"
12#include "ui-refs.h" 13#include "ui-refs.h"
14#include "ui-blob.h"
13 15
14int urls = 0; 16int urls = 0;
15 17
16static void print_url(char *base, char *suffix) 18static void print_url(char *base, char *suffix)
17{ 19{
18 if (!base || !*base) 20 if (!base || !*base)
19 return; 21 return;
20 if (urls++ == 0) { 22 if (urls++ == 0) {
21 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 23 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
22 html("<tr><th class='left' colspan='4'>Clone</th></tr>\n"); 24 html("<tr><th class='left' colspan='4'>Clone</th></tr>\n");
23 } 25 }
24 if (suffix && *suffix) 26 if (suffix && *suffix)
25 base = fmt("%s/%s", base, suffix); 27 base = fmt("%s/%s", base, suffix);
26 html("<tr><td colspan='4'><a href='"); 28 html("<tr><td colspan='4'><a href='");
27 html_url_path(base); 29 html_url_path(base);
28 html("'>"); 30 html("'>");
29 html_txt(base); 31 html_txt(base);
30 html("</a></td></tr>\n"); 32 html("</a></td></tr>\n");
31} 33}
32 34
33static void print_urls(char *txt, char *suffix) 35static void print_urls(char *txt, char *suffix)
34{ 36{
35 char *h = txt, *t, c; 37 char *h = txt, *t, c;
36 38
37 while (h && *h) { 39 while (h && *h) {
38 while (h && *h == ' ') 40 while (h && *h == ' ')
39 h++; 41 h++;
40 t = h; 42 t = h;
41 while (t && *t && *t != ' ') 43 while (t && *t && *t != ' ')
42 t++; 44 t++;
43 c = *t; 45 c = *t;
44 *t = 0; 46 *t = 0;
45 print_url(h, suffix); 47 print_url(h, suffix);
46 *t = c; 48 *t = c;
47 h = t; 49 h = t;
48 } 50 }
49} 51}
50 52
51void cgit_print_summary() 53void cgit_print_summary()
52{ 54{
53 html("<table summary='repository info' class='list nowrap'>"); 55 html("<table summary='repository info' class='list nowrap'>");
54 cgit_print_branches(ctx.cfg.summary_branches); 56 cgit_print_branches(ctx.cfg.summary_branches);
55 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 57 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
56 cgit_print_tags(ctx.cfg.summary_tags); 58 cgit_print_tags(ctx.cfg.summary_tags);
57 if (ctx.cfg.summary_log > 0) { 59 if (ctx.cfg.summary_log > 0) {
58 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 60 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
59 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, 61 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL,
60 NULL, NULL, 0); 62 NULL, NULL, 0);
61 } 63 }
62 if (ctx.repo->clone_url) 64 if (ctx.repo->clone_url)
63 print_urls(ctx.repo->clone_url, NULL); 65 print_urls(ctx.repo->clone_url, NULL);
64 else if (ctx.cfg.clone_prefix) 66 else if (ctx.cfg.clone_prefix)
65 print_urls(ctx.cfg.clone_prefix, ctx.repo->url); 67 print_urls(ctx.cfg.clone_prefix, ctx.repo->url);
66 html("</table>"); 68 html("</table>");
67} 69}
68 70
69void cgit_print_repo_readme(char *path) 71void cgit_print_repo_readme(char *path)
70{ 72{
71 char *slash, *tmp; 73 char *slash, *tmp, *colon, *ref = 0;
72 74
73 if (!ctx.repo->readme) 75 if (!ctx.repo->readme)
74 return; 76 return;
75 77
76 if (path) { 78 if (path) {
77 slash = strrchr(ctx.repo->readme, '/'); 79 slash = strrchr(ctx.repo->readme, '/');
78 if (!slash) 80 if (!slash) {
79 return; 81 slash = strchr(ctx.repo->readme, ':');
82 if (!slash)
83 return;
84 }
80 tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1); 85 tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1);
81 strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1); 86 strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1);
82 strcpy(tmp + (slash - ctx.repo->readme + 1), path); 87 strcpy(tmp + (slash - ctx.repo->readme + 1), path);
83 } else 88 } else
84 tmp = ctx.repo->readme; 89 tmp = ctx.repo->readme;
90 colon = strchr(tmp, ':');
91 if (colon && strlen(colon) > 1) {
92 *colon = '\0';
93 ref = tmp;
94 tmp = colon + 1;
95 while ((*tmp == '/' || *tmp == ':') && *tmp != '\0')
96 ++tmp;
97 if (!(*tmp))
98 return;
99 }
85 html("<div id='summary'>"); 100 html("<div id='summary'>");
86 if (ctx.repo->about_filter) 101 if (ctx.repo->about_filter)
87 cgit_open_filter(ctx.repo->about_filter); 102 cgit_open_filter(ctx.repo->about_filter);
88 html_include(tmp); 103 if (ref)
104 cgit_print_file(tmp, ref);
105 else
106 html_include(tmp);
89 if (ctx.repo->about_filter) 107 if (ctx.repo->about_filter)
90 cgit_close_filter(ctx.repo->about_filter); 108 cgit_close_filter(ctx.repo->about_filter);
91 html("</div>"); 109 html("</div>");
92} 110}