summaryrefslogtreecommitdiff
path: root/include/git2/message.h
blob: d5229660dead449f117e7ed79246aab5719ed1eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright (C) the libgit2 contributors. All rights reserved.
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
#ifndef INCLUDE_git_message_h__
#define INCLUDE_git_message_h__

#include "common.h"
#include "buffer.h"

/**
 * @file git2/message.h
 * @brief Git message management routines
 * @ingroup Git
 * @{
 */
GIT_BEGIN_DECL

/**
 * Clean up message from excess whitespace and make sure that the last line
 * ends with a '\n'.
 *
 * Optionally, can remove lines starting with a "#".
 *
 * @param out The user-allocated git_buf which will be filled with the
 *     cleaned up message.
 *
 * @param message The message to be prettified.
 *
 * @param strip_comments Non-zero to remove comment lines, 0 to leave them in.
 *
 * @param comment_char Comment character. Lines starting with this character
 * are considered to be comments and removed if `strip_comments` is non-zero.
 *
 * @return 0 or an error code.
 */
GIT_EXTERN(int) git_message_prettify(git_buf *out, const char *message, int strip_comments, char comment_char);

typedef int(*git_message_trailer_cb)(const char *key, const char *value, void *payload);

/**
 * Parse trailers out of a message, calling a callback once for each trailer.
 *
 * Return non-zero from the callback to stop processing.
 *
 * Trailers are key/value pairs in the last paragraph of a message, not
 * including any patches or conflicts that may be present.
 *
 * @param message The message to be parsed
 * @param cb The callback to call for each trailer found in the message. The
 *     key and value arguments are pointers to NUL-terminated C strings. These
 *     pointers are only guaranteed to be valid until the callback returns.
 *     User code must make a copy of this data should it need to be retained
 * @param payload Pointer to callback data (optional)
 * @return 0 on success, or non-zero callback return value.
 */
GIT_EXTERN(int) git_message_trailers(const char *message, git_message_trailer_cb cb, void *payload);

typedef struct git_message_trailer_iterator git_message_trailer_iterator;

GIT_EXTERN(int) git_message_trailer_iterator_new(
	git_message_trailer_iterator **out,
	const char *message);

GIT_EXTERN(int) git_message_trailer_iterator_next(
	const char **key_out,
	const char **value_out,
	git_message_trailer_iterator *iter);

GIT_EXTERN(void) git_message_trailer_iterator_free(git_message_trailer_iterator *iter);

/** @} */
GIT_END_DECL

#endif /* INCLUDE_git_message_h__ */