Differential D16460 Diff 39599 src/applications/diffusion/query/rawdiff/DiffusionGitRawDiffQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/query/rawdiff/DiffusionGitRawDiffQuery.php
| <?php | <?php | ||||
| final class DiffusionGitRawDiffQuery extends DiffusionRawDiffQuery { | final class DiffusionGitRawDiffQuery extends DiffusionRawDiffQuery { | ||||
| protected function executeQuery() { | protected function newQueryFuture() { | ||||
| $drequest = $this->getRequest(); | $drequest = $this->getRequest(); | ||||
| $repository = $drequest->getRepository(); | $repository = $drequest->getRepository(); | ||||
| $commit = $this->getAnchorCommit(); | $commit = $this->getAnchorCommit(); | ||||
| $options = array( | $options = array( | ||||
| '-M', | '-M', | ||||
| '-C', | '-C', | ||||
| '--no-ext-diff', | '--no-ext-diff', | ||||
| '--no-color', | '--no-color', | ||||
| '--src-prefix=a/', | '--src-prefix=a/', | ||||
| '--dst-prefix=b/', | '--dst-prefix=b/', | ||||
| '-U'.(int)$this->getLinesOfContext(), | '-U'.(int)$this->getLinesOfContext(), | ||||
| ); | ); | ||||
| $options = implode(' ', $options); | |||||
| $against = $this->getAgainstCommit(); | $against = $this->getAgainstCommit(); | ||||
| if ($against === null) { | if ($against === null) { | ||||
| $against = $commit.'^'; | // Check if this is the root commit by seeing if it has parents, since | ||||
| } | // `git diff X^ X` does not work if "X" is the initial commit. | ||||
| // If there's no path, get the entire raw diff. | |||||
| $path = nonempty($drequest->getPath(), '.'); | |||||
| $future = $repository->getLocalCommandFuture( | |||||
| 'diff %C %s %s -- %s', | |||||
| $options, | |||||
| $against, | |||||
| $commit, | |||||
| $path); | |||||
| $this->configureFuture($future); | |||||
| try { | |||||
| list($raw_diff) = $future->resolvex(); | |||||
| } catch (CommandException $ex) { | |||||
| // Check if this is the root commit by seeing if it has parents. | |||||
| list($parents) = $repository->execxLocalCommand( | list($parents) = $repository->execxLocalCommand( | ||||
| 'log --format=%s %s --', | 'log --format=%s %s --', | ||||
| '%P', // "parents" | '%P', | ||||
| $commit); | $commit); | ||||
| if (strlen(trim($parents))) { | if (strlen(trim($parents))) { | ||||
| throw $ex; | $against = $commit.'^'; | ||||
| } else { | |||||
| $against = ArcanistGitAPI::GIT_MAGIC_ROOT_COMMIT; | |||||
| } | |||||
| } | } | ||||
| // No parents means we're looking at the root revision. Diff against | $path = $drequest->getPath(); | ||||
| // the empty tree hash instead, since there is no parent so "^" does | if (!strlen($path)) { | ||||
| // not work. See ArcanistGitAPI for more discussion. | $path = '.'; | ||||
| $future = $repository->getLocalCommandFuture( | |||||
| 'diff %C %s %s -- %s', | |||||
| $options, | |||||
| ArcanistGitAPI::GIT_MAGIC_ROOT_COMMIT, | |||||
| $commit, | |||||
| $drequest->getPath()); | |||||
| $this->configureFuture($future); | |||||
| list($raw_diff) = $future->resolvex(); | |||||
| } | } | ||||
| return $raw_diff; | return $repository->getLocalCommandFuture( | ||||
| 'diff %Ls %s %s -- %s', | |||||
| $options, | |||||
| $against, | |||||
| $commit, | |||||
| $path); | |||||
| } | } | ||||
| } | } | ||||