]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Handle binary file moves in `arc patch` under Git
authorvrana <jakubv@fb.com>
Tue, 18 Sep 2012 23:03:32 +0000 (16:03 -0700)
committervrana <jakubv@fb.com>
Thu, 20 Sep 2012 20:16:11 +0000 (13:16 -0700)
Summary: We don't store old file PHID for binary file moves here.

Test Plan: `arc patch` on revision with binary file moves which was failing earlier.

Reviewers: epriestley, btrahan

Reviewed By: btrahan

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D3521

src/parser/ArcanistBundle.php

index ab9faa8e4ceef360bf040707c39d09fe5c138a43..18222579653a3975a072c6a95a6b56e02ab14fee 100644 (file)
@@ -299,6 +299,21 @@ final class ArcanistBundle {
       }
     }
 
+    $old_file_phids = array();
+    foreach ($changes as $change) {
+      $type = $change->getType();
+      if ($type == ArcanistDiffChangeType::TYPE_MOVE_AWAY) {
+        $file_type = $change->getFileType();
+        $is_binary = ($file_type == ArcanistDiffChangeType::FILE_BINARY ||
+                      $file_type == ArcanistDiffChangeType::FILE_IMAGE);
+        if ($is_binary) {
+          foreach ($change->getAwayPaths() as $path) {
+            $old_file_phids[$path] = $change->getMetadata('old:binary-phid');
+          }
+        }
+      }
+    }
+
     foreach ($changes as $change) {
       $type = $change->getType();
       $file_type = $change->getFileType();
@@ -326,7 +341,8 @@ final class ArcanistBundle {
                     $file_type == ArcanistDiffChangeType::FILE_IMAGE);
 
       if ($is_binary) {
-        $change_body = $this->buildBinaryChange($change);
+        $old_phid = idx($old_file_phids, $this->getCurrentPath($change));
+        $change_body = $this->buildBinaryChange($change, $old_phid);
       } else {
         $change_body = $this->buildHunkChanges($change->getHunks());
       }
@@ -604,24 +620,11 @@ final class ArcanistBundle {
     throw new Exception("Nowhere to load blob '{$phid}' from!");
   }
 
-  private function buildBinaryChange(ArcanistDiffChange $change) {
-    $old_phid = $change->getMetadata('old:binary-phid');
+  private function buildBinaryChange(ArcanistDiffChange $change, $old_phid) {
+    $old_phid = idx($change->getAllMetadata(), 'old:binary-phid', $old_phid);
     $new_phid = $change->getMetadata('new:binary-phid');
 
-    $type = $change->getType();
-    if ($type == ArcanistDiffChangeType::TYPE_ADD) {
-      $old_null = true;
-    } else {
-      $old_null = false;
-    }
-
-    if ($type == ArcanistDiffChangeType::TYPE_DELETE) {
-      $new_null = true;
-    } else {
-      $new_null = false;
-    }
-
-    if ($old_null) {
+    if (!$old_phid) {
       $old_data = '';
       $old_length = 0;
       $old_sha1 = str_repeat('0', 40);
@@ -631,7 +634,7 @@ final class ArcanistBundle {
       $old_sha1 = sha1("blob {$old_length}\0{$old_data}");
     }
 
-    if ($new_null) {
+    if (!$new_phid) {
       $new_data = '';
       $new_length = 0;
       $new_sha1 = str_repeat('0', 40);