]> git.cameronkatri.com Git - cgit.git/blob - ui-summary.c
Remove redundant calls to fmt("%s", ...)
[cgit.git] / ui-summary.c
1 /* ui-summary.c: functions for generating repo summary page
2 *
3 * Copyright (C) 2006 Lars Hjemli
4 * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com>
5 *
6 * Licensed under GNU General Public License v2
7 * (see COPYING for full license text)
8 */
9
10 #include "cgit.h"
11 #include "ui-summary.h"
12 #include "html.h"
13 #include "ui-log.h"
14 #include "ui-refs.h"
15 #include "ui-blob.h"
16
17 static void print_url(char *base, char *suffix)
18 {
19 int columns = 3;
20
21 if (ctx.repo->enable_log_filecount)
22 columns++;
23 if (ctx.repo->enable_log_linecount)
24 columns++;
25
26 if (!base || !*base)
27 return;
28 if (suffix && *suffix)
29 base = fmt("%s/%s", base, suffix);
30 htmlf("<tr><td colspan='%d'><a href='", columns);
31 html_url_path(base);
32 html("'>");
33 html_txt(base);
34 html("</a></td></tr>\n");
35 }
36
37 static void print_urls(char *txt, char *suffix)
38 {
39 char *h = txt, *t, c;
40 int urls = 0;
41 int columns = 3;
42
43 if (ctx.repo->enable_log_filecount)
44 columns++;
45 if (ctx.repo->enable_log_linecount)
46 columns++;
47
48
49 while (h && *h) {
50 while (h && *h == ' ')
51 h++;
52 if (!*h)
53 break;
54 t = h;
55 while (t && *t && *t != ' ')
56 t++;
57 c = *t;
58 *t = 0;
59 if (urls++ == 0) {
60 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
61 htmlf("<tr><th class='left' colspan='%d'>Clone</th></tr>\n", columns);
62 }
63 print_url(h, suffix);
64 *t = c;
65 h = t;
66 }
67 }
68
69 void cgit_print_summary()
70 {
71 int columns = 3;
72
73 if (ctx.repo->enable_log_filecount)
74 columns++;
75 if (ctx.repo->enable_log_linecount)
76 columns++;
77
78 html("<table summary='repository info' class='list nowrap'>");
79 cgit_print_branches(ctx.cfg.summary_branches);
80 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
81 cgit_print_tags(ctx.cfg.summary_tags);
82 if (ctx.cfg.summary_log > 0) {
83 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
84 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL,
85 NULL, NULL, 0, 0, 0);
86 }
87 if (ctx.repo->clone_url)
88 print_urls(expand_macros(ctx.repo->clone_url), NULL);
89 else if (ctx.cfg.clone_prefix)
90 print_urls(ctx.cfg.clone_prefix, ctx.repo->url);
91 html("</table>");
92 }
93
94 void cgit_print_repo_readme(char *path)
95 {
96 char *slash, *tmp, *colon, *ref;
97
98 if (!ctx.repo->readme || !(*ctx.repo->readme))
99 return;
100
101 ref = NULL;
102
103 /* Check if the readme is tracked in the git repo. */
104 colon = strchr(ctx.repo->readme, ':');
105 if (colon && strlen(colon) > 1) {
106 *colon = '\0';
107 ref = ctx.repo->readme;
108 ctx.repo->readme = colon + 1;
109 if (!(*ctx.repo->readme))
110 return;
111 }
112
113 /* Prepend repo path to relative readme path unless tracked. */
114 if (!ref && *ctx.repo->readme != '/')
115 ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path,
116 ctx.repo->readme));
117
118 /* If a subpath is specified for the about page, make it relative
119 * to the directory containing the configured readme.
120 */
121 if (path) {
122 slash = strrchr(ctx.repo->readme, '/');
123 if (!slash) {
124 if (!colon)
125 return;
126 slash = colon;
127 }
128 tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1);
129 strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1);
130 strcpy(tmp + (slash - ctx.repo->readme + 1), path);
131 } else
132 tmp = ctx.repo->readme;
133
134 /* Print the calculated readme, either from the git repo or from the
135 * filesystem, while applying the about-filter.
136 */
137 html("<div id='summary'>");
138 if (ctx.repo->about_filter)
139 cgit_open_filter(ctx.repo->about_filter);
140 if (ref)
141 cgit_print_file(tmp, ref);
142 else
143 html_include(tmp);
144 if (ctx.repo->about_filter)
145 cgit_close_filter(ctx.repo->about_filter);
146 html("</div>");
147 }