]> git.ipfire.org Git - thirdparty/git.git/blame - trailer.h
Merge branch 'rj/add-i-leak-fix'
[thirdparty/git.git] / trailer.h
CommitLineData
b1d78d77
CC
1#ifndef TRAILER_H
2#define TRAILER_H
3
51166b87 4#include "list.h"
f0939a0e 5#include "strbuf.h"
ef3ca954 6
52fc319d 7enum trailer_where {
0ea5292e 8 WHERE_DEFAULT,
52fc319d
PB
9 WHERE_END,
10 WHERE_AFTER,
11 WHERE_BEFORE,
12 WHERE_START
13};
14enum trailer_if_exists {
0ea5292e 15 EXISTS_DEFAULT,
52fc319d
PB
16 EXISTS_ADD_IF_DIFFERENT_NEIGHBOR,
17 EXISTS_ADD_IF_DIFFERENT,
18 EXISTS_ADD,
19 EXISTS_REPLACE,
20 EXISTS_DO_NOTHING
21};
22enum trailer_if_missing {
0ea5292e 23 MISSING_DEFAULT,
52fc319d
PB
24 MISSING_ADD,
25 MISSING_DO_NOTHING
26};
27
28int trailer_set_where(enum trailer_where *item, const char *value);
29int trailer_set_if_exists(enum trailer_if_exists *item, const char *value);
30int trailer_set_if_missing(enum trailer_if_missing *item, const char *value);
31
e8c352c3
JT
32struct trailer_info {
33 /*
34 * True if there is a blank line before the location pointed to by
de7c27a1 35 * trailer_block_start.
e8c352c3
JT
36 */
37 int blank_line_before_trailer;
38
39 /*
de7c27a1
LA
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()).
e8c352c3 43 */
de7c27a1 44 size_t trailer_block_start, trailer_block_end;
e8c352c3
JT
45
46 /*
47 * Array of trailers found.
48 */
49 char **trailers;
50 size_t trailer_nr;
51};
52
51166b87
PB
53/*
54 * A list that represents newly-added trailers, such as those provided
55 * with the --trailer command line option of git-interpret-trailers.
56 */
57struct new_trailer_item {
58 struct list_head list;
59
60 const char *text;
0ea5292e
PB
61
62 enum trailer_where where;
63 enum trailer_if_exists if_exists;
64 enum trailer_if_missing if_missing;
51166b87
PB
65};
66
8abc8980
JK
67struct process_trailer_options {
68 int in_place;
69 int trim_empty;
56c493ed 70 int only_trailers;
fdbdb64f 71 int only_input;
00002396 72 int unfold;
1688c9a4 73 int no_divider;
9d87d5ae 74 int key_only;
d9b936db 75 int value_only;
0b691d86 76 const struct strbuf *separator;
058761f1 77 const struct strbuf *key_value_separator;
250bea0c
AW
78 int (*filter)(const struct strbuf *, void *);
79 void *filter_data;
8abc8980
JK
80};
81
82#define PROCESS_TRAILER_OPTIONS_INIT {0}
83
ae0ec2e0
LA
84void parse_trailers_from_config(struct list_head *config_head);
85
86void parse_trailers_from_command_line_args(struct list_head *arg_head,
87 struct list_head *new_trailer_head);
88
89void process_trailers_lists(struct list_head *head,
90 struct list_head *arg_head);
91
92void parse_trailers(const struct process_trailer_options *,
93 struct trailer_info *,
94 const char *str,
95 struct list_head *head);
b1d78d77 96
9aa1b2bc
LA
97void trailer_info_get(const struct process_trailer_options *,
98 const char *str,
99 struct trailer_info *);
e8c352c3
JT
100
101void trailer_info_release(struct trailer_info *info);
102
ae0ec2e0 103void trailer_config_init(void);
3452d173 104void format_trailers(const struct process_trailer_options *,
bf35e0a0
LA
105 struct list_head *trailers,
106 struct strbuf *out);
ae0ec2e0
LA
107void free_trailers(struct list_head *);
108
a388b10f 109/*
3452d173
LA
110 * Convenience function to format the trailers from the commit msg "msg" into
111 * the strbuf "out". Reuses format_trailers() internally.
a388b10f 112 */
3452d173 113void format_trailers_from_commit(const struct process_trailer_options *,
0383dc56
LA
114 const char *msg,
115 struct strbuf *out);
a388b10f 116
f0939a0e
JK
117/*
118 * An interface for iterating over the trailers found in a particular commit
119 * message. Use like:
120 *
121 * struct trailer_iterator iter;
122 * trailer_iterator_init(&iter, msg);
123 * while (trailer_iterator_advance(&iter))
124 * ... do something with iter.key and iter.val ...
125 * trailer_iterator_release(&iter);
126 */
127struct trailer_iterator {
128 struct strbuf key;
129 struct strbuf val;
130
131 /* private */
13211ae2
LA
132 struct {
133 struct trailer_info info;
134 size_t cur;
135 } internal;
f0939a0e
JK
136};
137
138/*
139 * Initialize "iter" in preparation for walking over the trailers in the commit
140 * message "msg". The "msg" pointer must remain valid until the iterator is
141 * released.
142 *
143 * After initializing, note that key/val will not yet point to any trailer.
144 * Call advance() to parse the first one (if any).
145 */
146void trailer_iterator_init(struct trailer_iterator *iter, const char *msg);
147
148/*
149 * Advance to the next trailer of the iterator. Returns 0 if there is no such
150 * trailer, and 1 otherwise. The key and value of the trailer can be
151 * fetched from the iter->key and iter->value fields (which are valid
152 * only until the next advance).
153 */
154int trailer_iterator_advance(struct trailer_iterator *iter);
155
156/*
157 * Release all resources associated with the trailer iteration.
158 */
159void trailer_iterator_release(struct trailer_iterator *iter);
160
b1d78d77 161#endif /* TRAILER_H */