| 1998 | } |
| 1999 | |
| 2000 | void repo_format_commit_message(struct repository *r, |
| 2001 | const struct commit *commit, |
| 2002 | const char *format, struct strbuf *sb, |
| 2003 | const struct pretty_print_context *pretty_ctx) |
| 2004 | { |
| 2005 | struct format_commit_context context = { |
| 2006 | .repository = r, |
| 2007 | .commit = commit, |
| 2008 | .pretty_ctx = pretty_ctx, |
| 2009 | .wrap_start = sb->len |
| 2010 | }; |
| 2011 | const char *output_enc = pretty_ctx->output_encoding; |
| 2012 | const char *utf8 = "UTF-8"; |
| 2013 | |
| 2014 | while (strbuf_expand_step(sb, &format)) { |
| 2015 | size_t len; |
| 2016 | |
| 2017 | if (skip_prefix(format, "%", &format)) |
| 2018 | strbuf_addch(sb, '%'); |
| 2019 | else if ((len = format_commit_item(sb, format, &context))) |
| 2020 | format += len; |
| 2021 | else |
| 2022 | strbuf_addch(sb, '%'); |
| 2023 | } |
| 2024 | rewrap_message_tail(sb, &context, 0, 0, 0); |
| 2025 | |
| 2026 | /* |
| 2027 | * Convert output to an actual output encoding; note that |
| 2028 | * format_commit_item() will always use UTF-8, so we don't |
| 2029 | * have to bother if that's what the output wants. |
| 2030 | */ |
| 2031 | if (output_enc) { |
| 2032 | if (same_encoding(utf8, output_enc)) |
| 2033 | output_enc = NULL; |
| 2034 | } else { |
| 2035 | if (context.commit_encoding && |
| 2036 | !same_encoding(context.commit_encoding, utf8)) |
| 2037 | output_enc = context.commit_encoding; |
| 2038 | } |
| 2039 | |
| 2040 | if (output_enc) { |
| 2041 | size_t outsz; |
| 2042 | char *out = reencode_string_len(sb->buf, sb->len, |
| 2043 | output_enc, utf8, &outsz); |
| 2044 | if (out) |
| 2045 | strbuf_attach(sb, out, outsz, outsz + 1); |
| 2046 | } |
| 2047 | |
| 2048 | free(context.commit_encoding); |
| 2049 | repo_unuse_commit_buffer(r, commit, context.message); |
| 2050 | signature_check_clear(&context.signature_check); |
| 2051 | } |
| 2052 | |
| 2053 | static void pp_header(struct pretty_print_context *pp, |
| 2054 | const char *encoding, |