summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/message.c25
-rw-r--r--src/message.h3
-rw-r--r--src/tag.c11
3 files changed, 27 insertions, 12 deletions
diff --git a/src/message.c b/src/message.c
index aa0220fd0..a4aadb28f 100644
--- a/src/message.c
+++ b/src/message.c
@@ -6,7 +6,6 @@
*/
#include "message.h"
-#include <ctype.h>
static size_t line_length_without_trailing_spaces(const char *line, size_t len)
{
@@ -22,7 +21,7 @@ static size_t line_length_without_trailing_spaces(const char *line, size_t len)
/* Greatly inspired from git.git "stripspace" */
/* see https://github.com/git/git/blob/497215d8811ac7b8955693ceaad0899ecd894ed2/builtin/stripspace.c#L4-67 */
-int git_message_prettify(git_buf *message_out, const char *message, int strip_comments)
+int git_message__prettify(git_buf *message_out, const char *message, int strip_comments)
{
const size_t message_len = strlen(message);
@@ -59,3 +58,25 @@ int git_message_prettify(git_buf *message_out, const char *message, int strip_co
return git_buf_oom(message_out) ? -1 : 0;
}
+
+int git_message_prettify(char *message_out, size_t buffer_size, const char *message, int strip_comments)
+{
+ git_buf buf = GIT_BUF_INIT;
+
+ if (strlen(message) + 1 > buffer_size) { /* We have to account for a potentially missing \n */
+ giterr_set(GITERR_INVALID, "Buffer too short to hold the cleaned message");
+ return -1;
+ }
+
+ *message_out = '\0';
+
+ if (git_message__prettify(&buf, message, strip_comments) < 0) {
+ git_buf_free(&buf);
+ return -1;
+ }
+
+ git_buf_copy_cstr(message_out, buffer_size, &buf);
+ git_buf_free(&buf);
+
+ return 0;
+}
diff --git a/src/message.h b/src/message.h
index ddfa13e18..7e4e7f337 100644
--- a/src/message.h
+++ b/src/message.h
@@ -7,8 +7,9 @@
#ifndef INCLUDE_message_h__
#define INCLUDE_message_h__
+#include "git2/message.h"
#include "buffer.h"
-int git_message_prettify(git_buf *message_out, const char *message, int strip_comments);
+int git_message__prettify(git_buf *message_out, const char *message, int strip_comments);
#endif /* INCLUDE_message_h__ */
diff --git a/src/tag.c b/src/tag.c
index 63424f530..463619f63 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -196,7 +196,7 @@ static int write_tag_annotation(
const git_signature *tagger,
const char *message)
{
- git_buf tag = GIT_BUF_INIT, cleaned_message = GIT_BUF_INIT;
+ git_buf tag = GIT_BUF_INIT;
git_odb *odb;
git_oid__writebuf(&tag, "object ", git_object_id(target));
@@ -205,15 +205,9 @@ static int write_tag_annotation(
git_signature__writebuf(&tag, "tagger ", tagger);
git_buf_putc(&tag, '\n');
- /* Remove comments by default */
- if (git_message_prettify(&cleaned_message, message, 1) < 0)
+ if (git_buf_puts(&tag, message) < 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;
@@ -225,7 +219,6 @@ static int write_tag_annotation(
on_error:
git_buf_free(&tag);
- git_buf_free(&cleaned_message);
giterr_set(GITERR_OBJECT, "Failed to create tag annotation.");
return -1;
}