MediaWiki REL1_39
GitInfo Class Reference

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
 Location of the .git directory.
 
 $cache = []
 Cached git information.
 
 $cacheFile
 Path to JSON cache file for pre-computed git information.
 
 $repoDir
 Location of the repository.
 

Static Protected Attributes

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

Detailed Description

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 40 of file GitInfo.php.

Constructor & Destructor Documentation

◆ __construct()

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 96 of file GitInfo.php.

References $path, $repoDir, and cacheIsComplete().

Member Function Documentation

◆ cacheIsComplete()

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 388 of file GitInfo.php.

Referenced by __construct(), and precomputeValues().

◆ currentBranch()

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

Definition at line 444 of file GitInfo.php.

References repo().

Referenced by MWDebug\getDebugInfo().

◆ getCurrentBranch()

GitInfo::getCurrentBranch ( )

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

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

Definition at line 305 of file GitInfo.php.

References getHead().

Referenced by precomputeValues().

◆ getHead()

GitInfo::getHead ( )

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

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

Definition at line 208 of file GitInfo.php.

Referenced by getCurrentBranch(), getHeadCommitDate(), getHeadSHA1(), and precomputeValues().

◆ getHeadCommitDate()

GitInfo::getHeadCommitDate ( )

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

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

Definition at line 264 of file GitInfo.php.

References getHead().

Referenced by precomputeValues().

◆ getHeadSHA1()

GitInfo::getHeadSHA1 ( )

Get the SHA1 for the current HEAD of the repo.

Returns
string|bool A SHA1 or false

Definition at line 232 of file GitInfo.php.

References $matches, and getHead().

Referenced by getHeadViewUrl(), and precomputeValues().

◆ getHeadViewUrl()

GitInfo::getHeadViewUrl ( )

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

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

Definition at line 323 of file GitInfo.php.

References $matches, $repo, getHeadSHA1(), and getRemoteUrl().

◆ getRemoteUrl()

GitInfo::getRemoteUrl ( )
protected

Get the URL of the remote origin.

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

Definition at line 349 of file GitInfo.php.

Referenced by getHeadViewUrl(), and precomputeValues().

◆ headSHA1()

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

Definition at line 436 of file GitInfo.php.

References repo().

Referenced by MWDebug\getDebugInfo().

◆ headViewUrl()

static GitInfo::headViewUrl ( )
static
See also
self::getHeadViewUrl()
Returns
bool|string

Definition at line 452 of file GitInfo.php.

References repo().

Referenced by MWDebug\getDebugInfo().

◆ isSHA1()

static 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 199 of file GitInfo.php.

Referenced by MWDebug\getDebugInfo().

◆ precomputeValues()

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 405 of file GitInfo.php.

References cacheIsComplete(), getCurrentBranch(), getHead(), getHeadCommitDate(), getHeadSHA1(), getRemoteUrl(), and wfMkdirParents().

◆ repo()

static GitInfo::repo ( )
static

Get the singleton for the repo at MW_INSTALL_PATH.

Returns
GitInfo

Definition at line 186 of file GitInfo.php.

References $repo.

Referenced by currentBranch(), headSHA1(), and headViewUrl().

Member Data Documentation

◆ $basedir

GitInfo::$basedir
protected

Location of the .git directory.

Definition at line 50 of file GitInfo.php.

◆ $cache

GitInfo::$cache = []
protected

Cached git information.

Definition at line 65 of file GitInfo.php.

◆ $cacheFile

GitInfo::$cacheFile
protected

Path to JSON cache file for pre-computed git information.

Definition at line 60 of file GitInfo.php.

◆ $repo

GitInfo::$repo = null
staticprotected

Singleton for the repo at $IP.

Definition at line 45 of file GitInfo.php.

Referenced by getHeadViewUrl(), and repo().

◆ $repoDir

GitInfo::$repoDir
protected

Location of the repository.

Definition at line 55 of file GitInfo.php.

Referenced by __construct().


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