]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Added local encoding parameter for arc diff workflow
authorDavid Reuss <david@upsys.dk>
Thu, 1 Dec 2011 16:56:03 +0000 (08:56 -0800)
committerepriestley <git@epriestley.com>
Thu, 1 Dec 2011 16:56:03 +0000 (08:56 -0800)
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

index 63ac69ec7f4b1cd59b8b02022e426f0fee4302c5..a64c661a56cff578c2fe2f57ec5a8d4ac89095fe 100644 (file)
@@ -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