blob: 38639cef31157c5b764a09321e7855aa2bfc8f9a [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{
Lukas Fleischeref8a97d2013-03-05 15:42:14 +010020 int columns = 3;
21
22 if (ctx.repo->enable_log_filecount)
23 columns++;
24 if (ctx.repo->enable_log_linecount)
25 columns++;
26
Lars Hjemli78af25c2008-07-27 11:54:06 +020027 if (!base || !*base)
28 return;
29 if (urls++ == 0) {
Lukas Fleischeref8a97d2013-03-05 15:42:14 +010030 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
31 htmlf("<tr><th class='left' colspan='%d'>Clone</th></tr>\n", columns);
Lars Hjemli78af25c2008-07-27 11:54:06 +020032 }
33 if (suffix && *suffix)
34 base = fmt("%s/%s", base, suffix);
Lukas Fleischeref8a97d2013-03-05 15:42:14 +010035 htmlf("<tr><td colspan='%d'><a href='", columns);
Lars Hjemli0071aa82008-10-05 21:21:42 +020036 html_url_path(base);
Lars Hjemli78af25c2008-07-27 11:54:06 +020037 html("'>");
38 html_txt(base);
39 html("</a></td></tr>\n");
40}
41
42static void print_urls(char *txt, char *suffix)
43{
44 char *h = txt, *t, c;
45
46 while (h && *h) {
47 while (h && *h == ' ')
48 h++;
49 t = h;
50 while (t && *t && *t != ' ')
51 t++;
52 c = *t;
53 *t = 0;
54 print_url(h, suffix);
55 *t = c;
56 h = t;
57 }
58}
59
Lars Hjemlid14c5f62006-12-11 17:04:19 +010060void cgit_print_summary()
Lars Hjemli14180342006-12-11 16:55:07 +010061{
Lukas Fleischeref8a97d2013-03-05 15:42:14 +010062 int columns = 3;
63
64 if (ctx.repo->enable_log_filecount)
65 columns++;
66 if (ctx.repo->enable_log_linecount)
67 columns++;
68
Lars Hjemli29154832007-11-11 13:04:28 +010069 html("<table summary='repository info' class='list nowrap'>");
Lars Hjemlib228d4f2008-02-16 13:07:13 +010070 cgit_print_branches(ctx.cfg.summary_branches);
Lukas Fleischeref8a97d2013-03-05 15:42:14 +010071 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
Lars Hjemlib228d4f2008-02-16 13:07:13 +010072 cgit_print_tags(ctx.cfg.summary_tags);
Lars Hjemli5764fe92008-04-14 22:13:38 +020073 if (ctx.cfg.summary_log > 0) {
Lukas Fleischeref8a97d2013-03-05 15:42:14 +010074 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
Lars Hjemli5764fe92008-04-14 22:13:38 +020075 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL,
Tobias Bieniek792f8132012-10-13 16:10:30 +020076 NULL, NULL, 0, 0, 0);
Lars Hjemli5764fe92008-04-14 22:13:38 +020077 }
Lars Hjemli78af25c2008-07-27 11:54:06 +020078 if (ctx.repo->clone_url)
Lars Hjemlia1429db2011-06-06 20:49:13 +000079 print_urls(expand_macros(ctx.repo->clone_url), NULL);
Lars Hjemli78af25c2008-07-27 11:54:06 +020080 else if (ctx.cfg.clone_prefix)
81 print_urls(ctx.cfg.clone_prefix, ctx.repo->url);
Lars Hjemli23734c52007-01-17 01:10:39 +010082 html("</table>");
Lars Hjemli14180342006-12-11 16:55:07 +010083}
Lars Hjemli90f64ad2008-04-28 23:06:57 +020084
Lars Hjemlie1782ff2009-08-09 11:50:34 +020085void cgit_print_repo_readme(char *path)
Lars Hjemli90f64ad2008-04-28 23:06:57 +020086{
Lars Hjemli515edb02010-08-21 15:08:01 +020087 char *slash, *tmp, *colon, *ref;
Lars Hjemlie1782ff2009-08-09 11:50:34 +020088
Lars Hjemli515edb02010-08-21 15:08:01 +020089 if (!ctx.repo->readme || !(*ctx.repo->readme))
Lars Hjemlie1782ff2009-08-09 11:50:34 +020090 return;
91
Lars Hjemli515edb02010-08-21 15:08:01 +020092 ref = NULL;
93
94 /* Check if the readme is tracked in the git repo. */
95 colon = strchr(ctx.repo->readme, ':');
96 if (colon && strlen(colon) > 1) {
97 *colon = '\0';
98 ref = ctx.repo->readme;
99 ctx.repo->readme = colon + 1;
100 if (!(*ctx.repo->readme))
101 return;
102 }
103
104 /* Prepend repo path to relative readme path unless tracked. */
105 if (!ref && *ctx.repo->readme != '/')
106 ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path,
107 ctx.repo->readme));
108
109 /* If a subpath is specified for the about page, make it relative
110 * to the directory containing the configured readme.
111 */
Lars Hjemlie1782ff2009-08-09 11:50:34 +0200112 if (path) {
113 slash = strrchr(ctx.repo->readme, '/');
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +0200114 if (!slash) {
Lars Hjemli515edb02010-08-21 15:08:01 +0200115 if (!colon)
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +0200116 return;
Lars Hjemli515edb02010-08-21 15:08:01 +0200117 slash = colon;
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +0200118 }
Lars Hjemlie1782ff2009-08-09 11:50:34 +0200119 tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1);
120 strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1);
121 strcpy(tmp + (slash - ctx.repo->readme + 1), path);
122 } else
123 tmp = ctx.repo->readme;
Lars Hjemli515edb02010-08-21 15:08:01 +0200124
125 /* Print the calculated readme, either from the git repo or from the
126 * filesystem, while applying the about-filter.
127 */
Lars Hjemlie1782ff2009-08-09 11:50:34 +0200128 html("<div id='summary'>");
Lars Hjemli537c05f2009-08-09 13:27:21 +0200129 if (ctx.repo->about_filter)
Lars Hjemli3ec6b302011-06-06 19:29:58 +0000130 cgit_open_filter(ctx.repo->about_filter);
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +0200131 if (ref)
132 cgit_print_file(tmp, ref);
133 else
134 html_include(tmp);
Lars Hjemli537c05f2009-08-09 13:27:21 +0200135 if (ctx.repo->about_filter)
136 cgit_close_filter(ctx.repo->about_filter);
Lars Hjemlie1782ff2009-08-09 11:50:34 +0200137 html("</div>");
Lars Hjemli90f64ad2008-04-28 23:06:57 +0200138}