reencode_string(): introduce and use same_encoding()
Callers of reencode_string() that re-encodes a string from one encoding to another all used ad-hoc way to bypass the case where the input and the output encodings are the same. Some did strcmp(), some did strcasecmp(), yet some others when converting to UTF-8 used is_encoding_utf8(). Introduce same_encoding() helper function to make these callers use the same logic. Notably, is_encoding_utf8() has a work-around for common misconfiguration to use "utf8" to name UTF-8 encoding, which does not match "UTF-8" hence strcasecmp() would not consider the same. Make use of it in this helper function. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Jeff King

parent
7e2010537e
commit
0e18bcd5e9
@ -58,7 +58,7 @@ static int get_message(struct commit *commit, struct commit_message *out)
|
||||
|
||||
out->reencoded_message = NULL;
|
||||
out->message = commit->buffer;
|
||||
if (strcmp(encoding, git_commit_encoding))
|
||||
if (same_encoding(encoding, git_commit_encoding))
|
||||
out->reencoded_message = reencode_string(commit->buffer,
|
||||
git_commit_encoding, encoding);
|
||||
if (out->reencoded_message)
|
||||
|
Reference in New Issue
Block a user