Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 1 | #ifndef PRETTY_H |
| 2 | #define PRETTY_H |
| 3 | |
Ævar Arnfjörð Bjarmason | 88c7b4c | 2022-02-16 09:14:02 +0100 | [diff] [blame] | 4 | #include "date.h" |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 5 | #include "string-list.h" |
| 6 | |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 7 | struct commit; |
Elijah Newren | ba3d1c7 | 2023-02-24 00:09:22 +0000 | [diff] [blame] | 8 | struct repository; |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 9 | struct strbuf; |
Hariom Verma | 90563ae | 2021-02-13 01:52:41 +0000 | [diff] [blame] | 10 | struct process_trailer_options; |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 11 | |
| 12 | /* Commit formats */ |
| 13 | enum cmit_fmt { |
| 14 | CMIT_FMT_RAW, |
| 15 | CMIT_FMT_MEDIUM, |
| 16 | CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM, |
| 17 | CMIT_FMT_SHORT, |
| 18 | CMIT_FMT_FULL, |
| 19 | CMIT_FMT_FULLER, |
| 20 | CMIT_FMT_ONELINE, |
| 21 | CMIT_FMT_EMAIL, |
| 22 | CMIT_FMT_MBOXRD, |
| 23 | CMIT_FMT_USERFORMAT, |
| 24 | |
| 25 | CMIT_FMT_UNSPECIFIED |
| 26 | }; |
| 27 | |
René Scharfe | 9609972 | 2021-02-28 12:22:47 +0100 | [diff] [blame] | 28 | struct pretty_print_describe_status { |
| 29 | unsigned int max_invocations; |
| 30 | }; |
| 31 | |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 32 | struct pretty_print_context { |
| 33 | /* |
| 34 | * Callers should tweak these to change the behavior of pp_* functions. |
| 35 | */ |
| 36 | enum cmit_fmt fmt; |
| 37 | int abbrev; |
| 38 | const char *after_subject; |
| 39 | int preserve_subject; |
| 40 | struct date_mode date_mode; |
| 41 | unsigned date_mode_explicit:1; |
| 42 | int print_email_subject; |
| 43 | int expand_tabs_in_log; |
| 44 | int need_8bit_cte; |
| 45 | char *notes_message; |
| 46 | struct reflog_walk_info *reflog_info; |
| 47 | struct rev_info *rev; |
| 48 | const char *output_encoding; |
| 49 | struct string_list *mailmap; |
| 50 | int color; |
| 51 | struct ident_split *from_ident; |
Emma Brooks | 19d097e | 2020-04-08 04:31:38 +0000 | [diff] [blame] | 52 | unsigned encode_email_headers:1; |
René Scharfe | 9609972 | 2021-02-28 12:22:47 +0100 | [diff] [blame] | 53 | struct pretty_print_describe_status *describe_status; |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * Fields below here are manipulated internally by pp_* functions and |
| 57 | * should not be counted on by callers. |
| 58 | */ |
| 59 | struct string_list in_body_headers; |
| 60 | int graph_width; |
| 61 | }; |
| 62 | |
Olga Telezhnaya | d0e6326 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 63 | /* Check whether commit format is mail. */ |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 64 | static inline int cmit_fmt_is_mail(enum cmit_fmt fmt) |
| 65 | { |
| 66 | return (fmt == CMIT_FMT_EMAIL || fmt == CMIT_FMT_MBOXRD); |
| 67 | } |
| 68 | |
Jeff King | 3c7e2e8 | 2021-06-22 12:03:54 -0400 | [diff] [blame] | 69 | /* |
| 70 | * Examine the user-specified format given by "fmt" (or if NULL, the global one |
| 71 | * previously saved by get_commit_format()), and set flags based on which items |
| 72 | * the format will need when it is expanded. |
| 73 | */ |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 74 | struct userformat_want { |
| 75 | unsigned notes:1; |
Issac Trotts | ad6f028 | 2019-01-10 22:30:46 -0800 | [diff] [blame] | 76 | unsigned source:1; |
Jeff King | b2086b5 | 2021-06-22 12:04:50 -0400 | [diff] [blame] | 77 | unsigned decorate:1; |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 78 | }; |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 79 | void userformat_find_requirements(const char *fmt, struct userformat_want *w); |
Olga Telezhnaya | d0e6326 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * Shortcut for invoking pretty_print_commit if we do not have any context. |
| 83 | * Context would be set empty except "fmt". |
| 84 | */ |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 85 | void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit, |
| 86 | struct strbuf *sb); |
Olga Telezhnaya | d0e6326 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 87 | |
| 88 | /* |
| 89 | * Get information about user and date from "line", format it and |
| 90 | * put it into "sb". |
| 91 | * Format of "line" must be readable for split_ident_line function. |
| 92 | * The resulting format is "what: name <email> date". |
| 93 | */ |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 94 | void pp_user_info(struct pretty_print_context *pp, const char *what, |
| 95 | struct strbuf *sb, const char *line, |
| 96 | const char *encoding); |
Olga Telezhnaya | d0e6326 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * Format title line of commit message taken from "msg_p" and |
| 100 | * put it into "sb". |
| 101 | * First line of "msg_p" is also affected. |
| 102 | */ |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 103 | void pp_title_line(struct pretty_print_context *pp, const char **msg_p, |
| 104 | struct strbuf *sb, const char *encoding, |
| 105 | int need_8bit_cte); |
Olga Telezhnaya | d0e6326 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * Get current state of commit message from "msg_p" and continue formatting |
| 109 | * by adding indentation and '>' signs. Put result into "sb". |
| 110 | */ |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 111 | void pp_remainder(struct pretty_print_context *pp, const char **msg_p, |
| 112 | struct strbuf *sb, int indent); |
| 113 | |
Olga Telezhnaya | d0e6326 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 114 | /* |
| 115 | * Create a text message about commit using given "format" and "context". |
| 116 | * Put the result to "sb". |
| 117 | * Please use this function for custom formats. |
| 118 | */ |
Stefan Beller | f54fbf5 | 2018-11-13 16:13:00 -0800 | [diff] [blame] | 119 | void repo_format_commit_message(struct repository *r, |
| 120 | const struct commit *commit, |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 121 | const char *format, struct strbuf *sb, |
| 122 | const struct pretty_print_context *context); |
| 123 | |
Olga Telezhnaya | d0e6326 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 124 | /* |
| 125 | * Parse given arguments from "arg", check it for correctness and |
| 126 | * fill struct rev_info. |
| 127 | */ |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 128 | void get_commit_format(const char *arg, struct rev_info *); |
| 129 | |
Olga Telezhnaya | d0e6326 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 130 | /* |
| 131 | * Make a commit message with all rules from given "pp" |
| 132 | * and put it into "sb". |
| 133 | * Please use this function if you have a context (candidate for "pp"). |
| 134 | */ |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 135 | void pretty_print_commit(struct pretty_print_context *pp, |
| 136 | const struct commit *commit, |
| 137 | struct strbuf *sb); |
| 138 | |
Olga Telezhnaya | d0e6326 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 139 | /* |
| 140 | * Change line breaks in "msg" to "line_separator" and put it into "sb". |
| 141 | * Return "msg" itself. |
| 142 | */ |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 143 | const char *format_subject(struct strbuf *sb, const char *msg, |
| 144 | const char *line_separator); |
| 145 | |
Olga Telezhnaya | d0e6326 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 146 | /* Check if "cmit_fmt" will produce an empty output. */ |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 147 | int commit_format_is_empty(enum cmit_fmt); |
| 148 | |
Hariom Verma | 47d4676 | 2020-08-21 21:41:49 +0000 | [diff] [blame] | 149 | /* Make subject of commit message suitable for filename */ |
| 150 | void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len); |
| 151 | |
Elijah Newren | b6c09c0 | 2023-02-24 00:09:28 +0000 | [diff] [blame] | 152 | int has_non_ascii(const char *text); |
| 153 | |
Hariom Verma | 90563ae | 2021-02-13 01:52:41 +0000 | [diff] [blame] | 154 | /* |
| 155 | * Set values of fields in "struct process_trailer_options" |
| 156 | * according to trailers arguments. |
| 157 | */ |
| 158 | int format_set_trailers_options(struct process_trailer_options *opts, |
| 159 | struct string_list *filter_list, |
| 160 | struct strbuf *sepbuf, |
| 161 | struct strbuf *kvsepbuf, |
Hariom Verma | 636a0ae | 2021-02-13 01:52:42 +0000 | [diff] [blame] | 162 | const char **arg, |
| 163 | char **invalid_arg); |
Hariom Verma | 90563ae | 2021-02-13 01:52:41 +0000 | [diff] [blame] | 164 | |
Ævar Arnfjörð Bjarmason | 88c7b4c | 2022-02-16 09:14:02 +0100 | [diff] [blame] | 165 | /* |
| 166 | * Like show_date, but pull the timestamp and tz parameters from |
| 167 | * the ident_split. It will also sanity-check the values and produce |
| 168 | * a well-known sentinel date if they appear bogus. |
| 169 | */ |
| 170 | const char *show_ident_date(const struct ident_split *id, |
| 171 | const struct date_mode *mode); |
| 172 | |
| 173 | |
Olga Telezhnaya | cf39471 | 2017-12-12 08:55:35 +0000 | [diff] [blame] | 174 | #endif /* PRETTY_H */ |