]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Correctly parse Mercurial output for "hg diff --git" when binary files are
authorepriestley <git@epriestley.com>
Fri, 18 Nov 2011 19:03:17 +0000 (11:03 -0800)
committerepriestley <git@epriestley.com>
Sun, 20 Nov 2011 22:21:40 +0000 (14:21 -0800)
removed

Summary: Mercurial output diverges from git output when binary files are
removed. Parse the Mercurial flavor.

Test Plan:
  - Unit test fails before this change and passes afterward.
  - Removed a binary file in my hg local and successfully "arc diff --only"'d
the change.

NOTE: Git can't apply these patches, and reports:

  $ git apply < ~/Desktop/patch.txt
  error: removal patch leaves file contents
  error: level.png: patch does not apply

Reviewers: Makinde, btrahan, jungejason, nh, tuomaspelkonen, aran

Reviewed By: jungejason

CC: aran, jungejason, Makinde
Differential Revision: 1126

src/parser/diff/ArcanistDiffParser.php
src/parser/diff/__tests__/ArcanistDiffParserTestCase.php
src/parser/diff/__tests__/data/hg-binary-delete.hgdiff [new file with mode: 0644]

index a31fc98057918ecedffc25449a74e9bd08f64a60..1a7d478da5e6de77026a1805fc337fe7dac99d8c 100644 (file)
@@ -620,6 +620,19 @@ class ArcanistDiffParser {
       return;
     }
 
+    // This occurs under "hg diff --git" when a binary file is removed. See
+    // test case "hg-binary-delete.hgdiff". (I believe it never occurs under
+    // git, which reports the "files X and /dev/null differ" string above. Git
+    // can not apply these patches.)
+    $is_hg_binary_delete = preg_match(
+      '/^Binary file .* has changed$/',
+      $line);
+    if ($is_hg_binary_delete) {
+      $this->nextNonemptyLine();
+      $this->markBinary($change);
+      return;
+    }
+
     // With "git diff --binary" (not a normal mode, but one users may explicitly
     // invoke and then, e.g., copy-paste into the web console) or "hg diff
     // --git" (normal under hg workflows), we may encounter a literal binary
index d7cd8fba6117b0ede4c6efbc94138f62f611c460..3bac9f98d50b140e7c22c1f0433d23e8d2a197b1 100644 (file)
@@ -488,6 +488,16 @@ EOTEXT
           ArcanistDiffChangeType::FILE_BINARY,
           $change->getFileType());
         break;
+      case 'hg-binary-delete.hgdiff':
+        $this->assertEqual(1, count($changes));
+        $change = reset($changes);
+        $this->assertEqual(
+          ArcanistDiffChangeType::TYPE_DELETE,
+          $change->getType());
+        $this->assertEqual(
+          ArcanistDiffChangeType::FILE_BINARY,
+          $change->getFileType());
+        break;
       case 'git-replace-symlink.gitdiff':
         $this->assertEqual(1, count($changes));
         $change = array_shift($changes);
diff --git a/src/parser/diff/__tests__/data/hg-binary-delete.hgdiff b/src/parser/diff/__tests__/data/hg-binary-delete.hgdiff
new file mode 100644 (file)
index 0000000..6d01163
--- /dev/null
@@ -0,0 +1,3 @@
+diff --git a/binary.png b/binary.png
+deleted file mode 100755
+Binary file binary.png has changed