SECURITY: describe how to report vulnerabilities
[git] / pretty.h
1 #ifndef PRETTY_H
2 #define PRETTY_H
3
4 #include "cache.h"
5 #include "string-list.h"
6
7 struct commit;
8 struct strbuf;
9 struct process_trailer_options;
10
11 /* Commit formats */
12 enum cmit_fmt {
13         CMIT_FMT_RAW,
14         CMIT_FMT_MEDIUM,
15         CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
16         CMIT_FMT_SHORT,
17         CMIT_FMT_FULL,
18         CMIT_FMT_FULLER,
19         CMIT_FMT_ONELINE,
20         CMIT_FMT_EMAIL,
21         CMIT_FMT_MBOXRD,
22         CMIT_FMT_USERFORMAT,
23
24         CMIT_FMT_UNSPECIFIED
25 };
26
27 struct pretty_print_context {
28         /*
29          * Callers should tweak these to change the behavior of pp_* functions.
30          */
31         enum cmit_fmt fmt;
32         int abbrev;
33         const char *after_subject;
34         int preserve_subject;
35         struct date_mode date_mode;
36         unsigned date_mode_explicit:1;
37         int print_email_subject;
38         int expand_tabs_in_log;
39         int need_8bit_cte;
40         char *notes_message;
41         struct reflog_walk_info *reflog_info;
42         struct rev_info *rev;
43         const char *output_encoding;
44         struct string_list *mailmap;
45         int color;
46         struct ident_split *from_ident;
47         unsigned encode_email_headers:1;
48
49         /*
50          * Fields below here are manipulated internally by pp_* functions and
51          * should not be counted on by callers.
52          */
53         struct string_list in_body_headers;
54         int graph_width;
55 };
56
57 /* Check whether commit format is mail. */
58 static inline int cmit_fmt_is_mail(enum cmit_fmt fmt)
59 {
60         return (fmt == CMIT_FMT_EMAIL || fmt == CMIT_FMT_MBOXRD);
61 }
62
63 struct userformat_want {
64         unsigned notes:1;
65         unsigned source:1;
66 };
67
68 /* Set the flag "w->notes" if there is placeholder %N in "fmt". */
69 void userformat_find_requirements(const char *fmt, struct userformat_want *w);
70
71 /*
72  * Shortcut for invoking pretty_print_commit if we do not have any context.
73  * Context would be set empty except "fmt".
74  */
75 void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
76                         struct strbuf *sb);
77
78 /*
79  * Get information about user and date from "line", format it and
80  * put it into "sb".
81  * Format of "line" must be readable for split_ident_line function.
82  * The resulting format is "what: name <email> date".
83  */
84 void pp_user_info(struct pretty_print_context *pp, const char *what,
85                         struct strbuf *sb, const char *line,
86                         const char *encoding);
87
88 /*
89  * Format title line of commit message taken from "msg_p" and
90  * put it into "sb".
91  * First line of "msg_p" is also affected.
92  */
93 void pp_title_line(struct pretty_print_context *pp, const char **msg_p,
94                         struct strbuf *sb, const char *encoding,
95                         int need_8bit_cte);
96
97 /*
98  * Get current state of commit message from "msg_p" and continue formatting
99  * by adding indentation and '>' signs. Put result into "sb".
100  */
101 void pp_remainder(struct pretty_print_context *pp, const char **msg_p,
102                         struct strbuf *sb, int indent);
103
104 /*
105  * Create a text message about commit using given "format" and "context".
106  * Put the result to "sb".
107  * Please use this function for custom formats.
108  */
109 void repo_format_commit_message(struct repository *r,
110                         const struct commit *commit,
111                         const char *format, struct strbuf *sb,
112                         const struct pretty_print_context *context);
113 #ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
114 #define format_commit_message(c, f, s, con) \
115         repo_format_commit_message(the_repository, c, f, s, con)
116 #endif
117
118 /*
119  * Parse given arguments from "arg", check it for correctness and
120  * fill struct rev_info.
121  */
122 void get_commit_format(const char *arg, struct rev_info *);
123
124 /*
125  * Make a commit message with all rules from given "pp"
126  * and put it into "sb".
127  * Please use this function if you have a context (candidate for "pp").
128  */
129 void pretty_print_commit(struct pretty_print_context *pp,
130                         const struct commit *commit,
131                         struct strbuf *sb);
132
133 /*
134  * Change line breaks in "msg" to "line_separator" and put it into "sb".
135  * Return "msg" itself.
136  */
137 const char *format_subject(struct strbuf *sb, const char *msg,
138                         const char *line_separator);
139
140 /* Check if "cmit_fmt" will produce an empty output. */
141 int commit_format_is_empty(enum cmit_fmt);
142
143 /* Make subject of commit message suitable for filename */
144 void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len);
145
146 /*
147  * Set values of fields in "struct process_trailer_options"
148  * according to trailers arguments.
149  */
150 int format_set_trailers_options(struct process_trailer_options *opts,
151                         struct string_list *filter_list,
152                         struct strbuf *sepbuf,
153                         struct strbuf *kvsepbuf,
154                         const char **arg,
155                         char **invalid_arg);
156
157 #endif /* PRETTY_H */