|
diff --git a/shared.c b/shared.c index 50fe8e1..e06df91 100644 --- a/ shared.c+++ b/ shared.c |
|
@@ -282,48 +282,79 @@ int hextoint(char c) |
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: |
|