summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--cgit.c13
-rw-r--r--cgit.h3
-rw-r--r--cgitrc.5.txt21
-rw-r--r--ui-atom.c2
-rw-r--r--ui-commit.c4
-rw-r--r--ui-patch.c6
-rw-r--r--ui-plain.c12
-rw-r--r--ui-tag.c2
-rw-r--r--ui-tree.c8
9 files changed, 66 insertions, 5 deletions
diff --git a/cgit.c b/cgit.c
index b3a98c1..dbec196 100644
--- a/cgit.c
+++ b/cgit.c
@@ -16,8 +16,16 @@
16#include "scan-tree.h" 16#include "scan-tree.h"
17 17
18const char *cgit_version = CGIT_VERSION; 18const char *cgit_version = CGIT_VERSION;
19 19
20void 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
20struct cgit_filter *new_filter(const char *cmd, int extra_args) 28struct cgit_filter *new_filter(const char *cmd, int extra_args)
21{ 29{
22 struct cgit_filter *f; 30 struct cgit_filter *f;
23 31
@@ -65,8 +73,10 @@ void config_cb(const char *name, const char *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);
@@ -119,8 +129,10 @@ void config_cb(const char *name, const char *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);
@@ -235,8 +247,9 @@ static void prepare_context(struct cgit_context *ctx)
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
241struct refmatch { 254struct refmatch {
242 char *req_ref; 255 char *req_ref;
diff --git a/cgit.h b/cgit.h
index f10ba05..b8557ac 100644
--- a/cgit.h
+++ b/cgit.h
@@ -14,8 +14,9 @@
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
@@ -178,14 +179,16 @@ struct cgit_config {
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
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index ffb3e0f..dc63637 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -152,8 +152,12 @@ 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
156mimetype.<ext>::
157 Set the mimetype for the specified filename extension. This is used
158 by the `plain` command when returning blob content.
159
156module-link:: 160module-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
@@ -163,8 +167,12 @@ 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
171noplainemail::
172 If set to "1" showing full author email adresses will be disabled.
173 Default value: "0".
174
167noheader:: 175noheader::
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
@@ -344,8 +352,21 @@ root-readme=/var/www/htdocs/about.html
344snapshots=tar.gz tar.bz2 zip 352snapshots=tar.gz tar.bz2 zip
345 353
346 354
347## 355##
356## List of common mimetypes
357##
358
359mimetype.git=image/git
360mimetype.html=text/html
361mimetype.jpg=image/jpeg
362mimetype.jpeg=image/jpeg
363mimetype.pdf=application/pdf
364mimetype.png=image/png
365mimetype.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')
diff --git a/ui-atom.c b/ui-atom.c
index e5c31d9..808b2d0 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -31,9 +31,9 @@ void add_entry(struct commit *commit, char *host)
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++;
diff --git a/ui-commit.c b/ui-commit.c
index 5815b58..d6b73ee 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -39,17 +39,21 @@ void cgit_print_commit(char *hex)
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 if (!ctx.cfg.noplainemail) {
43 html(" "); 44 html(" ");
44 html_txt(info->author_email); 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);
52 if (!ctx.cfg.noplainemail) {
50 html(" "); 53 html(" ");
51 html_txt(info->committer_email); 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'>");
diff --git a/ui-patch.c b/ui-patch.c
index 5d665d3..2a8f7a5 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -107,9 +107,13 @@ void cgit_print_patch(char *hex)
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) {
diff --git a/ui-plain.c b/ui-plain.c
index 93a3a05..27c6dae 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -16,10 +16,11 @@ int match;
16 16
17static void print_object(const unsigned char *sha1, const char *path) 17static 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);
@@ -30,12 +31,21 @@ static void print_object(const unsigned char *sha1, const char *path)
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 }
35 ctx.page.mimetype = NULL;
36 ext = strrchr(path, '.');
37 if (ext && *(++ext)) {
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) {
34 if (buffer_is_binary(buf, size)) 43 if (buffer_is_binary(buf, size))
35 ctx.page.mimetype = "application/octet-stream"; 44 ctx.page.mimetype = "application/octet-stream";
36 else 45 else
37 ctx.page.mimetype = "text/plain"; 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);
diff --git a/ui-tag.c b/ui-tag.c
index 0e056e0..a9c8670 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -63,9 +63,9 @@ void cgit_print_tag(char *revname)
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");
diff --git a/ui-tree.c b/ui-tree.c
index caf6a9e..c608754 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -112,8 +112,9 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
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);
@@ -144,9 +145,14 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
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