|
diff --git a/parsing.c b/parsing.c index 4420e58..b86467a 100644 --- a/ parsing.c+++ b/ parsing.c |
|
@@ -173,121 +173,126 @@ void cgit_parse_url(const char *url) |
173 | cgit_cmd = cgit_get_cmd_index(cmd + 1); |
173 | cgit_cmd = cgit_get_cmd_index(cmd + 1); |
174 | cgit_query_page = xstrdup(cmd + 1); |
174 | cgit_query_page = xstrdup(cmd + 1); |
175 | return; |
175 | return; |
176 | } |
176 | } |
177 | } |
177 | } |
178 | |
178 | |
179 | char *substr(const char *head, const char *tail) |
179 | char *substr(const char *head, const char *tail) |
180 | { |
180 | { |
181 | char *buf; |
181 | char *buf; |
182 | |
182 | |
183 | buf = xmalloc(tail - head + 1); |
183 | buf = xmalloc(tail - head + 1); |
184 | strncpy(buf, head, tail - head); |
184 | strncpy(buf, head, tail - head); |
185 | buf[tail - head] = '\0'; |
185 | buf[tail - head] = '\0'; |
186 | return buf; |
186 | return buf; |
187 | } |
187 | } |
188 | |
188 | |
189 | struct commitinfo *cgit_parse_commit(struct commit *commit) |
189 | struct commitinfo *cgit_parse_commit(struct commit *commit) |
190 | { |
190 | { |
191 | struct commitinfo *ret; |
191 | struct commitinfo *ret; |
192 | char *p = commit->buffer, *t = commit->buffer; |
192 | char *p = commit->buffer, *t = commit->buffer; |
193 | |
193 | |
194 | ret = xmalloc(sizeof(*ret)); |
194 | ret = xmalloc(sizeof(*ret)); |
195 | ret->commit = commit; |
195 | ret->commit = commit; |
196 | ret->author = NULL; |
196 | ret->author = NULL; |
197 | ret->author_email = NULL; |
197 | ret->author_email = NULL; |
198 | ret->committer = NULL; |
198 | ret->committer = NULL; |
199 | ret->committer_email = NULL; |
199 | ret->committer_email = NULL; |
200 | ret->subject = NULL; |
200 | ret->subject = NULL; |
201 | ret->msg = NULL; |
201 | ret->msg = NULL; |
202 | |
202 | |
203 | if (strncmp(p, "tree ", 5)) |
203 | if (strncmp(p, "tree ", 5)) |
204 | die("Bad commit: %s", sha1_to_hex(commit->object.sha1)); |
204 | die("Bad commit: %s", sha1_to_hex(commit->object.sha1)); |
205 | else |
205 | else |
206 | p += 46; // "tree " + hex[40] + "\n" |
206 | p += 46; // "tree " + hex[40] + "\n" |
207 | |
207 | |
208 | while (!strncmp(p, "parent ", 7)) |
208 | while (!strncmp(p, "parent ", 7)) |
209 | p += 48; // "parent " + hex[40] + "\n" |
209 | p += 48; // "parent " + hex[40] + "\n" |
210 | |
210 | |
211 | if (!strncmp(p, "author ", 7)) { |
211 | if (!strncmp(p, "author ", 7)) { |
212 | p += 7; |
212 | p += 7; |
213 | t = strchr(p, '<') - 1; |
213 | t = strchr(p, '<') - 1; |
214 | ret->author = substr(p, t); |
214 | ret->author = substr(p, t); |
215 | p = t; |
215 | p = t; |
216 | t = strchr(t, '>') + 1; |
216 | t = strchr(t, '>') + 1; |
217 | ret->author_email = substr(p, t); |
217 | ret->author_email = substr(p, t); |
218 | ret->author_date = atol(++t); |
218 | ret->author_date = atol(++t); |
219 | p = strchr(t, '\n') + 1; |
219 | p = strchr(t, '\n') + 1; |
220 | } |
220 | } |
221 | |
221 | |
222 | if (!strncmp(p, "committer ", 9)) { |
222 | if (!strncmp(p, "committer ", 9)) { |
223 | p += 9; |
223 | p += 9; |
224 | t = strchr(p, '<') - 1; |
224 | t = strchr(p, '<') - 1; |
225 | ret->committer = substr(p, t); |
225 | ret->committer = substr(p, t); |
226 | p = t; |
226 | p = t; |
227 | t = strchr(t, '>') + 1; |
227 | t = strchr(t, '>') + 1; |
228 | ret->committer_email = substr(p, t); |
228 | ret->committer_email = substr(p, t); |
229 | ret->committer_date = atol(++t); |
229 | ret->committer_date = atol(++t); |
230 | p = strchr(t, '\n') + 1; |
230 | p = strchr(t, '\n') + 1; |
231 | } |
231 | } |
232 | |
232 | |
233 | while (*p == '\n') |
233 | while (*p == '\n') |
234 | p = strchr(p, '\n') + 1; |
234 | p = strchr(p, '\n') + 1; |
235 | |
235 | |
236 | t = strchr(p, '\n'); |
236 | t = strchr(p, '\n'); |
237 | if (t && *t) { |
237 | if (t) { |
238 | ret->subject = substr(p, t); |
238 | if (*t == '\0') |
| |
239 | ret->subject = strdup("** empty **"); |
| |
240 | else |
| |
241 | ret->subject = substr(p, t); |
239 | p = t + 1; |
242 | p = t + 1; |
240 | |
243 | |
241 | while (*p == '\n') |
244 | while (*p == '\n') |
242 | p = strchr(p, '\n') + 1; |
245 | p = strchr(p, '\n') + 1; |
243 | ret->msg = p; |
246 | ret->msg = p; |
244 | } |
247 | } else |
| |
248 | ret->subject = substr(p, p+strlen(p)); |
| |
249 | |
245 | return ret; |
250 | return ret; |
246 | } |
251 | } |
247 | |
252 | |
248 | |
253 | |
249 | struct taginfo *cgit_parse_tag(struct tag *tag) |
254 | struct taginfo *cgit_parse_tag(struct tag *tag) |
250 | { |
255 | { |
251 | void *data; |
256 | void *data; |
252 | enum object_type type; |
257 | enum object_type type; |
253 | unsigned long size; |
258 | unsigned long size; |
254 | char *p, *t; |
259 | char *p, *t; |
255 | struct taginfo *ret; |
260 | struct taginfo *ret; |
256 | |
261 | |
257 | data = read_sha1_file(tag->object.sha1, &type, &size); |
262 | data = read_sha1_file(tag->object.sha1, &type, &size); |
258 | if (!data || type != OBJ_TAG) { |
263 | if (!data || type != OBJ_TAG) { |
259 | free(data); |
264 | free(data); |
260 | return 0; |
265 | return 0; |
261 | } |
266 | } |
262 | |
267 | |
263 | ret = xmalloc(sizeof(*ret)); |
268 | ret = xmalloc(sizeof(*ret)); |
264 | ret->tagger = NULL; |
269 | ret->tagger = NULL; |
265 | ret->tagger_email = NULL; |
270 | ret->tagger_email = NULL; |
266 | ret->tagger_date = 0; |
271 | ret->tagger_date = 0; |
267 | ret->msg = NULL; |
272 | ret->msg = NULL; |
268 | |
273 | |
269 | p = data; |
274 | p = data; |
270 | |
275 | |
271 | while (p && *p) { |
276 | while (p && *p) { |
272 | if (*p == '\n') |
277 | if (*p == '\n') |
273 | break; |
278 | break; |
274 | |
279 | |
275 | if (!strncmp(p, "tagger ", 7)) { |
280 | if (!strncmp(p, "tagger ", 7)) { |
276 | p += 7; |
281 | p += 7; |
277 | t = strchr(p, '<') - 1; |
282 | t = strchr(p, '<') - 1; |
278 | ret->tagger = substr(p, t); |
283 | ret->tagger = substr(p, t); |
279 | p = t; |
284 | p = t; |
280 | t = strchr(t, '>') + 1; |
285 | t = strchr(t, '>') + 1; |
281 | ret->tagger_email = substr(p, t); |
286 | ret->tagger_email = substr(p, t); |
282 | ret->tagger_date = atol(++t); |
287 | ret->tagger_date = atol(++t); |
283 | } |
288 | } |
284 | p = strchr(p, '\n') + 1; |
289 | p = strchr(p, '\n') + 1; |
285 | } |
290 | } |
286 | |
291 | |
287 | while (p && (*p == '\n')) |
292 | while (p && (*p == '\n')) |
288 | p = strchr(p, '\n') + 1; |
293 | p = strchr(p, '\n') + 1; |
289 | if (p && *p) |
294 | if (p && *p) |
290 | ret->msg = xstrdup(p); |
295 | ret->msg = xstrdup(p); |
291 | free(data); |
296 | free(data); |
292 | return ret; |
297 | return ret; |
293 | } |
298 | } |
|