protected $isGit;
protected $isMercurial;
protected $detectBinaryFiles = false;
+ protected $tryEncoding;
protected $changes = array();
private $forcePath;
return $this;
}
+ public function setTryEncoding($encoding) {
+ $this->tryEncoding = $encoding;
+ }
+
public function forcePath($path) {
$this->forcePath = $path;
return $this;
$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) {
+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');