MediaWiki master
MediaWiki\Utils\GitInfo Class Reference

Fetch status information from a local git repository. More...

Public Member Functions

 __construct ( $repoDir, $usePrecomputed=true)
 
 cacheIsComplete ()
 Check to see if the current cache is fully populated.
 
 getCurrentBranch ()
 Get the name of the current branch, or HEAD if not found.
 
 getHead ()
 Get the HEAD of the repo (without any opening "ref: ")
 
 getHeadCommitDate ()
 Get the commit date of HEAD entry of the git code repository.
 
 getHeadSHA1 ()
 Get the SHA1 for the current HEAD of the repo.
 
 getHeadViewUrl ()
 Get an URL to a web viewer link to the HEAD revision.
 
 precomputeValues ()
 Precompute and cache git information.
 

Static Public Member Functions

static currentBranch ()
 
static headSHA1 ()
 
static headViewUrl ()
 
static isSHA1 ( $str)
 Check if a string looks like a hex encoded SHA1 hash.
 
static repo ()
 Get the singleton for the repo at MW_INSTALL_PATH.
 

Protected Member Functions

 getRemoteUrl ()
 Get the URL of the remote origin.
 

Protected Attributes

 $basedir
 
 $cache = []
 
 $cacheFile
 
 $repoDir
 

Static Protected Attributes

static $repo = null
 Singleton for the repo at $IP.
 

Detailed Description

Fetch status information from a local git repository.

This is used by Special:Version. It can also be used by developers in their LocalSettings.php to ease testing of a branch you work on for a longer period of time. For example:

if ( GitInfo::currentBranch() === 'myrewriteproject' ) {
}
Stability: newable
Note
marked as newable in 1.35 for lack of a better alternative, but should become a stateless service eventually.

Definition at line 47 of file GitInfo.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Utils\GitInfo::__construct (   $repoDir,
  $usePrecomputed = true 
)
Stability: stable
to call
Parameters
string$repoDirThe root directory of the repo where .git can be found
bool$usePrecomputedUse precomputed information if available
See also
precomputeValues

Definition at line 87 of file GitInfo.php.

References $path, MediaWiki\Utils\GitInfo\$repoDir, MediaWiki\Utils\GitInfo\cacheIsComplete(), and MediaWiki\MediaWikiServices\getInstance().

Member Function Documentation

◆ cacheIsComplete()

MediaWiki\Utils\GitInfo::cacheIsComplete ( )

Check to see if the current cache is fully populated.

Note: This method is public only to make unit testing easier. There's really no strong reason that anything other than a test should want to call this method.

Returns
bool True if all expected cache keys exist, false otherwise

Definition at line 378 of file GitInfo.php.

Referenced by MediaWiki\Utils\GitInfo\__construct(), and MediaWiki\Utils\GitInfo\precomputeValues().

◆ currentBranch()

static MediaWiki\Utils\GitInfo::currentBranch ( )
static
See also
self::getCurrentBranch
Returns
string

Definition at line 434 of file GitInfo.php.

References MediaWiki\Utils\GitInfo\repo().

◆ getCurrentBranch()

MediaWiki\Utils\GitInfo::getCurrentBranch ( )

Get the name of the current branch, or HEAD if not found.

Returns
string|false The branch name, HEAD, or false

Definition at line 296 of file GitInfo.php.

References MediaWiki\Utils\GitInfo\getHead().

Referenced by MediaWiki\Utils\GitInfo\precomputeValues().

◆ getHead()

MediaWiki\Utils\GitInfo::getHead ( )

Get the HEAD of the repo (without any opening "ref: ")

Returns
string|false The HEAD (git reference or SHA1) or false

Definition at line 198 of file GitInfo.php.

Referenced by MediaWiki\Utils\GitInfo\getCurrentBranch(), MediaWiki\Utils\GitInfo\getHeadCommitDate(), MediaWiki\Utils\GitInfo\getHeadSHA1(), and MediaWiki\Utils\GitInfo\precomputeValues().

◆ getHeadCommitDate()

MediaWiki\Utils\GitInfo::getHeadCommitDate ( )

Get the commit date of HEAD entry of the git code repository.

Since
1.22
Returns
int|false Commit date (UNIX timestamp) or false

Definition at line 254 of file GitInfo.php.

References MediaWiki\Utils\GitInfo\getHead(), and MediaWiki\MainConfigNames\GitBin.

Referenced by MediaWiki\Utils\GitInfo\precomputeValues().

◆ getHeadSHA1()

MediaWiki\Utils\GitInfo::getHeadSHA1 ( )

Get the SHA1 for the current HEAD of the repo.

Returns
string|false A SHA1 or false

Definition at line 222 of file GitInfo.php.

References $matches, and MediaWiki\Utils\GitInfo\getHead().

Referenced by MediaWiki\Utils\GitInfo\getHeadViewUrl(), and MediaWiki\Utils\GitInfo\precomputeValues().

◆ getHeadViewUrl()

MediaWiki\Utils\GitInfo::getHeadViewUrl ( )

Get an URL to a web viewer link to the HEAD revision.

Returns
string|false String if a URL is available or false otherwise

Definition at line 314 of file GitInfo.php.

References $matches, MediaWiki\Utils\GitInfo\$repo, MediaWiki\Utils\GitInfo\getHeadSHA1(), and MediaWiki\Utils\GitInfo\getRemoteUrl().

◆ getRemoteUrl()

MediaWiki\Utils\GitInfo::getRemoteUrl ( )
protected

Get the URL of the remote origin.

Returns
string|false String if a URL is available or false otherwise.

Definition at line 340 of file GitInfo.php.

Referenced by MediaWiki\Utils\GitInfo\getHeadViewUrl(), and MediaWiki\Utils\GitInfo\precomputeValues().

◆ headSHA1()

static MediaWiki\Utils\GitInfo::headSHA1 ( )
static
See also
self::getHeadSHA1
Returns
string

Definition at line 426 of file GitInfo.php.

References MediaWiki\Utils\GitInfo\repo().

◆ headViewUrl()

static MediaWiki\Utils\GitInfo::headViewUrl ( )
static
See also
self::getHeadViewUrl()
Returns
string|false

Definition at line 442 of file GitInfo.php.

References MediaWiki\Utils\GitInfo\repo().

◆ isSHA1()

static MediaWiki\Utils\GitInfo::isSHA1 (   $str)
static

Check if a string looks like a hex encoded SHA1 hash.

Parameters
string$strThe string to check
Returns
bool Whether or not the string looks like a SHA1

Definition at line 189 of file GitInfo.php.

◆ precomputeValues()

MediaWiki\Utils\GitInfo::precomputeValues ( )

Precompute and cache git information.

Creates a JSON file in the cache directory associated with this GitInfo instance. This cache file will be used by subsequent GitInfo objects referencing the same directory to avoid needing to examine the .git directory again.

Since
1.24

Definition at line 395 of file GitInfo.php.

References MediaWiki\Utils\GitInfo\cacheIsComplete(), MediaWiki\Utils\GitInfo\getCurrentBranch(), MediaWiki\Utils\GitInfo\getHead(), MediaWiki\Utils\GitInfo\getHeadCommitDate(), MediaWiki\Utils\GitInfo\getHeadSHA1(), MediaWiki\Utils\GitInfo\getRemoteUrl(), and wfMkdirParents().

◆ repo()

static MediaWiki\Utils\GitInfo::repo ( )
static

Get the singleton for the repo at MW_INSTALL_PATH.

Returns
GitInfo

Definition at line 176 of file GitInfo.php.

References MediaWiki\Utils\GitInfo\$repo.

Referenced by MediaWiki\Utils\GitInfo\currentBranch(), MediaWiki\Utils\GitInfo\headSHA1(), and MediaWiki\Utils\GitInfo\headViewUrl().

Member Data Documentation

◆ $basedir

MediaWiki\Utils\GitInfo::$basedir
protected

Definition at line 53 of file GitInfo.php.

◆ $cache

MediaWiki\Utils\GitInfo::$cache = []
protected

Definition at line 62 of file GitInfo.php.

◆ $cacheFile

MediaWiki\Utils\GitInfo::$cacheFile
protected

Definition at line 59 of file GitInfo.php.

◆ $repo

MediaWiki\Utils\GitInfo::$repo = null
staticprotected

Singleton for the repo at $IP.

Definition at line 50 of file GitInfo.php.

Referenced by MediaWiki\Utils\GitInfo\getHeadViewUrl(), and MediaWiki\Utils\GitInfo\repo().

◆ $repoDir

MediaWiki\Utils\GitInfo::$repoDir
protected

Definition at line 56 of file GitInfo.php.

Referenced by MediaWiki\Utils\GitInfo\__construct().


The documentation for this class was generated from the following file: