summaryrefslogtreecommitdiff
path: root/src/commit.c
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-05-08 14:13:43 -0700
committerVicent Martí <tanoku@gmail.com>2012-05-08 14:13:43 -0700
commitc99bdacf712d8993bb48c11e204492b4a4dd0990 (patch)
tree490a5b4ac255acd20acc24c20060bf23fea5db7a /src/commit.c
parent364f51bdca8cd5bb11bb322f8cac1b0d7dfcf686 (diff)
parent458b94503d023a07247153f44d34bcc65e6f8103 (diff)
downloadlibgit2-c99bdacf712d8993bb48c11e204492b4a4dd0990.tar.gz
Merge pull request #670 from nulltoken/ntk/topic/clean-commit_message
Clean commit and tag messages
Diffstat (limited to 'src/commit.c')
-rw-r--r--src/commit.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/commit.c b/src/commit.c
index 04f37fe16..2bf12f3a5 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -14,6 +14,7 @@
#include "odb.h"
#include "commit.h"
#include "signature.h"
+#include "message.h"
#include <stdarg.h>
@@ -161,7 +162,7 @@ int git_commit_create(
int parent_count,
const git_commit *parents[])
{
- git_buf commit = GIT_BUF_INIT;
+ git_buf commit = GIT_BUF_INIT, cleaned_message = GIT_BUF_INIT;
int i;
git_odb *odb;
@@ -181,11 +182,16 @@ int git_commit_create(
git_buf_printf(&commit, "encoding %s\n", message_encoding);
git_buf_putc(&commit, '\n');
- git_buf_puts(&commit, message);
- if (git_buf_oom(&commit))
+ /* Remove comments by default */
+ if (git_message_prettify(&cleaned_message, message, 1) < 0)
goto on_error;
+ if (git_buf_puts(&commit, git_buf_cstr(&cleaned_message)) < 0)
+ goto on_error;
+
+ git_buf_free(&cleaned_message);
+
if (git_repository_odb__weakptr(&odb, repo) < 0)
goto on_error;
@@ -201,6 +207,8 @@ int git_commit_create(
on_error:
git_buf_free(&commit);
+ git_buf_free(&cleaned_message);
+ giterr_set(GITERR_OBJECT, "Failed to create commit.");
return -1;
}