From 1f69ab5fdb3742f950f116fb4dccdd9215f27d85 Mon Sep 17 00:00:00 2001 From: David Reuss Date: Thu, 1 Dec 2011 08:56:03 -0800 Subject: [PATCH] Added local encoding parameter for arc diff workflow Summary: If any hunks is detected as non-utf8, and you've never submitted diffs for a certain project before, you would get a ERR-BAD-ARCANIST-PROJECT exception. This makes it possible to submit the patch properly, so you can set the encoding in the interface afterwards. Further this fixes cases where you don't supply a diff but will result in hunks getting treated as binary, but that still beats the exception behaviour. Test Plan: Ran `arc diff` with and without the new --encoding param and got the expected results. Also ensured the diff (with non utf-8 hunks) would be properly created even when no encoding is specified. Reviewers: epriestley Reviewed By: epriestley CC: aran, epriestley Differential Revision: 1135 --- src/workflow/diff/ArcanistDiffWorkflow.php | 30 +++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/workflow/diff/ArcanistDiffWorkflow.php b/src/workflow/diff/ArcanistDiffWorkflow.php index 63ac69ec..a64c661a 100644 --- a/src/workflow/diff/ArcanistDiffWorkflow.php +++ b/src/workflow/diff/ArcanistDiffWorkflow.php @@ -138,6 +138,11 @@ EOTEXT 'message' => '--preview does not update any revision.', ), ), + 'encoding' => array( + 'param' => 'encoding', + 'help' => + "Attempt to convert non UTF-8 hunks into specified encoding.", + ), 'allow-untracked' => array( 'help' => "Skip checks for untracked files in the working copy.", @@ -751,15 +756,28 @@ EOTEXT // 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. - $project_info = $this->getConduit()->callMethodSynchronous( - 'arcanist.projectinfo', - array( - 'name' => $this->getWorkingCopy()->getProjectID(), - )); - $try_encoding = nonempty($project_info['encoding'], false); + try { + $project_info = $this->getConduit()->callMethodSynchronous( + 'arcanist.projectinfo', + array( + 'name' => $this->getWorkingCopy()->getProjectID(), + )); + $try_encoding = nonempty($project_info['encoding'], false); + } 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 ($try_encoding) { // NOTE: This feature is HIGHLY EXPERIMENTAL and will cause a lot -- 2.43.0