Differential D11874 Diff 37841 src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryGitCommitChangeParserWorker.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryGitCommitChangeParserWorker.php
<?php | <?php | ||||
final class PhabricatorRepositoryGitCommitChangeParserWorker | final class PhabricatorRepositoryGitCommitChangeParserWorker | ||||
extends PhabricatorRepositoryCommitChangeParserWorker { | extends PhabricatorRepositoryCommitChangeParserWorker { | ||||
protected function parseCommitChanges( | protected function parseCommitChanges( | ||||
PhabricatorRepository $repository, | PhabricatorRepository $repository, | ||||
PhabricatorRepositoryCommit $commit) { | PhabricatorRepositoryCommit $commit) { | ||||
// Check if the commit has parents. We're testing to see whether it is the | $viewer = PhabricatorUser::getOmnipotentUser(); | ||||
// first commit in history (in which case we must use "git log") or some | $raw = DiffusionQuery::callConduitWithDiffusionRequest( | ||||
// other commit (in which case we can use "git diff"). We'd rather use | $viewer, | ||||
// "git diff" because it has the right behavior for merge commits, but | DiffusionRequest::newFromDictionary( | ||||
// it requires the commit to have a parent that we can diff against. The | array( | ||||
// first commit doesn't, so "commit^" is not a valid ref. | 'repository' => $repository, | ||||
list($parents) = $repository->execxLocalCommand( | 'user' => $viewer, | ||||
'log -n1 --format=%s %s', | )), | ||||
'%P', | 'diffusion.internal.gitrawdiffquery', | ||||
$commit->getCommitIdentifier()); | array( | ||||
'commit' => $commit->getCommitIdentifier(), | |||||
$use_log = !strlen(trim($parents)); | )); | ||||
if ($use_log) { | |||||
// 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. | |||||
// NOTE: "--pretty=format: " is to disable diff output, we only want the | |||||
// part we get from "--raw". | |||||
list($raw) = $repository->execxLocalCommand( | |||||
'log -n1 -M -C -B --find-copies-harder --raw -t '. | |||||
'--pretty=format: --abbrev=40 %s', | |||||
$commit->getCommitIdentifier()); | |||||
} else { | |||||
// Otherwise, we can use "diff", which will give us output for merges. | |||||
// We diff against the first parent, as this is generally the expectation | |||||
// and results in sensible behavior. | |||||
list($raw) = $repository->execxLocalCommand( | |||||
'diff -n1 -M -C -B --find-copies-harder --raw -t '. | |||||
'--abbrev=40 %s^1 %s', | |||||
$commit->getCommitIdentifier(), | |||||
$commit->getCommitIdentifier()); | |||||
} | |||||
$changes = array(); | $changes = array(); | ||||
$move_away = array(); | $move_away = array(); | ||||
$copy_away = array(); | $copy_away = array(); | ||||
epriestley: Omit this; all pathways which fail to produce output throw an exception so this code is… | |||||
$lines = explode("\n", $raw); | $lines = explode("\n", $raw); | ||||
foreach ($lines as $line) { | foreach ($lines as $line) { | ||||
if (!strlen(trim($line))) { | if (!strlen(trim($line))) { | ||||
continue; | continue; | ||||
} | } | ||||
list($old_mode, $new_mode, | list($old_mode, $new_mode, | ||||
$old_hash, $new_hash, | $old_hash, $new_hash, | ||||
$more_stuff) = preg_split('/ +/', $line, 5); | $more_stuff) = preg_split('/ +/', $line, 5); | ||||
▲ Show 20 Lines • Show All 195 Lines • Show Last 20 Lines |
Omit this; all pathways which fail to produce output throw an exception so this code is unreachable.