]> khamidou — GitHub mirrors - arcanist.git/commitdiff
When converting a file to a binary, populate the binary's data
authorepriestley <git@epriestley.com>
Tue, 27 Aug 2013 16:34:30 +0000 (09:34 -0700)
committerepriestley <git@epriestley.com>
Tue, 27 Aug 2013 16:34:30 +0000 (09:34 -0700)
Summary:
Currently, we prompt the user to mark non-UTF8 files as binary, but don't actually attach the data to the change when they do. This means we don't upload the data, and can't patch it later.

A simple reproduction case is to build a test file (I used one with bytes from 1..255):

  $ # Don't include \0, since Git treats that specially.
  $ ./echo_every_byte_from_1_to_255_inclusive.erl > example.txt

Then add it:

  $ git add example.txt
  $ git commit -a -m derp
  $ arc diff --only HEAD^

You'll be prompted to convert the file to binary:

  Do you want to mark this file as binary and continue? [Y/n] y

Before this patch, that would be followed by:

  Uploading 0 files...

...which is incorrect; we need to upload the new data. After this patch, this shows:

  Uploading 1 files...

...which is also incorrect, but only grammatically. Diffs created after this patch apply back cleanly with `arc patch` and restore the file properly.

Test Plan: Followed instructions above, restoring a textual binary conversion by using `arc patch`.

Reviewers: zeeg, btrahan

Reviewed By: btrahan

CC: aran
Differential Revision: https://secure.phabricator.com/D6815

src/parser/diff/ArcanistDiffChange.php
src/workflow/ArcanistDiffWorkflow.php

index 770ecc86f682602fce494f02eca872626d6fc52e..26d187b9c9b2c3ea440814c58ee3cd16cfc5bef7 100644 (file)
@@ -234,7 +234,18 @@ final class ArcanistDiffChange {
     return $line_map;
   }
 
-  public function convertToBinaryChange() {
+  public function convertToBinaryChange(ArcanistRepositoryAPI $api) {
+
+    // Fill in the binary data from the working copy.
+
+    $this->setOriginalFileData(
+      $api->getOriginalFileData(
+        $this->getOldPath()));
+
+    $this->setCurrentFileData(
+      $api->getCurrentFileData(
+        $this->getCurrentPath()));
+
     $this->hunks = array();
     $this->setFileType(ArcanistDiffChangeType::FILE_BINARY);
     return $this;
index 7129a49b34f87f4034111b835d20af34d1a4f045..1187fd9fb3421cf4086832f11a94f303d40a4f2b 100644 (file)
@@ -994,7 +994,7 @@ EOTEXT
             "{$byte_warning} If the file is not a text file, you can ".
             "mark it 'binary'. Mark this file as 'binary' and continue?";
           if (phutil_console_confirm($confirm)) {
-            $change->convertToBinaryChange();
+            $change->convertToBinaryChange($repository_api);
           } else {
             throw new ArcanistUsageException(
               "Aborted generation of gigantic diff.");
@@ -1080,7 +1080,7 @@ EOTEXT
         throw new ArcanistUsageException("Aborted workflow to fix UTF-8.");
       } else {
         foreach ($utf8_problems as $change) {
-          $change->convertToBinaryChange();
+          $change->convertToBinaryChange($repository_api);
         }
       }
     }
@@ -2477,8 +2477,9 @@ EOTEXT
       $change->setMetadata("{$type}:file:size", $size);
       if ($spec['data'] === null) {
         // This covers the case where a file was added or removed; we don't
-        // need to upload it. (This is distinct from an empty file, which we
-        // do upload.)
+        // need to upload the other half of it (e.g., the old file data for
+        // a file which was just added). This is distinct from an empty
+        // file, which we do upload.
         unset($need_upload[$key]);
         continue;
       }