Changeset View
Changeset View
Standalone View
Standalone View
src/land/engine/ArcanistMercurialLandEngine.php
<?php | <?php | ||||
final class ArcanistMercurialLandEngine | final class ArcanistMercurialLandEngine | ||||
extends ArcanistLandEngine { | extends ArcanistLandEngine { | ||||
protected function getDefaultSymbols() { | protected function getDefaultSymbols() { | ||||
$api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
$log = $this->getLogEngine(); | $log = $this->getLogEngine(); | ||||
$bookmark = $api->getActiveBookmark(); | $markers = $api->newMarkerRefQuery() | ||||
if ($bookmark !== null) { | ->withIsActive(true) | ||||
->execute(); | |||||
$bookmark = null; | |||||
foreach ($markers as $marker) { | |||||
if ($marker->isBookmark()) { | |||||
$bookmark = $marker->getName(); | |||||
break; | |||||
} | |||||
} | |||||
if ($bookmark !== null) { | |||||
$log->writeStatus( | $log->writeStatus( | ||||
pht('SOURCE'), | pht('SOURCE'), | ||||
pht( | pht( | ||||
'Landing the active bookmark, "%s".', | 'Landing the active bookmark, "%s".', | ||||
$bookmark)); | $bookmark)); | ||||
return array($bookmark); | return array($bookmark); | ||||
} | } | ||||
$branch = $api->getBranchName(); | $branch = null; | ||||
if ($branch !== null) { | foreach ($markers as $marker) { | ||||
if ($marker->isBranch()) { | |||||
$branch = $marker->getName(); | |||||
break; | |||||
} | |||||
} | |||||
if ($branch !== null) { | |||||
$log->writeStatus( | $log->writeStatus( | ||||
pht('SOURCE'), | pht('SOURCE'), | ||||
pht( | pht( | ||||
'Landing the current branch, "%s".', | 'Landing the active branch, "%s".', | ||||
$branch)); | $branch)); | ||||
return array($branch); | return array($branch); | ||||
} | } | ||||
throw new Exception(pht('TODO: Operate on raw revision.')); | $commit = $api->getCanonicalRevisionName('.'); | ||||
$log->writeStatus( | |||||
pht('SOURCE'), | |||||
pht( | |||||
'Landing the active commit, "%s".', | |||||
$this->getDisplayHash($commit))); | |||||
return array($commit); | |||||
} | } | ||||
protected function resolveSymbols(array $symbols) { | protected function resolveSymbols(array $symbols) { | ||||
assert_instances_of($symbols, 'ArcanistLandSymbol'); | assert_instances_of($symbols, 'ArcanistLandSymbol'); | ||||
$api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
foreach ($symbols as $symbol) { | $marker_types = array( | ||||
$raw_symbol = $symbol->getSymbol(); | ArcanistMarkerRef::TYPE_BOOKMARK, | ||||
ArcanistMarkerRef::TYPE_BRANCH, | |||||
); | |||||
$unresolved = $symbols; | |||||
foreach ($marker_types as $marker_type) { | |||||
$markers = $api->newMarkerRefQuery() | |||||
->withMarkerTypes(array($marker_type)) | |||||
->execute(); | |||||
if ($api->isBookmark($raw_symbol)) { | $markers = mgroup($markers, 'getName'); | ||||
$hash = $api->getBookmarkCommitHash($raw_symbol); | |||||
$symbol->setCommit($hash); | |||||
// TODO: Set that this is a bookmark? | foreach ($unresolved as $key => $symbol) { | ||||
$raw_symbol = $symbol->getSymbol(); | |||||
$named_markers = idx($markers, $raw_symbol); | |||||
if (!$named_markers) { | |||||
continue; | continue; | ||||
} | } | ||||
if ($api->isBranch($raw_symbol)) { | if (count($named_markers) > 1) { | ||||
$hash = $api->getBranchCommitHash($raw_symbol); | throw new PhutilArgumentUsageException( | ||||
$symbol->setCommit($hash); | pht( | ||||
'Symbol "%s" is ambiguous: it matches multiple markers '. | |||||
'(of type "%s"). Use an unambiguous identifier.', | |||||
$raw_symbol, | |||||
$marker_type)); | |||||
} | |||||
$marker = head($named_markers); | |||||
// TODO: Set that this is a branch? | $symbol->setCommit($marker->getCommitHash()); | ||||
continue; | unset($unresolved[$key]); | ||||
} | |||||
} | } | ||||
foreach ($unresolved as $symbol) { | |||||
$raw_symbol = $symbol->getSymbol(); | |||||
// TODO: This doesn't have accurate error behavior if the user provides | |||||
// a revset like "x::y". | |||||
try { | |||||
$commit = $api->getCanonicalRevisionName($raw_symbol); | |||||
} catch (CommandException $ex) { | |||||
$commit = null; | |||||
} | |||||
if ($commit === null) { | |||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
'Symbol "%s" is not a bookmark or branch name.', | 'Symbol "%s" does not identify a bookmark, branch, or commit.', | ||||
$raw_symbol)); | $raw_symbol)); | ||||
} | } | ||||
$symbol->setCommit($commit); | |||||
} | |||||
} | } | ||||
protected function selectOntoRemote(array $symbols) { | protected function selectOntoRemote(array $symbols) { | ||||
assert_instances_of($symbols, 'ArcanistLandSymbol'); | assert_instances_of($symbols, 'ArcanistLandSymbol'); | ||||
$remote = $this->newOntoRemote($symbols); | $remote = $this->newOntoRemote($symbols); | ||||
// TODO: Verify this remote actually exists. | // TODO: Verify this remote actually exists. | ||||
▲ Show 20 Lines • Show All 581 Lines • Show Last 20 Lines |