|
diff --git a/shared.c b/shared.c index 50fe8e1..e06df91 100644 --- a/ shared.c+++ b/ shared.c |
|
@@ -258,96 +258,127 @@ void cgit_querystring_cb(const char *name, const char *value) |
258 | } |
258 | } |
259 | } |
259 | } |
260 | |
260 | |
261 | void *cgit_free_commitinfo(struct commitinfo *info) |
261 | void *cgit_free_commitinfo(struct commitinfo *info) |
262 | { |
262 | { |
263 | free(info->author); |
263 | free(info->author); |
264 | free(info->author_email); |
264 | free(info->author_email); |
265 | free(info->committer); |
265 | free(info->committer); |
266 | free(info->committer_email); |
266 | free(info->committer_email); |
267 | free(info->subject); |
267 | free(info->subject); |
268 | free(info); |
268 | free(info); |
269 | return NULL; |
269 | return NULL; |
270 | } |
270 | } |
271 | |
271 | |
272 | int hextoint(char c) |
272 | int hextoint(char c) |
273 | { |
273 | { |
274 | if (c >= 'a' && c <= 'f') |
274 | if (c >= 'a' && c <= 'f') |
275 | return 10 + c - 'a'; |
275 | return 10 + c - 'a'; |
276 | else if (c >= 'A' && c <= 'F') |
276 | else if (c >= 'A' && c <= 'F') |
277 | return 10 + c - 'A'; |
277 | return 10 + c - 'A'; |
278 | else if (c >= '0' && c <= '9') |
278 | else if (c >= '0' && c <= '9') |
279 | return c - '0'; |
279 | return c - '0'; |
280 | else |
280 | else |
281 | return -1; |
281 | return -1; |
282 | } |
282 | } |
283 | |
283 | |
284 | char *trim_end(const char *str, char c) |
284 | char *trim_end(const char *str, char c) |
285 | { |
285 | { |
286 | int len; |
286 | int len; |
287 | char *s, *t; |
287 | char *s, *t; |
288 | |
288 | |
289 | if (str == NULL) |
289 | if (str == NULL) |
290 | return NULL; |
290 | return NULL; |
291 | t = (char *)str; |
291 | t = (char *)str; |
292 | len = strlen(t); |
292 | len = strlen(t); |
293 | while(len > 0 && t[len - 1] == c) |
293 | while(len > 0 && t[len - 1] == c) |
294 | len--; |
294 | len--; |
295 | |
295 | |
296 | if (len == 0) |
296 | if (len == 0) |
297 | return NULL; |
297 | return NULL; |
298 | |
298 | |
299 | c = t[len]; |
299 | c = t[len]; |
300 | t[len] = '\0'; |
300 | t[len] = '\0'; |
301 | s = xstrdup(t); |
301 | s = xstrdup(t); |
302 | t[len] = c; |
302 | t[len] = c; |
303 | return s; |
303 | return s; |
304 | } |
304 | } |
305 | |
305 | |
| |
306 | char *strlpart(char *txt, int maxlen) |
| |
307 | { |
| |
308 | char *result; |
| |
309 | |
| |
310 | if (!txt) |
| |
311 | return txt; |
| |
312 | |
| |
313 | if (strlen(txt) <= maxlen) |
| |
314 | return txt; |
| |
315 | result = xmalloc(maxlen + 1); |
| |
316 | memcpy(result, txt, maxlen - 3); |
| |
317 | result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.'; |
| |
318 | result[maxlen] = '\0'; |
| |
319 | return result; |
| |
320 | } |
| |
321 | |
| |
322 | char *strrpart(char *txt, int maxlen) |
| |
323 | { |
| |
324 | char *result; |
| |
325 | |
| |
326 | if (!txt) |
| |
327 | return txt; |
| |
328 | |
| |
329 | if (strlen(txt) <= maxlen) |
| |
330 | return txt; |
| |
331 | result = xmalloc(maxlen + 1); |
| |
332 | memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3); |
| |
333 | result[0] = result[1] = result[2] = '.'; |
| |
334 | return result; |
| |
335 | } |
| |
336 | |
306 | void cgit_add_ref(struct reflist *list, struct refinfo *ref) |
337 | void cgit_add_ref(struct reflist *list, struct refinfo *ref) |
307 | { |
338 | { |
308 | size_t size; |
339 | size_t size; |
309 | |
340 | |
310 | if (list->count >= list->alloc) { |
341 | if (list->count >= list->alloc) { |
311 | list->alloc += (list->alloc ? list->alloc : 4); |
342 | list->alloc += (list->alloc ? list->alloc : 4); |
312 | size = list->alloc * sizeof(struct refinfo *); |
343 | size = list->alloc * sizeof(struct refinfo *); |
313 | list->refs = xrealloc(list->refs, size); |
344 | list->refs = xrealloc(list->refs, size); |
314 | } |
345 | } |
315 | list->refs[list->count++] = ref; |
346 | list->refs[list->count++] = ref; |
316 | } |
347 | } |
317 | |
348 | |
318 | struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) |
349 | struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) |
319 | { |
350 | { |
320 | struct refinfo *ref; |
351 | struct refinfo *ref; |
321 | |
352 | |
322 | ref = xmalloc(sizeof (struct refinfo)); |
353 | ref = xmalloc(sizeof (struct refinfo)); |
323 | ref->refname = xstrdup(refname); |
354 | ref->refname = xstrdup(refname); |
324 | ref->object = parse_object(sha1); |
355 | ref->object = parse_object(sha1); |
325 | switch (ref->object->type) { |
356 | switch (ref->object->type) { |
326 | case OBJ_TAG: |
357 | case OBJ_TAG: |
327 | ref->tag = cgit_parse_tag((struct tag *)ref->object); |
358 | ref->tag = cgit_parse_tag((struct tag *)ref->object); |
328 | break; |
359 | break; |
329 | case OBJ_COMMIT: |
360 | case OBJ_COMMIT: |
330 | ref->commit = cgit_parse_commit((struct commit *)ref->object); |
361 | ref->commit = cgit_parse_commit((struct commit *)ref->object); |
331 | break; |
362 | break; |
332 | } |
363 | } |
333 | return ref; |
364 | return ref; |
334 | } |
365 | } |
335 | |
366 | |
336 | int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, |
367 | int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, |
337 | void *cb_data) |
368 | void *cb_data) |
338 | { |
369 | { |
339 | struct reflist *list = (struct reflist *)cb_data; |
370 | struct reflist *list = (struct reflist *)cb_data; |
340 | struct refinfo *info = cgit_mk_refinfo(refname, sha1); |
371 | struct refinfo *info = cgit_mk_refinfo(refname, sha1); |
341 | |
372 | |
342 | if (info) |
373 | if (info) |
343 | cgit_add_ref(list, info); |
374 | cgit_add_ref(list, info); |
344 | return 0; |
375 | return 0; |
345 | } |
376 | } |
346 | |
377 | |
347 | void cgit_diff_tree_cb(struct diff_queue_struct *q, |
378 | void cgit_diff_tree_cb(struct diff_queue_struct *q, |
348 | struct diff_options *options, void *data) |
379 | struct diff_options *options, void *data) |
349 | { |
380 | { |
350 | int i; |
381 | int i; |
351 | |
382 | |
352 | for (i = 0; i < q->nr; i++) { |
383 | for (i = 0; i < q->nr; i++) { |
353 | if (q->queue[i]->status == 'U') |
384 | if (q->queue[i]->status == 'U') |
|