- ret->author = NULL;
- ret->author_email = NULL;
- ret->committer = NULL;
- ret->committer_email = NULL;
- ret->subject = NULL;
- ret->msg = NULL;
-
- 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);
- p = strchr(t, '\n') + 1;
+
+ if (!p)
+ return ret;
+
+ if (!skip_prefix(p, "tree ", &p))
+ die("Bad commit: %s", oid_to_hex(&commit->object.oid));
+ p += sha1hex_len + 1;
+
+ while (skip_prefix(p, "parent ", &p))
+ p += sha1hex_len + 1;
+
+ if (p && skip_prefix(p, "author ", &p)) {
+ parse_user(p, &ret->author, &ret->author_email,
+ &ret->author_date, &ret->author_tz);
+ p = next_header_line(p);
+ }
+
+ if (p && skip_prefix(p, "committer ", &p)) {
+ parse_user(p, &ret->committer, &ret->committer_email,
+ &ret->committer_date, &ret->committer_tz);
+ p = next_header_line(p);