private $projectID;
private $baseRevision;
private $revisionID;
+ private $encoding;
public function setConduit(ConduitClient $conduit) {
$this->conduit = $conduit;
$this->baseRevision = $base_revision;
}
+ public function setEncoding($encoding) {
+ $this->encoding = $encoding;
+ return $this;
+ }
+
+ public function getEncoding() {
+ return $this->encoding;
+ }
+
public function getBaseRevision() {
return $this->baseRevision;
}
$project_name = idx($meta_info, 'projectName');
$base_revision = idx($meta_info, 'baseRevision');
$revision_id = idx($meta_info, 'revisionID');
+ $encoding = idx($meta_info, 'encoding');
// this arc bundle was probably made before we started storing meta info
} else {
$version = 0;
$project_name = null;
$base_revision = null;
$revision_id = null;
+ $encoding = null;
}
$future = new ExecFuture(
$obj->setProjectID($project_name);
$obj->setBaseRevision($base_revision);
$obj->setRevisionID($revision_id);
+ $obj->setEncoding($encoding);
return $obj;
}
'projectName' => $this->getProjectID(),
'baseRevision' => $this->getBaseRevision(),
'revisionID' => $this->getRevisionID(),
+ 'encoding' => $this->getEncoding(),
);
$dir = Filesystem::createTemporaryDirectory();
$result[] = $this->buildHunkChanges($change->getHunks());
}
- return implode("\n", $result)."\n";
+ $diff = implode("\n", $result)."\n";
+ return $this->convertNonUTF8Diff($diff);
}
public function toGitPatch() {
}
$result[] = $change_body;
}
- return implode("\n", $result)."\n";
+
+ $diff = implode("\n", $result)."\n";
+ return $this->convertNonUTF8Diff($diff);
+ }
+
+ 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?");
+ }
+ }
+ return $diff;
}
public function getChanges() {
}
private function buildHunkChanges(array $hunks) {
+
$result = array();
foreach ($hunks as $hunk) {
$small_hunks = $this->breakHunkIntoSmallHunks($hunk);
private $arguments;
private $command;
+ private $repositoryEncoding;
+
private $arcanistConfiguration;
private $parentWorkflow;
private $workingDirectory;
return $repository_api->getPath('.arc/'.$path);
}
+ protected function getRepositoryEncoding() {
+ if ($this->repositoryEncoding) {
+ return $this->repositoryEncoding;
+ }
+
+ $project_info = $this->getConduit()->callMethodSynchronous(
+ 'arcanist.projectinfo',
+ array(
+ 'name' => $this->getWorkingCopy()->getProjectID(),
+ ));
+ $this->repositoryEncoding = nonempty($project_info['encoding'], 'UTF-8');
+ return $this->repositoryEncoding;
+ }
+
}
}
}
- $try_encoding = null;
+ $try_encoding = nonempty($this->getArgument('encoding'), null);
$utf8_problems = array();
foreach ($changes as $change) {
// liberal about what they're willing to process.
$is_binary = ArcanistDiffUtils::isHeuristicBinaryFile($corpus);
if (!$is_binary) {
- $try_encoding = nonempty($this->getArgument('encoding'), null);
- if ($try_encoding === null) {
- // Make a call to check if there's an encoding specified for this
- // project.
+
+ if (!$try_encoding) {
try {
- $project_info = $this->getConduit()->callMethodSynchronous(
- 'arcanist.projectinfo',
- array(
- 'name' => $this->getWorkingCopy()->getProjectID(),
- ));
- $try_encoding = nonempty($project_info['encoding'], false);
+ $try_encoding = $this->getRepositoryEncoding();
} catch (ConduitClientException $e) {
- if ($e->getErrorCode() == 'ERR-BAD-ARCANIST-PROJECT') {
- echo phutil_console_wrap(
- "Lookup of encoding in arcanist project failed\n".
- $e->getMessage()
- );
- $try_encoding = false;
- } else {
- throw $e;
- }
+ if ($e->getErrorCode() == 'ERR-BAD-ARCANIST-PROJECT') {
+ echo phutil_console_wrap(
+ "Lookup of encoding in arcanist project failed\n".
+ $e->getMessage());
+ } else {
+ throw $e;
+ }
}
}
+
if ($try_encoding) {
// NOTE: This feature is HIGHLY EXPERIMENTAL and will cause a lot
// of issues. Use it at your own risk.
"Export change as an arc bundle. This format can represent all ".
"changes. These bundles can be applied with 'arc patch'.",
),
+ 'encoding' => array(
+ 'param' => 'encoding',
+ 'help' =>
+ "Attempt to convert non UTF-8 patch into specified encoding.",
+ ),
'revision' => array(
'param' => 'revision_id',
'help' =>
break;
}
+ $try_encoding = nonempty($this->getArgument('encoding'), null);
+ if (!$try_encoding) {
+ try {
+ $try_encoding = $this->getRepositoryEncoding();
+ } catch (ConduitClientException $e) {
+ $try_encoding = null;
+ }
+ }
+
+ if ($try_encoding) {
+ $bundle->setEncoding($try_encoding);
+ }
+
$format = $this->getFormat();
switch ($format) {
phutil_require_module('arcanist', 'workflow/base');
phutil_require_module('phutil', 'console');
+phutil_require_module('phutil', 'utils');
phutil_require_source('ArcanistExportWorkflow.php');
'help' =>
"Apply changes from a git patchfile or unified patchfile.",
),
+ 'encoding' => array(
+ 'param' => 'encoding',
+ 'help' =>
+ "Attempt to convert non UTF-8 patch into specified encoding.",
+ ),
'update' => array(
'supports' => array(
'git', 'svn', 'hg'
throw $ex;
}
}
+
+ $try_encoding = nonempty($this->getArgument('encoding'), null);
+ if (!$try_encoding) {
+ try {
+ $try_encoding = $this->getRepositoryEncoding();
+ } catch (ConduitClientException $e) {
+ $try_encoding = null;
+ }
+ }
+
+ if ($try_encoding) {
+ $bundle->setEncoding($try_encoding);
+ }
+
$force = $this->getArgument('force', false);
if ($force) {
// force means don't do any sanity checks about the patch