diff options
author | nulltoken <emeric.fermas@gmail.com> | 2013-10-02 12:42:41 +0200 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2013-10-03 07:59:55 +0200 |
commit | 598f069b998c42c12439f3f353b6d075905becba (patch) | |
tree | 071f4d9bd0ebd9b626ad831909bc2912cd4638d8 /src/commit.c | |
parent | 5bfead1dba919f6b47f52da675ea94407e8baf49 (diff) | |
download | libgit2-598f069b998c42c12439f3f353b6d075905becba.tar.gz |
commit: Introduce git_commit_message_raw()
Diffstat (limited to 'src/commit.c')
-rw-r--r-- | src/commit.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/commit.c b/src/commit.c index ab475a8f8..91b60bbb2 100644 --- a/src/commit.c +++ b/src/commit.c @@ -29,7 +29,7 @@ void git_commit__free(void *_commit) git_signature_free(commit->committer); git__free(commit->raw_header); - git__free(commit->message); + git__free(commit->raw_message); git__free(commit->message_encoding); git__free(commit); @@ -240,13 +240,13 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj) buffer_end = buffer + git_odb_object_size(odb_obj); buffer += header_len; - while (buffer < buffer_end && *buffer == '\n') + if (*buffer == '\n') ++buffer; /* extract commit message */ if (buffer <= buffer_end) { - commit->message = git__strndup(buffer, buffer_end - buffer); - GITERR_CHECK_ALLOC(commit->message); + commit->raw_message = git__strndup(buffer, buffer_end - buffer); + GITERR_CHECK_ALLOC(commit->raw_message); } return 0; @@ -265,7 +265,7 @@ bad_buffer: GIT_COMMIT_GETTER(const git_signature *, author, commit->author) GIT_COMMIT_GETTER(const git_signature *, committer, commit->committer) -GIT_COMMIT_GETTER(const char *, message, commit->message) +GIT_COMMIT_GETTER(const char *, message_raw, commit->raw_message) GIT_COMMIT_GETTER(const char *, message_encoding, commit->message_encoding) GIT_COMMIT_GETTER(const char *, raw_header, commit->raw_header) GIT_COMMIT_GETTER(git_time_t, time, commit->committer->when.time) @@ -273,6 +273,19 @@ GIT_COMMIT_GETTER(int, time_offset, commit->committer->when.offset) GIT_COMMIT_GETTER(unsigned int, parentcount, (unsigned int)git_array_size(commit->parent_ids)) GIT_COMMIT_GETTER(const git_oid *, tree_id, &commit->tree_id); +const char *git_commit_message(const git_commit *commit) +{ + const char *message = commit->raw_message; + + assert(commit); + + /* trim leading newlines from raw message */ + while (*message && *message == '\n') + ++message; + + return message; +} + int git_commit_tree(git_tree **tree_out, const git_commit *commit) { assert(commit); |