Fix parsing of commits that have no newlines in the message.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
diff --git a/src/commit.c b/src/commit.c
index 4dbd771..08243f5 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -176,14 +176,15 @@ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int
char *line_end;
size_t message_len = buffer_end - buffer;
- /* Short message */
+ /* Long message */
message_len = buffer_end - buffer;
commit->message = git__malloc(message_len + 1);
memcpy(commit->message, buffer, message_len);
commit->message[message_len] = 0;
- /* Long message */
- line_end = memchr(buffer, '\n', buffer_end - buffer);
+ /* Short message */
+ if((line_end = memchr(buffer, '\n', buffer_end - buffer)) == NULL)
+ line_end = buffer_end;
message_len = line_end - buffer;
commit->message_short = git__malloc(message_len + 1);
diff --git a/tests/t0401-parse.c b/tests/t0401-parse.c
index 0ce59fc..331d389 100644
--- a/tests/t0401-parse.c
+++ b/tests/t0401-parse.c
@@ -71,11 +71,19 @@ committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
\n\
a simple commit which works\n",
-/* simple commit, 1 parents */
+/* simple commit, no parent, no newline in message */
"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
\n\
+a simple commit which works",
+
+/* simple commit, 1 parent */
+"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
+parent e90810b8df3e80c413d903f631643c716887138d\n\
+author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
+committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
+\n\
a simple commit which works\n",
};
@@ -210,7 +218,7 @@ BEGIN_TEST(parse_person_test)
"author ");
#undef TEST_PERSON_PASS
-#undef TESt_PERSON_FAIL
+#undef TEST_PERSON_FAIL
END_TEST
@@ -252,6 +260,16 @@ BEGIN_TEST(parse_buffer_test)
commit,
test_commits_working[i],
strlen(test_commits_working[i]),
+ 0x0)
+ );
+
+ memset(commit, 0x0, sizeof(git_commit));
+ commit->object.repo = repo;
+
+ must_pass(commit_parse_buffer(
+ commit,
+ test_commits_working[i],
+ strlen(test_commits_working[i]),
0x1)
);