Changeset View
Changeset View
Standalone View
Standalone View
src/repository/api/ArcanistMercurialAPI.php
Show First 20 Lines • Show All 528 Lines • ▼ Show 20 Lines | public function supportsCommitRanges() { | ||||
return true; | return true; | ||||
} | } | ||||
public function supportsLocalCommits() { | public function supportsLocalCommits() { | ||||
return true; | return true; | ||||
} | } | ||||
public function getAllBranches() { | public function getAllBranches() { | ||||
// TODO: This is wrong, and returns bookmarks. | |||||
list($branch_info) = $this->execxLocal('bookmarks'); | list($branch_info) = $this->execxLocal('bookmarks'); | ||||
if (trim($branch_info) == 'no bookmarks set') { | if (trim($branch_info) == 'no bookmarks set') { | ||||
return array(); | return array(); | ||||
} | } | ||||
$matches = null; | $matches = null; | ||||
preg_match_all( | preg_match_all( | ||||
'/^\s*(\*?)\s*(.+)\s(\S+)$/m', | '/^\s*(\*?)\s*(.+)\s(\S+)$/m', | ||||
$branch_info, | $branch_info, | ||||
$matches, | $matches, | ||||
PREG_SET_ORDER); | PREG_SET_ORDER); | ||||
$return = array(); | $return = array(); | ||||
foreach ($matches as $match) { | foreach ($matches as $match) { | ||||
list(, $current, $name) = $match; | list(, $current, $name, $hash) = $match; | ||||
list($id, $hash) = explode(':', $hash); | |||||
$return[] = array( | $return[] = array( | ||||
'current' => (bool)$current, | 'current' => (bool)$current, | ||||
'name' => rtrim($name), | 'name' => rtrim($name), | ||||
'hash' => $hash, | |||||
); | ); | ||||
} | } | ||||
return $return; | return $return; | ||||
} | } | ||||
public function getAllBranchRefs() { | public function getAllBranchRefs() { | ||||
$branches = $this->getAllBranches(); | $branches = $this->getAllBranches(); | ||||
$refs = array(); | $refs = array(); | ||||
foreach ($branches as $branch) { | foreach ($branches as $branch) { | ||||
$commit_ref = $this->newCommitRef() | |||||
->setCommitHash($branch['hash']); | |||||
$refs[] = $this->newBranchRef() | $refs[] = $this->newBranchRef() | ||||
->setBranchName($branch['name']) | ->setBranchName($branch['name']) | ||||
->setIsCurrentBranch($branch['current']); | ->setIsCurrentBranch($branch['current']) | ||||
->attachCommitRef($commit_ref); | |||||
} | } | ||||
return $refs; | return $refs; | ||||
} | } | ||||
public function getBaseCommitRef() { | public function getBaseCommitRef() { | ||||
$base_commit = $this->getBaseCommit(); | $base_commit = $this->getBaseCommit(); | ||||
▲ Show 20 Lines • Show All 483 Lines • ▼ Show 20 Lines | if ($raw_output !== 'no bookmarks set') { | ||||
'revision' => $revision, | 'revision' => $revision, | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
return $bookmarks; | return $bookmarks; | ||||
} | } | ||||
public function getBookmarkCommitHash($name) { | |||||
// TODO: Cache this. | |||||
$bookmarks = $this->getBookmarks($name); | |||||
$bookmarks = ipull($bookmarks, null, 'name'); | |||||
foreach ($bookmarks as $bookmark) { | |||||
if ($bookmark['name'] === $name) { | |||||
return $bookmark['revision']; | |||||
} | |||||
} | |||||
throw new Exception(pht('No bookmark "%s".', $name)); | |||||
} | |||||
public function getBranchCommitHash($name) { | |||||
// TODO: Cache this. | |||||
// TODO: This won't work when there are multiple branch heads with the | |||||
// same name. | |||||
$branches = $this->getBranches($name); | |||||
$heads = array(); | |||||
foreach ($branches as $branch) { | |||||
if ($branch['name'] === $name) { | |||||
$heads[] = $branch; | |||||
} | |||||
} | |||||
if (count($heads) === 1) { | |||||
return idx(head($heads), 'revision'); | |||||
} | |||||
if (!$heads) { | |||||
throw new Exception(pht('No branch "%s".', $name)); | |||||
} | |||||
throw new Exception(pht('Too many branch heads for "%s".', $name)); | |||||
} | |||||
private function splitBranchOrBookmarkLine($line) { | private function splitBranchOrBookmarkLine($line) { | ||||
// branches and bookmarks are printed in the format: | // branches and bookmarks are printed in the format: | ||||
// default 0:a5ead76cdf85 (inactive) | // default 0:a5ead76cdf85 (inactive) | ||||
// * mybook 2:6b274d49be97 | // * mybook 2:6b274d49be97 | ||||
// this code divides the name half from the revision half | // this code divides the name half from the revision half | ||||
// it does not parse the * and (inactive) bits | // it does not parse the * and (inactive) bits | ||||
$colon_index = strrpos($line, ':'); | $colon_index = strrpos($line, ':'); | ||||
$before_colon = substr($line, 0, $colon_index); | $before_colon = substr($line, 0, $colon_index); | ||||
Show All 28 Lines | private function getMercurialEnvironmentVariables() { | ||||
// There is an HGPLAIN environmental variable which enables "plain mode" | // There is an HGPLAIN environmental variable which enables "plain mode" | ||||
// and hopefully disables this stuff. | // and hopefully disables this stuff. | ||||
$env['HGPLAIN'] = 1; | $env['HGPLAIN'] = 1; | ||||
return $env; | return $env; | ||||
} | } | ||||
protected function newLandEngine() { | |||||
return new ArcanistMercurialLandEngine(); | |||||
} | |||||
public function newLocalState() { | |||||
return id(new ArcanistMercurialLocalState()) | |||||
->setRepositoryAPI($this); | |||||
} | |||||
} | } |