Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistDiffWorkflow.php
| Show All 15 Lines | final class ArcanistDiffWorkflow extends ArcanistWorkflow { | ||||
| private $excuses = array('lint' => null, 'unit' => null); | private $excuses = array('lint' => null, 'unit' => null); | ||||
| private $testResults; | private $testResults; | ||||
| private $diffID; | private $diffID; | ||||
| private $revisionID; | private $revisionID; | ||||
| private $haveUncommittedChanges = false; | private $haveUncommittedChanges = false; | ||||
| private $diffPropertyFutures = array(); | private $diffPropertyFutures = array(); | ||||
| private $commitMessageFromRevision; | private $commitMessageFromRevision; | ||||
| private $hitAutotargets; | private $hitAutotargets; | ||||
| private $revisionTransactions; | |||||
| const STAGING_PUSHED = 'pushed'; | const STAGING_PUSHED = 'pushed'; | ||||
| const STAGING_USER_SKIP = 'user.skip'; | const STAGING_USER_SKIP = 'user.skip'; | ||||
| const STAGING_DIFF_RAW = 'diff.raw'; | const STAGING_DIFF_RAW = 'diff.raw'; | ||||
| const STAGING_REPOSITORY_UNKNOWN = 'repository.unknown'; | const STAGING_REPOSITORY_UNKNOWN = 'repository.unknown'; | ||||
| const STAGING_REPOSITORY_UNAVAILABLE = 'repository.unavailable'; | const STAGING_REPOSITORY_UNAVAILABLE = 'repository.unavailable'; | ||||
| const STAGING_REPOSITORY_UNSUPPORTED = 'repository.unsupported'; | const STAGING_REPOSITORY_UNSUPPORTED = 'repository.unsupported'; | ||||
| const STAGING_REPOSITORY_UNCONFIGURED = 'repository.unconfigured'; | const STAGING_REPOSITORY_UNCONFIGURED = 'repository.unconfigured'; | ||||
| ▲ Show 20 Lines • Show All 488 Lines • ▼ Show 20 Lines | if ($this->shouldOnlyCreateDiff()) { | ||||
| foreach (array('edit-messages.json', 'update-messages.json') as $file) { | foreach (array('edit-messages.json', 'update-messages.json') as $file) { | ||||
| $messages = $this->readScratchJSONFile($file); | $messages = $this->readScratchJSONFile($file); | ||||
| unset($messages[$revision['id']]); | unset($messages[$revision['id']]); | ||||
| $this->writeScratchJSONFile($file, $messages); | $this->writeScratchJSONFile($file, $messages); | ||||
| } | } | ||||
| echo pht('Updated an existing Differential revision:')."\n"; | echo pht('Updated an existing Differential revision:')."\n"; | ||||
| } else { | } else { | ||||
| // NOTE: We're either using "differential.revision.edit" (preferred) | |||||
| // if we can, or falling back to "differential.createrevision" | |||||
| // (the older way) if not. | |||||
| $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); | $revision = $this->dispatchWillCreateRevisionEvent($revision); | ||||
| $result = $conduit->callMethodSynchronous( | $result = $conduit->callMethodSynchronous( | ||||
| 'differential.createrevision', | 'differential.createrevision', | ||||
| $revision); | $revision); | ||||
| $result_uri = $result['uri']; | |||||
| $result_id = $result['revisionid']; | |||||
| } | |||||
| $revised_message = $conduit->callMethodSynchronous( | $revised_message = $conduit->callMethodSynchronous( | ||||
| 'differential.getcommitmessage', | 'differential.getcommitmessage', | ||||
| array( | array( | ||||
| 'revision_id' => $result['revisionid'], | 'revision_id' => $result_id, | ||||
| )); | )); | ||||
| if ($this->shouldAmend()) { | if ($this->shouldAmend()) { | ||||
| $repository_api = $this->getRepositoryAPI(); | $repository_api = $this->getRepositoryAPI(); | ||||
| if ($repository_api->supportsAmend()) { | if ($repository_api->supportsAmend()) { | ||||
| echo pht('Updating commit message...')."\n"; | echo pht('Updating commit message...')."\n"; | ||||
| $repository_api->amendCommit($revised_message); | $repository_api->amendCommit($revised_message); | ||||
| } else { | } else { | ||||
| echo pht( | echo pht( | ||||
| 'Commit message was not amended. Amending commit message is '. | 'Commit message was not amended. Amending commit message is '. | ||||
| 'only supported in git and hg (version 2.2 or newer)'); | 'only supported in git and hg (version 2.2 or newer)'); | ||||
| } | } | ||||
| } | } | ||||
| echo pht('Created a new Differential revision:')."\n"; | echo pht('Created a new Differential revision:')."\n"; | ||||
| } | } | ||||
| $uri = $result['uri']; | $uri = $result_uri; | ||||
| echo phutil_console_format( | echo phutil_console_format( | ||||
| " **%s** __%s__\n\n", | " **%s** __%s__\n\n", | ||||
| pht('Revision URI:'), | pht('Revision URI:'), | ||||
| $uri); | $uri); | ||||
| if ($this->shouldOpenCreatedObjectsInBrowser()) { | if ($this->shouldOpenCreatedObjectsInBrowser()) { | ||||
| $this->openURIsInBrowser(array($uri)); | $this->openURIsInBrowser(array($uri)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | private function buildRevisionFromCommitMessage( | ||||
| ArcanistDifferentialCommitMessage $message) { | ArcanistDifferentialCommitMessage $message) { | ||||
| $conduit = $this->getConduit(); | $conduit = $this->getConduit(); | ||||
| $revision_id = $message->getRevisionID(); | $revision_id = $message->getRevisionID(); | ||||
| $revision = array( | $revision = array( | ||||
| 'fields' => $message->getFields(), | 'fields' => $message->getFields(), | ||||
| ); | ); | ||||
| $xactions = $message->getTransactions(); | |||||
| if ($revision_id) { | if ($revision_id) { | ||||
| // With '--verbatim', pass the (possibly modified) local fields. This | // With '--verbatim', pass the (possibly modified) local fields. This | ||||
| // allows the user to edit some fields (like "title" and "summary") | // allows the user to edit some fields (like "title" and "summary") | ||||
| // locally without '--edit' and have changes automatically synchronized. | // locally without '--edit' and have changes automatically synchronized. | ||||
| // Without '--verbatim', we do not update the revision to reflect local | // Without '--verbatim', we do not update the revision to reflect local | ||||
| // commit message changes. | // commit message changes. | ||||
| Show All 38 Lines | if ($revision_id) { | ||||
| $remote_corpus = ArcanistCommentRemover::removeComments( | $remote_corpus = ArcanistCommentRemover::removeComments( | ||||
| $remote_corpus); | $remote_corpus); | ||||
| $new_message = ArcanistDifferentialCommitMessage::newFromRawCorpus( | $new_message = ArcanistDifferentialCommitMessage::newFromRawCorpus( | ||||
| $remote_corpus); | $remote_corpus); | ||||
| $new_message->pullDataFromConduit($conduit); | $new_message->pullDataFromConduit($conduit); | ||||
| } | } | ||||
| $revision['fields'] = $new_message->getFields(); | $revision['fields'] = $new_message->getFields(); | ||||
| $xactions = $new_message->getTransactions(); | |||||
| $revision['id'] = $revision_id; | $revision['id'] = $revision_id; | ||||
| $this->revisionID = $revision_id; | $this->revisionID = $revision_id; | ||||
| $revision['message'] = $this->getArgument('message'); | $revision['message'] = $this->getArgument('message'); | ||||
| if (!strlen($revision['message'])) { | if (!strlen($revision['message'])) { | ||||
| $update_messages = $this->readScratchJSONFile('update-messages.json'); | $update_messages = $this->readScratchJSONFile('update-messages.json'); | ||||
| $update_messages[$revision_id] = $this->getUpdateMessage( | $update_messages[$revision_id] = $this->getUpdateMessage( | ||||
| $revision['fields'], | $revision['fields'], | ||||
| idx($update_messages, $revision_id)); | idx($update_messages, $revision_id)); | ||||
| $revision['message'] = ArcanistCommentRemover::removeComments( | $revision['message'] = ArcanistCommentRemover::removeComments( | ||||
| $update_messages[$revision_id]); | $update_messages[$revision_id]); | ||||
| if (!strlen(trim($revision['message']))) { | if (!strlen(trim($revision['message']))) { | ||||
| throw new ArcanistUserAbortException(); | throw new ArcanistUserAbortException(); | ||||
| } | } | ||||
| $this->writeScratchJSONFile('update-messages.json', $update_messages); | $this->writeScratchJSONFile('update-messages.json', $update_messages); | ||||
| } | } | ||||
| } | } | ||||
| $this->revisionTransactions = $xactions; | |||||
| return $revision; | return $revision; | ||||
| } | } | ||||
| protected function shouldOnlyCreateDiff() { | protected function shouldOnlyCreateDiff() { | ||||
| if ($this->getArgument('create')) { | if ($this->getArgument('create')) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 2,174 Lines • Show Last 20 Lines | |||||