blob: bd123ef4b81c78dd265fc0116f1ba8e00871b044 [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"
John Keeping8f208792013-04-06 11:37:59 +010011#include "ui-summary.h"
Lars Hjemlib1f9b9c2008-02-23 22:45:33 +010012#include "html.h"
Lars Hjemlic5984a92008-03-24 16:38:47 +010013#include "ui-log.h"
14#include "ui-refs.h"
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +020015#include "ui-blob.h"
Lars Hjemli14180342006-12-11 16:55:07 +010016
Lars Hjemli78af25c2008-07-27 11:54:06 +020017static void print_url(char *base, char *suffix)
18{
Lukas Fleischeref8a97d2013-03-05 15:42:14 +010019 int columns = 3;
20
21 if (ctx.repo->enable_log_filecount)
22 columns++;
23 if (ctx.repo->enable_log_linecount)
24 columns++;
25
Lars Hjemli78af25c2008-07-27 11:54:06 +020026 if (!base || !*base)
27 return;
Lars Hjemli78af25c2008-07-27 11:54:06 +020028 if (suffix && *suffix)
29 base = fmt("%s/%s", base, suffix);
Lukas Fleischeref8a97d2013-03-05 15:42:14 +010030 htmlf("<tr><td colspan='%d'><a href='", columns);
Lars Hjemli0071aa82008-10-05 21:21:42 +020031 html_url_path(base);
Lars Hjemli78af25c2008-07-27 11:54:06 +020032 html("'>");
33 html_txt(base);
34 html("</a></td></tr>\n");
35}
36
37static void print_urls(char *txt, char *suffix)
38{
39 char *h = txt, *t, c;
Lukas Fleischer977a3ad2013-03-05 16:48:27 +010040 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
Lars Hjemli78af25c2008-07-27 11:54:06 +020048
49 while (h && *h) {
50 while (h && *h == ' ')
51 h++;
Lukas Fleischer977a3ad2013-03-05 16:48:27 +010052 if (!*h)
53 break;
Lars Hjemli78af25c2008-07-27 11:54:06 +020054 t = h;
55 while (t && *t && *t != ' ')
56 t++;
57 c = *t;
58 *t = 0;
Lukas Fleischer977a3ad2013-03-05 16:48:27 +010059 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 }
Lars Hjemli78af25c2008-07-27 11:54:06 +020063 print_url(h, suffix);
64 *t = c;
65 h = t;
66 }
67}
68
Lars Hjemlid14c5f62006-12-11 17:04:19 +010069void cgit_print_summary()
Lars Hjemli14180342006-12-11 16:55:07 +010070{
Lukas Fleischeref8a97d2013-03-05 15:42:14 +010071 int columns = 3;
72
73 if (ctx.repo->enable_log_filecount)
74 columns++;
75 if (ctx.repo->enable_log_linecount)
76 columns++;
77
Lars Hjemli29154832007-11-11 13:04:28 +010078 html("<table summary='repository info' class='list nowrap'>");
Lars Hjemlib228d4f2008-02-16 13:07:13 +010079 cgit_print_branches(ctx.cfg.summary_branches);
Lukas Fleischeref8a97d2013-03-05 15:42:14 +010080 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
Lars Hjemlib228d4f2008-02-16 13:07:13 +010081 cgit_print_tags(ctx.cfg.summary_tags);
Lars Hjemli5764fe92008-04-14 22:13:38 +020082 if (ctx.cfg.summary_log > 0) {
Lukas Fleischeref8a97d2013-03-05 15:42:14 +010083 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
Lars Hjemli5764fe92008-04-14 22:13:38 +020084 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL,
Tobias Bieniek792f8132012-10-13 16:10:30 +020085 NULL, NULL, 0, 0, 0);
Lars Hjemli5764fe92008-04-14 22:13:38 +020086 }
Lars Hjemli78af25c2008-07-27 11:54:06 +020087 if (ctx.repo->clone_url)
Lars Hjemlia1429db2011-06-06 20:49:13 +000088 print_urls(expand_macros(ctx.repo->clone_url), NULL);
Lars Hjemli78af25c2008-07-27 11:54:06 +020089 else if (ctx.cfg.clone_prefix)
90 print_urls(ctx.cfg.clone_prefix, ctx.repo->url);
Lars Hjemli23734c52007-01-17 01:10:39 +010091 html("</table>");
Lars Hjemli14180342006-12-11 16:55:07 +010092}
Lars Hjemli90f64ad2008-04-28 23:06:57 +020093
Lars Hjemlie1782ff2009-08-09 11:50:34 +020094void cgit_print_repo_readme(char *path)
Lars Hjemli90f64ad2008-04-28 23:06:57 +020095{
Lars Hjemli515edb02010-08-21 15:08:01 +020096 char *slash, *tmp, *colon, *ref;
Lars Hjemlie1782ff2009-08-09 11:50:34 +020097
Lars Hjemli515edb02010-08-21 15:08:01 +020098 if (!ctx.repo->readme || !(*ctx.repo->readme))
Lars Hjemlie1782ff2009-08-09 11:50:34 +020099 return;
100
Lars Hjemli515edb02010-08-21 15:08:01 +0200101 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 */
Lars Hjemlie1782ff2009-08-09 11:50:34 +0200121 if (path) {
122 slash = strrchr(ctx.repo->readme, '/');
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +0200123 if (!slash) {
Lars Hjemli515edb02010-08-21 15:08:01 +0200124 if (!colon)
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +0200125 return;
Lars Hjemli515edb02010-08-21 15:08:01 +0200126 slash = colon;
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +0200127 }
Lars Hjemlie1782ff2009-08-09 11:50:34 +0200128 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;
Lars Hjemli515edb02010-08-21 15:08:01 +0200133
134 /* Print the calculated readme, either from the git repo or from the
135 * filesystem, while applying the about-filter.
136 */
Lars Hjemlie1782ff2009-08-09 11:50:34 +0200137 html("<div id='summary'>");
Lars Hjemli537c05f2009-08-09 13:27:21 +0200138 if (ctx.repo->about_filter)
Lars Hjemli3ec6b302011-06-06 19:29:58 +0000139 cgit_open_filter(ctx.repo->about_filter);
Jason A. Donenfeld379e80e2010-08-04 00:45:42 +0200140 if (ref)
141 cgit_print_file(tmp, ref);
142 else
143 html_include(tmp);
Lars Hjemli537c05f2009-08-09 13:27:21 +0200144 if (ctx.repo->about_filter)
145 cgit_close_filter(ctx.repo->about_filter);
Lars Hjemlie1782ff2009-08-09 11:50:34 +0200146 html("</div>");
Lars Hjemli90f64ad2008-04-28 23:06:57 +0200147}