Skip to content

Commit 4893a9c

Browse files
authored
Merge pull request libgit2#4451 from libgit2/charliesome/trailer-info
Implement message trailer parsing API
2 parents ecd55ce + d4a3a4b commit 4893a9c

File tree

3 files changed

+622
-0
lines changed

3 files changed

+622
-0
lines changed

include/git2/message.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,47 @@ GIT_BEGIN_DECL
3838
*/
3939
GIT_EXTERN(int) git_message_prettify(git_buf *out, const char *message, int strip_comments, char comment_char);
4040

41+
/**
42+
* Represents a single git message trailer.
43+
*/
44+
typedef struct {
45+
const char *key;
46+
const char *value;
47+
} git_message_trailer;
48+
49+
/**
50+
* Represents an array of git message trailers.
51+
*
52+
* Struct members under the private comment are private, subject to change
53+
* and should not be used by callers.
54+
*/
55+
typedef struct {
56+
git_message_trailer *trailers;
57+
size_t count;
58+
59+
/* private */
60+
char *_trailer_block;
61+
} git_message_trailer_array;
62+
63+
/**
64+
* Parse trailers out of a message, filling the array pointed to by +arr+.
65+
*
66+
* Trailers are key/value pairs in the last paragraph of a message, not
67+
* including any patches or conflicts that may be present.
68+
*
69+
* @param arr A pre-allocated git_message_trailer_array struct to be filled in
70+
* with any trailers found during parsing.
71+
* @param message The message to be parsed
72+
* @return 0 on success, or non-zero on error.
73+
*/
74+
GIT_EXTERN(int) git_message_trailers(git_message_trailer_array *arr, const char *message);
75+
76+
/**
77+
* Clean's up any allocated memory in the git_message_trailer_array filled by
78+
* a call to git_message_trailers.
79+
*/
80+
GIT_EXTERN(void) git_message_trailer_array_free(git_message_trailer_array *arr);
81+
4182
/** @} */
4283
GIT_END_DECL
4384

0 commit comments

Comments
 (0)