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)
18 static void print_url(char *base, char *suffix)
23 html("<tr class='nohover'><td colspan='4'> </td></tr>");
24 html("<tr><th class='left' colspan='4'>Clone</th></tr>\n");
26 if (suffix && *suffix)
27 base = fmt("%s/%s", base, suffix);
28 html("<tr><td colspan='4'><a href='");
32 html("</a></td></tr>\n");
35 static void print_urls(char *txt, char *suffix)
40 while (h && *h == ' ')
43 while (t && *t && *t != ' ')
53 void cgit_print_summary()
55 html("<table summary='repository info' class='list nowrap'>");
56 cgit_print_branches(ctx.cfg.summary_branches);
57 html("<tr class='nohover'><td colspan='4'> </td></tr>");
58 cgit_print_tags(ctx.cfg.summary_tags);
59 if (ctx.cfg.summary_log > 0) {
60 html("<tr class='nohover'><td colspan='4'> </td></tr>");
61 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL,
64 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);
71 void cgit_print_repo_readme(char *path)
73 char *slash, *tmp, *colon, *ref;
75 if (!ctx.repo->readme || !(*ctx.repo->readme))
80 /* Check if the readme is tracked in the git repo. */
81 colon = strchr(ctx.repo->readme, ':');
82 if (colon && strlen(colon) > 1) {
84 ref = ctx.repo->readme;
85 ctx.repo->readme = colon + 1;
86 if (!(*ctx.repo->readme))
90 /* Prepend repo path to relative readme path unless tracked. */
91 if (!ref && *ctx.repo->readme != '/')
92 ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path,
95 /* If a subpath is specified for the about page, make it relative
96 * to the directory containing the configured readme.
99 slash = strrchr(ctx.repo->readme, '/');
105 tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1);
106 strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1);
107 strcpy(tmp + (slash - ctx.repo->readme + 1), path);
109 tmp = ctx.repo->readme;
111 /* Print the calculated readme, either from the git repo or from the
112 * filesystem, while applying the about-filter.
114 html("<div id='summary'>");
115 if (ctx.repo->about_filter)
116 cgit_open_filter(ctx.repo->about_filter);
118 cgit_print_file(tmp, ref);
121 if (ctx.repo->about_filter)
122 cgit_close_filter(ctx.repo->about_filter);