From: Asher Baker Date: Wed, 23 Jan 2013 02:13:53 +0000 (-0800) Subject: Added support for hg diffs generated in git mode X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=087ad5f84aaed0977103524829c38411ce80fa27;p=arcanist.git Added support for hg diffs generated in git mode Summary: Fixes T2112. These are fairly common now, and are used as the storage format for `hg export` and mq in most installs. Test Plan: Ran unit tests, used `arc patch --patch`, uploaded some diffs manually. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2112 Differential Revision: https://secure.phabricator.com/D4592 --- diff --git a/src/parser/ArcanistDiffParser.php b/src/parser/ArcanistDiffParser.php index 4ddf5284..2313cb1c 100644 --- a/src/parser/ArcanistDiffParser.php +++ b/src/parser/ArcanistDiffParser.php @@ -210,7 +210,6 @@ final class ArcanistDiffParser { '(?PBinary) files '. '(?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". 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.+)', @@ -226,7 +225,7 @@ final class ArcanistDiffParser { // contains some meta information and comment at the beginning // (isFirstNonEmptyLine() to check for beginning). Actual mercurial // code detects where comment ends and unified diff starts by - // searching "diff -r" in the text. + // searching for "diff -r" or "diff --git" in the text. $this->saveLine(); $line = $this->nextLineThatLooksLikeDiffStart(); if (!$this->tryMatchHeader($patterns, $line, $match)) { @@ -1049,7 +1048,7 @@ final class ArcanistDiffParser { protected function nextLineThatLooksLikeDiffStart() { while (($line = $this->nextLine()) !== null) { - if (preg_match('/^\s*diff\s+-r/', $line)) { + if (preg_match('/^\s*diff\s+-(?:r|-git)/', $line)) { break; } } diff --git a/src/parser/__tests__/ArcanistDiffParserTestCase.php b/src/parser/__tests__/ArcanistDiffParserTestCase.php index d01bcf65..49443013 100644 --- a/src/parser/__tests__/ArcanistDiffParserTestCase.php +++ b/src/parser/__tests__/ArcanistDiffParserTestCase.php @@ -526,6 +526,9 @@ EOTEXT case 'hg-patch.hgdiff': $this->assertEqual(1, count($changes)); break; + case 'hg-patch-git.hgdiff': + $this->assertEqual(1, count($changes)); + break; case 'custom-prefixes.gitdiff': $this->assertEqual(1, count($changes)); $change = head($changes); diff --git a/src/parser/__tests__/diff/hg-patch-git.hgdiff b/src/parser/__tests__/diff/hg-patch-git.hgdiff new file mode 100644 index 00000000..358037b5 --- /dev/null +++ b/src/parser/__tests__/diff/hg-patch-git.hgdiff @@ -0,0 +1,17 @@ +# HG changeset patch +# Date 1358829820 0 +# Node ID 0c4c74e145f5e842a855330f600dba87b2f80fc9 +# Parent 80034eb49c320ccd43a1635471baf5c359f43cb5 +Added .arcconfig + +diff --git a/.arcconfig b/.arcconfig +new file mode 100644 +--- /dev/null ++++ b/.arcconfig +@@ -0,0 +1,5 @@ ++{ ++ "project_id" : "TestProject", ++ "conduit_uri" : "http://phabricator.example.com/", ++ "history.immutable" : true ++} +