From 89cb92a22ca69f10dc0256a11d2756c1290da789 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 20 Dec 2011 15:05:46 -0800 Subject: [PATCH] Parse full URIs for "Differential Revision" in Arcanist 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 --- .../ArcanistDifferentialCommitMessage.php | 25 ++++++++++++++++--- src/differential/commitmessage/__init__.php | 3 +++ src/workflow/diff/ArcanistDiffWorkflow.php | 15 +++++++---- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/differential/commitmessage/ArcanistDifferentialCommitMessage.php b/src/differential/commitmessage/ArcanistDifferentialCommitMessage.php index baf0d667..8924f65c 100644 --- a/src/differential/commitmessage/ArcanistDifferentialCommitMessage.php +++ b/src/differential/commitmessage/ArcanistDifferentialCommitMessage.php @@ -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'; diff --git a/src/differential/commitmessage/__init__.php b/src/differential/commitmessage/__init__.php index 49f0e53a..9a694506 100644 --- a/src/differential/commitmessage/__init__.php +++ b/src/differential/commitmessage/__init__.php @@ -6,6 +6,9 @@ +phutil_require_module('arcanist', 'exception/usage'); + +phutil_require_module('phutil', 'parser/uri'); phutil_require_module('phutil', 'utils'); diff --git a/src/workflow/diff/ArcanistDiffWorkflow.php b/src/workflow/diff/ArcanistDiffWorkflow.php index 9cf0bb62..0119ce5a 100644 --- a/src/workflow/diff/ArcanistDiffWorkflow.php +++ b/src/workflow/diff/ArcanistDiffWorkflow.php @@ -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"; }