aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
@@ -17,6 +17,14 @@
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)
{
struct cgit_filter *f;
@@ -66,6 +74,8 @@ void config_cb(const char *name, const char *value)
ctx.cfg.virtual_root = "";
} else if (!strcmp(name, "nocache"))
ctx.cfg.nocache = atoi(value);
+ else if (!strcmp(name, "noplainemail"))
+ ctx.cfg.noplainemail = atoi(value);
else if (!strcmp(name, "noheader"))
ctx.cfg.noheader = atoi(value);
else if (!strcmp(name, "snapshots"))
@@ -122,6 +132,8 @@ void config_cb(const char *name, const char *value)
ctx.cfg.clone_prefix = xstrdup(value);
else if (!strcmp(name, "local-time"))
ctx.cfg.local_time = atoi(value);
+ else if (!prefixcmp(name, "mimetype."))
+ add_mimetype(name + 9, value);
else if (!strcmp(name, "repo.group"))
ctx.cfg.repo_group = xstrdup(value);
else if (!strcmp(name, "repo.url"))
@@ -240,6 +252,7 @@ static void prepare_context(struct cgit_context *ctx)
ctx->page.modified = time(NULL);
ctx->page.expires = ctx->page.modified;
ctx->page.etag = NULL;
+ memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list));
}
struct refmatch {
diff --git a/cgit.h b/cgit.h
index b8f4850..4c854ea 100644
--- a/cgit.h
+++ b/cgit.h
@@ -15,6 +15,7 @@
#include <revision.h>
#include <log-tree.h>
#include <archive.h>
+#include <string-list.h>
#include <xdiff-interface.h>
#include <xdiff/xdiff.h>
#include <utf8.h>
@@ -180,12 +181,14 @@ struct cgit_config {
int max_repodesc_len;
int max_stats;
int nocache;
+ int noplainemail;
int noheader;
int renamelimit;
int snapshots;
int summary_branches;
int summary_log;
int summary_tags;
+ struct string_list mimetypes;
struct cgit_filter *about_filter;
struct cgit_filter *commit_filter;
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::
"month", "quarter" and "year". If unspecified, statistics are
disabled. Default value: none. See also: "repo.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::
Text which will be used as the formatstring for a hyperlink when a
submodule is printed in a directory listing. The arguments for the
@@ -171,6 +175,10 @@ nocache::
deprecated, and will not be honored starting with cgit-1.0. Default
value: "0".
+noplainemail::
+ If set to "1" showing full author email adresses will be disabled.
+ Default value: "0".
+
noheader::
Flag which, when set to "1", will make cgit omit the standard header
on all pages. Default value: none. See also: "embedded".
@@ -355,6 +363,19 @@ 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.
## PS: Any repositories listed when repo.group is unset will not be
## displayed under a group heading
diff --git a/ui-atom.c b/ui-atom.c
index e5c31d9..808b2d0 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -32,7 +32,7 @@ void add_entry(struct commit *commit, char *host)
html_txt(info->author);
html("</name>\n");
}
- if (info->author_email) {
+ if (info->author_email && !ctx.cfg.noplainemail) {
mail = xstrdup(info->author_email);
t = strchr(mail, '<');
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)
html("<table summary='commit info' class='commit-info'>\n");
html("<tr><th>author</th><td>");
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'>");
cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
html("</td></tr>\n");
html("<tr><th>committer</th><td>");
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'>");
cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
html("</td></tr>\n");
diff --git a/ui-patch.c b/ui-patch.c
index 5d665d3..2a8f7a5 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -108,7 +108,11 @@ void cgit_print_patch(char *hex)
ctx.page.filename = patchname;
cgit_print_http_headers(&ctx);
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: ");
cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time);
htmlf("Subject: %s\n\n", info->subject);
diff --git a/ui-plain.c b/ui-plain.c
index 93a3a05..27c6dae 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -17,8 +17,9 @@ int match;
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;
type = sha1_object_info(sha1, &size);
if (type == OBJ_BAD) {
@@ -31,10 +32,19 @@ static void print_object(const unsigned char *sha1, const char *path)
html_status(404, "Not found", 0);
return;
}
- 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);
ctx.page.size = size;
ctx.page.etag = sha1_to_hex(sha1);
diff --git a/ui-tag.c b/ui-tag.c
index 0e056e0..a9c8670 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -64,7 +64,7 @@ void cgit_print_tag(char *revname)
if (info->tagger) {
html("<tr><td>Tagged by</td><td>");
html_txt(info->tagger);
- if (info->tagger_email) {
+ if (info->tagger_email && !ctx.cfg.noplainemail) {
html(" ");
html_txt(info->tagger_email);
}
diff --git a/ui-tree.c b/ui-tree.c
index caf6a9e..c608754 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -113,6 +113,7 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
{
char *name;
char *fullpath;
+ char *class;
enum object_type type;
unsigned long size = 0;
@@ -145,7 +146,12 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head,
curr_rev, fullpath);
} 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);
}
htmlf("</td><td class='ls-size'>%li</td>", size);