Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Hgblame.php

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

Hgblame

Namespace

PHP_CodeSniffer\Reports

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal