1 /* ui-summary.c: functions for generating repo summary page
3 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
10 #include "ui-summary.h"
17 static void print_url(char *base, char *suffix)
20 struct strbuf basebuf = STRBUF_INIT;
22 if (ctx.repo->enable_log_filecount)
24 if (ctx.repo->enable_log_linecount)
29 if (suffix && *suffix) {
30 strbuf_addf(&basebuf, "%s/%s", base, suffix);
33 htmlf("<tr><td colspan='%d'><a href='", columns);
37 html("</a></td></tr>\n");
38 strbuf_release(&basebuf);
41 static void print_urls(char *txt, char *suffix)
47 if (ctx.repo->enable_log_filecount)
49 if (ctx.repo->enable_log_linecount)
54 while (h && *h == ' ')
59 while (t && *t && *t != ' ')
64 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns);
65 htmlf("<tr><th class='left' colspan='%d'>Clone</th></tr>\n", columns);
73 void cgit_print_summary()
77 if (ctx.repo->enable_log_filecount)
79 if (ctx.repo->enable_log_linecount)
82 html("<table summary='repository info' class='list nowrap'>");
83 cgit_print_branches(ctx.cfg.summary_branches);
84 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns);
85 cgit_print_tags(ctx.cfg.summary_tags);
86 if (ctx.cfg.summary_log > 0) {
87 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns);
88 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL,
91 if (ctx.repo->clone_url)
92 print_urls(expand_macros(ctx.repo->clone_url), NULL);
93 else if (ctx.cfg.clone_prefix)
94 print_urls(ctx.cfg.clone_prefix, ctx.repo->url);
98 /* The caller must free the return value. */
99 static char* append_readme_path(const char *filename, const char *ref, const char *path)
101 char *file, *base_dir, *full_path, *resolved_base = NULL, *resolved_full = NULL;
102 /* If a subpath is specified for the about page, make it relative
103 * to the directory containing the configured readme. */
105 file = xstrdup(filename);
106 base_dir = dirname(file);
107 if (!strcmp(base_dir, ".") || !strcmp(base_dir, "..")) {
112 full_path = xstrdup(path);
114 full_path = fmtalloc("%s/%s", base_dir, path);
117 resolved_base = realpath(base_dir, NULL);
118 resolved_full = realpath(full_path, NULL);
119 if (!resolved_base || !resolved_full || prefixcmp(resolved_full, resolved_base)) {
132 void cgit_print_repo_readme(char *path)
134 char *filename, *ref;
135 int free_filename = 0;
137 if (ctx.repo->readme.nr == 0)
140 filename = ctx.repo->readme.items[0].string;
141 ref = ctx.repo->readme.items[0].util;
145 filename = append_readme_path(filename, ref, path);
150 /* Print the calculated readme, either from the git repo or from the
151 * filesystem, while applying the about-filter.
153 html("<div id='summary'>");
154 if (ctx.repo->about_filter)
155 cgit_open_filter(ctx.repo->about_filter, filename);
158 cgit_print_file(filename, ref, 1);
160 html_include(filename);
162 if (ctx.repo->about_filter)
163 cgit_close_filter(ctx.repo->about_filter);