diff options
author | Patrick Steinhardt <ps@pks.im> | 2015-12-01 10:03:56 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2015-12-01 10:07:00 +0100 |
commit | 7f8fe1d45e086adc9e7f3f0c33b624eeb3774033 (patch) | |
tree | 638145f66aaa879b564d46e034eb7298a4de8070 /src/commit.c | |
parent | 337b2b08f46ea77d61fa66657ad62d8702bc233a (diff) | |
download | libgit2-7f8fe1d45e086adc9e7f3f0c33b624eeb3774033.tar.gz |
commit: introduce `git_commit_body`
It is already possible to get a commit's summary with the
`git_commit_summary` function. It is not possible to get the
remaining part of the commit message, that is the commit
message's body.
Fix this by introducing a new function `git_commit_body`.
Diffstat (limited to 'src/commit.c')
-rw-r--r-- | src/commit.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/commit.c b/src/commit.c index b42f9de28..81aae489f 100644 --- a/src/commit.c +++ b/src/commit.c @@ -31,6 +31,7 @@ void git_commit__free(void *_commit) git__free(commit->raw_message); git__free(commit->message_encoding); git__free(commit->summary); + git__free(commit->body); git__free(commit); } @@ -472,6 +473,33 @@ const char *git_commit_summary(git_commit *commit) return commit->summary; } +const char *git_commit_body(git_commit *commit) +{ + const char *msg, *end; + + assert(commit); + + if (!commit->body) { + /* search for end of summary */ + for (msg = git_commit_message(commit); *msg; ++msg) + if (msg[0] == '\n' && (!msg[1] || msg[1] == '\n')) + break; + + /* trim leading and trailing whitespace */ + for (; *msg; ++msg) + if (!git__isspace(*msg)) + break; + for (end = msg + strlen(msg) - 1; msg <= end; --end) + if (!git__isspace(*end)) + break; + + if (*msg) + commit->body = git__strndup(msg, end - msg + 1); + } + + return commit->body; +} + int git_commit_tree(git_tree **tree_out, const git_commit *commit) { assert(commit); |