1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-29 02:02:40 +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 $isGit;
protected $isMercurial; protected $isMercurial;
protected $detectBinaryFiles = false; protected $detectBinaryFiles = false;
protected $tryEncoding;
protected $changes = array(); protected $changes = array();
private $forcePath; private $forcePath;
@ -47,6 +48,10 @@ class ArcanistDiffParser {
return $this; return $this;
} }
public function setTryEncoding($encoding) {
$this->tryEncoding = $encoding;
}
public function forcePath($path) { public function forcePath($path) {
$this->forcePath = $path; $this->forcePath = $path;
return $this; return $this;
@ -807,6 +812,21 @@ 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);
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) { 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/change');
phutil_require_module('arcanist', 'parser/diff/changetype'); phutil_require_module('arcanist', 'parser/diff/changetype');
phutil_require_module('arcanist', 'parser/diff/hunk'); phutil_require_module('arcanist', 'parser/diff/hunk');