diff options
Diffstat (limited to 'src/commit.c')
| -rw-r--r-- | src/commit.c | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/src/commit.c b/src/commit.c index 4ddfafb41..730fa6403 100644 --- a/src/commit.c +++ b/src/commit.c @@ -69,7 +69,7 @@ int git_commit_create_v( return res; } -int git_commit_create_from_oids( +int git_commit_create_from_ids( git_oid *oid, git_repository *repo, const char *update_ref, @@ -112,7 +112,7 @@ int git_commit_create_from_oids( git_buf_free(&commit); if (update_ref != NULL) - return git_reference__update_terminal(repo, update_ref, oid); + return git_reference__update_terminal(repo, update_ref, oid, NULL, NULL); return 0; @@ -148,7 +148,7 @@ int git_commit_create( parent_oids[i] = git_object_id((const git_object *)parents[i]); } - retval = git_commit_create_from_oids( + retval = git_commit_create_from_ids( oid, repo, update_ref, author, committer, message_encoding, message, git_object_id((const git_object *)tree), parent_count, parent_oids); @@ -164,33 +164,15 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj) const char *buffer_start = git_odb_object_data(odb_obj), *buffer; const char *buffer_end = buffer_start + git_odb_object_size(odb_obj); git_oid parent_id; - uint32_t parent_count = 0; size_t header_len; - /* find end-of-header (counting parents as we go) */ - for (buffer = buffer_start; buffer < buffer_end; ++buffer) { - if (!strncmp("\n\n", buffer, 2)) { - ++buffer; - break; - } - if (!strncmp("\nparent ", buffer, strlen("\nparent "))) - ++parent_count; - } - - header_len = buffer - buffer_start; - commit->raw_header = git__strndup(buffer_start, header_len); - GITERR_CHECK_ALLOC(commit->raw_header); + buffer = buffer_start; - /* point "buffer" to header data */ - buffer = commit->raw_header; - buffer_end = commit->raw_header + header_len; - - if (parent_count < 1) - parent_count = 1; - - git_array_init_to_size(commit->parent_ids, parent_count); + /* Allocate for one, which will allow not to realloc 90% of the time */ + git_array_init_to_size(commit->parent_ids, 1); GITERR_CHECK_ARRAY(commit->parent_ids); + /* The tree is always the first field */ if (git_oid__parse(&commit->tree_id, &buffer, buffer_end, "tree ") < 0) goto bad_buffer; @@ -221,6 +203,9 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj) /* Parse add'l header entries */ while (buffer < buffer_end) { const char *eoln = buffer; + if (buffer[-1] == '\n' && buffer[0] == '\n') + break; + while (eoln < buffer_end && *eoln != '\n') ++eoln; @@ -236,13 +221,12 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj) buffer = eoln; } - /* point "buffer" to data after header */ - buffer = git_odb_object_data(odb_obj); - buffer_end = buffer + git_odb_object_size(odb_obj); + header_len = buffer - buffer_start; + commit->raw_header = git__strndup(buffer_start, header_len); + GITERR_CHECK_ALLOC(commit->raw_header); - buffer += header_len; - if (*buffer == '\n') - ++buffer; + /* point "buffer" to data after header, +1 for the final LF */ + buffer = buffer_start + header_len + 1; /* extract commit message */ if (buffer <= buffer_end) { @@ -311,7 +295,10 @@ const char *git_commit_summary(git_commit *commit) git_buf_putc(&summary, *msg); } - commit->summary = git_buf_detach(&summary); + if (summary.asize == 0) + commit->summary = git__strdup(""); + else + commit->summary = git_buf_detach(&summary); } return commit->summary; |
