]>
git.cameronkatri.com Git - cgit.git/blob - ui-summary.c
1 /* ui-summary.c: functions for generating repo summary page
3 * Copyright (C) 2006 Lars Hjemli
4 * Copyright (C) 2010-2013 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"
18 static void print_url(char *base
, char *suffix
)
21 struct strbuf basebuf
= STRBUF_INIT
;
23 if (ctx
.repo
->enable_log_filecount
)
25 if (ctx
.repo
->enable_log_linecount
)
30 if (suffix
&& *suffix
) {
31 strbuf_addf(&basebuf
, "%s/%s", base
, suffix
);
34 htmlf("<tr><td colspan='%d'><a href='", columns
);
38 html("</a></td></tr>\n");
39 strbuf_release(&basebuf
);
42 static void print_urls(char *txt
, char *suffix
)
48 if (ctx
.repo
->enable_log_filecount
)
50 if (ctx
.repo
->enable_log_linecount
)
55 while (h
&& *h
== ' ')
60 while (t
&& *t
&& *t
!= ' ')
65 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns
);
66 htmlf("<tr><th class='left' colspan='%d'>Clone</th></tr>\n", columns
);
74 void cgit_print_summary()
78 if (ctx
.repo
->enable_log_filecount
)
80 if (ctx
.repo
->enable_log_linecount
)
83 html("<table summary='repository info' class='list nowrap'>");
84 cgit_print_branches(ctx
.cfg
.summary_branches
);
85 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns
);
86 cgit_print_tags(ctx
.cfg
.summary_tags
);
87 if (ctx
.cfg
.summary_log
> 0) {
88 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns
);
89 cgit_print_log(ctx
.qry
.head
, 0, ctx
.cfg
.summary_log
, NULL
,
92 if (ctx
.repo
->clone_url
)
93 print_urls(expand_macros(ctx
.repo
->clone_url
), NULL
);
94 else if (ctx
.cfg
.clone_prefix
)
95 print_urls(ctx
.cfg
.clone_prefix
, ctx
.repo
->url
);
99 /* The caller must free the return value. */
100 static char* append_readme_path(const char *filename
, const char *ref
, const char *path
)
102 char *file
, *base_dir
, *full_path
, *resolved_base
= NULL
, *resolved_full
= NULL
;
103 /* If a subpath is specified for the about page, make it relative
104 * to the directory containing the configured readme. */
106 file
= xstrdup(filename
);
107 base_dir
= dirname(file
);
108 if (!strcmp(base_dir
, ".") || !strcmp(base_dir
, "..")) {
113 full_path
= xstrdup(path
);
115 full_path
= fmtalloc("%s/%s", base_dir
, path
);
118 resolved_base
= realpath(base_dir
, NULL
);
119 resolved_full
= realpath(full_path
, NULL
);
120 if (!resolved_base
|| !resolved_full
|| strncmp(resolved_base
, resolved_full
, strlen(resolved_base
))) {
133 void cgit_print_repo_readme(char *path
)
135 char *filename
, *ref
;
136 int free_filename
= 0;
138 if (ctx
.repo
->readme
.nr
== 0)
141 filename
= ctx
.repo
->readme
.items
[0].string
;
142 ref
= ctx
.repo
->readme
.items
[0].util
;
146 filename
= append_readme_path(filename
, ref
, path
);
151 /* Print the calculated readme, either from the git repo or from the
152 * filesystem, while applying the about-filter.
154 html("<div id='summary'>");
155 if (ctx
.repo
->about_filter
) {
156 ctx
.repo
->about_filter
->argv
[1] = filename
;
157 cgit_open_filter(ctx
.repo
->about_filter
);
160 cgit_print_file(filename
, ref
, 1);
162 html_include(filename
);
163 if (ctx
.repo
->about_filter
) {
164 cgit_close_filter(ctx
.repo
->about_filter
);
165 ctx
.repo
->about_filter
->argv
[1] = NULL
;