From 98cc64302ef6b0186c514572e2acf0276c8ff0ec Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 27 Oct 2017 09:27:41 -0700 Subject: [PATCH] If possible, use "differential.revision.edit" in "arc diff" Summary: Depends on D18741. Switches to "differential.revision.edit" if we get a transaction list back from parsing (added by D18740). This will allow us to use new transactions, notably "Hold as Draft" for "--draft". Test Plan: Ran `arc diff`, got a revision via `differential.revision.edit`. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D18742 --- .../ArcanistDifferentialCommitMessage.php | 8 +++ src/workflow/ArcanistDiffWorkflow.php | 51 ++++++++++++++++--- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/differential/ArcanistDifferentialCommitMessage.php b/src/differential/ArcanistDifferentialCommitMessage.php index b76011f5..132ddadf 100644 --- a/src/differential/ArcanistDifferentialCommitMessage.php +++ b/src/differential/ArcanistDifferentialCommitMessage.php @@ -8,6 +8,7 @@ final class ArcanistDifferentialCommitMessage extends Phobject { private $rawCorpus; private $revisionID; private $fields = array(); + private $xactions = null; private $gitSVNBaseRevision; private $gitSVNBasePath; @@ -50,6 +51,9 @@ final class ArcanistDifferentialCommitMessage extends Phobject { $this->fields = $result['fields']; + // NOTE: This does not exist prior to late October 2017. + $this->xactions = idx($result, 'transactions'); + if (!empty($result['errors'])) { throw new ArcanistDifferentialCommitMessageParserException( $result['errors']); @@ -93,6 +97,10 @@ final class ArcanistDifferentialCommitMessage extends Phobject { return md5($fields); } + public function getTransactions() { + return $this->xactions; + } + /** * Extract the revision ID from a commit message. * diff --git a/src/workflow/ArcanistDiffWorkflow.php b/src/workflow/ArcanistDiffWorkflow.php index 3ef87cc4..9f891c1f 100644 --- a/src/workflow/ArcanistDiffWorkflow.php +++ b/src/workflow/ArcanistDiffWorkflow.php @@ -21,6 +21,7 @@ final class ArcanistDiffWorkflow extends ArcanistWorkflow { private $diffPropertyFutures = array(); private $commitMessageFromRevision; private $hitAutotargets; + private $revisionTransactions; const STAGING_PUSHED = 'pushed'; const STAGING_USER_SKIP = 'user.skip'; @@ -525,16 +526,50 @@ EOTEXT echo pht('Updated an existing Differential revision:')."\n"; } else { - $revision = $this->dispatchWillCreateRevisionEvent($revision); + // NOTE: We're either using "differential.revision.edit" (preferred) + // if we can, or falling back to "differential.createrevision" + // (the older way) if not. - $result = $conduit->callMethodSynchronous( - 'differential.createrevision', - $revision); + $xactions = $this->revisionTransactions; + if ($xactions) { + $xactions[] = array( + 'type' => 'update', + 'value' => $diff_info['phid'], + ); + + $result = $conduit->callMethodSynchronous( + 'differential.revision.edit', + array( + 'transactions' => $xactions, + )); + + $result_id = idxv($result, array('object', 'id')); + if (!$result_id) { + throw new Exception( + pht( + 'Expected a revision ID to be returned by '. + '"differential.revision.edit".')); + } + + // TODO: This is hacky, but we don't currently receive a URI back + // from "differential.revision.edit". + $result_uri = id(new PhutilURI($this->getConduitURI())) + ->setPath('/D'.$result_id); + } else { + $revision = $this->dispatchWillCreateRevisionEvent($revision); + + $result = $conduit->callMethodSynchronous( + 'differential.createrevision', + $revision); + + $result_uri = $result['uri']; + $result_id = $result['revisionid']; + } $revised_message = $conduit->callMethodSynchronous( 'differential.getcommitmessage', array( - 'revision_id' => $result['revisionid'], + 'revision_id' => $result_id, )); if ($this->shouldAmend()) { @@ -552,7 +587,7 @@ EOTEXT echo pht('Created a new Differential revision:')."\n"; } - $uri = $result['uri']; + $uri = $result_uri; echo phutil_console_format( " **%s** __%s__\n\n", pht('Revision URI:'), @@ -640,6 +675,7 @@ EOTEXT $revision = array( 'fields' => $message->getFields(), ); + $xactions = $message->getTransactions(); if ($revision_id) { @@ -694,6 +730,7 @@ EOTEXT } $revision['fields'] = $new_message->getFields(); + $xactions = $new_message->getTransactions(); $revision['id'] = $revision_id; $this->revisionID = $revision_id; @@ -716,6 +753,8 @@ EOTEXT } } + $this->revisionTransactions = $xactions; + return $revision; }