1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-10 08:52:39 +01:00

Support other encodings in ArcanistDiffParser

Test Plan:
Tried viewing a diff detected as binary in diffusion with and without
setting my desired encoding. Worked as expected.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, epriestley

Differential Revision: 1008
This commit is contained in:
David Reuss 2011-10-28 08:01:21 -07:00 committed by epriestley
parent 311449bcf8
commit ebc2644994
2 changed files with 21 additions and 0 deletions

View file

@ -29,6 +29,7 @@ class ArcanistDiffParser {
protected $isGit;
protected $isMercurial;
protected $detectBinaryFiles = false;
protected $tryEncoding;
protected $changes = array();
private $forcePath;
@ -47,6 +48,10 @@ class ArcanistDiffParser {
return $this;
}
public function setTryEncoding($encoding) {
$this->tryEncoding = $encoding;
}
public function forcePath($path) {
$this->forcePath = $path;
return $this;
@ -807,6 +812,21 @@ class ArcanistDiffParser {
$is_binary = false;
if ($this->detectBinaryFiles) {
$is_binary = !phutil_is_utf8($corpus);
if ($is_binary && $this->tryEncoding) {
$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);
}
}
}
}
if ($is_binary) {

View file

@ -6,6 +6,7 @@
phutil_require_module('arcanist', 'difference');
phutil_require_module('arcanist', 'parser/diff/change');
phutil_require_module('arcanist', 'parser/diff/changetype');
phutil_require_module('arcanist', 'parser/diff/hunk');