]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'lh/about'
authorLars Hjemli <hjemli@gmail.com>
Sun, 9 Aug 2009 11:46:34 +0000 (13:46 +0200)
committerLars Hjemli <hjemli@gmail.com>
Sun, 9 Aug 2009 11:46:34 +0000 (13:46 +0200)
Conflicts:
cgit.h

cgit.c
cgit.h
cgitrc.5.txt
ui-atom.c
ui-commit.c
ui-patch.c
ui-plain.c
ui-tag.c
ui-tree.c

diff --git a/cgit.c b/cgit.c
index cb1149d44189d17a13bbec97f8aa4f28c84c7f91..7b228af83046faef92602b0a74a6e1e6e58fea47 100644 (file)
--- a/cgit.c
+++ b/cgit.c
 
 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 b8f485047e48d49f1c3fbdd0fe84a6aac6c6b355..4c854eaa8320771466460f18ff0839c73cc2dafc 100644 (file)
--- 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;
index d8e4b97b18f80e4ef50fff0b551b2257e8773eb7..4d656fee5323fb35f0846ec086d7dfbd016d21c3 100644 (file)
@@ -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".
@@ -354,6 +362,19 @@ root-readme=/var/www/htdocs/about.html
 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
index e5c31d9dd066fd7e7a63da846ab6add0b9aea0e6..808b2d0abede36fc73c8633ba36044a9d5547c30 100644 (file)
--- 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)
index 5815b585509d4459bbd4a2b516ac1250a6d609a1..d6b73eed90aaf5ee232e89f5a1655c94db392577 100644 (file)
@@ -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");
index 5d665d3edbe826c01705ef7f009d045860b6e243..2a8f7a573ca8433bdc1e46dcca444202a4431d46 100644 (file)
@@ -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);
index 93a3a05ac50f7a43b3c50529a011f0c9fdbf547c..27c6daec7f1dc71bfd7b8b74c8179467a5d39224 100644 (file)
@@ -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);
index 0e056e016092f53c508d86cdefd3e76f0fcb7d36..a9c867070f9c71a042a99ae7c3a4ddc85dbd5ae5 100644 (file)
--- 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);
                        }
index caf6a9e979bea7d9994e8137f25e0563358abea9..c608754f3e8e930169fda2ad08b7aba00a07cdb1 100644 (file)
--- 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);