]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'iconv-rebased' of http://x2a.org/pub/git/cgit
authorLars Hjemli <hjemli@gmail.com>
Mon, 5 Nov 2007 23:38:18 +0000 (00:38 +0100)
committerLars Hjemli <hjemli@gmail.com>
Mon, 5 Nov 2007 23:38:18 +0000 (00:38 +0100)
* 'iconv-rebased' of http://x2a.org/pub/git/cgit:
  Use utf8::reencode_string from git
  Convert subject and message with iconv_msg.
  Add iconv_msg function.
  Set msg_encoding according to the header.
  Add commit->msg_encoding, allocate msg dynamicly.

cgit.h
parsing.c
shared.c
ui-shared.c

diff --git a/cgit.h b/cgit.h
index 163f355a022dab2dbbdb6f61b6040bacf3730c68..6291c585d57536ac69e00993e347152b096ad949 100644 (file)
--- a/cgit.h
+++ b/cgit.h
@@ -16,6 +16,7 @@
 #include <log-tree.h>
 #include <archive.h>
 #include <xdiff/xdiff.h>
+#include <utf8.h>
 
 
 /*
 #define TM_MONTH (TM_YEAR / 12.0)
 
 
+/*
+ * Default encoding
+ */
+#define PAGE_ENCODING "UTF-8"
+
 typedef void (*configfn)(const char *name, const char *value);
 typedef void (*filepair_fn)(struct diff_filepair *pair);
 typedef void (*linediff_fn)(char *line, int len);
@@ -90,6 +96,7 @@ struct commitinfo {
        unsigned long committer_date;
        char *subject;
        char *msg;
+       char *msg_encoding;
 };
 
 struct taginfo {
index 30e7648958789fb72930c405d1ba8d8c5a382f27..e8c7ab986ae563424c98d1d21fe3549e2f27b22f 100644 (file)
--- a/parsing.c
+++ b/parsing.c
@@ -199,6 +199,7 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
        ret->committer_email = NULL;
        ret->subject = NULL;
        ret->msg = NULL;
+       ret->msg_encoding = NULL;
 
        if (p == NULL)
                return ret;
@@ -233,6 +234,14 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
                p = strchr(t, '\n') + 1;
        }
 
+       if (!strncmp(p, "encoding ", 9)) {
+               p += 9;
+               t = strchr(p, '\n') + 1;
+               ret->msg_encoding = substr(p, t);
+               p = t;
+       } else
+               ret->msg_encoding = xstrdup(PAGE_ENCODING);
+
        while (*p && (*p != '\n'))
                p = strchr(p, '\n') + 1; // skip unknown header fields
 
@@ -253,6 +262,22 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
        } else
                ret->subject = substr(p, p+strlen(p));
 
+       if(strcmp(ret->msg_encoding, PAGE_ENCODING)) {
+               t = reencode_string(ret->subject, PAGE_ENCODING,
+                                   ret->msg_encoding);
+               if(t) {
+                       free(ret->subject);
+                       ret->subject = t;
+               }
+
+               t = reencode_string(ret->msg, PAGE_ENCODING,
+                                   ret->msg_encoding);
+               if(t) {
+                       free(ret->msg);
+                       ret->msg = t;
+               }
+       }
+
        return ret;
 }
 
index e06df91bb8c74a617fa95d67e8b0737b4a1099cb..a04c4dc7eece8257c9d3145f72e4bea0e8b17148 100644 (file)
--- a/shared.c
+++ b/shared.c
@@ -265,6 +265,8 @@ void *cgit_free_commitinfo(struct commitinfo *info)
        free(info->committer);
        free(info->committer_email);
        free(info->subject);
+       free(info->msg);
+       free(info->msg_encoding);
        free(info);
        return NULL;
 }
index 72a7b44472ddb483b9bc6640d029380ac11afd8b..7c69f60f80a5a8dd495b73497132693297496a81 100644 (file)
@@ -352,7 +352,7 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
 
 void cgit_print_docstart(char *title, struct cacheitem *item)
 {
-       html("Content-Type: text/html; charset=utf-8\n");
+       html("Content-Type: text/html; charset=" PAGE_ENCODING "\n");
        htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
        htmlf("Expires: %s\n", http_date(item->st.st_mtime +
                                         ttl_seconds(item->ttl)));