*/
public function __construct( $repoDir, $usePrecomputed = true ) {
$this->cacheFile = self::getCacheFilePath( $repoDir );
+ wfDebugLog( 'gitinfo',
+ "Computed cacheFile={$this->cacheFile} for {$repoDir}"
+ );
if ( $usePrecomputed &&
$this->cacheFile !== null &&
is_readable( $this->cacheFile )
file_get_contents( $this->cacheFile ),
true
);
+ wfDebugLog( 'gitinfo', "Loaded git data from cache for {$repoDir}" );
}
if ( !$this->cacheIsComplete() ) {
+ wfDebugLog( 'gitinfo', "Cache incomplete for {$repoDir}" );
$this->basedir = $repoDir . DIRECTORY_SEPARATOR . '.git';
if ( is_readable( $this->basedir ) && !is_dir( $this->basedir ) ) {
$GITfile = file_get_contents( $this->basedir );
* Compute the path to the cache file for a given directory.
*
* @param string $repoDir The root directory of the repo where .git can be found
- * @return string Path to GitInfo cache file in $wgCacheDirectory or null if
- * $wgCacheDirectory is false (cache disabled).
+ * @return string Path to GitInfo cache file in $wgGitInfoCacheDirectory or
+ * null if $wgGitInfoCacheDirectory is false (cache disabled).
+ * @since 1.24
*/
protected static function getCacheFilePath( $repoDir ) {
- global $IP, $wgCacheDirectory;
- if ( $wgCacheDirectory ) {
- // Transform path to git repo to something we can safely embed in a filename
- $repoName = $repoDir;
- if ( strpos( $repoName, $IP ) === 0 ) {
+ global $IP, $wgGitInfoCacheDirectory;
+
+ if ( $wgGitInfoCacheDirectory ) {
+ // Convert both $IP and $repoDir to canonical paths to protect against
+ // $IP having changed between the settings files and runtime.
+ $realIP = realpath( $IP );
+ $repoName = realpath( $repoDir );
+ if ( $repoName === false ) {
+ // Unit tests use fake path names
+ $repoName = $repoDir;
+ }
+ if ( strpos( $repoName, $realIP ) === 0 ) {
// Strip $IP from path
- $repoName = substr( $repoName, strlen( $IP ) );
+ $repoName = substr( $repoName, strlen( $realIP ) );
}
+ // Transform path to git repo to something we can safely embed in
+ // a filename
$repoName = strtr( $repoName, DIRECTORY_SEPARATOR, '-' );
$fileName = 'info' . $repoName . '.json';
- return implode(
- DIRECTORY_SEPARATOR,
- array( $wgCacheDirectory, 'gitinfo', $fileName )
- );
+ return "{$wgGitInfoCacheDirectory}/{$fileName}";
}
return null;
}
$this->getRemoteUrl();
if ( !$this->cacheIsComplete() ) {
- wfDebugLog( "Failed to compute GitInfo for \"{$this->basedir}\"" );
+ wfDebugLog( 'gitinfo',
+ "Failed to compute GitInfo for \"{$this->basedir}\""
+ );
return;
}