From: epriestley Date: Wed, 25 Jul 2012 22:55:32 +0000 (-0700) Subject: Fix parsing of "hg diff -r x:y" diffs X-Git-Tag: conduit-6~189 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=11d0331d21f6d46b37eb80b27a0e5c947f3fe48b;p=arcanist.git Fix parsing of "hg diff -r x:y" diffs 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 --- diff --git a/src/parser/ArcanistDiffParser.php b/src/parser/ArcanistDiffParser.php index da962351..34060b70 100644 --- a/src/parser/ArcanistDiffParser.php +++ b/src/parser/ArcanistDiffParser.php @@ -229,8 +229,9 @@ final class ArcanistDiffParser { '(?P.+)\s+\d{4}-\d{2}-\d{2} and '. '(?P.+)\s+\d{4}-\d{2}-\d{2} differ.*', - // This is a normal Mercurial text change, probably from "hg diff". - '(?Pdiff -r) (?P[a-f0-9]+) (?P.+)', + // 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". + '(?Pdiff -r) (?P[a-f0-9]+) (?:-r [a-f0-9]+ )?(?P.+)', ); $ok = false; diff --git a/src/parser/__tests__/ArcanistDiffParserTestCase.php b/src/parser/__tests__/ArcanistDiffParserTestCase.php index 90c6cae5..20e2ef7d 100644 --- a/src/parser/__tests__/ArcanistDiffParserTestCase.php +++ b/src/parser/__tests__/ArcanistDiffParserTestCase.php @@ -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 index 00000000..1f9f3382 --- /dev/null +++ b/src/parser/__tests__/diff/hg-diff-range.hgdiff @@ -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!"); + } + }