]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix parsing of "hg diff -r x:y" diffs
authorepriestley <git@epriestley.com>
Wed, 25 Jul 2012 22:55:32 +0000 (15:55 -0700)
committerepriestley <git@epriestley.com>
Wed, 25 Jul 2012 22:55:32 +0000 (15:55 -0700)
Summary: When you run `hg diff -r x:y`, we get two "-r" arguments in the diff header. Currently, we parse this incorrectly.

Test Plan: Added unit test which previously failed; test now passes.

Reviewers: dschleimer, btrahan

Reviewed By: dschleimer

CC: aran, cakoose
Maniphest Tasks: T1550

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

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

index da9623517fe60a95e0498b7472147af8dfbe9b5f..34060b70a8741cbd7716204be072a0441afe79ce 100644 (file)
@@ -229,8 +229,9 @@ final class ArcanistDiffParser {
           '(?P<old>.+)\s+\d{4}-\d{2}-\d{2} and '.
           '(?P<new>.+)\s+\d{4}-\d{2}-\d{2} differ.*',
 
-        // This is a normal Mercurial text change, probably from "hg diff".
-        '(?P<type>diff -r) (?P<hgrev>[a-f0-9]+) (?P<cur>.+)',
+        // This is a normal Mercurial text change, probably from "hg diff". It
+        // may have two "-r" blocks if it came from "hg diff -r x:y".
+        '(?P<type>diff -r) (?P<hgrev>[a-f0-9]+) (?:-r [a-f0-9]+ )?(?P<cur>.+)',
       );
 
       $ok = false;
index 90c6cae5496eb74eec30914d6dc8769c70a92718..20e2ef7d18887b73da21269d5ad38481883b683d 100644 (file)
@@ -527,6 +527,16 @@ EOTEXT
         $this->assertEqual('*', idx($new_properties, 'svn:executable'));
         $this->assertEqual('text/html', idx($new_properties, 'svn:mime-type'));
         break;
+      case 'hg-diff-range.hgdiff':
+        $this->assertEqual(1, count($changes));
+        $change = array_shift($changes);
+        $this->assertEqual(
+          'Test.java',
+          $change->getOldPath());
+        $this->assertEqual(
+          'Test.java',
+          $change->getCurrentPath());
+        break;
       default:
         throw new Exception("No test block for diff file {$diff_file}.");
         break;
diff --git a/src/parser/__tests__/diff/hg-diff-range.hgdiff b/src/parser/__tests__/diff/hg-diff-range.hgdiff
new file mode 100644 (file)
index 0000000..1f9f338
--- /dev/null
@@ -0,0 +1,11 @@
+diff -r 2ccefc36d42f -r 6a07a384974e Test.java
+--- a/Test.java        Tue Jul 24 14:57:51 2012 -0700
++++ b/Test.java        Tue Jul 24 14:59:23 2012 -0700
+@@ -2,6 +2,6 @@
+ {
+     public static void main(String[] args)
+     {
+-        System.out.println("Hello!");
++        System.out.println("Hello, world!");
+     }
+ }