diff options
-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
@@ -17,6 +17,14 @@ | |||
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; |
@@ -66,6 +74,8 @@ void config_cb(const char *name, const char *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")) |
@@ -122,6 +132,8 @@ void config_cb(const char *name, const char *value) | |||
122 | ctx.cfg.clone_prefix = xstrdup(value); | 132 | ctx.cfg.clone_prefix = xstrdup(value); |
123 | else if (!strcmp(name, "local-time")) | 133 | else if (!strcmp(name, "local-time")) |
124 | ctx.cfg.local_time = atoi(value); | 134 | ctx.cfg.local_time = atoi(value); |
135 | else if (!prefixcmp(name, "mimetype.")) | ||
136 | add_mimetype(name + 9, value); | ||
125 | else if (!strcmp(name, "repo.group")) | 137 | else if (!strcmp(name, "repo.group")) |
126 | ctx.cfg.repo_group = xstrdup(value); | 138 | ctx.cfg.repo_group = xstrdup(value); |
127 | else if (!strcmp(name, "repo.url")) | 139 | else if (!strcmp(name, "repo.url")) |
@@ -240,6 +252,7 @@ static void prepare_context(struct cgit_context *ctx) | |||
240 | ctx->page.modified = time(NULL); | 252 | ctx->page.modified = time(NULL); |
241 | ctx->page.expires = ctx->page.modified; | 253 | ctx->page.expires = ctx->page.modified; |
242 | ctx->page.etag = NULL; | 254 | ctx->page.etag = NULL; |
255 | memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); | ||
243 | } | 256 | } |
244 | 257 | ||
245 | struct refmatch { | 258 | struct refmatch { |
@@ -15,6 +15,7 @@ | |||
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> |
@@ -180,12 +181,14 @@ struct cgit_config { | |||
180 | int max_repodesc_len; | 181 | int max_repodesc_len; |
181 | int max_stats; | 182 | int max_stats; |
182 | int nocache; | 183 | int nocache; |
184 | int noplainemail; | ||
183 | int noheader; | 185 | int noheader; |
184 | int renamelimit; | 186 | int renamelimit; |
185 | int snapshots; | 187 | int snapshots; |
186 | int summary_branches; | 188 | int summary_branches; |
187 | int summary_log; | 189 | int summary_log; |
188 | int summary_tags; | 190 | int summary_tags; |
191 | struct string_list mimetypes; | ||
189 | struct cgit_filter *about_filter; | 192 | struct cgit_filter *about_filter; |
190 | struct cgit_filter *commit_filter; | 193 | struct cgit_filter *commit_filter; |
191 | struct cgit_filter *source_filter; | 194 | struct cgit_filter *source_filter; |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index d8e4b97..4d656fe 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -160,6 +160,10 @@ max-stats:: | |||
160 | "month", "quarter" and "year". If unspecified, statistics are | 160 | "month", "quarter" and "year". If unspecified, statistics are |
161 | disabled. Default value: none. See also: "repo.max-stats". | 161 | disabled. Default value: none. See also: "repo.max-stats". |
162 | 162 | ||
163 | mimetype.<ext>:: | ||
164 | Set the mimetype for the specified filename extension. This is used | ||
165 | by the `plain` command when returning blob content. | ||
166 | |||
163 | module-link:: | 167 | module-link:: |
164 | Text which will be used as the formatstring for a hyperlink when a | 168 | Text which will be used as the formatstring for a hyperlink when a |
165 | submodule is printed in a directory listing. The arguments for the | 169 | submodule is printed in a directory listing. The arguments for the |
@@ -171,6 +175,10 @@ nocache:: | |||
171 | deprecated, and will not be honored starting with cgit-1.0. Default | 175 | deprecated, and will not be honored starting with cgit-1.0. Default |
172 | value: "0". | 176 | value: "0". |
173 | 177 | ||
178 | noplainemail:: | ||
179 | If set to "1" showing full author email adresses will be disabled. | ||
180 | Default value: "0". | ||
181 | |||
174 | noheader:: | 182 | noheader:: |
175 | Flag which, when set to "1", will make cgit omit the standard header | 183 | Flag which, when set to "1", will make cgit omit the standard header |
176 | on all pages. Default value: none. See also: "embedded". | 184 | on all pages. Default value: none. See also: "embedded". |
@@ -355,6 +363,19 @@ snapshots=tar.gz tar.bz2 zip | |||
355 | 363 | ||
356 | 364 | ||
357 | ## | 365 | ## |
366 | ## List of common mimetypes | ||
367 | ## | ||
368 | |||
369 | mimetype.git=image/git | ||
370 | mimetype.html=text/html | ||
371 | mimetype.jpg=image/jpeg | ||
372 | mimetype.jpeg=image/jpeg | ||
373 | mimetype.pdf=application/pdf | ||
374 | mimetype.png=image/png | ||
375 | mimetype.svg=image/svg+xml | ||
376 | |||
377 | |||
378 | ## | ||
358 | ## List of repositories. | 379 | ## List of repositories. |
359 | ## PS: Any repositories listed when repo.group is unset will not be | 380 | ## PS: Any repositories listed when repo.group is unset will not be |
360 | ## displayed under a group heading | 381 | ## displayed under a group heading |
@@ -32,7 +32,7 @@ void add_entry(struct commit *commit, char *host) | |||
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) |
diff --git a/ui-commit.c b/ui-commit.c index 5815b58..d6b73ee 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -40,15 +40,19 @@ void cgit_print_commit(char *hex) | |||
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"); |
@@ -108,7 +108,11 @@ void cgit_print_patch(char *hex) | |||
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); |
@@ -17,8 +17,9 @@ int match; | |||
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) { |
@@ -31,10 +32,19 @@ static void print_object(const unsigned char *sha1, const char *path) | |||
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); |
@@ -64,7 +64,7 @@ void cgit_print_tag(char *revname) | |||
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 | } |
@@ -113,6 +113,7 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen, | |||
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 | ||
@@ -145,7 +146,12 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen, | |||
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); |