1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 16:22:42 +01:00

Switch arcanist to phutil_utf8_convert()

Summary: See D3252. Reduces code duplication a little bit. Also remove some dire warnings about impending doom -- this has been in use in the wild for a long time.

Test Plan: Added a file in ISO-8859-1, ran `arc diff --encoding ISO-8859-1` to generate this revision, got an encoding note in output.

Reviewers: davidreuss, vrana, btrahan

Reviewed By: davidreuss

CC: aran

Maniphest Tasks: T452

Differential Revision: https://secure.phabricator.com/D3253
This commit is contained in:
epriestley 2012-08-12 08:50:01 -07:00
parent c0c78c2ff4
commit be3ce781bb
3 changed files with 12 additions and 27 deletions

View file

@ -399,16 +399,8 @@ final class ArcanistBundle {
}
private function convertNonUTF8Diff($diff) {
$try_encoding_is_non_utf8 =
($this->encoding && strtoupper($this->encoding) != 'UTF-8');
if ($try_encoding_is_non_utf8) {
$diff = mb_convert_encoding($diff, $this->encoding, 'UTF-8');
if (!$diff) {
throw new Exception(
"Attempted conversion of diff to encoding ".
"'{$this->encoding}' failed. Have you specified ".
"the proper encoding correctly?");
}
if ($this->encoding) {
$diff = phutil_utf8_convert($diff, $this->encoding, 'UTF-8');
}
return $diff;
}

View file

@ -913,18 +913,17 @@ final class ArcanistDiffParser {
$is_binary = false;
if ($this->detectBinaryFiles) {
$is_binary = !phutil_is_utf8($corpus);
$try_encoding = $this->tryEncoding;
if ($is_binary && $this->tryEncoding) {
if ($is_binary && $try_encoding) {
$is_binary = ArcanistDiffUtils::isHeuristicBinaryFile($corpus);
if (!$is_binary) {
// NOTE: This feature is HIGHLY EXPERIMENTAL and will cause a lot
// of issues. Use it at your own risk.
$corpus = mb_convert_encoding(
$corpus, 'UTF-8', $this->tryEncoding);
if (!phutil_is_utf8($corpus)) {
throw new Exception(
'Failed converting hunk to '.$this->tryEncoding);
}
$corpus = phutil_utf8_convert($corpus, 'UTF-8', $try_encoding);
if (!phutil_is_utf8($corpus)) {
throw new Exception(
"Failed to convert a hunk from '{$try_encoding}' to UTF-8. ".
"Check that the specified encoding is correct.");
}
}
}

View file

@ -916,14 +916,8 @@ EOTEXT
}
}
if ($try_encoding && $try_encoding != 'UTF-8') {
if (!function_exists('mb_convert_encoding')) {
throw new ArcanistUsageException(
"This diff includes a file encoded in '{$try_encoding}', ".
"but you don't have the PHP mbstring extension installed ".
"so it can't be converted to UTF-8. Install mbstring.");
}
$corpus = mb_convert_encoding($corpus, 'UTF-8', $try_encoding);
if ($try_encoding) {
$corpus = phutil_utf8_convert($corpus, 'UTF-8', $try_encoding);
$name = $change->getCurrentPath();
if (phutil_is_utf8($corpus)) {
$this->writeStatusMessage(