]>
git.cameronkatri.com Git - cgit.git/blob - ui-summary.c
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"
16 #include "ui-shared.h"
20 static void print_url(const char *url
)
24 if (ctx
.repo
->enable_log_filecount
)
26 if (ctx
.repo
->enable_log_linecount
)
30 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns
);
31 htmlf("<tr class='nohover'><th class='left' colspan='%d'>Clone</th></tr>\n", columns
);
34 htmlf("<tr><td colspan='%d'><a rel='vcs-git' href='", columns
);
37 html_attr(ctx
.repo
->name
);
38 html(" Git repository'>");
40 html("</a></td></tr>\n");
43 void cgit_print_summary(void)
47 if (ctx
.repo
->enable_log_filecount
)
49 if (ctx
.repo
->enable_log_linecount
)
52 cgit_print_layout_start();
53 html("<table summary='repository info' class='list nowrap'>");
54 cgit_print_branches(ctx
.cfg
.summary_branches
);
55 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns
);
56 cgit_print_tags(ctx
.cfg
.summary_tags
);
57 if (ctx
.cfg
.summary_log
> 0) {
58 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns
);
59 cgit_print_log(ctx
.qry
.head
, 0, ctx
.cfg
.summary_log
, NULL
,
63 cgit_add_clone_urls(print_url
);
65 cgit_print_layout_end();
68 /* The caller must free the return value. */
69 static char* append_readme_path(const char *filename
, const char *ref
, const char *path
)
71 char *file
, *base_dir
, *full_path
, *resolved_base
= NULL
, *resolved_full
= NULL
;
72 /* If a subpath is specified for the about page, make it relative
73 * to the directory containing the configured readme. */
75 file
= xstrdup(filename
);
76 base_dir
= dirname(file
);
77 if (!strcmp(base_dir
, ".") || !strcmp(base_dir
, "..")) {
82 full_path
= xstrdup(path
);
84 full_path
= fmtalloc("%s/%s", base_dir
, path
);
87 resolved_base
= realpath(base_dir
, NULL
);
88 resolved_full
= realpath(full_path
, NULL
);
89 if (!resolved_base
|| !resolved_full
|| !starts_with(resolved_full
, resolved_base
)) {
102 void cgit_print_repo_readme(const char *path
)
104 char *filename
, *ref
, *mimetype
;
105 int free_filename
= 0;
107 mimetype
= get_mimetype_for_filename(path
);
108 if (mimetype
&& (!strncmp(mimetype
, "image/", 6) || !strncmp(mimetype
, "video/", 6))) {
109 ctx
.page
.mimetype
= mimetype
;
110 ctx
.page
.charset
= NULL
;
117 cgit_print_layout_start();
118 if (ctx
.repo
->readme
.nr
== 0)
121 filename
= ctx
.repo
->readme
.items
[0].string
;
122 ref
= ctx
.repo
->readme
.items
[0].util
;
126 filename
= append_readme_path(filename
, ref
, path
);
131 /* Print the calculated readme, either from the git repo or from the
132 * filesystem, while applying the about-filter.
134 html("<div id='summary'>");
135 cgit_open_filter(ctx
.repo
->about_filter
, filename
);
137 cgit_print_file(filename
, ref
, 1);
139 html_include(filename
);
140 cgit_close_filter(ctx
.repo
->about_filter
);
147 cgit_print_layout_end();