Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/query/blame/DiffusionMercurialBlameQuery.php
<?php | <?php | ||||
final class DiffusionMercurialBlameQuery extends DiffusionBlameQuery { | final class DiffusionMercurialBlameQuery extends DiffusionBlameQuery { | ||||
protected function newBlameFuture(DiffusionRequest $request, $path) { | protected function newBlameFuture(DiffusionRequest $request, $path) { | ||||
$repository = $request->getRepository(); | $repository = $request->getRepository(); | ||||
$commit = $request->getCommit(); | $commit = $request->getCommit(); | ||||
// NOTE: We're using "--debug" to make "--changeset" give us the full | // NOTE: Using "--template" or "--debug" to get the full commit hashes. | ||||
// commit hashes. | $hg_analyzer = PhutilBinaryAnalyzer::getForBinary('hg'); | ||||
if ($hg_analyzer->isMercurialAnnotateTemplatesAvailable()) { | |||||
// See `hg help annotate --verbose` for more info on the template format. | |||||
// Use array of arguments so the template line does not need wrapped in | |||||
// quotes. | |||||
$template = array( | |||||
'--template', | |||||
"{lines % '{node}: {line}'}", | |||||
); | |||||
} else { | |||||
$template = array( | |||||
'--debug', | |||||
'--changeset', | |||||
); | |||||
} | |||||
return $repository->getLocalCommandFuture( | return $repository->getLocalCommandFuture( | ||||
'annotate --debug --changeset --rev %s -- %s', | 'annotate %Ls --rev %s -- %s', | ||||
$template, | |||||
$commit, | $commit, | ||||
$path); | $path); | ||||
} | } | ||||
protected function resolveBlameFuture(ExecFuture $future) { | protected function resolveBlameFuture(ExecFuture $future) { | ||||
list($err, $stdout) = $future->resolve(); | list($err, $stdout) = $future->resolve(); | ||||
if ($err) { | if ($err) { | ||||
return null; | return null; | ||||
} | } | ||||
$result = array(); | $result = array(); | ||||
$lines = phutil_split_lines($stdout); | $lines = phutil_split_lines($stdout); | ||||
foreach ($lines as $line) { | foreach ($lines as $line) { | ||||
// If the `--debug` flag was used above instead of `--template` then | |||||
// there's a good change additional output was included which is not | |||||
// relevant to the information we want. It should be safe to call this | |||||
// regardless of whether we used `--debug` or `--template` so there isn't | |||||
// a need to track which argument was used. | |||||
$line = DiffusionMercurialCommandEngine::filterMercurialDebugOutput( | |||||
$line); | |||||
// Just in case new versions of Mercurial add arbitrary output when using | |||||
// the `--debug`, do a quick sanity check that this line is formatted in | |||||
// a way we're expecting. | |||||
if (strpos($line, ':') === false) { | |||||
phlog(pht('Unexpected output from hg annotate: %s', $line)); | |||||
continue; | |||||
} | |||||
list($commit) = explode(':', $line, 2); | list($commit) = explode(':', $line, 2); | ||||
$result[] = $commit; | $result[] = $commit; | ||||
} | } | ||||
return $result; | return $result; | ||||
} | } | ||||
} | } |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0