mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-29 10:12:41 +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:
parent
c0c78c2ff4
commit
be3ce781bb
3 changed files with 12 additions and 27 deletions
|
@ -399,16 +399,8 @@ final class ArcanistBundle {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function convertNonUTF8Diff($diff) {
|
private function convertNonUTF8Diff($diff) {
|
||||||
$try_encoding_is_non_utf8 =
|
if ($this->encoding) {
|
||||||
($this->encoding && strtoupper($this->encoding) != 'UTF-8');
|
$diff = phutil_utf8_convert($diff, $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?");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $diff;
|
return $diff;
|
||||||
}
|
}
|
||||||
|
|
|
@ -913,18 +913,17 @@ final class ArcanistDiffParser {
|
||||||
$is_binary = false;
|
$is_binary = false;
|
||||||
if ($this->detectBinaryFiles) {
|
if ($this->detectBinaryFiles) {
|
||||||
$is_binary = !phutil_is_utf8($corpus);
|
$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);
|
$is_binary = ArcanistDiffUtils::isHeuristicBinaryFile($corpus);
|
||||||
if (!$is_binary) {
|
if (!$is_binary) {
|
||||||
// NOTE: This feature is HIGHLY EXPERIMENTAL and will cause a lot
|
$corpus = phutil_utf8_convert($corpus, 'UTF-8', $try_encoding);
|
||||||
// of issues. Use it at your own risk.
|
if (!phutil_is_utf8($corpus)) {
|
||||||
$corpus = mb_convert_encoding(
|
throw new Exception(
|
||||||
$corpus, 'UTF-8', $this->tryEncoding);
|
"Failed to convert a hunk from '{$try_encoding}' to UTF-8. ".
|
||||||
if (!phutil_is_utf8($corpus)) {
|
"Check that the specified encoding is correct.");
|
||||||
throw new Exception(
|
}
|
||||||
'Failed converting hunk to '.$this->tryEncoding);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -916,14 +916,8 @@ EOTEXT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($try_encoding && $try_encoding != 'UTF-8') {
|
if ($try_encoding) {
|
||||||
if (!function_exists('mb_convert_encoding')) {
|
$corpus = phutil_utf8_convert($corpus, 'UTF-8', $try_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);
|
|
||||||
$name = $change->getCurrentPath();
|
$name = $change->getCurrentPath();
|
||||||
if (phutil_is_utf8($corpus)) {
|
if (phutil_is_utf8($corpus)) {
|
||||||
$this->writeStatusMessage(
|
$this->writeStatusMessage(
|
||||||
|
|
Loading…
Reference in a new issue