1 /* ui-summary.c: functions for generating repo summary page
3 * Copyright (C) 2006 Lars Hjemli
4 * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com>
6 * Licensed under GNU General Public License v2
7 * (see COPYING for full license text)
11 #include "ui-summary.h"
17 static void print_url(char *base, char *suffix)
21 if (ctx.repo->enable_log_filecount)
23 if (ctx.repo->enable_log_linecount)
28 if (suffix && *suffix)
29 base = fmt("%s/%s", base, suffix);
30 htmlf("<tr><td colspan='%d'><a href='", columns);
34 html("</a></td></tr>\n");
37 static void print_urls(char *txt, char *suffix)
43 if (ctx.repo->enable_log_filecount)
45 if (ctx.repo->enable_log_linecount)
50 while (h && *h == ' ')
55 while (t && *t && *t != ' ')
60 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns);
61 htmlf("<tr><th class='left' colspan='%d'>Clone</th></tr>\n", columns);
69 void cgit_print_summary()
73 if (ctx.repo->enable_log_filecount)
75 if (ctx.repo->enable_log_linecount)
78 html("<table summary='repository info' class='list nowrap'>");
79 cgit_print_branches(ctx.cfg.summary_branches);
80 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns);
81 cgit_print_tags(ctx.cfg.summary_tags);
82 if (ctx.cfg.summary_log > 0) {
83 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns);
84 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL,
87 if (ctx.repo->clone_url)
88 print_urls(expand_macros(ctx.repo->clone_url), NULL);
89 else if (ctx.cfg.clone_prefix)
90 print_urls(ctx.cfg.clone_prefix, ctx.repo->url);
94 void cgit_print_repo_readme(char *path)
96 char *slash, *tmp, *colon, *ref;
98 if (!ctx.repo->readme || !(*ctx.repo->readme))
103 /* Check if the readme is tracked in the git repo. */
104 colon = strchr(ctx.repo->readme, ':');
105 if (colon && strlen(colon) > 1) {
107 ref = ctx.repo->readme;
108 ctx.repo->readme = colon + 1;
109 if (!(*ctx.repo->readme))
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,
118 /* If a subpath is specified for the about page, make it relative
119 * to the directory containing the configured readme.
122 slash = strrchr(ctx.repo->readme, '/');
128 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);
132 tmp = ctx.repo->readme;
134 /* Print the calculated readme, either from the git repo or from the
135 * filesystem, while applying the about-filter.
137 html("<div id='summary'>");
138 if (ctx.repo->about_filter)
139 cgit_open_filter(ctx.repo->about_filter);
141 cgit_print_file(tmp, ref);
144 if (ctx.repo->about_filter)
145 cgit_close_filter(ctx.repo->about_filter);