]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix some regexp issues for parsing SVN diffs with \r\n newlines
authorepriestley <git@epriestley.com>
Mon, 22 Oct 2012 18:15:36 +0000 (11:15 -0700)
committerepriestley <git@epriestley.com>
Mon, 22 Oct 2012 18:15:36 +0000 (11:15 -0700)
Summary: We need to tweak a few patterns to accommodate the possibility that lines end in "\r\n".

Test Plan: Added failing unit test and made it pass.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran, mbishopim3
Maniphest Tasks: T1944

Differential Revision: https://secure.phabricator.com/D3772

src/parser/ArcanistDiffParser.php
src/parser/__tests__/ArcanistDiffParserTestCase.php
src/parser/__tests__/diff/more-newlines.svndiff [new file with mode: 0644]

index 188e6d4bc6bfb6e8606e8492036878ce097ef55c..ee55d721f2d448277bbe1b042c0cc066f92f5402 100644 (file)
@@ -649,7 +649,7 @@ final class ArcanistDiffParser {
     $line = $this->getLine();
 
     if ($is_svn) {
-      $ok = preg_match('/^=+$/', $line);
+      $ok = preg_match('/^=+\s*$/', $line);
       if (!$ok) {
         $this->didFailParse("Expected '=======================' divider line.");
       } else {
@@ -684,8 +684,8 @@ final class ArcanistDiffParser {
     }
 
     $is_binary_add = preg_match(
-      '/^Cannot display: file marked as a binary type.$/',
-      $line);
+      '/^Cannot display: file marked as a binary type\.$/',
+      rtrim($line));
     if ($is_binary_add) {
       $this->nextLine(); // Cannot display: file marked as a binary type.
       $this->nextNonemptyLine(); // svn:mime-type = application/octet-stream
@@ -697,7 +697,7 @@ final class ArcanistDiffParser {
     // WITHOUT a binary mime-type and is changed and given a binary mime-type.
     $is_binary_diff = preg_match(
       '/^Binary files .* and .* differ$/',
-      $line);
+      rtrim($line));
     if ($is_binary_diff) {
       $this->nextNonemptyLine(); // Binary files x and y differ
       $this->markBinary($change);
@@ -710,7 +710,7 @@ final class ArcanistDiffParser {
     // can not apply these patches.)
     $is_hg_binary_delete = preg_match(
       '/^Binary file .* has changed$/',
-      $line);
+      rtrim($line));
     if ($is_hg_binary_delete) {
       $this->nextNonemptyLine();
       $this->markBinary($change);
@@ -723,7 +723,7 @@ final class ArcanistDiffParser {
     // patch.
     $is_git_binary_patch = preg_match(
       '/^GIT binary patch$/',
-      $line);
+      rtrim($line));
     if ($is_git_binary_patch) {
       $this->nextLine();
       $this->parseGitBinaryPatch();
@@ -739,7 +739,7 @@ final class ArcanistDiffParser {
 
     if ($is_git) {
       // "git diff -b" ignores whitespace, but has an empty hunk target
-      if (preg_match('@^diff --git a/.*$@', $line)) {
+      if (preg_match('@^diff --git .*$@', $line)) {
         $this->nextLine();
         return null;
       }
index e59a2df5a90e4320cac4a914aef3251f3e0acc02..e4c4c3e8c605121bb515b55fb099dbf971a8b147 100644 (file)
@@ -549,6 +549,9 @@ EOTEXT
           'dst/file',
           $change->getCurrentPath());
         break;
+      case 'more-newlines.svndiff':
+        $this->assertEqual(1, count($changes));
+        break;
       default:
         throw new Exception("No test block for diff file {$diff_file}.");
         break;
diff --git a/src/parser/__tests__/diff/more-newlines.svndiff b/src/parser/__tests__/diff/more-newlines.svndiff
new file mode 100644 (file)
index 0000000..ce40e70
--- /dev/null
@@ -0,0 +1,13 @@
+Index: Database/tables/dbo.Account.sql\r
+===================================================================\r
+--- Database/tables/dbo.Account.sql    (revision 1587)\r
++++ Database/tables/dbo.Account.sql    (working copy)\r
+@@ -23,6 +23,8 @@\r
+ GO\r
+ CREATE CLUSTERED INDEX IX_Account ON [Account] ([CreationDateTime])\r
+ GO\r
++ALTER TABLE [dbo].[Account] ADD CONSTRAINT [UK_Account_APIKey] UNIQUE ([APIKey])\r
++GO\r
+ ALTER TABLE [dbo].[Account] ADD  CONSTRAINT [DF_Account_AccountId]  DEFAULT (newid()) FOR [AccountId]\r
+ GO\r
+ ALTER TABLE [dbo].[Account] ADD  CONSTRAINT [DF_Account_CreationDateTime]  DEFAULT (getutcdate()) FOR [CreationDateTime]\r