]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Refine whitespace and end-of-block detection for git binary literal patches in
authorepriestley <git@epriestley.com>
Tue, 25 Oct 2011 23:55:32 +0000 (16:55 -0700)
committerepriestley <git@epriestley.com>
Wed, 26 Oct 2011 00:02:27 +0000 (17:02 -0700)
mercurial changesets

Summary: Makes the parsing slightly more liberal so a test case from @Makinde
passes.

Test Plan: Ran unit tests.

Reviewers: Makinde, jungejason, nh, tuomaspelkonen, aran

Reviewed By: Makinde

CC: aran, Makinde
Differential Revision: 1054

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

index f828fc4ba3cccc2f8e7cee687aa56710ba26b044..f550d4c0a8b922fab86e435658b06c62a0e245c0 100644 (file)
@@ -663,12 +663,14 @@ class ArcanistDiffParser {
     }
     do {
       $line = $this->nextLine();
-      if ($line === '') {
+      if ($line === '' || $line === null) {
+        // Some versions of Mercurial apparently omit the terminal newline,
+        // although it's unclear if Git will ever do this. In either case,
+        // rely on the base85 check for sanity.
         $this->nextNonemptyLine();
         return;
-      } else if ($line === null) {
-        throw new Exception(
-          "Expected empty line to terminate binary patch.");
+      } else if (!preg_match('/^[a-zA-Z]/', $line)) {
+        $this->didFailParse("Expected base85 line length character (a-zA-Z).");
       }
     } while (true);
   }
index 552426045c71e10d1734f6576cd1e02e0f31ccaf..d7cd8fba6117b0ede4c6efbc94138f62f611c460 100644 (file)
@@ -478,6 +478,7 @@ EOTEXT
           $change->getFileType());
         break;
       case 'hg-binary-change.hgdiff':
+      case 'hg-solo-binary-change.hgdiff':
         $this->assertEqual(1, count($changes));
         $change = reset($changes);
         $this->assertEqual(
diff --git a/src/parser/diff/__tests__/data/hg-solo-binary-change.hgdiff b/src/parser/diff/__tests__/data/hg-solo-binary-change.hgdiff
new file mode 100644 (file)
index 0000000..1814e12
--- /dev/null
@@ -0,0 +1,7 @@
+diff --git a/x/inherit.gif b/x/inherit.gif
+new file mode 100644
+index 0000000000000000000000000000000000000000..c814867a13deb0ca7ea2156c6ca1d5a03372af7e
+GIT binary patch
+literal 57
+zc${<hbhEHb<Y(YxXkcLY|NlP&1A`6_Gk`=Gm?T>IIT!9-C*e{wE9>Kx3D)-;0v)C;
+KYxQGgum%9JOA&7X
\ No newline at end of file