Differential D21511 Diff 51201 src/applications/diffusion/conduit/DiffusionInternalGitRawDiffQueryConduitAPIMethod.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/conduit/DiffusionInternalGitRawDiffQueryConduitAPIMethod.php
| Show All 37 Lines | protected function getResult(ConduitAPIRequest $request) { | ||||
| // Check if the commit has parents. We're testing to see whether it is the | // Check if the commit has parents. We're testing to see whether it is the | ||||
| // first commit in history (in which case we must use "git log") or some | // first commit in history (in which case we must use "git log") or some | ||||
| // other commit (in which case we can use "git diff"). We'd rather use | // other commit (in which case we can use "git diff"). We'd rather use | ||||
| // "git diff" because it has the right behavior for merge commits, but | // "git diff" because it has the right behavior for merge commits, but | ||||
| // it requires the commit to have a parent that we can diff against. The | // it requires the commit to have a parent that we can diff against. The | ||||
| // first commit doesn't, so "commit^" is not a valid ref. | // first commit doesn't, so "commit^" is not a valid ref. | ||||
| list($parents) = $repository->execxLocalCommand( | list($parents) = $repository->execxLocalCommand( | ||||
| 'log -n1 --format=%s %s', | 'log -n1 %s %s --', | ||||
| '%P', | '--format=%P', | ||||
| $commit); | gitsprintf('%s', $commit)); | ||||
| $use_log = !strlen(trim($parents)); | $use_log = !strlen(trim($parents)); | ||||
| // First, get a fast raw diff without "--find-copies-harder". This flag | // First, get a fast raw diff without "--find-copies-harder". This flag | ||||
| // produces better results for moves and copies, but is explosively slow | // produces better results for moves and copies, but is explosively slow | ||||
| // for large changes to large repositories. See T10423. | // for large changes to large repositories. See T10423. | ||||
| $raw = $this->getRawDiff($repository, $commit, $use_log, false); | $raw = $this->getRawDiff($repository, $commit, $use_log, false); | ||||
| // If we got a normal-sized diff (no more than 100 modified files), we'll | // If we got a normal-sized diff (no more than 100 modified files), we'll | ||||
| Show All 34 Lines | private function getRawDiff( | ||||
| if ($use_log) { | if ($use_log) { | ||||
| // This is the first commit so we need to use "log". We know it's not a | // This is the first commit so we need to use "log". We know it's not a | ||||
| // merge commit because it couldn't be merging anything, so this is safe. | // merge commit because it couldn't be merging anything, so this is safe. | ||||
| // NOTE: "--pretty=format: " is to disable diff output, we only want the | // NOTE: "--pretty=format: " is to disable diff output, we only want the | ||||
| // part we get from "--raw". | // part we get from "--raw". | ||||
| $future = $repository->getLocalCommandFuture( | $future = $repository->getLocalCommandFuture( | ||||
| 'log %Ls --pretty=format: %s', | 'log %Ls --pretty=format: %s --', | ||||
| $flags, | $flags, | ||||
| $commit); | gitsprintf('%s', $commit)); | ||||
| } else { | } else { | ||||
| // Otherwise, we can use "diff", which will give us output for merges. | // Otherwise, we can use "diff", which will give us output for merges. | ||||
| // We diff against the first parent, as this is generally the expectation | // We diff against the first parent, as this is generally the expectation | ||||
| // and results in sensible behavior. | // and results in sensible behavior. | ||||
| $future = $repository->getLocalCommandFuture( | $future = $repository->getLocalCommandFuture( | ||||
| 'diff %Ls %s^1 %s', | 'diff %Ls %s %s --', | ||||
| $flags, | $flags, | ||||
| $commit, | gitsprintf('%s^1', $commit), | ||||
| $commit); | gitsprintf('%s', $commit)); | ||||
| } | } | ||||
| // Don't spend more than 30 seconds generating the slower output. | // Don't spend more than 30 seconds generating the slower output. | ||||
| if ($try_harder) { | if ($try_harder) { | ||||
| $future->setTimeout(30); | $future->setTimeout(30); | ||||
| } | } | ||||
| list($raw) = $future->resolvex(); | list($raw) = $future->resolvex(); | ||||
| return $raw; | return $raw; | ||||
| } | } | ||||
| } | } | ||||