MCPcopy Index your code
hub / github.com/git/git / repo_logmsg_reencode

Function repo_logmsg_reencode

pretty.c:708–775  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

706}
707
708const char *repo_logmsg_reencode(struct repository *r,
709 const struct commit *commit,
710 char **commit_encoding,
711 const char *output_encoding)
712{
713 static const char *utf8 = "UTF-8";
714 const char *use_encoding;
715 char *encoding;
716 const char *msg = repo_get_commit_buffer(r, commit, NULL);
717 char *out;
718
719 if (!output_encoding || !*output_encoding) {
720 if (commit_encoding)
721 *commit_encoding = get_header(msg, "encoding");
722 return msg;
723 }
724 encoding = get_header(msg, "encoding");
725 if (commit_encoding)
726 *commit_encoding = encoding;
727 use_encoding = encoding ? encoding : utf8;
728 if (same_encoding(use_encoding, output_encoding)) {
729 /*
730 * No encoding work to be done. If we have no encoding header
731 * at all, then there's nothing to do, and we can return the
732 * message verbatim (whether newly allocated or not).
733 */
734 if (!encoding)
735 return msg;
736
737 /*
738 * Otherwise, we still want to munge the encoding header in the
739 * result, which will be done by modifying the buffer. If we
740 * are using a fresh copy, we can reuse it. But if we are using
741 * the cached copy from repo_get_commit_buffer, we need to duplicate it
742 * to avoid munging the cached copy.
743 */
744 if (msg == get_cached_commit_buffer(r, commit, NULL))
745 out = xstrdup(msg);
746 else
747 out = (char *)msg;
748 }
749 else {
750 /*
751 * There's actual encoding work to do. Do the reencoding, which
752 * still leaves the header to be replaced in the next step. At
753 * this point, we are done with msg. If we allocated a fresh
754 * copy, we can free it.
755 */
756 out = reencode_string(msg, output_encoding, use_encoding);
757 if (out)
758 repo_unuse_commit_buffer(r, commit, msg);
759 }
760
761 /*
762 * This replacement actually consumes the buffer we hand it, so we do
763 * not have to worry about freeing the old "out" here.
764 */
765 if (out)

Callers 15

commit_matchFunction · 0.85
get_messageFunction · 0.85
try_to_commitFunction · 0.85
update_squash_messagesFunction · 0.85
walk_revs_populate_todoFunction · 0.85
make_patchFunction · 0.85
do_mergeFunction · 0.85
commit_staged_changesFunction · 0.85
format_commit_oneFunction · 0.85
pretty_print_commitFunction · 0.85
generate_revert_messageFunction · 0.85

Calls 8

repo_get_commit_bufferFunction · 0.85
same_encodingFunction · 0.85
get_cached_commit_bufferFunction · 0.85
xstrdupFunction · 0.85
reencode_stringFunction · 0.85
repo_unuse_commit_bufferFunction · 0.85
replace_encoding_headerFunction · 0.85
get_headerFunction · 0.70

Tested by

no test coverage detected