summaryrefslogtreecommitdiff
path: root/src/message.c
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-06-15 22:24:59 +0200
committernulltoken <emeric.fermas@gmail.com>2012-06-19 10:02:22 +0200
commit743a4b3bdd0ff37eacf49e496ba2e5cd7b9a3f83 (patch)
tree70a6ea1a449e504bfe66dbf47168a360f049086f /src/message.c
parent68f527c4480f0c1e24f29dc0a2337469fe50967f (diff)
downloadlibgit2-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/message.c')
-rw-r--r--src/message.c25
1 files changed, 23 insertions, 2 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;
+}