]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Switch arcanist to phutil_utf8_convert()
authorepriestley <git@epriestley.com>
Sun, 12 Aug 2012 15:50:01 +0000 (08:50 -0700)
committerepriestley <git@epriestley.com>
Sun, 12 Aug 2012 15:50:01 +0000 (08:50 -0700)
Summary: See D3252. Reduces code duplication a little bit. Also remove some dire warnings about impending doom -- this has been in use in the wild for a long time.

Test Plan: Added a file in ISO-8859-1, ran `arc diff --encoding ISO-8859-1` to generate this revision, got an encoding note in output.

Reviewers: davidreuss, vrana, btrahan

Reviewed By: davidreuss

CC: aran
Maniphest Tasks: T452

Differential Revision: https://secure.phabricator.com/D3253

src/parser/ArcanistBundle.php
src/parser/ArcanistDiffParser.php
src/workflow/ArcanistDiffWorkflow.php

index 2eb3d9d92cd8f1d6a03cd4edc294a6da965cf57d..ebf2e095cc88d943d9ce9f385e7e9848489c1647 100644 (file)
@@ -399,16 +399,8 @@ final class ArcanistBundle {
   }
 
   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?");
-      }
+    if ($this->encoding) {
+      $diff = phutil_utf8_convert($diff, $this->encoding, 'UTF-8');
     }
     return $diff;
   }
index 31b7404100ccc56d43617353f5e16cc1740c3d4c..fcada2a0005e7826dffd75d548b0d486519435dd 100644 (file)
@@ -913,18 +913,17 @@ final class ArcanistDiffParser {
       $is_binary = false;
       if ($this->detectBinaryFiles) {
         $is_binary = !phutil_is_utf8($corpus);
+        $try_encoding = $this->tryEncoding;
 
-        if ($is_binary && $this->tryEncoding) {
+        if ($is_binary && $try_encoding) {
           $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);
-              }
+            $corpus = phutil_utf8_convert($corpus, 'UTF-8', $try_encoding);
+            if (!phutil_is_utf8($corpus)) {
+              throw new Exception(
+                "Failed to convert a hunk from '{$try_encoding}' to UTF-8. ".
+                "Check that the specified encoding is correct.");
+            }
           }
         }
 
index 256b76768bbb060c489ee5a796fb98ca0c4f80a5..fa850845de49160f31799772ad660967ed26ef43 100644 (file)
@@ -916,14 +916,8 @@ EOTEXT
               }
             }
 
-            if ($try_encoding && $try_encoding != 'UTF-8') {
-              if (!function_exists('mb_convert_encoding')) {
-                throw new ArcanistUsageException(
-                  "This diff includes a file encoded in '{$try_encoding}', ".
-                  "but you don't have the PHP mbstring extension installed ".
-                  "so it can't be converted to UTF-8. Install mbstring.");
-              }
-              $corpus = mb_convert_encoding($corpus, 'UTF-8', $try_encoding);
+            if ($try_encoding) {
+              $corpus = phutil_utf8_convert($corpus, 'UTF-8', $try_encoding);
               $name = $change->getCurrentPath();
               if (phutil_is_utf8($corpus)) {
                 $this->writeStatusMessage(