summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore 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.c12
-rw-r--r--ui-patch.c6
-rw-r--r--ui-plain.c20
-rw-r--r--ui-tag.c2
-rw-r--r--ui-tree.c8
9 files changed, 74 insertions, 13 deletions
diff --git a/cgit.c b/cgit.c
index cb1149d..7b228af 100644
--- a/cgit.c
+++ b/cgit.c
@@ -19,2 +19,10 @@ const char *cgit_version = CGIT_VERSION;
+void add_mimetype(const char *name, const char *value)
+{
+ struct string_list_item *item;
+
+ item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes);
+ item->util = xstrdup(value);
+}
+
struct cgit_filter *new_filter(const char *cmd, int extra_args)
@@ -68,2 +76,4 @@ void config_cb(const char *name, const char *value)
ctx.cfg.nocache = atoi(value);
+ else if (!strcmp(name, "noplainemail"))
+ ctx.cfg.noplainemail = atoi(value);
else if (!strcmp(name, "noheader"))
@@ -124,2 +134,4 @@ void config_cb(const char *name, const char *value)
ctx.cfg.local_time = atoi(value);
+ else if (!prefixcmp(name, "mimetype."))
+ add_mimetype(name + 9, value);
else if (!strcmp(name, "repo.group"))
@@ -242,2 +254,3 @@ static void prepare_context(struct cgit_context *ctx)
ctx->page.etag = NULL;
+ memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list));
}
diff --git a/cgit.h b/cgit.h
index b8f4850..4c854ea 100644
--- a/cgit.h
+++ b/cgit.h
@@ -17,2 +17,3 @@
#include <archive.h>
+#include <string-list.h>
#include <xdiff-interface.h>
@@ -182,2 +183,3 @@ struct cgit_config {
int nocache;
+ int noplainemail;
int noheader;
@@ -188,2 +190,3 @@ struct cgit_config {
int summary_tags;
+ struct string_list mimetypes;
struct cgit_filter *about_filter;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index d8e4b97..4d656fe 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -162,2 +162,6 @@ max-stats::
+mimetype.<ext>::
+ Set the mimetype for the specified filename extension. This is used
+ by the `plain` command when returning blob content.
+
module-link::
@@ -173,2 +177,6 @@ nocache::
+noplainemail::
+ If set to "1" showing full author email adresses will be disabled.
+ Default value: "0".
+
noheader::
@@ -357,2 +365,15 @@ snapshots=tar.gz tar.bz2 zip
##
+## List of common mimetypes
+##
+
+mimetype.git=image/git
+mimetype.html=text/html
+mimetype.jpg=image/jpeg
+mimetype.jpeg=image/jpeg
+mimetype.pdf=application/pdf
+mimetype.png=image/png
+mimetype.svg=image/svg+xml
+
+
+##
## List of repositories.
diff --git a/ui-atom.c b/ui-atom.c
index e5c31d9..808b2d0 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -34,3 +34,3 @@ void add_entry(struct commit *commit, char *host)
}
- if (info->author_email) {
+ if (info->author_email && !ctx.cfg.noplainemail) {
mail = xstrdup(info->author_email);
diff --git a/ui-commit.c b/ui-commit.c
index 5815b58..d6b73ee 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -42,4 +42,6 @@ void cgit_print_commit(char *hex)
html_txt(info->author);
- html(" ");
- html_txt(info->author_email);
+ if (!ctx.cfg.noplainemail) {
+ html(" ");
+ html_txt(info->author_email);
+ }
html("</td><td class='right'>");
@@ -49,4 +51,6 @@ void cgit_print_commit(char *hex)
html_txt(info->committer);
- html(" ");
- html_txt(info->committer_email);
+ if (!ctx.cfg.noplainemail) {
+ html(" ");
+ html_txt(info->committer_email);
+ }
html("</td><td class='right'>");
diff --git a/ui-patch.c b/ui-patch.c
index 5d665d3..2a8f7a5 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -110,3 +110,7 @@ void cgit_print_patch(char *hex)
htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1));
- htmlf("From: %s %s\n", info->author, info->author_email);
+ htmlf("From: %s", info->author);
+ if (!ctx.cfg.noplainemail) {
+ htmlf(" %s", info->author_email);
+ }
+ html("\n");
html("Date: ");
diff --git a/ui-plain.c b/ui-plain.c
index 93a3a05..27c6dae 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -19,4 +19,5 @@ static void print_object(const unsigned char *sha1, const char *path)
enum object_type type;
- char *buf;
+ char *buf, *ext;
unsigned long size;
+ struct string_list_item *mime;
@@ -33,6 +34,15 @@ static void print_object(const unsigned char *sha1, const char *path)
}
- if (buffer_is_binary(buf, size))
- ctx.page.mimetype = "application/octet-stream";
- else
- ctx.page.mimetype = "text/plain";
+ ctx.page.mimetype = NULL;
+ ext = strrchr(path, '.');
+ if (ext && *(++ext)) {
+ mime = string_list_lookup(ext, &ctx.cfg.mimetypes);
+ if (mime)
+ ctx.page.mimetype = (char *)mime->util;
+ }
+ if (!ctx.page.mimetype) {
+ if (buffer_is_binary(buf, size))
+ ctx.page.mimetype = "application/octet-stream";
+ else
+ ctx.page.mimetype = "text/plain";
+ }
ctx.page.filename = fmt("%s", path);
diff --git a/ui-tag.c b/ui-tag.c
index 0e056e0..a9c8670 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -66,3 +66,3 @@ void cgit_print_tag(char *revname)
html_txt(info->tagger);
- if (info->tagger_email) {
+ if (info->tagger_email && !ctx.cfg.noplainemail) {
html(" ");
diff --git a/ui-tree.c b/ui-tree.c
index caf6a9e..c608754 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -115,2 +115,3 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
char *fullpath;
+ char *class;
enum object_type type;
@@ -147,3 +148,8 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
} else {
- cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head,
+ class = strrchr(name, '.');
+ if (class != NULL) {
+ class = fmt("ls-blob %s", class + 1);
+ } else
+ class = "ls-blob";
+ cgit_tree_link(name, NULL, class, ctx.qry.head,
curr_rev, fullpath);