summaryrefslogtreecommitdiff
path: root/src/commit.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-06-11 08:24:58 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-06-11 08:24:58 +0200
commit65d69fe854ceeb65eeaed7f38a1f4a4771532b9d (patch)
tree55d6875d7962ba2bdd757dc5b604c365376a8737 /src/commit.c
parentfa934fabf76c06e843e9bb22d6679b3e882c3e4e (diff)
downloadlibgit2-cmn/double-author.tar.gz
commit: ignore multiple author fieldscmn/double-author
Some tools create multiple author fields. git is rather lax when parsing them, although fsck does complain about them. This means that they exist in the wild. As it's not too taxing to check for them, and there shouldn't be a noticeable slowdown when dealing with correct commits, add logic to skip over these extra fields when parsing the commit.
Diffstat (limited to 'src/commit.c')
-rw-r--r--src/commit.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/commit.c b/src/commit.c
index 84f24c6cf..ce13bdb85 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -309,6 +309,7 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj)
const char *buffer_end = buffer_start + git_odb_object_size(odb_obj);
git_oid parent_id;
size_t header_len;
+ git_signature dummy_sig;
buffer = buffer_start;
@@ -337,6 +338,15 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj)
if (git_signature__parse(commit->author, &buffer, buffer_end, "author ", '\n') < 0)
return -1;
+ /* Some tools create multiple author fields, ignore the extra ones */
+ while ((size_t)(buffer_end - buffer) >= strlen("author ") && !git__prefixcmp(buffer, "author ")) {
+ if (git_signature__parse(&dummy_sig, &buffer, buffer_end, "author ", '\n') < 0)
+ return -1;
+
+ git__free(dummy_sig.name);
+ git__free(dummy_sig.email);
+ }
+
/* Always parse the committer; we need the commit time */
commit->committer = git__malloc(sizeof(git_signature));
GITERR_CHECK_ALLOC(commit->committer);