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