Clean up use of IDatabase::affectedRows() in WikiPage::updateRedirectOn()
[lhc/web/wiklou.git] / includes / GitInfo.php
index f170a02..102510e 100644 (file)
@@ -37,6 +37,11 @@ class GitInfo {
         */
        protected $basedir;
 
+       /**
+        * Location of the repository
+        */
+       protected $repoDir;
+
        /**
         * Path to JSON cache file for pre-computed git information.
         */
@@ -58,9 +63,10 @@ class GitInfo {
         * @see precomputeValues
         */
        public function __construct( $repoDir, $usePrecomputed = true ) {
+               $this->repoDir = $repoDir;
                $this->cacheFile = self::getCacheFilePath( $repoDir );
                wfDebugLog( 'gitinfo',
-                       "Computed cacheFile={$this->cacheFile} for {$repoDir}"
+                       "Candidate cacheFile={$this->cacheFile} for {$repoDir}"
                );
                if ( $usePrecomputed &&
                        $this->cacheFile !== null &&
@@ -150,7 +156,7 @@ class GitInfo {
         * @return bool Whether or not the string looks like a SHA1
         */
        public static function isSHA1( $str ) {
-               return !!preg_match( '/^[0-9A-F]{40}$/i', $str );
+               return (bool)preg_match( '/^[0-9A-F]{40}$/i', $str );
        }
 
        /**
@@ -221,6 +227,7 @@ class GitInfo {
                        $date = false;
                        if ( is_file( $wgGitBin ) &&
                                is_executable( $wgGitBin ) &&
+                               !Shell::isDisabled() &&
                                $this->getHead() !== false
                        ) {
                                $cmd = [
@@ -230,10 +237,11 @@ class GitInfo {
                                        '--format=format:%ct',
                                        'HEAD',
                                ];
+                               $gitDir = realpath( $this->basedir );
                                $result = Shell::command( $cmd )
-                                       ->environment( [ 'GIT_DIR' => $this->basedir ] )
+                                       ->environment( [ 'GIT_DIR' => $gitDir ] )
                                        ->restrict( Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK )
-                                       ->whitelistPaths( [ $this->basedir ] )
+                                       ->whitelistPaths( [ $gitDir, $this->repoDir ] )
                                        ->execute();
 
                                if ( $result->getExitCode() === 0 ) {
@@ -299,9 +307,9 @@ class GitInfo {
                        $config = "{$this->basedir}/config";
                        $url = false;
                        if ( is_readable( $config ) ) {
-                               MediaWiki\suppressWarnings();
+                               Wikimedia\suppressWarnings();
                                $configArray = parse_ini_file( $config, true );
-                               MediaWiki\restoreWarnings();
+                               Wikimedia\restoreWarnings();
                                $remote = false;
 
                                // Use the "origin" remote repo if available or any other repo if not.