]>
Commit | Line | Data |
---|---|---|
cf394719 OT |
1 | #ifndef PRETTY_H |
2 | #define PRETTY_H | |
3 | ||
ef3ca954 EN |
4 | #include "cache.h" |
5 | #include "string-list.h" | |
6 | ||
cf394719 | 7 | struct commit; |
ef3ca954 | 8 | struct strbuf; |
90563aed | 9 | struct process_trailer_options; |
cf394719 OT |
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; | |
19d097e3 | 47 | unsigned encode_email_headers:1; |
cf394719 OT |
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 | ||
d0e63260 | 57 | /* Check whether commit format is mail. */ |
cf394719 OT |
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; | |
ad6f028f | 65 | unsigned source:1; |
cf394719 OT |
66 | }; |
67 | ||
d0e63260 | 68 | /* Set the flag "w->notes" if there is placeholder %N in "fmt". */ |
cf394719 | 69 | void userformat_find_requirements(const char *fmt, struct userformat_want *w); |
d0e63260 OT |
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 | */ | |
cf394719 OT |
75 | void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit, |
76 | struct strbuf *sb); | |
d0e63260 OT |
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 | */ | |
cf394719 OT |
84 | void pp_user_info(struct pretty_print_context *pp, const char *what, |
85 | struct strbuf *sb, const char *line, | |
86 | const char *encoding); | |
d0e63260 OT |
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 | */ | |
cf394719 OT |
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); | |
d0e63260 OT |
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 | */ | |
cf394719 OT |
101 | void pp_remainder(struct pretty_print_context *pp, const char **msg_p, |
102 | struct strbuf *sb, int indent); | |
103 | ||
d0e63260 OT |
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 | */ | |
f54fbf5e SB |
109 | void repo_format_commit_message(struct repository *r, |
110 | const struct commit *commit, | |
cf394719 OT |
111 | const char *format, struct strbuf *sb, |
112 | const struct pretty_print_context *context); | |
f54fbf5e SB |
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 | |
cf394719 | 117 | |
d0e63260 OT |
118 | /* |
119 | * Parse given arguments from "arg", check it for correctness and | |
120 | * fill struct rev_info. | |
121 | */ | |
cf394719 OT |
122 | void get_commit_format(const char *arg, struct rev_info *); |
123 | ||
d0e63260 OT |
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 | */ | |
cf394719 OT |
129 | void pretty_print_commit(struct pretty_print_context *pp, |
130 | const struct commit *commit, | |
131 | struct strbuf *sb); | |
132 | ||
d0e63260 OT |
133 | /* |
134 | * Change line breaks in "msg" to "line_separator" and put it into "sb". | |
135 | * Return "msg" itself. | |
136 | */ | |
cf394719 OT |
137 | const char *format_subject(struct strbuf *sb, const char *msg, |
138 | const char *line_separator); | |
139 | ||
d0e63260 | 140 | /* Check if "cmit_fmt" will produce an empty output. */ |
cf394719 OT |
141 | int commit_format_is_empty(enum cmit_fmt); |
142 | ||
47d4676a HV |
143 | /* Make subject of commit message suitable for filename */ |
144 | void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len); | |
145 | ||
90563aed HV |
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 | ||
cf394719 | 156 | #endif /* PRETTY_H */ |