function Hgblame::getBlameContent
Gets the blame output.
Parameters
string $filename File to blame.:
Return value
array
Throws
\PHP_CodeSniffer\Exceptions\DeepExitException
Overrides VersionControl::getBlameContent
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Reports/ Hgblame.php, line 69
Class
Namespace
PHP_CodeSniffer\ReportsCode
protected function getBlameContent($filename) {
$cwd = getcwd();
$fileParts = explode(DIRECTORY_SEPARATOR, $filename);
$found = false;
$location = '';
while (empty($fileParts) === false) {
array_pop($fileParts);
$location = implode(DIRECTORY_SEPARATOR, $fileParts);
if (is_dir($location . DIRECTORY_SEPARATOR . '.hg') === true) {
$found = true;
break;
}
}
if ($found === true) {
chdir($location);
}
else {
$error = 'ERROR: Could not locate .hg directory ' . PHP_EOL . PHP_EOL;
throw new DeepExitException($error, 3);
}
$command = 'hg blame -u -d -v "' . $filename . '" 2>&1';
$handle = popen($command, 'r');
if ($handle === false) {
$error = 'ERROR: Could not execute "' . $command . '"' . PHP_EOL . PHP_EOL;
throw new DeepExitException($error, 3);
}
$rawContent = stream_get_contents($handle);
pclose($handle);
$blames = explode("\n", $rawContent);
chdir($cwd);
return $blames;
}