]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Parse full URIs for "Differential Revision" in Arcanist
authorepriestley <git@epriestley.com>
Tue, 20 Dec 2011 23:05:46 +0000 (15:05 -0800)
committerepriestley <git@epriestley.com>
Wed, 21 Dec 2011 03:57:55 +0000 (19:57 -0800)
Summary:
  - Allow Arcanist to parse either "123", "D123" (existing behaviors) or
"http://phabricator.example.com/D123" (new behavior) values.
  - Drop support for labeling this field "DiffCamp". This should only impact
people trying to update revisions that are more than ~a year old, which should
be very very few.

Test Plan:   - Ran "arc diff" with values "74", "D74", "x74",
"http://local.aphront.com/D74", "http://local.aphront.com/x74". Got the expected
behaviors.

Reviewers: jungejason, btrahan

Reviewed By: jungejason

CC: aran, jungejason
Maniphest Tasks: T54, T692

Differential Revision: 1249

src/differential/commitmessage/ArcanistDifferentialCommitMessage.php
src/differential/commitmessage/__init__.php
src/workflow/diff/ArcanistDiffWorkflow.php

index baf0d667db4113df5283146a3b7a6b7e7c720126..8924f65cdc96ecbb9037320ef3b7538a51fe4e21 100644 (file)
@@ -35,10 +35,29 @@ class ArcanistDifferentialCommitMessage {
     $obj = new ArcanistDifferentialCommitMessage();
     $obj->rawCorpus = $corpus;
 
-    // TODO: Remove "Diffcamp" backward compatibility.
+    // Parse older-style "123" fields, or newer-style full-URI fields.
+    // TODO: Remove support for older-style fields.
+
     $match = null;
-    if (preg_match('/^(?:Differential|DiffCamp) Revision:\s*D?(\d+)/im', $corpus, $match)) {
-      $obj->revisionID = (int)$match[1];
+    if (preg_match('/^Differential Revision:\s*(.*)/im', $corpus, $match)) {
+      $revision_id = trim($match[1]);
+      if (strlen($revision_id)) {
+        if (preg_match('/^D?\d+$/', $revision_id)) {
+          $obj->revisionID = (int)trim($revision_id, 'D');
+        } else {
+          $uri = new PhutilURI($revision_id);
+          $path = $uri->getPath();
+          $path = trim($path, '/');
+          if (preg_match('/^D\d+$/', $path)) {
+            $obj->revisionID = (int)trim($path, 'D');
+          } else {
+            throw new ArcanistUsageException(
+              "Invalid 'Differential Revision' field. The field should have a ".
+              "Phabricator URI like 'http://phabricator.example.com/D123', ".
+              "but has '{$match[1]}'.");
+          }
+        }
+      }
     }
 
     $pattern = '/^git-svn-id:\s*([^@]+)@(\d+)\s+(.*)$/m';
index 49f0e53a9ef0c4904026153ced0cd985f2514e58..9a69450607458a9cef3b5623ee7618544852c5fb 100644 (file)
@@ -6,6 +6,9 @@
 
 
 
+phutil_require_module('arcanist', 'exception/usage');
+
+phutil_require_module('phutil', 'parser/uri');
 phutil_require_module('phutil', 'utils');
 
 
index 9cf0bb621cd9eefc2f554872056fd2d8b5486e3c..0119ce5a41c877c59820197f3fe80e934d143f2f 100644 (file)
@@ -499,11 +499,16 @@ EOTEXT
           'differential.createrevision',
           $revision);
         $result = $future->resolve();
-        echo "Updating commit message to include Differential revision ID...\n";
-        $repository_api->amendGitHeadCommit(
-          $message->getRawCorpus().
-          "\n\n".
-          "Differential Revision: ".$result['revisionid']."\n");
+
+        $revised_message = $conduit->callMethodSynchronous(
+          'differential.getcommitmessage',
+          array(
+            'revision_id' => $result['revisionid'],
+          ));
+
+        echo "Updating commit message...\n";
+        $repository_api->amendGitHeadCommit($revised_message);
+
         echo "Created a new Differential revision:\n";
       }