X-Git-Url: http://git.cyclocoop.org/%22%20.%20%20%20%24self2%20.%20%20%20%22&var_mode_affiche=boucle?a=blobdiff_plain;f=includes%2FGitInfo.php;h=3c600ed984057918d3a7f8c2bb07af0797e8bcbc;hb=505e7ee4039c4448e69f2f522830fb2fbf9235c4;hp=29516ab7cd9494499823fc8293bee602396c569e;hpb=99340a1ea8e9a8041661eadb77291f5b1d0cd1cf;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/GitInfo.php b/includes/GitInfo.php index 29516ab7cd..3c600ed984 100644 --- a/includes/GitInfo.php +++ b/includes/GitInfo.php @@ -46,7 +46,7 @@ class GitInfo { protected $cache = []; /** - * Map of repo URLs to viewer URLs. Access via static method getViewers(). + * @var array|false Map of repo URLs to viewer URLs. Access via static method getViewers(). */ private static $viewers = false; @@ -191,8 +191,14 @@ class GitInfo { } else { // If not a SHA1 it may be a ref: $refFile = "{$this->basedir}/{$head}"; + $packedRefs = "{$this->basedir}/packed-refs"; + $headRegex = preg_quote( $head, '/' ); if ( is_readable( $refFile ) ) { $sha1 = rtrim( file_get_contents( $refFile ) ); + } elseif ( is_readable( $packedRefs ) && + preg_match( "/^([0-9A-Fa-f]{40}) $headRegex$/m", file_get_contents( $packedRefs ), $matches ) + ) { + $sha1 = $matches[1]; } } $this->cache['headSHA1'] = $sha1; @@ -257,9 +263,6 @@ class GitInfo { if ( $url === false ) { return false; } - if ( substr( $url, -4 ) !== '.git' ) { - $url .= '.git'; - } foreach ( self::getViewers() as $repo => $viewer ) { $pattern = '#^' . $repo . '$#'; if ( preg_match( $pattern, $url, $matches ) ) { @@ -269,6 +272,7 @@ class GitInfo { '%h' => substr( $headSHA1, 0, 7 ), '%H' => $headSHA1, '%r' => urlencode( $matches[1] ), + '%R' => $matches[1], ]; return strtr( $viewerUrl, $replacements ); }