14 enum trailer_if_exists
{
16 EXISTS_ADD_IF_DIFFERENT_NEIGHBOR
,
17 EXISTS_ADD_IF_DIFFERENT
,
22 enum trailer_if_missing
{
28 int trailer_set_where(enum trailer_where
*item
, const char *value
);
29 int trailer_set_if_exists(enum trailer_if_exists
*item
, const char *value
);
30 int trailer_set_if_missing(enum trailer_if_missing
*item
, const char *value
);
34 * True if there is a blank line before the location pointed to by
35 * trailer_block_start.
37 int blank_line_before_trailer
;
40 * Offsets to the trailer block start and end positions in the input
41 * string. If no trailer block is found, these are both set to the
42 * "true" end of the input (find_end_of_log_message()).
44 size_t trailer_block_start
, trailer_block_end
;
47 * Array of trailers found.
54 * A list that represents newly-added trailers, such as those provided
55 * with the --trailer command line option of git-interpret-trailers.
57 struct new_trailer_item
{
58 struct list_head list
;
62 enum trailer_where where
;
63 enum trailer_if_exists if_exists
;
64 enum trailer_if_missing if_missing
;
67 struct process_trailer_options
{
76 const struct strbuf
*separator
;
77 const struct strbuf
*key_value_separator
;
78 int (*filter
)(const struct strbuf
*, void *);
82 #define PROCESS_TRAILER_OPTIONS_INIT {0}
84 void parse_trailers_from_config(struct list_head
*config_head
);
86 void parse_trailers_from_command_line_args(struct list_head
*arg_head
,
87 struct list_head
*new_trailer_head
);
89 void process_trailers_lists(struct list_head
*head
,
90 struct list_head
*arg_head
);
92 void parse_trailers(const struct process_trailer_options
*,
93 struct trailer_info
*,
95 struct list_head
*head
);
97 void trailer_info_get(const struct process_trailer_options
*,
99 struct trailer_info
*);
100 size_t trailer_block_start(struct trailer_info
*);
101 size_t trailer_block_end(struct trailer_info
*);
102 int blank_line_before_trailer_block(struct trailer_info
*);
103 struct trailer_info
*trailer_info_new(void);
105 void trailer_info_release(struct trailer_info
*info
);
107 void trailer_config_init(void);
108 void format_trailers(const struct process_trailer_options
*,
109 struct list_head
*trailers
,
111 void free_trailers(struct list_head
*);
114 * Convenience function to format the trailers from the commit msg "msg" into
115 * the strbuf "out". Reuses format_trailers() internally.
117 void format_trailers_from_commit(const struct process_trailer_options
*,
122 * An interface for iterating over the trailers found in a particular commit
125 * struct trailer_iterator iter;
126 * trailer_iterator_init(&iter, msg);
127 * while (trailer_iterator_advance(&iter))
128 * ... do something with iter.key and iter.val ...
129 * trailer_iterator_release(&iter);
131 struct trailer_iterator
{
133 * Raw line (e.g., "foo: bar baz") before being parsed as a trailer
134 * key/val pair as part of a trailer block (as the "key" and "val"
135 * fields below). If a line fails to parse as a trailer, then the "key"
136 * will be the entire line and "val" will be the empty string.
144 struct trailer_info info
;
150 * Initialize "iter" in preparation for walking over the trailers in the commit
151 * message "msg". The "msg" pointer must remain valid until the iterator is
154 * After initializing, note that key/val will not yet point to any trailer.
155 * Call advance() to parse the first one (if any).
157 void trailer_iterator_init(struct trailer_iterator
*iter
, const char *msg
);
160 * Advance to the next trailer of the iterator. Returns 0 if there is no such
161 * trailer, and 1 otherwise. The key and value of the trailer can be
162 * fetched from the iter->key and iter->value fields (which are valid
163 * only until the next advance).
165 int trailer_iterator_advance(struct trailer_iterator
*iter
);
168 * Release all resources associated with the trailer iteration.
170 void trailer_iterator_release(struct trailer_iterator
*iter
);
172 #endif /* TRAILER_H */