Skip to content
Snippets Groups Projects
Commit 9010b20b authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch 'task-1797-revision-wrongly-caches' into 'master'

Task 1797 revision wrongly caches

See merge request !77
parents 68cef2c7 35639ecd
No related branches found
No related tags found
No related merge requests found
......@@ -1255,7 +1255,7 @@ class project extends base {
* @return array
*/
public function getRepoRevision($bRefresh = false) {
$this->log(__FUNCTION__ . " start");
$this->log(__FUNCTION__ . "($bRefresh) start");
if (!$this->_aPrjConfig["build"]["type"]) {
$this->_aData["phases"]["source"] = array("error" => t("class-project-error-repo-type-not-set"),);
......
<?php
require_once("vcs.interface.php");
require_once 'cache.class.php';
/**
* version control system :: GIT
......@@ -184,7 +185,6 @@ class vcs implements iVcs {
*/
public function cleanupCache($iAge) {
$this->log(__FUNCTION__." start");
require_once 'cache.class.php';
$oCache = new AhCache($this->_getNameOfCacheModule());
ob_start();
$oCache->cleanup((int)$iAge);
......@@ -193,6 +193,18 @@ class vcs implements iVcs {
return $sOut;
}
/**
* helper: cache hash with all branches
* @return boolean
*/
private function _cacheRemoteBranches() {
$iTtl=300;
$oCache = new AhCache($this->_getNameOfCacheModule(), "RemoteBranches");
// $this->log(__FUNCTION__." <pre>".print_r($this->_aRemoteBranches, 1)."</pre>");
$oCache->write($this->_aRemoteBranches, $iTtl);
return true;
}
/**
* read remote repository and get an array with names and revisions of
* all branches and tags
......@@ -208,8 +220,6 @@ class vcs implements iVcs {
return false;
}
$iTtl = 300; // cache for 5 min
require_once 'cache.class.php';
$oCache = new AhCache($this->_getNameOfCacheModule(), "RemoteBranches");
$aOutput=false;
$iRc=false;
......@@ -233,20 +243,32 @@ class vcs implements iVcs {
// use cache that getCommitmessageByBranch can access it
$this->_aRemoteBranches = $oCache->read();
$this->log(__FUNCTION__ . ' data from cache: <pre>'.print_r($this->_aRemoteBranches, 1).'</pre>');
/**
* $aOutput = Array
* (
* [0] => cd7b238a75fe3df3f53ca3c258078d6736cc5bec refs/heads/foreman-integration
* [1] => 68cef2c74b58db8e13413c1c54104e060d8ffbb3 refs/heads/master
* [2] => cae3a1eaee180b05fff883d1cfb36d09778dec2c refs/heads/task-1726-gitssh-extensions
* )
*/
foreach ($aOutput as $sBranchLine) {
$this->log(__FUNCTION__ . ' loop over output of git ls-remote <pre>'.print_r($sBranchLine, 1).'</pre>');
$aTmp = explode("\t", $sBranchLine);
$aBranch = explode("/", $aTmp[1]);
$sBranch = array_pop($aBranch);
$sRevision = $aTmp[0];
$sBranch = array_pop($aBranch); // remove "refs"
// skip dereferences
// http://stackoverflow.com/questions/15472107/when-listing-git-ls-remote-why-theres-after-the-tag-name
if (!preg_match('/\^\{\}$/', $sBranch)) {
$sRevision = $aTmp[0];
$sType = array_pop($aBranch);
$sName = ($sType == "heads") ? "origin/" . $sBranch : $sBranch;
$sBranchKey = $sName;
$this->log(__FUNCTION__ . ' $sBranchKey = '.$sBranchKey);
$sMessage = $this->getCommitmessageByBranch($sName, $sRevision);
$aReturn[$sBranchKey] = array(
......@@ -260,7 +282,7 @@ class vcs implements iVcs {
}
}
$this->_aRemoteBranches = $aReturn;
$oCache->write($aReturn, $iTtl);
$this->_cacheRemoteBranches();
}
} else {
$this->_aRemoteBranches = $oCache->read();
......@@ -335,6 +357,14 @@ class vcs implements iVcs {
} else {
$a = $this->getRevision(false);
}
// merge with cached info ... to add type and label
if(isset($this->_aRemoteBranches[$a['branch']])){
$this->_aRemoteBranches[$a['branch']]=array_merge($this->_aRemoteBranches[$a['branch']], $a);
} else {
$this->_aRemoteBranches[$a['branch']]=$a;
}
// store in cache
$this->_cacheRemoteBranches();
return $a['message'];
}
......@@ -427,7 +457,7 @@ class vcs implements iVcs {
$aReturn = array(
"branch" => $this->_sCurrentBranch,
"revision" => $sRevision,
"message" => $sCommitMsg
"message" => $sCommitMsg // ."\n". microtime(true),
);
} else {
if (!$sLoginfo) {
......@@ -438,6 +468,7 @@ class vcs implements iVcs {
"error" => '<pre>' . $sLoginfo . '<hr>' . $sGitCmd . '</pre>'
);
}
// $this->log(__FUNCTION__ . ' return is <pre>'.print_r($aReturn, 1).'</pre>');
return $aReturn;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment