-rw-r--r-- | cgit.c | 13 | ||||
-rw-r--r-- | cgit.h | 3 | ||||
-rw-r--r-- | cgitrc.5.txt | 21 | ||||
-rw-r--r-- | ui-atom.c | 2 | ||||
-rw-r--r-- | ui-commit.c | 12 | ||||
-rw-r--r-- | ui-patch.c | 6 | ||||
-rw-r--r-- | ui-plain.c | 20 | ||||
-rw-r--r-- | ui-tag.c | 2 | ||||
-rw-r--r-- | ui-tree.c | 8 |
9 files changed, 74 insertions, 13 deletions
@@ -8,24 +8,32 @@ | |||
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "cache.h" | 10 | #include "cache.h" |
11 | #include "cmd.h" | 11 | #include "cmd.h" |
12 | #include "configfile.h" | 12 | #include "configfile.h" |
13 | #include "html.h" | 13 | #include "html.h" |
14 | #include "ui-shared.h" | 14 | #include "ui-shared.h" |
15 | #include "ui-stats.h" | 15 | #include "ui-stats.h" |
16 | #include "scan-tree.h" | 16 | #include "scan-tree.h" |
17 | 17 | ||
18 | const char *cgit_version = CGIT_VERSION; | 18 | const char *cgit_version = CGIT_VERSION; |
19 | 19 | ||
20 | void add_mimetype(const char *name, const char *value) | ||
21 | { | ||
22 | struct string_list_item *item; | ||
23 | |||
24 | item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes); | ||
25 | item->util = xstrdup(value); | ||
26 | } | ||
27 | |||
20 | struct cgit_filter *new_filter(const char *cmd, int extra_args) | 28 | struct cgit_filter *new_filter(const char *cmd, int extra_args) |
21 | { | 29 | { |
22 | struct cgit_filter *f; | 30 | struct cgit_filter *f; |
23 | 31 | ||
24 | if (!cmd || !cmd[0]) | 32 | if (!cmd || !cmd[0]) |
25 | return NULL; | 33 | return NULL; |
26 | 34 | ||
27 | f = xmalloc(sizeof(struct cgit_filter)); | 35 | f = xmalloc(sizeof(struct cgit_filter)); |
28 | f->cmd = xstrdup(cmd); | 36 | f->cmd = xstrdup(cmd); |
29 | f->argv = xmalloc((2 + extra_args) * sizeof(char *)); | 37 | f->argv = xmalloc((2 + extra_args) * sizeof(char *)); |
30 | f->argv[0] = f->cmd; | 38 | f->argv[0] = f->cmd; |
31 | f->argv[1] = NULL; | 39 | f->argv[1] = NULL; |
@@ -57,24 +65,26 @@ void config_cb(const char *name, const char *value) | |||
57 | else if (!strcmp(name, "index-info")) | 65 | else if (!strcmp(name, "index-info")) |
58 | ctx.cfg.index_info = xstrdup(value); | 66 | ctx.cfg.index_info = xstrdup(value); |
59 | else if (!strcmp(name, "logo-link")) | 67 | else if (!strcmp(name, "logo-link")) |
60 | ctx.cfg.logo_link = xstrdup(value); | 68 | ctx.cfg.logo_link = xstrdup(value); |
61 | else if (!strcmp(name, "module-link")) | 69 | else if (!strcmp(name, "module-link")) |
62 | ctx.cfg.module_link = xstrdup(value); | 70 | ctx.cfg.module_link = xstrdup(value); |
63 | else if (!strcmp(name, "virtual-root")) { | 71 | else if (!strcmp(name, "virtual-root")) { |
64 | ctx.cfg.virtual_root = trim_end(value, '/'); | 72 | ctx.cfg.virtual_root = trim_end(value, '/'); |
65 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) | 73 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) |
66 | ctx.cfg.virtual_root = ""; | 74 | ctx.cfg.virtual_root = ""; |
67 | } else if (!strcmp(name, "nocache")) | 75 | } else if (!strcmp(name, "nocache")) |
68 | ctx.cfg.nocache = atoi(value); | 76 | ctx.cfg.nocache = atoi(value); |
77 | else if (!strcmp(name, "noplainemail")) | ||
78 | ctx.cfg.noplainemail = atoi(value); | ||
69 | else if (!strcmp(name, "noheader")) | 79 | else if (!strcmp(name, "noheader")) |
70 | ctx.cfg.noheader = atoi(value); | 80 | ctx.cfg.noheader = atoi(value); |
71 | else if (!strcmp(name, "snapshots")) | 81 | else if (!strcmp(name, "snapshots")) |
72 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); | 82 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); |
73 | else if (!strcmp(name, "enable-index-links")) | 83 | else if (!strcmp(name, "enable-index-links")) |
74 | ctx.cfg.enable_index_links = atoi(value); | 84 | ctx.cfg.enable_index_links = atoi(value); |
75 | else if (!strcmp(name, "enable-log-filecount")) | 85 | else if (!strcmp(name, "enable-log-filecount")) |
76 | ctx.cfg.enable_log_filecount = atoi(value); | 86 | ctx.cfg.enable_log_filecount = atoi(value); |
77 | else if (!strcmp(name, "enable-log-linecount")) | 87 | else if (!strcmp(name, "enable-log-linecount")) |
78 | ctx.cfg.enable_log_linecount = atoi(value); | 88 | ctx.cfg.enable_log_linecount = atoi(value); |
79 | else if (!strcmp(name, "max-stats")) | 89 | else if (!strcmp(name, "max-stats")) |
80 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); | 90 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); |
@@ -111,24 +121,26 @@ void config_cb(const char *name, const char *value) | |||
111 | else if (!strcmp(name, "summary-tags")) | 121 | else if (!strcmp(name, "summary-tags")) |
112 | ctx.cfg.summary_tags = atoi(value); | 122 | ctx.cfg.summary_tags = atoi(value); |
113 | else if (!strcmp(name, "agefile")) | 123 | else if (!strcmp(name, "agefile")) |
114 | ctx.cfg.agefile = xstrdup(value); | 124 | ctx.cfg.agefile = xstrdup(value); |
115 | else if (!strcmp(name, "renamelimit")) | 125 | else if (!strcmp(name, "renamelimit")) |
116 | ctx.cfg.renamelimit = atoi(value); | 126 | ctx.cfg.renamelimit = atoi(value); |
117 | else if (!strcmp(name, "robots")) | 127 | else if (!strcmp(name, "robots")) |
118 | ctx.cfg.robots = xstrdup(value); | 128 | ctx.cfg.robots = xstrdup(value); |
119 | else if (!strcmp(name, "clone-prefix")) | 129 | else if (!strcmp(name, "clone-prefix")) |
120 | ctx.cfg.clone_prefix = xstrdup(value); | 130 | ctx.cfg.clone_prefix = xstrdup(value); |
121 | else if (!strcmp(name, "local-time")) | 131 | else if (!strcmp(name, "local-time")) |
122 | ctx.cfg.local_time = atoi(value); | 132 | ctx.cfg.local_time = atoi(value); |
133 | else if (!prefixcmp(name, "mimetype.")) | ||
134 | add_mimetype(name + 9, value); | ||
123 | else if (!strcmp(name, "repo.group")) | 135 | else if (!strcmp(name, "repo.group")) |
124 | ctx.cfg.repo_group = xstrdup(value); | 136 | ctx.cfg.repo_group = xstrdup(value); |
125 | else if (!strcmp(name, "repo.url")) | 137 | else if (!strcmp(name, "repo.url")) |
126 | ctx.repo = cgit_add_repo(value); | 138 | ctx.repo = cgit_add_repo(value); |
127 | else if (!strcmp(name, "repo.name")) | 139 | else if (!strcmp(name, "repo.name")) |
128 | ctx.repo->name = xstrdup(value); | 140 | ctx.repo->name = xstrdup(value); |
129 | else if (ctx.repo && !strcmp(name, "repo.path")) | 141 | else if (ctx.repo && !strcmp(name, "repo.path")) |
130 | ctx.repo->path = trim_end(value, '/'); | 142 | ctx.repo->path = trim_end(value, '/'); |
131 | else if (ctx.repo && !strcmp(name, "repo.clone-url")) | 143 | else if (ctx.repo && !strcmp(name, "repo.clone-url")) |
132 | ctx.repo->clone_url = xstrdup(value); | 144 | ctx.repo->clone_url = xstrdup(value); |
133 | else if (ctx.repo && !strcmp(name, "repo.desc")) | 145 | else if (ctx.repo && !strcmp(name, "repo.desc")) |
134 | ctx.repo->desc = xstrdup(value); | 146 | ctx.repo->desc = xstrdup(value); |
@@ -227,24 +239,25 @@ static void prepare_context(struct cgit_context *ctx) | |||
227 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; | 239 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; |
228 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; | 240 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
229 | ctx->cfg.summary_branches = 10; | 241 | ctx->cfg.summary_branches = 10; |
230 | ctx->cfg.summary_log = 10; | 242 | ctx->cfg.summary_log = 10; |
231 | ctx->cfg.summary_tags = 10; | 243 | ctx->cfg.summary_tags = 10; |
232 | ctx->page.mimetype = "text/html"; | 244 | ctx->page.mimetype = "text/html"; |
233 | ctx->page.charset = PAGE_ENCODING; | 245 | ctx->page.charset = PAGE_ENCODING; |
234 | ctx->page.filename = NULL; | 246 | ctx->page.filename = NULL; |
235 | ctx->page.size = 0; | 247 | ctx->page.size = 0; |
236 | ctx->page.modified = time(NULL); | 248 | ctx->page.modified = time(NULL); |
237 | ctx->page.expires = ctx->page.modified; | 249 | ctx->page.expires = ctx->page.modified; |
238 | ctx->page.etag = NULL; | 250 | ctx->page.etag = NULL; |
251 | memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); | ||
239 | } | 252 | } |
240 | 253 | ||
241 | struct refmatch { | 254 | struct refmatch { |
242 | char *req_ref; | 255 | char *req_ref; |
243 | char *first_ref; | 256 | char *first_ref; |
244 | int match; | 257 | int match; |
245 | }; | 258 | }; |
246 | 259 | ||
247 | int find_current_ref(const char *refname, const unsigned char *sha1, | 260 | int find_current_ref(const char *refname, const unsigned char *sha1, |
248 | int flags, void *cb_data) | 261 | int flags, void *cb_data) |
249 | { | 262 | { |
250 | struct refmatch *info; | 263 | struct refmatch *info; |
@@ -6,24 +6,25 @@ | |||
6 | #include <cache.h> | 6 | #include <cache.h> |
7 | #include <grep.h> | 7 | #include <grep.h> |
8 | #include <object.h> | 8 | #include <object.h> |
9 | #include <tree.h> | 9 | #include <tree.h> |
10 | #include <commit.h> | 10 | #include <commit.h> |
11 | #include <tag.h> | 11 | #include <tag.h> |
12 | #include <diff.h> | 12 | #include <diff.h> |
13 | #include <diffcore.h> | 13 | #include <diffcore.h> |
14 | #include <refs.h> | 14 | #include <refs.h> |
15 | #include <revision.h> | 15 | #include <revision.h> |
16 | #include <log-tree.h> | 16 | #include <log-tree.h> |
17 | #include <archive.h> | 17 | #include <archive.h> |
18 | #include <string-list.h> | ||
18 | #include <xdiff-interface.h> | 19 | #include <xdiff-interface.h> |
19 | #include <xdiff/xdiff.h> | 20 | #include <xdiff/xdiff.h> |
20 | #include <utf8.h> | 21 | #include <utf8.h> |
21 | 22 | ||
22 | 23 | ||
23 | /* | 24 | /* |
24 | * Dateformats used on misc. pages | 25 | * Dateformats used on misc. pages |
25 | */ | 26 | */ |
26 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)" | 27 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)" |
27 | #define FMT_SHORTDATE "%Y-%m-%d" | 28 | #define FMT_SHORTDATE "%Y-%m-%d" |
28 | #define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ" | 29 | #define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ" |
29 | 30 | ||
@@ -170,30 +171,32 @@ struct cgit_config { | |||
170 | int embedded; | 171 | int embedded; |
171 | int enable_index_links; | 172 | int enable_index_links; |
172 | int enable_log_filecount; | 173 | int enable_log_filecount; |
173 | int enable_log_linecount; | 174 | int enable_log_linecount; |
174 | int local_time; | 175 | int local_time; |
175 | int max_repo_count; | 176 | int max_repo_count; |
176 | int max_commit_count; | 177 | int max_commit_count; |
177 | int max_lock_attempts; | 178 | int max_lock_attempts; |
178 | int max_msg_len; | 179 | int max_msg_len; |
179 | int max_repodesc_len; | 180 | int max_repodesc_len; |
180 | int max_stats; | 181 | int max_stats; |
181 | int nocache; | 182 | int nocache; |
183 | int noplainemail; | ||
182 | int noheader; | 184 | int noheader; |
183 | int renamelimit; | 185 | int renamelimit; |
184 | int snapshots; | 186 | int snapshots; |
185 | int summary_branches; | 187 | int summary_branches; |
186 | int summary_log; | 188 | int summary_log; |
187 | int summary_tags; | 189 | int summary_tags; |
190 | struct string_list mimetypes; | ||
188 | struct cgit_filter *commit_filter; | 191 | struct cgit_filter *commit_filter; |
189 | struct cgit_filter *source_filter; | 192 | struct cgit_filter *source_filter; |
190 | }; | 193 | }; |
191 | 194 | ||
192 | struct cgit_page { | 195 | struct cgit_page { |
193 | time_t modified; | 196 | time_t modified; |
194 | time_t expires; | 197 | time_t expires; |
195 | size_t size; | 198 | size_t size; |
196 | char *mimetype; | 199 | char *mimetype; |
197 | char *charset; | 200 | char *charset; |
198 | char *filename; | 201 | char *filename; |
199 | char *etag; | 202 | char *etag; |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index ffb3e0f..dc63637 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -144,35 +144,43 @@ max-repo-count:: | |||
144 | Specifies the number of entries to list per page on therepository | 144 | Specifies the number of entries to list per page on therepository |
145 | index page. Default value: "50". | 145 | index page. Default value: "50". |
146 | 146 | ||
147 | max-repodesc-length:: | 147 | max-repodesc-length:: |
148 | Specifies the maximum number of repo description characters to display | 148 | Specifies the maximum number of repo description characters to display |
149 | on the repository index page. Default value: "80". | 149 | on the repository index page. Default value: "80". |
150 | 150 | ||
151 | max-stats:: | 151 | max-stats:: |
152 | Set the default maximum statistics period. Valid values are "week", | 152 | Set the default maximum statistics period. Valid values are "week", |
153 | "month", "quarter" and "year". If unspecified, statistics are | 153 | "month", "quarter" and "year". If unspecified, statistics are |
154 | disabled. Default value: none. See also: "repo.max-stats". | 154 | disabled. Default value: none. See also: "repo.max-stats". |
155 | 155 | ||
156 | mimetype.<ext>:: | ||
157 | Set the mimetype for the specified filename extension. This is used | ||
158 | by the `plain` command when returning blob content. | ||
159 | |||
156 | module-link:: | 160 | module-link:: |
157 | Text which will be used as the formatstring for a hyperlink when a | 161 | Text which will be used as the formatstring for a hyperlink when a |
158 | submodule is printed in a directory listing. The arguments for the | 162 | submodule is printed in a directory listing. The arguments for the |
159 | formatstring are the path and SHA1 of the submodule commit. Default | 163 | formatstring are the path and SHA1 of the submodule commit. Default |
160 | value: "./?repo=%s&page=commit&id=%s" | 164 | value: "./?repo=%s&page=commit&id=%s" |
161 | 165 | ||
162 | nocache:: | 166 | nocache:: |
163 | If set to the value "1" caching will be disabled. This settings is | 167 | If set to the value "1" caching will be disabled. This settings is |
164 | deprecated, and will not be honored starting with cgit-1.0. Default | 168 | deprecated, and will not be honored starting with cgit-1.0. Default |
165 | value: "0". | 169 | value: "0". |
166 | 170 | ||
171 | noplainemail:: | ||
172 | If set to "1" showing full author email adresses will be disabled. | ||
173 | Default value: "0". | ||
174 | |||
167 | noheader:: | 175 | noheader:: |
168 | Flag which, when set to "1", will make cgit omit the standard header | 176 | Flag which, when set to "1", will make cgit omit the standard header |
169 | on all pages. Default value: none. See also: "embedded". | 177 | on all pages. Default value: none. See also: "embedded". |
170 | 178 | ||
171 | renamelimit:: | 179 | renamelimit:: |
172 | Maximum number of files to consider when detecting renames. The value | 180 | Maximum number of files to consider when detecting renames. The value |
173 | "-1" uses the compiletime value in git (for further info, look at | 181 | "-1" uses the compiletime value in git (for further info, look at |
174 | `man git-diff`). Default value: "-1". | 182 | `man git-diff`). Default value: "-1". |
175 | 183 | ||
176 | repo.group:: | 184 | repo.group:: |
177 | A value for the current repository group, which all repositories | 185 | A value for the current repository group, which all repositories |
178 | specified after this setting will inherit. Default value: none. | 186 | specified after this setting will inherit. Default value: none. |
@@ -336,24 +344,37 @@ root-title=foobar.com git repositories | |||
336 | root-desc=tracking the foobar development | 344 | root-desc=tracking the foobar development |
337 | 345 | ||
338 | 346 | ||
339 | # Include some more info about foobar.com on the index page | 347 | # Include some more info about foobar.com on the index page |
340 | root-readme=/var/www/htdocs/about.html | 348 | root-readme=/var/www/htdocs/about.html |
341 | 349 | ||
342 | 350 | ||
343 | # Allow download of tar.gz, tar.bz2 and zip-files | 351 | # Allow download of tar.gz, tar.bz2 and zip-files |
344 | snapshots=tar.gz tar.bz2 zip | 352 | snapshots=tar.gz tar.bz2 zip |
345 | 353 | ||
346 | 354 | ||
347 | ## | 355 | ## |
356 | ## List of common mimetypes | ||
357 | ## | ||
358 | |||
359 | mimetype.git=image/git | ||
360 | mimetype.html=text/html | ||
361 | mimetype.jpg=image/jpeg | ||
362 | mimetype.jpeg=image/jpeg | ||
363 | mimetype.pdf=application/pdf | ||
364 | mimetype.png=image/png | ||
365 | mimetype.svg=image/svg+xml | ||
366 | |||
367 | |||
368 | ## | ||
348 | ## List of repositories. | 369 | ## List of repositories. |
349 | ## PS: Any repositories listed when repo.group is unset will not be | 370 | ## PS: Any repositories listed when repo.group is unset will not be |
350 | ## displayed under a group heading | 371 | ## displayed under a group heading |
351 | ## PPS: This list could be kept in a different file (e.g. '/etc/cgitrepos') | 372 | ## PPS: This list could be kept in a different file (e.g. '/etc/cgitrepos') |
352 | ## and included like this: | 373 | ## and included like this: |
353 | ## include=/etc/cgitrepos | 374 | ## include=/etc/cgitrepos |
354 | ## | 375 | ## |
355 | 376 | ||
356 | 377 | ||
357 | repo.url=foo | 378 | repo.url=foo |
358 | repo.path=/pub/git/foo.git | 379 | repo.path=/pub/git/foo.git |
359 | repo.desc=the master foo repository | 380 | repo.desc=the master foo repository |
@@ -23,25 +23,25 @@ void add_entry(struct commit *commit, char *host) | |||
23 | html("<title>"); | 23 | html("<title>"); |
24 | html_txt(info->subject); | 24 | html_txt(info->subject); |
25 | html("</title>\n"); | 25 | html("</title>\n"); |
26 | html("<updated>"); | 26 | html("<updated>"); |
27 | cgit_print_date(info->author_date, FMT_ATOMDATE, ctx.cfg.local_time); | 27 | cgit_print_date(info->author_date, FMT_ATOMDATE, ctx.cfg.local_time); |
28 | html("</updated>\n"); | 28 | html("</updated>\n"); |
29 | html("<author>\n"); | 29 | html("<author>\n"); |
30 | if (info->author) { | 30 | if (info->author) { |
31 | html("<name>"); | 31 | html("<name>"); |
32 | html_txt(info->author); | 32 | html_txt(info->author); |
33 | html("</name>\n"); | 33 | html("</name>\n"); |
34 | } | 34 | } |
35 | if (info->author_email) { | 35 | if (info->author_email && !ctx.cfg.noplainemail) { |
36 | mail = xstrdup(info->author_email); | 36 | mail = xstrdup(info->author_email); |
37 | t = strchr(mail, '<'); | 37 | t = strchr(mail, '<'); |
38 | if (t) | 38 | if (t) |
39 | t++; | 39 | t++; |
40 | else | 40 | else |
41 | t = mail; | 41 | t = mail; |
42 | t2 = strchr(t, '>'); | 42 | t2 = strchr(t, '>'); |
43 | if (t2) | 43 | if (t2) |
44 | *t2 = '\0'; | 44 | *t2 = '\0'; |
45 | html("<email>"); | 45 | html("<email>"); |
46 | html_txt(t); | 46 | html_txt(t); |
47 | html("</email>\n"); | 47 | html("</email>\n"); |
diff --git a/ui-commit.c b/ui-commit.c index 5815b58..d6b73ee 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -31,33 +31,37 @@ void cgit_print_commit(char *hex) | |||
31 | commit = lookup_commit_reference(sha1); | 31 | commit = lookup_commit_reference(sha1); |
32 | if (!commit) { | 32 | if (!commit) { |
33 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 33 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
34 | return; | 34 | return; |
35 | } | 35 | } |
36 | info = cgit_parse_commit(commit); | 36 | info = cgit_parse_commit(commit); |
37 | 37 | ||
38 | load_ref_decorations(); | 38 | load_ref_decorations(); |
39 | 39 | ||
40 | html("<table summary='commit info' class='commit-info'>\n"); | 40 | html("<table summary='commit info' class='commit-info'>\n"); |
41 | html("<tr><th>author</th><td>"); | 41 | html("<tr><th>author</th><td>"); |
42 | html_txt(info->author); | 42 | html_txt(info->author); |
43 | html(" "); | 43 | if (!ctx.cfg.noplainemail) { |
44 | html_txt(info->author_email); | 44 | html(" "); |
45 | html_txt(info->author_email); | ||
46 | } | ||
45 | html("</td><td class='right'>"); | 47 | html("</td><td class='right'>"); |
46 | cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time); | 48 | cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time); |
47 | html("</td></tr>\n"); | 49 | html("</td></tr>\n"); |
48 | html("<tr><th>committer</th><td>"); | 50 | html("<tr><th>committer</th><td>"); |
49 | html_txt(info->committer); | 51 | html_txt(info->committer); |
50 | html(" "); | 52 | if (!ctx.cfg.noplainemail) { |
51 | html_txt(info->committer_email); | 53 | html(" "); |
54 | html_txt(info->committer_email); | ||
55 | } | ||
52 | html("</td><td class='right'>"); | 56 | html("</td><td class='right'>"); |
53 | cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time); | 57 | cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time); |
54 | html("</td></tr>\n"); | 58 | html("</td></tr>\n"); |
55 | html("<tr><th>commit</th><td colspan='2' class='sha1'>"); | 59 | html("<tr><th>commit</th><td colspan='2' class='sha1'>"); |
56 | tmp = sha1_to_hex(commit->object.sha1); | 60 | tmp = sha1_to_hex(commit->object.sha1); |
57 | cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp); | 61 | cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp); |
58 | html(" ("); | 62 | html(" ("); |
59 | cgit_patch_link("patch", NULL, NULL, NULL, tmp); | 63 | cgit_patch_link("patch", NULL, NULL, NULL, tmp); |
60 | html(")</td></tr>\n"); | 64 | html(")</td></tr>\n"); |
61 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); | 65 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); |
62 | tmp = xstrdup(hex); | 66 | tmp = xstrdup(hex); |
63 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, | 67 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, |
@@ -99,25 +99,29 @@ void cgit_print_patch(char *hex) | |||
99 | info = cgit_parse_commit(commit); | 99 | info = cgit_parse_commit(commit); |
100 | 100 | ||
101 | if (commit->parents && commit->parents->item) | 101 | if (commit->parents && commit->parents->item) |
102 | hashcpy(old_sha1, commit->parents->item->object.sha1); | 102 | hashcpy(old_sha1, commit->parents->item->object.sha1); |
103 | else | 103 | else |
104 | hashclr(old_sha1); | 104 | hashclr(old_sha1); |
105 | 105 | ||
106 | patchname = fmt("%s.patch", sha1_to_hex(sha1)); | 106 | patchname = fmt("%s.patch", sha1_to_hex(sha1)); |
107 | ctx.page.mimetype = "text/plain"; | 107 | ctx.page.mimetype = "text/plain"; |
108 | ctx.page.filename = patchname; | 108 | ctx.page.filename = patchname; |
109 | cgit_print_http_headers(&ctx); | 109 | cgit_print_http_headers(&ctx); |
110 | htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); | 110 | htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); |
111 | htmlf("From: %s %s\n", info->author, info->author_email); | 111 | htmlf("From: %s", info->author); |
112 | if (!ctx.cfg.noplainemail) { | ||
113 | htmlf(" %s", info->author_email); | ||
114 | } | ||
115 | html("\n"); | ||
112 | html("Date: "); | 116 | html("Date: "); |
113 | cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time); | 117 | cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time); |
114 | htmlf("Subject: %s\n\n", info->subject); | 118 | htmlf("Subject: %s\n\n", info->subject); |
115 | if (info->msg && *info->msg) { | 119 | if (info->msg && *info->msg) { |
116 | htmlf("%s", info->msg); | 120 | htmlf("%s", info->msg); |
117 | if (info->msg[strlen(info->msg) - 1] != '\n') | 121 | if (info->msg[strlen(info->msg) - 1] != '\n') |
118 | html("\n"); | 122 | html("\n"); |
119 | } | 123 | } |
120 | html("---\n"); | 124 | html("---\n"); |
121 | cgit_diff_tree(old_sha1, sha1, filepair_cb, NULL); | 125 | cgit_diff_tree(old_sha1, sha1, filepair_cb, NULL); |
122 | html("--\n"); | 126 | html("--\n"); |
123 | htmlf("cgit %s\n", CGIT_VERSION); | 127 | htmlf("cgit %s\n", CGIT_VERSION); |
@@ -8,42 +8,52 @@ | |||
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | 12 | ||
13 | char *curr_rev; | 13 | char *curr_rev; |
14 | char *match_path; | 14 | char *match_path; |
15 | int match; | 15 | int match; |
16 | 16 | ||
17 | static void print_object(const unsigned char *sha1, const char *path) | 17 | static void print_object(const unsigned char *sha1, const char *path) |
18 | { | 18 | { |
19 | enum object_type type; | 19 | enum object_type type; |
20 | char *buf; | 20 | char *buf, *ext; |
21 | unsigned long size; | 21 | unsigned long size; |
22 | struct string_list_item *mime; | ||
22 | 23 | ||
23 | type = sha1_object_info(sha1, &size); | 24 | type = sha1_object_info(sha1, &size); |
24 | if (type == OBJ_BAD) { | 25 | if (type == OBJ_BAD) { |
25 | html_status(404, "Not found", 0); | 26 | html_status(404, "Not found", 0); |
26 | return; | 27 | return; |
27 | } | 28 | } |
28 | 29 | ||
29 | buf = read_sha1_file(sha1, &type, &size); | 30 | buf = read_sha1_file(sha1, &type, &size); |
30 | if (!buf) { | 31 | if (!buf) { |
31 | html_status(404, "Not found", 0); | 32 | html_status(404, "Not found", 0); |
32 | return; | 33 | return; |
33 | } | 34 | } |
34 | if (buffer_is_binary(buf, size)) | 35 | ctx.page.mimetype = NULL; |
35 | ctx.page.mimetype = "application/octet-stream"; | 36 | ext = strrchr(path, '.'); |
36 | else | 37 | if (ext && *(++ext)) { |
37 | ctx.page.mimetype = "text/plain"; | 38 | mime = string_list_lookup(ext, &ctx.cfg.mimetypes); |
39 | if (mime) | ||
40 | ctx.page.mimetype = (char *)mime->util; | ||
41 | } | ||
42 | if (!ctx.page.mimetype) { | ||
43 | if (buffer_is_binary(buf, size)) | ||
44 | ctx.page.mimetype = "application/octet-stream"; | ||
45 | else | ||
46 | ctx.page.mimetype = "text/plain"; | ||
47 | } | ||
38 | ctx.page.filename = fmt("%s", path); | 48 | ctx.page.filename = fmt("%s", path); |
39 | ctx.page.size = size; | 49 | ctx.page.size = size; |
40 | ctx.page.etag = sha1_to_hex(sha1); | 50 | ctx.page.etag = sha1_to_hex(sha1); |
41 | cgit_print_http_headers(&ctx); | 51 | cgit_print_http_headers(&ctx); |
42 | html_raw(buf, size); | 52 | html_raw(buf, size); |
43 | match = 1; | 53 | match = 1; |
44 | } | 54 | } |
45 | 55 | ||
46 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | 56 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
47 | const char *pathname, unsigned mode, int stage, | 57 | const char *pathname, unsigned mode, int stage, |
48 | void *cbdata) | 58 | void *cbdata) |
49 | { | 59 | { |
@@ -55,25 +55,25 @@ void cgit_print_tag(char *revname) | |||
55 | html("<table class='commit-info'>\n"); | 55 | html("<table class='commit-info'>\n"); |
56 | htmlf("<tr><td>Tag name</td><td>"); | 56 | htmlf("<tr><td>Tag name</td><td>"); |
57 | html_txt(revname); | 57 | html_txt(revname); |
58 | htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1)); | 58 | htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1)); |
59 | if (info->tagger_date > 0) { | 59 | if (info->tagger_date > 0) { |
60 | html("<tr><td>Tag date</td><td>"); | 60 | html("<tr><td>Tag date</td><td>"); |
61 | cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time); | 61 | cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time); |
62 | html("</td></tr>\n"); | 62 | html("</td></tr>\n"); |
63 | } | 63 | } |
64 | if (info->tagger) { | 64 | if (info->tagger) { |
65 | html("<tr><td>Tagged by</td><td>"); | 65 | html("<tr><td>Tagged by</td><td>"); |
66 | html_txt(info->tagger); | 66 | html_txt(info->tagger); |
67 | if (info->tagger_email) { | 67 | if (info->tagger_email && !ctx.cfg.noplainemail) { |
68 | html(" "); | 68 | html(" "); |
69 | html_txt(info->tagger_email); | 69 | html_txt(info->tagger_email); |
70 | } | 70 | } |
71 | html("</td></tr>\n"); | 71 | html("</td></tr>\n"); |
72 | } | 72 | } |
73 | html("<tr><td>Tagged object</td><td>"); | 73 | html("<tr><td>Tagged object</td><td>"); |
74 | cgit_object_link(tag->tagged); | 74 | cgit_object_link(tag->tagged); |
75 | html("</td></tr>\n"); | 75 | html("</td></tr>\n"); |
76 | html("</table>\n"); | 76 | html("</table>\n"); |
77 | print_tag_content(info->msg); | 77 | print_tag_content(info->msg); |
78 | } else { | 78 | } else { |
79 | html("<table class='commit-info'>\n"); | 79 | html("<table class='commit-info'>\n"); |
@@ -104,24 +104,25 @@ static void print_object(const unsigned char *sha1, char *path, const char *base | |||
104 | print_binary_buffer(buf, size); | 104 | print_binary_buffer(buf, size); |
105 | else | 105 | else |
106 | print_text_buffer(basename, buf, size); | 106 | print_text_buffer(basename, buf, size); |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, | 110 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
111 | const char *pathname, unsigned int mode, int stage, | 111 | const char *pathname, unsigned int mode, int stage, |
112 | void *cbdata) | 112 | void *cbdata) |
113 | { | 113 | { |
114 | char *name; | 114 | char *name; |
115 | char *fullpath; | 115 | char *fullpath; |
116 | char *class; | ||
116 | enum object_type type; | 117 | enum object_type type; |
117 | unsigned long size = 0; | 118 | unsigned long size = 0; |
118 | 119 | ||
119 | name = xstrdup(pathname); | 120 | name = xstrdup(pathname); |
120 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", | 121 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", |
121 | ctx.qry.path ? "/" : "", name); | 122 | ctx.qry.path ? "/" : "", name); |
122 | 123 | ||
123 | if (!S_ISGITLINK(mode)) { | 124 | if (!S_ISGITLINK(mode)) { |
124 | type = sha1_object_info(sha1, &size); | 125 | type = sha1_object_info(sha1, &size); |
125 | if (type == OBJ_BAD) { | 126 | if (type == OBJ_BAD) { |
126 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", | 127 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
127 | name, | 128 | name, |
@@ -136,25 +137,30 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen, | |||
136 | if (S_ISGITLINK(mode)) { | 137 | if (S_ISGITLINK(mode)) { |
137 | htmlf("<a class='ls-mod' href='"); | 138 | htmlf("<a class='ls-mod' href='"); |
138 | html_attr(fmt(ctx.repo->module_link, | 139 | html_attr(fmt(ctx.repo->module_link, |
139 | name, | 140 | name, |
140 | sha1_to_hex(sha1))); | 141 | sha1_to_hex(sha1))); |
141 | html("'>"); | 142 | html("'>"); |
142 | html_txt(name); | 143 | html_txt(name); |
143 | html("</a>"); | 144 | html("</a>"); |
144 | } else if (S_ISDIR(mode)) { | 145 | } else if (S_ISDIR(mode)) { |
145 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, | 146 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, |
146 | curr_rev, fullpath); | 147 | curr_rev, fullpath); |
147 | } else { | 148 | } else { |
148 | cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head, | 149 | class = strrchr(name, '.'); |
150 | if (class != NULL) { | ||
151 | class = fmt("ls-blob %s", class + 1); | ||
152 | } else | ||
153 | class = "ls-blob"; | ||
154 | cgit_tree_link(name, NULL, class, ctx.qry.head, | ||
149 | curr_rev, fullpath); | 155 | curr_rev, fullpath); |
150 | } | 156 | } |
151 | htmlf("</td><td class='ls-size'>%li</td>", size); | 157 | htmlf("</td><td class='ls-size'>%li</td>", size); |
152 | 158 | ||
153 | html("<td>"); | 159 | html("<td>"); |
154 | cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, | 160 | cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, |
155 | fullpath, 0, NULL, NULL, ctx.qry.showmsg); | 161 | fullpath, 0, NULL, NULL, ctx.qry.showmsg); |
156 | if (ctx.repo->max_stats) | 162 | if (ctx.repo->max_stats) |
157 | cgit_stats_link("stats", NULL, "button", ctx.qry.head, | 163 | cgit_stats_link("stats", NULL, "button", ctx.qry.head, |
158 | fullpath); | 164 | fullpath); |
159 | html("</td></tr>\n"); | 165 | html("</td></tr>\n"); |
160 | free(name); | 166 | free(name); |