author | Lars Hjemli <hjemli@gmail.com> | 2007-11-05 23:38:18 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-11-05 23:38:18 (UTC) |
commit | 55ac326ecb01161bf62865ae3350acf85db97d63 (patch) (side-by-side diff) | |
tree | e37bcd8fef5523aa627ec9fdcd3401105f8e579d | |
parent | d04c4734bcf40b1d17c55b18fba2aa8344678e8f (diff) | |
parent | a2ebbd6948da96172108db5e9c02c141923ad05c (diff) | |
download | cgit-55ac326ecb01161bf62865ae3350acf85db97d63.zip cgit-55ac326ecb01161bf62865ae3350acf85db97d63.tar.gz cgit-55ac326ecb01161bf62865ae3350acf85db97d63.tar.bz2 |
Merge branch 'iconv-rebased' of http://x2a.org/pub/git/cgit
* '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.
-rw-r--r-- | cgit.h | 7 | ||||
-rw-r--r-- | parsing.c | 25 | ||||
-rw-r--r-- | shared.c | 2 | ||||
-rw-r--r-- | ui-shared.c | 2 |
4 files changed, 35 insertions, 1 deletions
@@ -11,16 +11,17 @@ #include <tag.h> #include <diff.h> #include <diffcore.h> #include <refs.h> #include <revision.h> #include <log-tree.h> #include <archive.h> #include <xdiff/xdiff.h> +#include <utf8.h> /* * The valid cgit repo-commands */ #define CMD_LOG 1 #define CMD_COMMIT 2 #define CMD_DIFF 3 @@ -43,16 +44,21 @@ #define TM_MIN 60 #define TM_HOUR (TM_MIN * 60) #define TM_DAY (TM_HOUR * 24) #define TM_WEEK (TM_DAY * 7) #define TM_YEAR (TM_DAY * 365) #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); struct cacheitem { char *name; struct stat st; int ttl; @@ -85,16 +91,17 @@ struct commitinfo { char *author; char *author_email; unsigned long author_date; char *committer; char *committer_email; unsigned long committer_date; char *subject; char *msg; + char *msg_encoding; }; struct taginfo { char *tagger; char *tagger_email; int tagger_date; char *msg; }; @@ -194,16 +194,17 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) ret = xmalloc(sizeof(*ret)); ret->commit = commit; ret->author = NULL; ret->author_email = NULL; ret->committer = NULL; ret->committer_email = NULL; ret->subject = NULL; ret->msg = NULL; + ret->msg_encoding = NULL; if (p == NULL) return ret; if (strncmp(p, "tree ", 5)) die("Bad commit: %s", sha1_to_hex(commit->object.sha1)); else p += 46; // "tree " + hex[40] + "\n" @@ -228,16 +229,24 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) ret->committer = substr(p, t); p = t; t = strchr(t, '>') + 1; ret->committer_email = substr(p, t); ret->committer_date = atol(++t); 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 while (*p == '\n') p = strchr(p, '\n') + 1; t = strchr(p, '\n'); if (t) { @@ -248,16 +257,32 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) p = t + 1; while (*p == '\n') p = strchr(p, '\n') + 1; ret->msg = xstrdup(p); } 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; } struct taginfo *cgit_parse_tag(struct tag *tag) { void *data; enum object_type type; @@ -260,16 +260,18 @@ void cgit_querystring_cb(const char *name, const char *value) void *cgit_free_commitinfo(struct commitinfo *info) { free(info->author); free(info->author_email); free(info->committer); free(info->committer_email); free(info->subject); + free(info->msg); + free(info->msg_encoding); free(info); return NULL; } int hextoint(char c) { if (c >= 'a' && c <= 'f') return 10 + c - 'a'; diff --git a/ui-shared.c b/ui-shared.c index 72a7b44..7c69f60 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -347,17 +347,17 @@ void cgit_print_age(time_t t, time_t max_relative, char *format) return; } htmlf("<span class='age-years'>%.0f years</span>", secs * 1.0 / TM_YEAR); } 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))); html("\n"); html(cgit_doctype); html("<html>\n"); html("<head>\n"); html("<title>"); |