X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FGitInfo.php;h=8095fd7308761ff182624386236d9d79927120a1;hb=4ca7f7a21c128b29c1a06093129d34150bfe6368;hp=de7e8c28e2d8373af10bbe253b696f1daaf11573;hpb=bdc24ab7a3235a18af53d67e21b00fbfa36e72d8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/GitInfo.php b/includes/GitInfo.php index de7e8c28e2..8095fd7308 100644 --- a/includes/GitInfo.php +++ b/includes/GitInfo.php @@ -23,6 +23,8 @@ * @file */ +use MediaWiki\Shell\Shell; + class GitInfo { /** @@ -46,7 +48,7 @@ class GitInfo { protected $cache = []; /** - * Map of repo URLs to viewer URLs. Access via static method getViewers(). + * @var array|false Map of repo URLs to viewer URLs. Access via static method getViewers(). */ private static $viewers = false; @@ -191,8 +193,14 @@ class GitInfo { } else { // If not a SHA1 it may be a ref: $refFile = "{$this->basedir}/{$head}"; + $packedRefs = "{$this->basedir}/packed-refs"; + $headRegex = preg_quote( $head, '/' ); if ( is_readable( $refFile ) ) { $sha1 = rtrim( file_get_contents( $refFile ) ); + } elseif ( is_readable( $packedRefs ) && + preg_match( "/^([0-9A-Fa-f]{40}) $headRegex$/m", file_get_contents( $packedRefs ), $matches ) + ) { + $sha1 = $matches[1]; } } $this->cache['headSHA1'] = $sha1; @@ -215,13 +223,19 @@ class GitInfo { is_executable( $wgGitBin ) && $this->getHead() !== false ) { - $environment = [ "GIT_DIR" => $this->basedir ]; - $cmd = wfEscapeShellArg( $wgGitBin ) . - " show -s --format=format:%ct HEAD"; - $retc = false; - $commitDate = wfShellExec( $cmd, $retc, $environment ); - if ( $retc === 0 ) { - $date = (int)$commitDate; + $cmd = [ + $wgGitBin, + 'show', + '-s', + '--format=format:%ct', + 'HEAD', + ]; + $result = Shell::command( $cmd ) + ->environment( [ 'GIT_DIR' => $this->basedir ] ) + ->execute(); + + if ( $result->getExitCode() === 0 ) { + $date = (int)$result->getStdout(); } } $this->cache['headCommitDate'] = $date;