From 99cee9e389d826af4f1ca1e2872fbf9e692c8246 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Fri, 21 Dec 2018 15:02:10 +0100 Subject: [PATCH] Fix #14635 - Git revision error See: #14762 Signed-off-by: William Desportes --- index.php | 2 ++ libraries/classes/Config.php | 23 +++++++++++++++++++---- libraries/classes/Display/GitRevision.php | 7 ++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index e80ceef4c8..2274e69122 100644 --- a/index.php +++ b/index.php @@ -134,10 +134,12 @@ if ($response->isAjax() && ! empty($_REQUEST['recent_table'])) { } if ($GLOBALS['PMA_Config']->isGitRevision()) { + // If ajax request to get revision if (isset($_REQUEST['git_revision']) && $response->isAjax()) { GitRevision::display(); exit; } + // Else show empty html echo '
'; } diff --git a/libraries/classes/Config.php b/libraries/classes/Config.php index 5cfea93261..8b6578fce2 100644 --- a/libraries/classes/Config.php +++ b/libraries/classes/Config.php @@ -363,18 +363,21 @@ class Config */ public function isGitRevision(&$git_location = NULL) { + // PMA config check if (! $this->get('ShowGitRevision')) { return false; } // caching - if (isset($_SESSION['is_git_revision'])) { - if ($_SESSION['is_git_revision']) { - $this->set('PMA_VERSION_GIT', 1); - } + if ( + isset($_SESSION['is_git_revision']) + && array_key_exists('git_location', $_SESSION) + ) { + // Define location using cached value $git_location = $_SESSION['git_location']; return $_SESSION['is_git_revision']; } + // find out if there is a .git folder // or a .git file (--separate-git-dir) $git = '.git'; @@ -382,6 +385,7 @@ class Config if (@is_file($git . '/config')) { $git_location = $git; } else { + $_SESSION['git_location'] = null; $_SESSION['is_git_revision'] = false; return false; } @@ -391,6 +395,7 @@ class Config // Matches expected format if (! preg_match('/^gitdir: (.*)$/', $contents, $gitmatch)) { + $_SESSION['git_location'] = null; $_SESSION['is_git_revision'] = false; return false; } else { @@ -398,14 +403,17 @@ class Config //Detected git external folder location $git_location = $gitmatch[1]; } else { + $_SESSION['git_location'] = null; $_SESSION['is_git_revision'] = false; return false; } } } else { + $_SESSION['git_location'] = null; $_SESSION['is_git_revision'] = false; return false; } + // Define session for caching $_SESSION['git_location'] = $git_location; $_SESSION['is_git_revision'] = true; return true; @@ -421,10 +429,12 @@ class Config // find out if there is a .git folder $git_folder = ''; if (! $this->isGitRevision($git_folder)) { + $this->set('PMA_VERSION_GIT', 0); return; } if (! $ref_head = @file_get_contents($git_folder . '/HEAD')) { + $this->set('PMA_VERSION_GIT', 0); return; } @@ -447,6 +457,7 @@ class Config if (@file_exists($ref_file)) { $hash = @file_get_contents($ref_file); if (! $hash) { + $this->set('PMA_VERSION_GIT', 0); return; } $hash = trim($hash); @@ -454,6 +465,7 @@ class Config // deal with packed refs $packed_refs = @file_get_contents($git_folder . '/packed-refs'); if (! $packed_refs) { + $this->set('PMA_VERSION_GIT', 0); return; } // split file to lines @@ -476,6 +488,7 @@ class Config } } if (! isset($hash)) { + $this->set('PMA_VERSION_GIT', 0); // Could not find ref return; } @@ -494,6 +507,7 @@ class Config . substr($hash, 0, 2) . '/' . substr($hash, 2); if (@file_exists($git_file_name) ) { if (! $commit = @file_get_contents($git_file_name)) { + $this->set('PMA_VERSION_GIT', 0); return; } $commit = explode("\0", gzuncompress($commit), 2); @@ -728,6 +742,7 @@ class Config 'date' => $commit_json->committer->date); $message = trim($commit_json->message); } else { + $this->set('PMA_VERSION_GIT', 0); return; } diff --git a/libraries/classes/Display/GitRevision.php b/libraries/classes/Display/GitRevision.php index 3de8c4e1f9..8b350e8caf 100644 --- a/libraries/classes/Display/GitRevision.php +++ b/libraries/classes/Display/GitRevision.php @@ -25,15 +25,16 @@ class GitRevision */ public static function display() { + + // load revision data from repo + $GLOBALS['PMA_Config']->checkGitRevision(); + if (! $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT')) { $response = Response::getInstance(); $response->setRequestStatus(false); return; } - // load revision data from repo - $GLOBALS['PMA_Config']->checkGitRevision(); - // if using a remote commit fast-forwarded, link to GitHub $commit_hash = substr( $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH'),