]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Added support for hg diffs generated in git mode
authorAsher Baker <asherkin@limetech.org>
Wed, 23 Jan 2013 02:13:53 +0000 (18:13 -0800)
committerepriestley <git@epriestley.com>
Wed, 23 Jan 2013 02:14:14 +0000 (18:14 -0800)
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

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

index 4ddf5284548ee4f0b8fe8e29ddb64b1bafdc5a82..2313cb1cf521a8e639afc721160d55904660b84f 100644 (file)
@@ -210,7 +210,6 @@ final class ArcanistDiffParser {
         '(?P<binary>Binary) files '.
           '(?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". 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>.+)',
@@ -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;
       }
     }
index d01bcf652bf7c7b4f6a673edfcd9535f73f2eb61..494430134667fbca67a5fe7556da83daaf197cb2 100644 (file)
@@ -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 (file)
index 0000000..358037b
--- /dev/null
@@ -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
++}
+