Added a cache layer to cache the execution of the scm commands.
This commit is contained in:
parent
c113c11da5
commit
adb5de13e2
@ -40,5 +40,43 @@ class IDF_Scm
|
|||||||
return call_user_func(array($scms[$scm], 'factory'),
|
return call_user_func(array($scms[$scm], 'factory'),
|
||||||
$request->project);
|
$request->project);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Equivalent to exec but with caching.
|
||||||
|
*
|
||||||
|
* @param string Command
|
||||||
|
* @param &array Output
|
||||||
|
* @param &int Return value
|
||||||
|
* @return string Last line of the output
|
||||||
|
*/
|
||||||
|
public static function exec($command, &$output=array(), &$return=0)
|
||||||
|
{
|
||||||
|
$key = md5($command);
|
||||||
|
$cache = Pluf_Cache::factory();
|
||||||
|
if (null === ($res=$cache->get($key))) {
|
||||||
|
$ll = exec($command, $output, $return);
|
||||||
|
$cache->set($key, array($ll, $return, $output));
|
||||||
|
} else {
|
||||||
|
list($ll, $return, $output) = $res;
|
||||||
|
}
|
||||||
|
return $ll;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Equivalent to shell_exec but with caching.
|
||||||
|
*
|
||||||
|
* @param string Command
|
||||||
|
* @return string Output of the command
|
||||||
|
*/
|
||||||
|
public static function shell_exec($command)
|
||||||
|
{
|
||||||
|
$key = md5($command);
|
||||||
|
$cache = Pluf_Cache::factory();
|
||||||
|
if (null === ($res=$cache->get($key))) {
|
||||||
|
$res = shell_exec($command);
|
||||||
|
$cache->set($key, $res);
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ class IDF_Scm_Git
|
|||||||
escapeshellarg($this->repo),
|
escapeshellarg($this->repo),
|
||||||
escapeshellarg($hash));
|
escapeshellarg($hash));
|
||||||
$ret = 0; $out = array();
|
$ret = 0; $out = array();
|
||||||
exec($cmd, &$out, &$ret);
|
IDF_Scm::exec($cmd, &$out, &$ret);
|
||||||
if ($ret != 0) return false;
|
if ($ret != 0) return false;
|
||||||
return trim($out[0]);
|
return trim($out[0]);
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ class IDF_Scm_Git
|
|||||||
$rawlog = array();
|
$rawlog = array();
|
||||||
$cmd = sprintf('GIT_DIR=%s git log --raw --abbrev=40 --pretty=oneline %s',
|
$cmd = sprintf('GIT_DIR=%s git log --raw --abbrev=40 --pretty=oneline %s',
|
||||||
escapeshellarg($this->repo), escapeshellarg($commit));
|
escapeshellarg($this->repo), escapeshellarg($commit));
|
||||||
exec($cmd, &$rawlog);
|
IDF_Scm::exec($cmd, &$rawlog);
|
||||||
// We reverse the log to be able to use a fixed efficient
|
// We reverse the log to be able to use a fixed efficient
|
||||||
// regex without back tracking.
|
// regex without back tracking.
|
||||||
$rawlog = implode("\n", array_reverse($rawlog));
|
$rawlog = implode("\n", array_reverse($rawlog));
|
||||||
@ -165,7 +165,7 @@ class IDF_Scm_Git
|
|||||||
escapeshellarg($tree));
|
escapeshellarg($tree));
|
||||||
$out = array();
|
$out = array();
|
||||||
$res = array();
|
$res = array();
|
||||||
exec($cmd, &$out);
|
IDF_Scm::exec($cmd, &$out);
|
||||||
foreach ($out as $line) {
|
foreach ($out as $line) {
|
||||||
list($perm, $type, $hash, $size, $file) = preg_split('/ |\t/', $line, 5, PREG_SPLIT_NO_EMPTY);
|
list($perm, $type, $hash, $size, $file) = preg_split('/ |\t/', $line, 5, PREG_SPLIT_NO_EMPTY);
|
||||||
$res[] = (object) array('perm' => $perm, 'type' => $type,
|
$res[] = (object) array('perm' => $perm, 'type' => $type,
|
||||||
@ -190,7 +190,7 @@ class IDF_Scm_Git
|
|||||||
escapeshellarg($this->repo),
|
escapeshellarg($this->repo),
|
||||||
escapeshellarg($commit));
|
escapeshellarg($commit));
|
||||||
$out = array();
|
$out = array();
|
||||||
exec($cmd, &$out);
|
IDF_Scm::exec($cmd, &$out);
|
||||||
foreach ($out as $line) {
|
foreach ($out as $line) {
|
||||||
list($perm, $type, $hash, $size, $file) = preg_split('/ |\t/', $line, 5, PREG_SPLIT_NO_EMPTY);
|
list($perm, $type, $hash, $size, $file) = preg_split('/ |\t/', $line, 5, PREG_SPLIT_NO_EMPTY);
|
||||||
if ($totest == $file) {
|
if ($totest == $file) {
|
||||||
@ -211,9 +211,9 @@ class IDF_Scm_Git
|
|||||||
*/
|
*/
|
||||||
public function getBlob($request_file_info, $dummy=null)
|
public function getBlob($request_file_info, $dummy=null)
|
||||||
{
|
{
|
||||||
return shell_exec(sprintf('GIT_DIR=%s git-cat-file blob %s',
|
return IDF_Scm::shell_exec(sprintf('GIT_DIR=%s git-cat-file blob %s',
|
||||||
escapeshellarg($this->repo),
|
escapeshellarg($this->repo),
|
||||||
escapeshellarg($request_file_info->hash)));
|
escapeshellarg($request_file_info->hash)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -224,8 +224,8 @@ class IDF_Scm_Git
|
|||||||
public function getBranches()
|
public function getBranches()
|
||||||
{
|
{
|
||||||
$out = array();
|
$out = array();
|
||||||
exec(sprintf('GIT_DIR=%s git branch',
|
IDF_Scm::exec(sprintf('GIT_DIR=%s git branch',
|
||||||
escapeshellarg($this->repo)), &$out);
|
escapeshellarg($this->repo)), &$out);
|
||||||
$res = array();
|
$res = array();
|
||||||
foreach ($out as $b) {
|
foreach ($out as $b) {
|
||||||
$res[] = substr($b, 2);
|
$res[] = substr($b, 2);
|
||||||
@ -246,7 +246,7 @@ class IDF_Scm_Git
|
|||||||
"'".$this->mediumtree_fmt."'",
|
"'".$this->mediumtree_fmt."'",
|
||||||
escapeshellarg($commit));
|
escapeshellarg($commit));
|
||||||
$out = array();
|
$out = array();
|
||||||
exec($cmd, &$out);
|
IDF_Scm::exec($cmd, &$out);
|
||||||
$log = array();
|
$log = array();
|
||||||
$change = array();
|
$change = array();
|
||||||
$inchange = false;
|
$inchange = false;
|
||||||
@ -281,7 +281,7 @@ class IDF_Scm_Git
|
|||||||
escapeshellarg($this->repo), $n, $this->mediumtree_fmt,
|
escapeshellarg($this->repo), $n, $this->mediumtree_fmt,
|
||||||
escapeshellarg($commit));
|
escapeshellarg($commit));
|
||||||
$out = array();
|
$out = array();
|
||||||
exec($cmd, &$out);
|
IDF_Scm::exec($cmd, &$out);
|
||||||
return self::parseLog($out, 4);
|
return self::parseLog($out, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ class IDF_Scm_Svn
|
|||||||
escapeshellarg($this->password),
|
escapeshellarg($this->password),
|
||||||
escapeshellarg($this->repo.'/'.$path),
|
escapeshellarg($this->repo.'/'.$path),
|
||||||
escapeshellarg($rev));
|
escapeshellarg($rev));
|
||||||
$xmlInfo = shell_exec($cmd);
|
$xmlInfo = IDF_Scm::shell_exec($cmd);
|
||||||
|
|
||||||
// If exception is thrown, return false
|
// If exception is thrown, return false
|
||||||
try {
|
try {
|
||||||
@ -142,7 +142,7 @@ class IDF_Scm_Svn
|
|||||||
escapeshellarg($this->password),
|
escapeshellarg($this->password),
|
||||||
escapeshellarg($this->repo.'/'.$folder),
|
escapeshellarg($this->repo.'/'.$folder),
|
||||||
escapeshellarg($rev));
|
escapeshellarg($rev));
|
||||||
$xmlLs = shell_exec($cmd);
|
$xmlLs = IDF_Scm::shell_exec($cmd);
|
||||||
$xml = simplexml_load_string($xmlLs);
|
$xml = simplexml_load_string($xmlLs);
|
||||||
$res = array();
|
$res = array();
|
||||||
foreach ($xml->list->entry as $entry) {
|
foreach ($xml->list->entry as $entry) {
|
||||||
@ -185,7 +185,7 @@ class IDF_Scm_Svn
|
|||||||
escapeshellarg($this->password),
|
escapeshellarg($this->password),
|
||||||
escapeshellarg($file),
|
escapeshellarg($file),
|
||||||
escapeshellarg($rev));
|
escapeshellarg($rev));
|
||||||
$xmlLog = shell_exec($cmd);
|
$xmlLog = IDF_Scm::shell_exec($cmd);
|
||||||
$xml = simplexml_load_string($xmlLog);
|
$xml = simplexml_load_string($xmlLog);
|
||||||
return (string) $xml->logentry->msg;
|
return (string) $xml->logentry->msg;
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ class IDF_Scm_Svn
|
|||||||
escapeshellarg($this->password),
|
escapeshellarg($this->password),
|
||||||
escapeshellarg($this->repo.'/'.$totest),
|
escapeshellarg($this->repo.'/'.$totest),
|
||||||
escapeshellarg($rev));
|
escapeshellarg($rev));
|
||||||
$xmlInfo = shell_exec($cmd);
|
$xmlInfo = IDF_Scm::shell_exec($cmd);
|
||||||
$xml = simplexml_load_string($xmlInfo);
|
$xml = simplexml_load_string($xmlInfo);
|
||||||
$entry = $xml->entry;
|
$entry = $xml->entry;
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ class IDF_Scm_Svn
|
|||||||
escapeshellarg($this->password),
|
escapeshellarg($this->password),
|
||||||
escapeshellarg($this->repo.'/'.$request_file_info->fullpath),
|
escapeshellarg($this->repo.'/'.$request_file_info->fullpath),
|
||||||
escapeshellarg($rev));
|
escapeshellarg($rev));
|
||||||
return shell_exec($cmd);
|
return IDF_Scm::shell_exec($cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ class IDF_Scm_Svn
|
|||||||
escapeshellarg($this->password),
|
escapeshellarg($this->password),
|
||||||
escapeshellarg($this->repo),
|
escapeshellarg($this->repo),
|
||||||
escapeshellarg($rev));
|
escapeshellarg($rev));
|
||||||
$xmlRes = shell_exec($cmd);
|
$xmlRes = IDF_Scm::shell_exec($cmd);
|
||||||
$xml = simplexml_load_string($xmlRes);
|
$xml = simplexml_load_string($xmlRes);
|
||||||
|
|
||||||
$res['author'] = (string) $xml->logentry->author;
|
$res['author'] = (string) $xml->logentry->author;
|
||||||
@ -289,7 +289,7 @@ class IDF_Scm_Svn
|
|||||||
escapeshellarg($this->username),
|
escapeshellarg($this->username),
|
||||||
escapeshellarg($this->password),
|
escapeshellarg($this->password),
|
||||||
escapeshellarg($this->repo));
|
escapeshellarg($this->repo));
|
||||||
return shell_exec($cmd);
|
return IDF_Scm::shell_exec($cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -310,7 +310,7 @@ class IDF_Scm_Svn
|
|||||||
escapeshellarg($this->password),
|
escapeshellarg($this->password),
|
||||||
escapeshellarg($this->repo),
|
escapeshellarg($this->repo),
|
||||||
escapeshellarg($rev));
|
escapeshellarg($rev));
|
||||||
$xmlRes = shell_exec($cmd);
|
$xmlRes = IDF_Scm::shell_exec($cmd);
|
||||||
$xml = simplexml_load_string($xmlRes);
|
$xml = simplexml_load_string($xmlRes);
|
||||||
|
|
||||||
$res = array();
|
$res = array();
|
||||||
@ -358,7 +358,7 @@ class IDF_Scm_Svn
|
|||||||
escapeshellarg($this->password),
|
escapeshellarg($this->password),
|
||||||
escapeshellarg($this->repo.'/'.$path),
|
escapeshellarg($this->repo.'/'.$path),
|
||||||
escapeshellarg($rev));
|
escapeshellarg($rev));
|
||||||
$xmlProps = shell_exec($cmd);
|
$xmlProps = IDF_Scm::shell_exec($cmd);
|
||||||
$props = simplexml_load_string($xmlProps);
|
$props = simplexml_load_string($xmlProps);
|
||||||
|
|
||||||
// No properties, returns an empty array
|
// No properties, returns an empty array
|
||||||
@ -393,7 +393,7 @@ class IDF_Scm_Svn
|
|||||||
escapeshellarg($this->password),
|
escapeshellarg($this->password),
|
||||||
escapeshellarg($this->repo.'/'.$path),
|
escapeshellarg($this->repo.'/'.$path),
|
||||||
escapeshellarg($rev));
|
escapeshellarg($rev));
|
||||||
$xmlProp = shell_exec($cmd);
|
$xmlProp = IDF_Scm::shell_exec($cmd);
|
||||||
$prop = simplexml_load_string($xmlProp);
|
$prop = simplexml_load_string($xmlProp);
|
||||||
|
|
||||||
return (string) $prop->target->property;
|
return (string) $prop->target->property;
|
||||||
@ -415,7 +415,7 @@ class IDF_Scm_Svn
|
|||||||
escapeshellarg($this->password),
|
escapeshellarg($this->password),
|
||||||
escapeshellarg($this->repo),
|
escapeshellarg($this->repo),
|
||||||
escapeshellarg($rev));
|
escapeshellarg($rev));
|
||||||
$xmlInfo = shell_exec($cmd);
|
$xmlInfo = IDF_Scm::shell_exec($cmd);
|
||||||
|
|
||||||
$xml = simplexml_load_string($xmlInfo);
|
$xml = simplexml_load_string($xmlInfo);
|
||||||
return (string) $xml->entry->commit['revision'];
|
return (string) $xml->entry->commit['revision'];
|
||||||
|
Loading…
Reference in New Issue
Block a user