Changeset View
Changeset View
Standalone View
Standalone View
src/repository/api/ArcanistGitAPI.php
| Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | public function getLocalCommitInformation() { | ||||
| return $commits; | return $commits; | ||||
| } | } | ||||
| protected function buildBaseCommit($symbolic_commit) { | protected function buildBaseCommit($symbolic_commit) { | ||||
| if ($symbolic_commit !== null) { | if ($symbolic_commit !== null) { | ||||
| if ($symbolic_commit == ArcanistGitAPI::GIT_MAGIC_ROOT_COMMIT) { | if ($symbolic_commit == ArcanistGitAPI::GIT_MAGIC_ROOT_COMMIT) { | ||||
| $this->setBaseCommitExplanation( | $this->setBaseCommitExplanation( | ||||
| "you explicitly specified the empty tree."); | 'you explicitly specified the empty tree.'); | ||||
| return $symbolic_commit; | return $symbolic_commit; | ||||
| } | } | ||||
| list($err, $merge_base) = $this->execManualLocal( | list($err, $merge_base) = $this->execManualLocal( | ||||
| 'merge-base %s HEAD', | 'merge-base %s HEAD', | ||||
| $symbolic_commit); | $symbolic_commit); | ||||
| if ($err) { | if ($err) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| Show All 14 Lines | protected function buildBaseCommit($symbolic_commit) { | ||||
| if ($err) { | if ($err) { | ||||
| list($err) = $this->execManualLocal('rev-parse --verify HEAD'); | list($err) = $this->execManualLocal('rev-parse --verify HEAD'); | ||||
| if ($err) { | if ($err) { | ||||
| $this->repositoryHasNoCommits = true; | $this->repositoryHasNoCommits = true; | ||||
| } | } | ||||
| if ($this->repositoryHasNoCommits) { | if ($this->repositoryHasNoCommits) { | ||||
| $this->setBaseCommitExplanation( | $this->setBaseCommitExplanation( | ||||
| "the repository has no commits."); | 'the repository has no commits.'); | ||||
| } else { | } else { | ||||
| $this->setBaseCommitExplanation( | $this->setBaseCommitExplanation( | ||||
| "the repository has only one commit."); | 'the repository has only one commit.'); | ||||
| } | } | ||||
| return self::GIT_MAGIC_ROOT_COMMIT; | return self::GIT_MAGIC_ROOT_COMMIT; | ||||
| } | } | ||||
| if ($this->getBaseCommitArgumentRules() || | if ($this->getBaseCommitArgumentRules() || | ||||
| $this->getConfigurationManager()->getConfigFromAnySource('base')) { | $this->getConfigurationManager()->getConfigFromAnySource('base')) { | ||||
| $base = $this->resolveBaseCommit(); | $base = $this->resolveBaseCommit(); | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | if (!$default_relative) { | ||||
| "just `arc diff`) or select a default for this working copy.\n\n". | "just `arc diff`) or select a default for this working copy.\n\n". | ||||
| "In most cases, the best default is 'origin/master'. You can also ". | "In most cases, the best default is 'origin/master'. You can also ". | ||||
| "select 'HEAD^' to preserve the old behavior, or some other remote ". | "select 'HEAD^' to preserve the old behavior, or some other remote ". | ||||
| "or branch. But you almost certainly want to select ". | "or branch. But you almost certainly want to select ". | ||||
| "'origin/master'.\n\n". | "'origin/master'.\n\n". | ||||
| "(Technically: the merge-base of the selected revision and HEAD is ". | "(Technically: the merge-base of the selected revision and HEAD is ". | ||||
| "used to determine the start of the commit range.)"); | "used to determine the start of the commit range.)"); | ||||
| $prompt = "What default do you want to use? [origin/master]"; | $prompt = 'What default do you want to use? [origin/master]'; | ||||
| $default = phutil_console_prompt($prompt); | $default = phutil_console_prompt($prompt); | ||||
| if (!strlen(trim($default))) { | if (!strlen(trim($default))) { | ||||
| $default = 'origin/master'; | $default = 'origin/master'; | ||||
| } | } | ||||
| $default_relative = $default; | $default_relative = $default; | ||||
| $do_write = true; | $do_write = true; | ||||
| ▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | private function executeSVNFindRev($input, $vcs) { | ||||
| // look-up, we need to parse the final line | // look-up, we need to parse the final line | ||||
| $lines = explode("\n", $stdout); | $lines = explode("\n", $stdout); | ||||
| $stdout = $lines[count($lines) - 2]; | $stdout = $lines[count($lines) - 2]; | ||||
| return rtrim($stdout); | return rtrim($stdout); | ||||
| } | } | ||||
| // Convert svn revision number to git hash | // Convert svn revision number to git hash | ||||
| public function getHashFromFromSVNRevisionNumber($revision_id) { | public function getHashFromFromSVNRevisionNumber($revision_id) { | ||||
| return $this->executeSVNFindRev("r".$revision_id, "Git"); | return $this->executeSVNFindRev('r'.$revision_id, 'Git'); | ||||
| } | } | ||||
| // Convert a git hash to svn revision number | // Convert a git hash to svn revision number | ||||
| public function getSVNRevisionNumberFromHash($hash) { | public function getSVNRevisionNumberFromHash($hash) { | ||||
| return $this->executeSVNFindRev($hash, "SVN"); | return $this->executeSVNFindRev($hash, 'SVN'); | ||||
| } | } | ||||
| protected function buildUncommittedStatus() { | protected function buildUncommittedStatus() { | ||||
| $diff_options = $this->getDiffBaseOptions(); | $diff_options = $this->getDiffBaseOptions(); | ||||
| if ($this->repositoryHasNoCommits) { | if ($this->repositoryHasNoCommits) { | ||||
| $diff_base = self::GIT_MAGIC_ROOT_COMMIT; | $diff_base = self::GIT_MAGIC_ROOT_COMMIT; | ||||
| ▲ Show 20 Lines • Show All 234 Lines • ▼ Show 20 Lines | private function parseGitTree($stdout) { | ||||
| $lines = explode("\n", $stdout); | $lines = explode("\n", $stdout); | ||||
| foreach ($lines as $line) { | foreach ($lines as $line) { | ||||
| $matches = array(); | $matches = array(); | ||||
| $ok = preg_match( | $ok = preg_match( | ||||
| '/^(\d{6}) (blob|tree|commit) ([a-z0-9]{40})[\t](.*)$/', | '/^(\d{6}) (blob|tree|commit) ([a-z0-9]{40})[\t](.*)$/', | ||||
| $line, | $line, | ||||
| $matches); | $matches); | ||||
| if (!$ok) { | if (!$ok) { | ||||
| throw new Exception("Failed to parse git ls-tree output!"); | throw new Exception('Failed to parse git ls-tree output!'); | ||||
| } | } | ||||
| $result[$matches[4]] = array( | $result[$matches[4]] = array( | ||||
| 'mode' => $matches[1], | 'mode' => $matches[1], | ||||
| 'type' => $matches[2], | 'type' => $matches[2], | ||||
| 'ref' => $matches[3], | 'ref' => $matches[3], | ||||
| ); | ); | ||||
| } | } | ||||
| return $result; | return $result; | ||||
| ▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | final class ArcanistGitAPI extends ArcanistRepositoryAPI { | ||||
| public function supportsLocalBranchMerge() { | public function supportsLocalBranchMerge() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| public function performLocalBranchMerge($branch, $message) { | public function performLocalBranchMerge($branch, $message) { | ||||
| if (!$branch) { | if (!$branch) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "Under git, you must specify the branch you want to merge."); | 'Under git, you must specify the branch you want to merge.'); | ||||
| } | } | ||||
| $err = phutil_passthru( | $err = phutil_passthru( | ||||
| '(cd %s && git merge --no-ff -m %s %s)', | '(cd %s && git merge --no-ff -m %s %s)', | ||||
| $this->getPath(), | $this->getPath(), | ||||
| $message, | $message, | ||||
| $branch); | $branch); | ||||
| 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 ". | ||||
| "'git push', or 'git svn dcommit', or by printing and faxing it)."; | "'git push', or 'git svn dcommit', or by printing and faxing it)."; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | public function loadWorkingCopyDifferentialRevisions( | ||||
| $results = $conduit->callMethodSynchronous( | $results = $conduit->callMethodSynchronous( | ||||
| 'differential.query', | 'differential.query', | ||||
| $query + array( | $query + array( | ||||
| 'commitHashes' => $hashes, | 'commitHashes' => $hashes, | ||||
| )); | )); | ||||
| foreach ($results as $key => $result) { | foreach ($results as $key => $result) { | ||||
| $results[$key]['why'] = | $results[$key]['why'] = | ||||
| "A git commit or tree hash in the commit range is already attached ". | 'A git commit or tree hash in the commit range is already attached '. | ||||
| "to the Differential revision."; | 'to the Differential revision.'; | ||||
| } | } | ||||
| return $results; | return $results; | ||||
| } | } | ||||
| public function updateWorkingCopy() { | public function updateWorkingCopy() { | ||||
| $this->execxLocal('pull'); | $this->execxLocal('pull'); | ||||
| $this->reloadWorkingCopy(); | $this->reloadWorkingCopy(); | ||||
| Show All 18 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 "This reverts commit ".$commit_hash."."; | return 'This reverts commit '.$commit_hash.'.'; | ||||
| } | } | ||||
| public function isGitSubversionRepo() { | public function isGitSubversionRepo() { | ||||
| return Filesystem::pathExists($this->getPath('.git/svn')); | return Filesystem::pathExists($this->getPath('.git/svn')); | ||||
| } | } | ||||
| public function resolveBaseCommitRule($rule, $source) { | public function resolveBaseCommitRule($rule, $source) { | ||||
| list($type, $name) = explode(':', $rule, 2); | list($type, $name) = explode(':', $rule, 2); | ||||
| ▲ Show 20 Lines • Show All 135 Lines • Show Last 20 Lines | |||||