-rw-r--r-- | parsing.c | 6 | ||||
-rw-r--r-- | ui-shared.c | 4 |
2 files changed, 7 insertions, 3 deletions
@@ -198,60 +198,60 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) 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" while (!strncmp(p, "parent ", 7)) p += 48; // "parent " + hex[40] + "\n" if (!strncmp(p, "author ", 7)) { p += 7; t = strchr(p, '<') - 1; ret->author = substr(p, t); p = t; t = strchr(t, '>') + 1; ret->author_email = substr(p, t); - ret->author_date = atol(++t); + ret->author_date = atol(t+1); p = strchr(t, '\n') + 1; } if (!strncmp(p, "committer ", 9)) { p += 9; t = strchr(p, '<') - 1; ret->committer = substr(p, t); p = t; t = strchr(t, '>') + 1; ret->committer_email = substr(p, t); - ret->committer_date = atol(++t); + ret->committer_date = atol(t+1); 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) { if (*t == '\0') ret->subject = "** empty **"; else ret->subject = substr(p, t); p = t + 1; @@ -294,39 +294,39 @@ struct taginfo *cgit_parse_tag(struct tag *tag) if (!data || type != OBJ_TAG) { free(data); return 0; } ret = xmalloc(sizeof(*ret)); ret->tagger = NULL; ret->tagger_email = NULL; ret->tagger_date = 0; ret->msg = NULL; p = data; while (p && *p) { if (*p == '\n') break; if (!strncmp(p, "tagger ", 7)) { p += 7; t = strchr(p, '<') - 1; ret->tagger = substr(p, t); p = t; t = strchr(t, '>') + 1; ret->tagger_email = substr(p, t); - ret->tagger_date = atol(++t); + ret->tagger_date = atol(t+1); } p = strchr(p, '\n') + 1; } while (p && *p && (*p != '\n')) p = strchr(p, '\n') + 1; // skip unknown tag fields while (p && (*p == '\n')) p = strchr(p, '\n') + 1; if (p && *p) ret->msg = xstrdup(p); free(data); return ret; } diff --git a/ui-shared.c b/ui-shared.c index be2c75d..3e13c86 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -283,57 +283,61 @@ void cgit_object_link(struct object *obj) } else if (obj->type == OBJ_TREE) { page = "tree"; arg = "id"; } else if (obj->type == OBJ_TAG) { page = "tag"; arg = "id"; } else { page = "blob"; arg = "id"; } url = cgit_pageurl(cgit_query_repo, page, fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); html_link_open(url, NULL, NULL); htmlf("%s %s", typename(obj->type), sha1_to_hex(obj->sha1)); html_link_close(); } void cgit_print_date(time_t secs, char *format) { char buf[64]; struct tm *time; + if (!secs) + return; time = gmtime(&secs); strftime(buf, sizeof(buf)-1, format, time); html_txt(buf); } void cgit_print_age(time_t t, time_t max_relative, char *format) { time_t now, secs; + if (!t) + return; time(&now); secs = now - t; if (secs > max_relative && max_relative >= 0) { cgit_print_date(t, format); return; } if (secs < TM_HOUR * 2) { htmlf("<span class='age-mins'>%.0f min.</span>", secs * 1.0 / TM_MIN); return; } if (secs < TM_DAY * 2) { htmlf("<span class='age-hours'>%.0f hours</span>", secs * 1.0 / TM_HOUR); return; } if (secs < TM_WEEK * 2) { htmlf("<span class='age-days'>%.0f days</span>", secs * 1.0 / TM_DAY); return; } if (secs < TM_MONTH * 2) { |