Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/tag.c
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-03-01 20:03:32 +0400
committernulltoken <emeric.fermas@gmail.com>2012-05-07 14:16:04 +0400
commit458b94503d023a07247153f44d34bcc65e6f8103 (patch)
tree02a14a37ebde58cdcf7164f0f362c705e510b201 /src/tag.c
parent9b62e40ecdb92ab7493eac514e1399d791fa6f62 (diff)
commit/tag: ensure the message is cleaned up
'git commit' and 'git tag -a' enforce some conventions, like cleaning up excess whitespace and making sure that the last line ends with a '\n'. This fix replicates this behavior. Fix libgit2/libgit2sharp#117
Diffstat (limited to 'src/tag.c')
-rw-r--r--src/tag.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/tag.c b/src/tag.c
index aa549fdd0..13481c2a6 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -9,6 +9,7 @@
#include "commit.h"
#include "tag.h"
#include "signature.h"
+#include "message.h"
#include "git2/object.h"
#include "git2/repository.h"
#include "git2/signature.h"
@@ -195,7 +196,7 @@ static int write_tag_annotation(
const git_signature *tagger,
const char *message)
{
- git_buf tag = GIT_BUF_INIT;
+ git_buf tag = GIT_BUF_INIT, cleaned_message = GIT_BUF_INIT;
git_odb *odb;
git_oid__writebuf(&tag, "object ", git_object_id(target));
@@ -203,11 +204,16 @@ static int write_tag_annotation(
git_buf_printf(&tag, "tag %s\n", tag_name);
git_signature__writebuf(&tag, "tagger ", tagger);
git_buf_putc(&tag, '\n');
- git_buf_puts(&tag, message);
- if (git_buf_oom(&tag))
+ /* Remove comments by default */
+ if (git_message_prettify(&cleaned_message, message, 1) < 0)
goto on_error;
+ if (git_buf_puts(&tag, 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;
@@ -216,8 +222,11 @@ static int write_tag_annotation(
git_buf_free(&tag);
return 0;
+
on_error:
git_buf_free(&tag);
+ git_buf_free(&cleaned_message);
+ giterr_set(GITERR_OBJECT, "Failed to create tag annotation.");
return -1;
}