blob: 02f191ea41065a0af04c2ca7d5154536d7abeba4 [file] [log] [blame]
Lars Hjemli14180342006-12-11 16:55:07 +01001/* ui-summary.c: functions for generating repo summary page
2 *
3 * Copyright (C) 2006 Lars Hjemli
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +02004 * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com>
Lars Hjemli14180342006-12-11 16:55:07 +01005 *
6 * Licensed under GNU General Public License v2
7 * (see COPYING for full license text)
8 */
9
10#include "cgit.h"
Lars Hjemlib1f9b9c2008-02-23 22:45:33 +010011#include "html.h"
Lars Hjemlic5984a92008-03-24 16:38:47 +010012#include "ui-log.h"
13#include "ui-refs.h"
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +020014#include "ui-blob.h"
Lars Hjemli14180342006-12-11 16:55:07 +010015
Lars Hjemli78af25c2008-07-27 11:54:06 +020016int urls = 0;
17
18static void print_url(char *base, char *suffix)
19{
20 if (!base || !*base)
21 return;
22 if (urls++ == 0) {
23 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
24 html("<tr><th class='left' colspan='4'>Clone</th></tr>\n");
25 }
26 if (suffix && *suffix)
27 base = fmt("%s/%s", base, suffix);
28 html("<tr><td colspan='4'><a href='");
Lars Hjemli0071aa82008-10-05 21:21:42 +020029 html_url_path(base);
Lars Hjemli78af25c2008-07-27 11:54:06 +020030 html("'>");
31 html_txt(base);
32 html("</a></td></tr>\n");
33}
34
35static void print_urls(char *txt, char *suffix)
36{
37 char *h = txt, *t, c;
38
39 while (h && *h) {
40 while (h && *h == ' ')
41 h++;
42 t = h;
43 while (t && *t && *t != ' ')
44 t++;
45 c = *t;
46 *t = 0;
47 print_url(h, suffix);
48 *t = c;
49 h = t;
50 }
51}
52
Lars Hjemlid14c5f62006-12-11 17:04:19 +010053void cgit_print_summary()
Lars Hjemli14180342006-12-11 16:55:07 +010054{
Lars Hjemli29154832007-11-11 13:04:28 +010055 html("<table summary='repository info' class='list nowrap'>");
Lars Hjemlib228d4f2008-02-16 13:07:13 +010056 cgit_print_branches(ctx.cfg.summary_branches);
Lars Hjemli23734c52007-01-17 01:10:39 +010057 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
Lars Hjemlib228d4f2008-02-16 13:07:13 +010058 cgit_print_tags(ctx.cfg.summary_tags);
Lars Hjemli5764fe92008-04-14 22:13:38 +020059 if (ctx.cfg.summary_log > 0) {
60 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
61 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL,
62 NULL, NULL, 0);
63 }
Lars Hjemli78af25c2008-07-27 11:54:06 +020064 if (ctx.repo->clone_url)
65 print_urls(ctx.repo->clone_url, NULL);
66 else if (ctx.cfg.clone_prefix)
67 print_urls(ctx.cfg.clone_prefix, ctx.repo->url);
Lars Hjemli23734c52007-01-17 01:10:39 +010068 html("</table>");
Lars Hjemli14180342006-12-11 16:55:07 +010069}
Lars Hjemli90f64ad2008-04-28 23:06:57 +020070
Lars Hjemlie1782ff2009-08-09 11:50:34 +020071void cgit_print_repo_readme(char *path)
Lars Hjemli90f64ad2008-04-28 23:06:57 +020072{
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +020073 char *slash, *tmp, *colon, *ref = 0;
Lars Hjemlie1782ff2009-08-09 11:50:34 +020074
75 if (!ctx.repo->readme)
76 return;
77
78 if (path) {
79 slash = strrchr(ctx.repo->readme, '/');
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +020080 if (!slash) {
81 slash = strchr(ctx.repo->readme, ':');
82 if (!slash)
83 return;
84 }
Lars Hjemlie1782ff2009-08-09 11:50:34 +020085 tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1);
86 strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1);
87 strcpy(tmp + (slash - ctx.repo->readme + 1), path);
88 } else
89 tmp = ctx.repo->readme;
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +020090 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 }
Lars Hjemlie1782ff2009-08-09 11:50:34 +0200100 html("<div id='summary'>");
Lars Hjemli537c05f2009-08-09 13:27:21 +0200101 if (ctx.repo->about_filter)
102 cgit_open_filter(ctx.repo->about_filter);
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +0200103 if (ref)
104 cgit_print_file(tmp, ref);
105 else
106 html_include(tmp);
Lars Hjemli537c05f2009-08-09 13:27:21 +0200107 if (ctx.repo->about_filter)
108 cgit_close_filter(ctx.repo->about_filter);
Lars Hjemlie1782ff2009-08-09 11:50:34 +0200109 html("</div>");
Lars Hjemli90f64ad2008-04-28 23:06:57 +0200110}