MediaWiki  1.28.0
GitInfo Class Reference

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

 getRemoteUrl ()
 Get the URL of the remote origin. More...
 

Static Protected Member Functions

static getCacheFilePath ($repoDir)
 Compute the path to the cache file for a given directory. More...
 
static getViewers ()
 Gets the list of repository viewers. More...
 

Protected Attributes

 $basedir
 Location of the .git directory. More...
 
 $cache = []
 Cached git information. More...
 
 $cacheFile
 Path to JSON cache file for pre-computed git information. More...
 

Static Protected Attributes

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

Static Private Attributes

static $viewers = false
 Map of repo URLs to viewer URLs. More...
 

Detailed Description

Definition at line 26 of file GitInfo.php.

Constructor & Destructor Documentation

GitInfo::__construct (   $repoDir,
  $usePrecomputed = true 
)
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 58 of file GitInfo.php.

References $path, cache, cacheIsComplete(), FormatJson\decode(), and wfDebugLog().

Member Function Documentation

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

References cache.

Referenced by __construct(), GitInfoTest\assertValidGitInfo(), and precomputeValues().

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

Definition at line 376 of file GitInfo.php.

Referenced by MWDebug\getDebugInfo().

static GitInfo::getCacheFilePath (   $repoDir)
staticprotected

Compute the path to the cache file for a given directory.

Parameters
string$repoDirThe root directory of the repo where .git can be found
Returns
string Path to GitInfo cache file in $wgGitInfoCacheDirectory or fallback in the extension directory itself
Since
1.24

Definition at line 102 of file GitInfo.php.

References $IP, $wgGitInfoCacheDirectory, and global.

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

References cache, and getHead().

Referenced by GitInfoTest\assertValidGitInfo(), and precomputeValues().

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

References cache.

Referenced by GitInfoTest\assertValidGitInfo(), getCurrentBranch(), getHeadCommitDate(), getHeadSHA1(), and precomputeValues().

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

References $basedir, cache, getHead(), global, wfEscapeShellArg(), and wfShellExec().

Referenced by GitInfoTest\assertValidGitInfo(), and precomputeValues().

GitInfo::getHeadSHA1 ( )

Get the SHA1 for the current HEAD of the repo.

Returns
string|bool A SHA1 or false

Definition at line 183 of file GitInfo.php.

References cache, and getHead().

Referenced by GitInfoTest\assertValidGitInfo(), getHeadViewUrl(), and precomputeValues().

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

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

Referenced by GitInfoTest\assertValidGitInfo().

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

References as, and cache.

Referenced by getHeadViewUrl(), and precomputeValues().

static GitInfo::getViewers ( )
staticprotected

Gets the list of repository viewers.

Returns
array

Definition at line 392 of file GitInfo.php.

References global, and Hooks\run().

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

Definition at line 368 of file GitInfo.php.

Referenced by MWDebug\getDebugInfo().

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

Definition at line 384 of file GitInfo.php.

Referenced by MWDebug\getDebugInfo().

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

Referenced by MWDebug\getDebugInfo().

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

References cache, cacheIsComplete(), FormatJson\encode(), getCurrentBranch(), getHead(), getHeadCommitDate(), getHeadSHA1(), getRemoteUrl(), wfDebugLog(), and wfMkdirParents().

static GitInfo::repo ( )
static

Get the singleton for the repo at $IP.

Returns
GitInfo

Definition at line 136 of file GitInfo.php.

References $IP, and global.

Member Data Documentation

GitInfo::$basedir
protected

Location of the .git directory.

Definition at line 36 of file GitInfo.php.

Referenced by getHeadCommitDate().

GitInfo::$cache = []
protected

Cached git information.

Definition at line 46 of file GitInfo.php.

GitInfo::$cacheFile
protected

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

Definition at line 41 of file GitInfo.php.

GitInfo::$repo = null
staticprotected

Singleton for the repo at $IP.

Definition at line 31 of file GitInfo.php.

Referenced by getHeadViewUrl().

GitInfo::$viewers = false
staticprivate

Map of repo URLs to viewer URLs.

Access via static method getViewers().

Definition at line 51 of file GitInfo.php.


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