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