Changeset View
Changeset View
Standalone View
Standalone View
src/repository/state/ArcanistMercurialLocalState.php
| <?php | <?php | ||||
| final class ArcanistMercurialLocalState | final class ArcanistMercurialLocalState | ||||
| extends ArcanistRepositoryLocalState { | extends ArcanistRepositoryLocalState { | ||||
| private $localCommit; | private $localCommit; | ||||
| private $localBranch; | private $localBranch; | ||||
| private $localBookmark; | |||||
| protected function executeSaveLocalState() { | protected function executeSaveLocalState() { | ||||
| $api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
| $log = $this->getWorkflow()->getLogEngine(); | $log = $this->getWorkflow()->getLogEngine(); | ||||
| // TODO: Both of these can be pulled from "hg arc-ls-markers" more | $markers = $api->newMarkerRefQuery() | ||||
| // efficiently. | ->execute(); | ||||
| $this->localCommit = $api->getCanonicalRevisionName('.'); | $local_commit = null; | ||||
| foreach ($markers as $marker) { | |||||
| if ($marker->isCommitState()) { | |||||
| $local_commit = $marker->getCommitHash(); | |||||
| } | |||||
| } | |||||
| if ($local_commit === null) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Unable to identify the current commit in the working copy.')); | |||||
| } | |||||
| list($branch) = $api->execxLocal('branch'); | $this->localCommit = $local_commit; | ||||
| $this->localBranch = trim($branch); | |||||
| $log->writeTrace( | $local_branch = null; | ||||
| pht('SAVE STATE'), | foreach ($markers as $marker) { | ||||
| if ($marker->isBranchState()) { | |||||
| $local_branch = $marker->getName(); | |||||
| break; | |||||
| } | |||||
| } | |||||
| if ($local_branch === null) { | |||||
| throw new Exception( | |||||
| pht( | pht( | ||||
| 'Unable to identify the current branch in the working copy.')); | |||||
| } | |||||
| if ($local_branch !== null) { | |||||
| $this->localBranch = $local_branch; | |||||
| } | |||||
| $local_bookmark = null; | |||||
| foreach ($markers as $marker) { | |||||
| if ($marker->isBookmark()) { | |||||
| if ($marker->getIsActive()) { | |||||
| $local_bookmark = $marker->getName(); | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| if ($local_bookmark !== null) { | |||||
| $this->localBookmark = $local_bookmark; | |||||
| } | |||||
| $has_bookmark = ($this->localBookmark !== null); | |||||
| if ($has_bookmark) { | |||||
| $location = pht( | |||||
| 'Saving local state (at "%s" on branch "%s", bookmarked as "%s").', | |||||
| $api->getDisplayHash($this->localCommit), | |||||
| $this->localBranch, | |||||
| $this->localBookmark); | |||||
| } else { | |||||
| $location = pht( | |||||
| 'Saving local state (at "%s" on branch "%s").', | 'Saving local state (at "%s" on branch "%s").', | ||||
| $api->getDisplayHash($this->localCommit), | $api->getDisplayHash($this->localCommit), | ||||
| $this->localBranch)); | $this->localBranch); | ||||
| } | |||||
| $log->writeTrace(pht('SAVE STATE'), $location); | |||||
| } | } | ||||
| protected function executeRestoreLocalState() { | protected function executeRestoreLocalState() { | ||||
| $api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
| $log = $this->getWorkflow()->getLogEngine(); | $log = $this->getWorkflow()->getLogEngine(); | ||||
| $log->writeStatus( | if ($this->localBookmark !== null) { | ||||
| pht('LOAD STATE'), | $location = pht( | ||||
| pht( | 'Restoring local state (at "%s" on branch "%s", bookmarked as "%s").', | ||||
| $api->getDisplayHash($this->localCommit), | |||||
| $this->localBranch, | |||||
| $this->localBookmark); | |||||
| } else { | |||||
| $location = pht( | |||||
| 'Restoring local state (at "%s" on branch "%s").', | 'Restoring local state (at "%s" on branch "%s").', | ||||
| $api->getDisplayHash($this->localCommit), | $api->getDisplayHash($this->localCommit), | ||||
| $this->localBranch)); | $this->localBranch); | ||||
| } | |||||
| $log->writeStatus(pht('LOAD STATE'), $location); | |||||
| $api->execxLocal('update -- %s', $this->localCommit); | $api->execxLocal('update -- %s', $this->localCommit); | ||||
| $api->execxLocal('branch --force -- %s', $this->localBranch); | $api->execxLocal('branch --force -- %s', $this->localBranch); | ||||
| if ($this->localBookmark !== null) { | |||||
| $api->execxLocal('bookmark --force -- %s', $this->localBookmark); | |||||
| } | |||||
| } | } | ||||
| protected function executeDiscardLocalState() { | protected function executeDiscardLocalState() { | ||||
| return; | return; | ||||
| } | } | ||||
| protected function canStashChanges() { | protected function canStashChanges() { | ||||
| $api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
| Show All 15 Lines | protected function newRestoreCommandsForDisplay() { | ||||
| $commands[] = csprintf( | $commands[] = csprintf( | ||||
| 'hg update -- %s', | 'hg update -- %s', | ||||
| $api->getDisplayHash($this->localCommit)); | $api->getDisplayHash($this->localCommit)); | ||||
| $commands[] = csprintf( | $commands[] = csprintf( | ||||
| 'hg branch --force -- %s', | 'hg branch --force -- %s', | ||||
| $this->localBranch); | $this->localBranch); | ||||
| if ($this->localBookmark !== null) { | |||||
| $commands[] = csprintf( | |||||
| 'hg bookmark --force -- %s', | |||||
| $this->localBookmark); | |||||
| } | |||||
| return $commands; | return $commands; | ||||
| } | } | ||||
| protected function saveStash() { | protected function saveStash() { | ||||
| $api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
| $log = $this->getWorkflow()->getLogEngine(); | $log = $this->getWorkflow()->getLogEngine(); | ||||
| $stash_ref = sprintf( | $stash_ref = sprintf( | ||||
| Show All 36 Lines | |||||