aboutsummaryrefslogtreecommitdiffstats
path: root/parsing.c
diff options
context:
space:
mode:
Diffstat (limited to 'parsing.c')
-rw-r--r--parsing.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/parsing.c b/parsing.c
index f37c49d..151c0fe 100644
--- a/parsing.c
+++ b/parsing.c
@@ -103,10 +103,17 @@ const char *reencode(char **txt, const char *src_enc, const char *dst_enc)
103{ 103{
104 char *tmp; 104 char *tmp;
105 105
106 if (!txt || !*txt || !src_enc || !dst_enc) 106 if (!txt)
107 return NULL;
108
109 if (!*txt || !src_enc || !dst_enc)
110 return *txt;
111
112 /* no encoding needed if src_enc equals dst_enc */
113 if(!strcasecmp(src_enc, dst_enc))
107 return *txt; 114 return *txt;
108 115
109 tmp = reencode_string(*txt, src_enc, dst_enc); 116 tmp = reencode_string(*txt, dst_enc, src_enc);
110 if (tmp) { 117 if (tmp) {
111 free(*txt); 118 free(*txt);
112 *txt = tmp; 119 *txt = tmp;
@@ -160,6 +167,10 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
160 } 167 }
161 } 168 }
162 169
170 /* if no special encoding is found, assume UTF-8 */
171 if(!ret->msg_encoding)
172 ret->msg_encoding = xstrdup("UTF-8");
173
163 // skip unknown header fields 174 // skip unknown header fields
164 while (p && *p && (*p != '\n')) { 175 while (p && *p && (*p != '\n')) {
165 p = strchr(p, '\n'); 176 p = strchr(p, '\n');
@@ -189,14 +200,12 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
189 } else 200 } else
190 ret->subject = xstrdup(p); 201 ret->subject = xstrdup(p);
191 202
192 if (ret->msg_encoding) { 203 reencode(&ret->author, ret->msg_encoding, PAGE_ENCODING);
193 reencode(&ret->author, PAGE_ENCODING, ret->msg_encoding); 204 reencode(&ret->author_email, ret->msg_encoding, PAGE_ENCODING);
194 reencode(&ret->author_email, PAGE_ENCODING, ret->msg_encoding); 205 reencode(&ret->committer, ret->msg_encoding, PAGE_ENCODING);
195 reencode(&ret->committer, PAGE_ENCODING, ret->msg_encoding); 206 reencode(&ret->committer_email, ret->msg_encoding, PAGE_ENCODING);
196 reencode(&ret->committer_email, PAGE_ENCODING, ret->msg_encoding); 207 reencode(&ret->subject, ret->msg_encoding, PAGE_ENCODING);
197 reencode(&ret->subject, PAGE_ENCODING, ret->msg_encoding); 208 reencode(&ret->msg, ret->msg_encoding, PAGE_ENCODING);
198 reencode(&ret->msg, PAGE_ENCODING, ret->msg_encoding);
199 }
200 209
201 return ret; 210 return ret;
202} 211}