Changeset View
Changeset View
Standalone View
Standalone View
src/repository/api/ArcanistMercurialAPI.php
| Show First 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | if ($symbolic_commit !== null) { | ||||
| hgsprintf('ancestor(%R,.)', $symbolic_commit)); | hgsprintf('ancestor(%R,.)', $symbolic_commit)); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "Commit '{$symbolic_commit}' is not a valid Mercurial commit ". | "Commit '{$symbolic_commit}' is not a valid Mercurial commit ". | ||||
| "identifier."); | "identifier."); | ||||
| } | } | ||||
| } | } | ||||
| $this->setBaseCommitExplanation("it is the greatest common ancestor of ". | $this->setBaseCommitExplanation('it is the greatest common ancestor of '. | ||||
| "the working directory and the commit you specified explicitly."); | 'the working directory and the commit you specified explicitly.'); | ||||
| return $commit; | return $commit; | ||||
| } | } | ||||
| if ($this->getBaseCommitArgumentRules() || | if ($this->getBaseCommitArgumentRules() || | ||||
| $this->getConfigurationManager()->getConfigFromAnySource('base')) { | $this->getConfigurationManager()->getConfigFromAnySource('base')) { | ||||
| $base = $this->resolveBaseCommit(); | $base = $this->resolveBaseCommit(); | ||||
| if (!$base) { | if (!$base) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| Show All 23 Lines | protected function buildBaseCommit($symbolic_commit) { | ||||
| } else { | } else { | ||||
| // Mercurial (in some versions?) raises an error when there's nothing | // Mercurial (in some versions?) raises an error when there's nothing | ||||
| // outgoing. | // outgoing. | ||||
| $logs = array(); | $logs = array(); | ||||
| } | } | ||||
| if (!$logs) { | if (!$logs) { | ||||
| $this->setBaseCommitExplanation( | $this->setBaseCommitExplanation( | ||||
| "you have no outgoing commits, so arc assumes you intend to submit ". | 'you have no outgoing commits, so arc assumes you intend to submit '. | ||||
| "uncommitted changes in the working copy."); | 'uncommitted changes in the working copy.'); | ||||
| return $this->getWorkingCopyRevision(); | return $this->getWorkingCopyRevision(); | ||||
| } | } | ||||
| $outgoing_revs = ipull($logs, 'rev'); | $outgoing_revs = ipull($logs, 'rev'); | ||||
| // This is essentially an implementation of a theoretical `hg merge-base` | // This is essentially an implementation of a theoretical `hg merge-base` | ||||
| // command. | // command. | ||||
| $against = $this->getWorkingCopyRevision(); | $against = $this->getWorkingCopyRevision(); | ||||
| Show All 25 Lines | while (true) { | ||||
| // meaning "diff against the empty state". | // meaning "diff against the empty state". | ||||
| $against = 'null'; | $against = 'null'; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if ($against == 'null') { | if ($against == 'null') { | ||||
| $this->setBaseCommitExplanation( | $this->setBaseCommitExplanation( | ||||
| "this is a new repository (all changes are outgoing)."); | 'this is a new repository (all changes are outgoing).'); | ||||
| } else { | } else { | ||||
| $this->setBaseCommitExplanation( | $this->setBaseCommitExplanation( | ||||
| "it is the first commit reachable from the working copy state ". | 'it is the first commit reachable from the working copy state '. | ||||
| "which is not outgoing."); | 'which is not outgoing.'); | ||||
| } | } | ||||
| return $against; | return $against; | ||||
| } | } | ||||
| public function getLocalCommitInformation() { | public function getLocalCommitInformation() { | ||||
| if ($this->localCommitInfo === null) { | if ($this->localCommitInfo === null) { | ||||
| $base_commit = $this->getBaseCommit(); | $base_commit = $this->getBaseCommit(); | ||||
| list($info) = $this->execxLocal( | list($info) = $this->execxLocal( | ||||
| "log --template %s --rev %s --branch %s --", | 'log --template %s --rev %s --branch %s --', | ||||
| "{node}\1{rev}\1{author}\1". | "{node}\1{rev}\1{author}\1". | ||||
| "{date|rfc822date}\1{branch}\1{tag}\1{parents}\1{desc}\2", | "{date|rfc822date}\1{branch}\1{tag}\1{parents}\1{desc}\2", | ||||
| hgsprintf('(%s::. - %s)', $base_commit, $base_commit), | hgsprintf('(%s::. - %s)', $base_commit, $base_commit), | ||||
| $this->getBranchName()); | $this->getBranchName()); | ||||
| $logs = array_filter(explode("\2", $info)); | $logs = array_filter(explode("\2", $info)); | ||||
| $last_node = null; | $last_node = null; | ||||
| ▲ Show 20 Lines • Show All 274 Lines • ▼ Show 20 Lines | public function isHistoryDefaultImmutable() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| public function supportsAmend() { | public function supportsAmend() { | ||||
| list($err, $stdout) = $this->execManualLocal('help commit'); | list($err, $stdout) = $this->execManualLocal('help commit'); | ||||
| if ($err) { | if ($err) { | ||||
| return false; | return false; | ||||
| } else { | } else { | ||||
| return (strpos($stdout, "amend") !== false); | return (strpos($stdout, 'amend') !== false); | ||||
| } | } | ||||
| } | } | ||||
| public function supportsRebase() { | public function supportsRebase() { | ||||
| if ($this->supportsRebase === null) { | if ($this->supportsRebase === null) { | ||||
| list ($err) = $this->execManualLocal("help rebase"); | list ($err) = $this->execManualLocal('help rebase'); | ||||
| $this->supportsRebase = $err === 0; | $this->supportsRebase = $err === 0; | ||||
| } | } | ||||
| return $this->supportsRebase; | return $this->supportsRebase; | ||||
| } | } | ||||
| public function supportsPhases() { | public function supportsPhases() { | ||||
| if ($this->supportsPhases === null) { | if ($this->supportsPhases === null) { | ||||
| list ($err) = $this->execManualLocal("help phase"); | list ($err) = $this->execManualLocal('help phase'); | ||||
| $this->supportsPhases = $err === 0; | $this->supportsPhases = $err === 0; | ||||
| } | } | ||||
| return $this->supportsPhases; | return $this->supportsPhases; | ||||
| } | } | ||||
| public function supportsCommitRanges() { | public function supportsCommitRanges() { | ||||
| return true; | return true; | ||||
| ▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | public function performLocalBranchMerge($branch, $message) { | ||||
| } else { | } else { | ||||
| $err = phutil_passthru( | $err = phutil_passthru( | ||||
| '(cd %s && HGPLAIN=1 hg merge && hg commit -m %s)', | '(cd %s && HGPLAIN=1 hg merge && hg commit -m %s)', | ||||
| $this->getPath(), | $this->getPath(), | ||||
| $message); | $message); | ||||
| } | } | ||||
| if ($err) { | if ($err) { | ||||
| throw new ArcanistUsageException("Merge failed!"); | throw new ArcanistUsageException('Merge failed!'); | ||||
| } | } | ||||
| } | } | ||||
| public function getFinalizedRevisionMessage() { | public function getFinalizedRevisionMessage() { | ||||
| return "You may now push this commit upstream, as appropriate (e.g. with ". | return "You may now push this commit upstream, as appropriate (e.g. with ". | ||||
| "'hg push' or by printing and faxing it)."; | "'hg push' or by printing and faxing it)."; | ||||
| } | } | ||||
| public function getCommitMessageLog() { | public function getCommitMessageLog() { | ||||
| $base_commit = $this->getBaseCommit(); | $base_commit = $this->getBaseCommit(); | ||||
| list($stdout) = $this->execxLocal( | list($stdout) = $this->execxLocal( | ||||
| "log --template %s --rev %s --branch %s --", | 'log --template %s --rev %s --branch %s --', | ||||
| "{node}\1{desc}\2", | "{node}\1{desc}\2", | ||||
| hgsprintf('(%s::. - %s)', $base_commit, $base_commit), | hgsprintf('(%s::. - %s)', $base_commit, $base_commit), | ||||
| $this->getBranchName()); | $this->getBranchName()); | ||||
| $map = array(); | $map = array(); | ||||
| $logs = explode("\2", trim($stdout)); | $logs = explode("\2", trim($stdout)); | ||||
| foreach (array_filter($logs) as $log) { | foreach (array_filter($logs) as $log) { | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | if ($hashes) { | ||||
| $results = $conduit->callMethodSynchronous( | $results = $conduit->callMethodSynchronous( | ||||
| 'differential.query', | 'differential.query', | ||||
| $query + array( | $query + array( | ||||
| 'commitHashes' => $hashes, | 'commitHashes' => $hashes, | ||||
| )); | )); | ||||
| foreach ($results as $key => $hash) { | foreach ($results as $key => $hash) { | ||||
| $results[$key]['why'] = | $results[$key]['why'] = | ||||
| "A mercurial commit hash in the commit range is already attached ". | 'A mercurial commit hash in the commit range is already attached '. | ||||
| "to the Differential revision."; | 'to the Differential revision.'; | ||||
| } | } | ||||
| return $results; | return $results; | ||||
| } | } | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | public function backoutCommit($commit_hash) { | ||||
| $this->reloadWorkingCopy(); | $this->reloadWorkingCopy(); | ||||
| if (!$this->getUncommittedStatus()) { | if (!$this->getUncommittedStatus()) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "{$commit_hash} has already been reverted."); | "{$commit_hash} has already been reverted."); | ||||
| } | } | ||||
| } | } | ||||
| public function getBackoutMessage($commit_hash) { | public function getBackoutMessage($commit_hash) { | ||||
| return "Backed out changeset ".$commit_hash."."; | return 'Backed out changeset '.$commit_hash.'.'; | ||||
| } | } | ||||
| public function resolveBaseCommitRule($rule, $source) { | public function resolveBaseCommitRule($rule, $source) { | ||||
| list($type, $name) = explode(':', $rule, 2); | list($type, $name) = explode(':', $rule, 2); | ||||
| // NOTE: This function MUST return node hashes or symbolic commits (like | // NOTE: This function MUST return node hashes or symbolic commits (like | ||||
| // branch names or the word "tip"), not revsets. This includes ".^" and | // branch names or the word "tip"), not revsets. This includes ".^" and | ||||
| // similar, which a revset, not a symbolic commit identifier. If you return | // similar, which a revset, not a symbolic commit identifier. If you return | ||||
| ▲ Show 20 Lines • Show All 263 Lines • Show Last 20 Lines | |||||