summaryrefslogtreecommitdiff
path: root/src/commit.c
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-12-03 02:11:55 -0800
committerVicent Martí <vicent@github.com>2013-12-03 02:11:55 -0800
commitdb0a7e39b3b168818cc71c409b1375a818c958c5 (patch)
treea4b66b917439ad930aa18d1b104cb8eda13aca66 /src/commit.c
parent96fb6a647f07e59b44551b23c000a44185cf5879 (diff)
parentbab0b9f2d21d993c3f25ee00ce2d243a4dc0de93 (diff)
downloadlibgit2-db0a7e39b3b168818cc71c409b1375a818c958c5.tar.gz
Merge pull request #1977 from ethomson/revert
Revert support for a single commit
Diffstat (limited to 'src/commit.c')
-rw-r--r--src/commit.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/commit.c b/src/commit.c
index 91b60bbb2..bbb76f350 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -31,6 +31,7 @@ void git_commit__free(void *_commit)
git__free(commit->raw_header);
git__free(commit->raw_message);
git__free(commit->message_encoding);
+ git__free(commit->summary);
git__free(commit);
}
@@ -286,6 +287,34 @@ const char *git_commit_message(const git_commit *commit)
return message;
}
+const char *git_commit_summary(git_commit *commit)
+{
+ git_buf summary = GIT_BUF_INIT;
+ const char *msg, *space;
+
+ assert(commit);
+
+ if (!commit->summary) {
+ for (msg = git_commit_message(commit), space = NULL; *msg; ++msg) {
+ if (msg[0] == '\n' && (!msg[1] || msg[1] == '\n'))
+ break;
+ else if (msg[0] == '\n')
+ git_buf_putc(&summary, ' ');
+ else if (git__isspace(msg[0]))
+ space = space ? space : msg;
+ else if (space) {
+ git_buf_put(&summary, space, (msg - space) + 1);
+ space = NULL;
+ } else
+ git_buf_putc(&summary, *msg);
+ }
+
+ commit->summary = git_buf_detach(&summary);
+ }
+
+ return commit->summary;
+}
+
int git_commit_tree(git_tree **tree_out, const git_commit *commit)
{
assert(commit);