Changeset View
Changeset View
Standalone View
Standalone View
src/land/engine/ArcanistMercurialLandEngine.php
| Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | protected function resolveSymbols(array $symbols) { | ||||
| $unresolved = $symbols; | $unresolved = $symbols; | ||||
| foreach ($marker_types as $marker_type) { | foreach ($marker_types as $marker_type) { | ||||
| $markers = $api->newMarkerRefQuery() | $markers = $api->newMarkerRefQuery() | ||||
| ->withMarkerTypes(array($marker_type)) | ->withMarkerTypes(array($marker_type)) | ||||
| ->execute(); | ->execute(); | ||||
| $markers = mgroup($markers, 'getName'); | $markers = mgroup($markers, 'getName'); | ||||
| foreach ($unresolved as $key => $symbol) { | foreach ($unresolved as $key => $symbol) { | ||||
| $raw_symbol = $symbol->getSymbol(); | $raw_symbol = $symbol->getSymbol(); | ||||
| $named_markers = idx($markers, $raw_symbol); | $named_markers = idx($markers, $raw_symbol); | ||||
| if (!$named_markers) { | if (!$named_markers) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (count($named_markers) > 1) { | if (count($named_markers) > 1) { | ||||
| throw new PhutilArgumentUsageException( | echo tsprintf( | ||||
| "\n%!\n%W\n\n", | |||||
| pht('AMBIGUOUS SYMBOL'), | |||||
| pht( | pht( | ||||
| 'Symbol "%s" is ambiguous: it matches multiple markers '. | 'Symbol "%s" is ambiguous: it matches multiple markers '. | ||||
| '(of type "%s"). Use an unambiguous identifier.', | '(of type "%s"). Use an unambiguous identifier.', | ||||
| $raw_symbol, | $raw_symbol, | ||||
| $marker_type)); | $marker_type)); | ||||
| foreach ($named_markers as $named_marker) { | |||||
| echo tsprintf('%s', $named_marker->newDisplayRef()); | |||||
| } | |||||
| echo tsprintf("\n"); | |||||
| throw new PhutilArgumentUsageException( | |||||
| pht( | |||||
Lint: Formatted String: Too few arguments to pht(). | |||||
| 'Symbol "%s" is ambiguous.')); | |||||
| } | } | ||||
| $marker = head($named_markers); | $marker = head($named_markers); | ||||
| $symbol->setCommit($marker->getCommitHash()); | $symbol->setCommit($marker->getCommitHash()); | ||||
| unset($unresolved[$key]); | unset($unresolved[$key]); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | protected function confirmOntoRefs(array $onto_refs) { | ||||
| $branches = array(); | $branches = array(); | ||||
| foreach ($onto_markers as $onto_marker) { | foreach ($onto_markers as $onto_marker) { | ||||
| if ($onto_marker->isBranch()) { | if ($onto_marker->isBranch()) { | ||||
| $branches[] = $onto_marker; | $branches[] = $onto_marker; | ||||
| } | } | ||||
| $branch_count = count($branches); | $branch_count = count($branches); | ||||
| if ($branch_count > 1) { | if ($branch_count > 1) { | ||||
| echo tsprintf( | |||||
| "\n%!\n%W\n\n%W\n\n%W\n\n", | |||||
| pht('MULTIPLE "ONTO" BRANCHES'), | |||||
| pht( | |||||
| 'You have selected multiple branches to push changes onto. '. | |||||
| 'Pushing to multiple branches is not supported by "arc land" '. | |||||
| 'in Mercurial: Mercurial commits may only belong to one '. | |||||
| 'branch, so this operation can not be executed atomically.'), | |||||
| pht( | |||||
| 'You may land one branches and any number of bookmarks in a '. | |||||
| 'single operation.'), | |||||
| pht('These branches were selected:')); | |||||
| foreach ($branches as $branch) { | |||||
| echo tsprintf('%s', $branch->newDisplayRef()); | |||||
| } | |||||
| echo tsprintf("\n"); | |||||
| throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
| pht( | pht( | ||||
| 'TODO: You can not push onto multiple branches in Mercurial.')); | 'Landing onto multiple branches at once is not supported in '. | ||||
| 'Mercurial.')); | |||||
| } else if ($branch_count) { | } else if ($branch_count) { | ||||
| $this->ontoBranchMarker = head($branches); | $this->ontoBranchMarker = head($branches); | ||||
| } | } | ||||
| } | } | ||||
| if ($new_markers) { | if ($new_markers) { | ||||
| // TODO: If we're creating bookmarks, ask the user to confirm. | echo tsprintf( | ||||
| "\n%!\n%W\n\n", | |||||
| pht('CREATE %s BOOKMARK(S)', phutil_count($new_markers)), | |||||
| pht( | |||||
| 'These %s symbol(s) do not exist in the remote. They will be created '. | |||||
Lint: Line Too Long This line is 81 characters long, but the convention is 80 characters. Lint: Line Too Long: This line is 81 characters long, but the convention is 80 characters. | |||||
| 'as new bookmarks:', | |||||
| phutil_count($new_markers))); | |||||
| foreach ($new_markers as $new_marker) { | |||||
| echo tsprintf('%s', $new_marker->newDisplayRef()); | |||||
| } | |||||
| echo tsprintf("\n"); | |||||
| $query = pht( | |||||
| 'Create %s new remote bookmark(s)?', | |||||
| phutil_count($new_markers)); | |||||
| $this->getWorkflow() | |||||
| ->getPrompt('arc.land.create') | |||||
| ->setQuery($query) | |||||
| ->execute(); | |||||
| } | } | ||||
| $this->ontoMarkers = $onto_markers; | $this->ontoMarkers = $onto_markers; | ||||
| } | } | ||||
| protected function selectIntoRemote() { | protected function selectIntoRemote() { | ||||
| $api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
| $log = $this->getLogEngine(); | $log = $this->getLogEngine(); | ||||
| ▲ Show 20 Lines • Show All 435 Lines • ▼ Show 20 Lines | protected function executeMerge(ArcanistLandCommitSet $set, $into_commit) { | ||||
| $new_cursor = trim($stdout); | $new_cursor = trim($stdout); | ||||
| return $new_cursor; | return $new_cursor; | ||||
| } | } | ||||
| protected function pushChange($into_commit) { | protected function pushChange($into_commit) { | ||||
| $api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
| list($head, $body, $tail) = $this->newPushCommands($into_commit); | |||||
| foreach ($head as $command) { | |||||
| $api->execxLocal('%Ls', $command); | |||||
| } | |||||
| try { | |||||
| foreach ($body as $command) { | |||||
| $this->newPasthru('%Ls', $command); | |||||
| } | |||||
| } finally { | |||||
| foreach ($tail as $command) { | |||||
| $api->execxLocal('%Ls', $command); | |||||
| } | |||||
| } | |||||
| } | |||||
| private function newPushCommands($into_commit) { | |||||
| $api = $this->getRepositoryAPI(); | |||||
| $head_commands = array(); | |||||
| $body_commands = array(); | |||||
| $tail_commands = array(); | |||||
| $bookmarks = array(); | $bookmarks = array(); | ||||
| foreach ($this->ontoMarkers as $onto_marker) { | foreach ($this->ontoMarkers as $onto_marker) { | ||||
| if (!$onto_marker->isBookmark()) { | if (!$onto_marker->isBookmark()) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| $bookmarks[] = $onto_marker; | $bookmarks[] = $onto_marker; | ||||
| } | } | ||||
| // If we're pushing to bookmarks, move all the bookmarks we want to push | // If we're pushing to bookmarks, move all the bookmarks we want to push | ||||
| // to the merge commit. (There doesn't seem to be any way to specify | // to the merge commit. (There doesn't seem to be any way to specify | ||||
| // "push commit X as bookmark Y" in Mercurial.) | // "push commit X as bookmark Y" in Mercurial.) | ||||
| $restore = array(); | $restore = array(); | ||||
| if ($bookmarks) { | if ($bookmarks) { | ||||
| $markers = $api->newMarkerRefQuery() | $markers = $api->newMarkerRefQuery() | ||||
| ->withNames(array(mpull($bookmarks, 'getName'))) | ->withNames(mpull($bookmarks, 'getName')) | ||||
| ->withTypes(array(ArcanistMarkerRef::TYPE_BOOKMARK)) | ->withMarkerTypes(array(ArcanistMarkerRef::TYPE_BOOKMARK)) | ||||
| ->execute(); | ->execute(); | ||||
| $markers = mpull($markers, 'getCommitHash', 'getName'); | $markers = mpull($markers, 'getCommitHash', 'getName'); | ||||
| foreach ($bookmarks as $bookmark) { | foreach ($bookmarks as $bookmark) { | ||||
| $bookmark_name = $bookmark->getName(); | $bookmark_name = $bookmark->getName(); | ||||
| $old_position = idx($markers, $bookmark_name); | $old_position = idx($markers, $bookmark_name); | ||||
| $new_position = $into_commit; | $new_position = $into_commit; | ||||
| if ($old_position === $new_position) { | if ($old_position === $new_position) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| $head_commands[] = array( | |||||
| 'bookmark', | |||||
| '--force', | |||||
| '--rev', | |||||
| hgsprintf('%s', $this->getDisplayHash($new_position)), | |||||
| '--', | |||||
| $bookmark_name, | |||||
| ); | |||||
| $api->execxLocal( | $api->execxLocal( | ||||
| 'bookmark --force --rev %s -- %s', | 'bookmark --force --rev %s -- %s', | ||||
| hgsprintf('%s', $new_position), | hgsprintf('%s', $new_position), | ||||
| $bookmark_name); | $bookmark_name); | ||||
| $restore[$bookmark_name] = $old_position; | $restore[$bookmark_name] = $old_position; | ||||
| } | } | ||||
| } | } | ||||
| // Now, do the actual push. | // Now, prepare the actual push. | ||||
| $argv = array(); | $argv = array(); | ||||
| $argv[] = 'push'; | $argv[] = 'push'; | ||||
| if ($bookmarks) { | if ($bookmarks) { | ||||
| // If we're pushing at least one bookmark, we can just specify the list | // If we're pushing at least one bookmark, we can just specify the list | ||||
| // of bookmarks as things we want to push. | // of bookmarks as things we want to push. | ||||
| foreach ($bookmarks as $bookmark) { | foreach ($bookmarks as $bookmark) { | ||||
| $argv[] = '--bookmark'; | $argv[] = '--bookmark'; | ||||
| $argv[] = $bookmark->getName(); | $argv[] = $bookmark->getName(); | ||||
| } | } | ||||
| } else { | } else { | ||||
| // Otherwise, specify the commit itself. | // Otherwise, specify the commit itself. | ||||
| $argv[] = '--rev'; | $argv[] = '--rev'; | ||||
| $argv[] = hgsprintf('%s', $into_commit); | $argv[] = hgsprintf('%s', $into_commit); | ||||
| } | } | ||||
| $argv[] = '--'; | $argv[] = '--'; | ||||
| $argv[] = $this->getOntoRemote(); | $argv[] = $this->getOntoRemote(); | ||||
| try { | $body_commands[] = $argv; | ||||
| $this->newPassthru('%Ls', $argv); | |||||
| } finally { | // Finally, restore the bookmarks. | ||||
| foreach ($restore as $bookmark_name => $old_position) { | foreach ($restore as $bookmark_name => $old_position) { | ||||
| $tail = array(); | |||||
| $tail[] = 'bookmark'; | |||||
| if ($old_position === null) { | if ($old_position === null) { | ||||
| $api->execxLocal( | $tail[] = '--delete'; | ||||
| 'bookmark --delete -- %s', | |||||
| $bookmark_name); | |||||
| } else { | } else { | ||||
| $api->execxLocal( | $tail[] = '--force'; | ||||
| 'bookmark --force --rev %s -- %s', | $tail[] = '--rev'; | ||||
| hgsprintf('%s', $old_position), | $tail[] = hgsprintf('%s', $this->getDisplayHash($old_position)); | ||||
| $bookmark_name); | |||||
| } | |||||
| } | } | ||||
| $tail[] = '--'; | |||||
| $tail[] = $bookmark_name; | |||||
| $tail_commands[] = $tail; | |||||
| } | } | ||||
| return array( | |||||
| $head_commands, | |||||
| $body_commands, | |||||
| $tail_commands, | |||||
| ); | |||||
| } | } | ||||
| protected function cascadeState(ArcanistLandCommitSet $set, $into_commit) { | protected function cascadeState(ArcanistLandCommitSet $set, $into_commit) { | ||||
| $api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
| $log = $this->getLogEngine(); | $log = $this->getLogEngine(); | ||||
| // This has no effect when we're executing a merge strategy. | // This has no effect when we're executing a merge strategy. | ||||
| if (!$this->isSquashStrategy()) { | if (!$this->isSquashStrategy()) { | ||||
| ▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | |||||
| protected function didHoldChanges($into_commit) { | protected function didHoldChanges($into_commit) { | ||||
| $log = $this->getLogEngine(); | $log = $this->getLogEngine(); | ||||
| $local_state = $this->getLocalState(); | $local_state = $this->getLocalState(); | ||||
| $message = pht( | $message = pht( | ||||
| 'Holding changes locally, they have not been pushed.'); | 'Holding changes locally, they have not been pushed.'); | ||||
| // TODO: This is only vaguely correct. | list($head, $body, $tail) = $this->newPushCommands($into_commit); | ||||
| $commands = array_merge($head, $body, $tail); | |||||
| $push_command = csprintf( | |||||
| '$ hg push --rev %s -- %s', | |||||
| hgsprintf('%s', $this->getDisplayHash($into_commit)), | |||||
| $this->getOntoRemote()); | |||||
| echo tsprintf( | echo tsprintf( | ||||
| "\n%!\n%s\n\n", | "\n%!\n%s\n\n", | ||||
| pht('HOLD CHANGES'), | pht('HOLD CHANGES'), | ||||
| $message); | $message); | ||||
| echo tsprintf( | echo tsprintf( | ||||
| "%s\n\n **%s**\n\n", | "%s\n\n", | ||||
| pht('To push changes manually, run this command:'), | pht('To push changes manually, run these %s command(s):', | ||||
| $push_command); | phutil_count($commands))); | ||||
| foreach ($commands as $command) { | |||||
| echo tsprintf('%>', csprintf('hg %Ls', $command)); | |||||
| } | |||||
| echo tsprintf("\n"); | |||||
| $restore_commands = $local_state->getRestoreCommandsForDisplay(); | $restore_commands = $local_state->getRestoreCommandsForDisplay(); | ||||
| if ($restore_commands) { | if ($restore_commands) { | ||||
| echo tsprintf( | echo tsprintf( | ||||
| "%s\n\n", | "%s\n\n", | ||||
| pht( | pht( | ||||
| 'To go back to how things were before you ran "arc land", run '. | 'To go back to how things were before you ran "arc land", run '. | ||||
| 'these %s command(s):', | 'these %s command(s):', | ||||
| phutil_count($restore_commands))); | phutil_count($restore_commands))); | ||||
| foreach ($restore_commands as $restore_command) { | foreach ($restore_commands as $restore_command) { | ||||
| echo tsprintf(" **%s**\n", $restore_command); | echo tsprintf('%>', $restore_command); | ||||
| } | } | ||||
| echo tsprintf("\n"); | echo tsprintf("\n"); | ||||
| } | } | ||||
| echo tsprintf( | echo tsprintf( | ||||
| "%s\n", | "%s\n", | ||||
| pht( | pht( | ||||
| 'Local branches and bookmarks have not been changed, and are still '. | 'Local branches and bookmarks have not been changed, and are still '. | ||||
| 'in the same state as before.')); | 'in the same state as before.')); | ||||
| } | } | ||||
| private function newRemoteMarkers($remote) { | |||||
| // See T9948. If the user specified "--into X" or "--onto X", we don't know | |||||
| // if it's a branch, a bookmark, or a symbol which doesn't exist yet. | |||||
| } | |||||
| } | } | ||||
Too few arguments to pht().