From: vrana Date: Tue, 18 Sep 2012 23:03:32 +0000 (-0700) Subject: Handle binary file moves in `arc patch` under Git X-Git-Tag: conduit-6~117 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=1d744e932f74594f4239c9e68c7dd7f646259b57;p=arcanist.git Handle binary file moves in `arc patch` under Git 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 --- diff --git a/src/parser/ArcanistBundle.php b/src/parser/ArcanistBundle.php index ab9faa8e..18222579 100644 --- a/src/parser/ArcanistBundle.php +++ b/src/parser/ArcanistBundle.php @@ -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);