diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-06-15 22:24:59 +0200 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-06-19 10:02:22 +0200 |
commit | 743a4b3bdd0ff37eacf49e496ba2e5cd7b9a3f83 (patch) | |
tree | 70a6ea1a449e504bfe66dbf47168a360f049086f /src | |
parent | 68f527c4480f0c1e24f29dc0a2337469fe50967f (diff) | |
download | libgit2-743a4b3bdd0ff37eacf49e496ba2e5cd7b9a3f83.tar.gz |
message: Expose git_message_prettify()
git_commit() and git_tag() no longer prettify the
message by default. This has to be taken care of
by the caller.
This has the nice side effect of putting the
caller in position to actually choose to strip
the comments or not.
Diffstat (limited to 'src')
-rw-r--r-- | src/message.c | 25 | ||||
-rw-r--r-- | src/message.h | 3 | ||||
-rw-r--r-- | src/tag.c | 11 |
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__ */ @@ -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; } |