/**
  * PopulateProjects
  *
  * Populates the internal list of projects
  *
  * @access protected
  */
 protected function PopulateProjects()
 {
     // HACK workaround for strange behavior of CACHING_LIFETIME_SAVED in smarty 3
     $oldLifetime = GitPHP_Cache::GetObjectCacheInstance()->GetLifetime();
     GitPHP_Cache::GetObjectCacheInstance()->SetLifetime(GitPHP_Config::GetInstance()->GetValue('cachelifetime', 3600));
     $key = 'projectdir|' . $this->projectDir . '|projectlist|directory';
     $cached = GitPHP_Cache::GetObjectCacheInstance()->Get($key);
     if ($cached && count($cached) > 0) {
         foreach ($cached as $proj) {
             $this->AddProject($proj);
         }
         GitPHP_Log::GetInstance()->Log('Loaded ' . count($this->projects) . ' projects from cache');
         GitPHP_Cache::GetObjectCacheInstance()->SetLifetime($oldLifetime);
         return;
     }
     $this->RecurseDir($this->projectDir);
     if (count($this->projects) > 0) {
         $projects = array();
         foreach ($this->projects as $proj) {
             $projects[] = $proj->GetProject();
         }
         GitPHP_Cache::GetObjectCacheInstance()->Set($key, $projects, GitPHP_Config::GetInstance()->GetValue('cachelifetime', 3600));
     }
     GitPHP_Cache::GetObjectCacheInstance()->SetLifetime($oldLifetime);
 }
Beispiel #2
0
 /**
  * GetObjectCacheInstance
  *
  * Return the singleton instance of the object cache
  *
  * @access public
  * @static
  * @return mixed instance of cache class
  */
 public static function GetObjectCacheInstance()
 {
     if (!self::$objectCacheInstance) {
         self::$objectCacheInstance = new GitPHP_Cache();
         if (GitPHP_Config::GetInstance()->GetValue('objectcache', false)) {
             self::$objectCacheInstance->SetEnabled(true);
             self::$objectCacheInstance->SetLifetime(GitPHP_Config::GetInstance()->GetValue('objectcachelifetime', 86400));
         }
     }
     return self::$objectCacheInstance;
 }
 /**
  * Notify that observable object changed
  *
  * @param GitPHP_Observable_Interface $object object
  * @param int $changeType type of change
  * @param array $args argument array
  */
 public function ObjectChanged($object, $changeType, $args = array())
 {
     if (!$object) {
         return;
     }
     if ($changeType !== GitPHP_Observer_Interface::CacheableDataChange) {
         return;
     }
     if (!$this->cache) {
         return;
     }
     if (!($object instanceof GitPHP_Observable_Interface && $object instanceof GitPHP_Cacheable_Interface)) {
         return;
     }
     $this->cache->Set($object->GetCacheKey(), $object);
 }
Beispiel #4
0
 /**
  * GetTree
  *
  * Gets a tree from this project
  *
  * @access public
  * @param string $hash tree hash
  */
 public function GetTree($hash)
 {
     if (empty($hash)) {
         return null;
     }
     $cacheKey = 'project|' . $this->project . '|tree|' . $hash;
     $cached = GitPHP_Cache::GetObjectCacheInstance()->Get($cacheKey);
     if ($cached) {
         return $cached;
     }
     return new GitPHP_Tree($this, $hash);
 }
Beispiel #5
0
 /**
  * ReadContents
  *
  * Reads the tree contents
  *
  * @access protected
  */
 protected function ReadContents()
 {
     $this->contentsRead = true;
     if ($this->GetProject()->GetCompat()) {
         $this->ReadContentsGit();
     } else {
         $this->ReadContentsRaw();
     }
     GitPHP_Cache::GetObjectCacheInstance()->Set($this->GetCacheKey(), $this);
 }
Beispiel #6
0
 public function testMemcachedLifetime()
 {
     if (!class_exists('Memcached')) {
         $this->markTestSkipped();
         return;
     }
     $cache = new GitPHP_Cache(new GitPHP_Cache_Memcached(array(array('127.0.0.1', 11211))));
     $cache->Clear();
     $cache->Set('testkey1|testkey2', 'testvalue1', 1);
     sleep(2);
     $this->assertFalse($cache->Exists('testkey1|testkey2'));
     $cache->SetLifetime(1);
     $cache->Set('testkey3|testkey4', 'testvalue2');
     sleep(2);
     $this->assertFalse($cache->Get('testkey3|testkey4'));
 }
Beispiel #7
0
 /**
  * ReadCommit
  *
  * Attempts to dereference the commit for this tag
  *
  * @access private
  */
 private function ReadCommit()
 {
     $exe = new GitPHP_GitExe($this->GetProject());
     $args = array();
     $args[] = '--tags';
     $args[] = '--dereference';
     $args[] = $this->refName;
     $ret = $exe->Execute(GIT_SHOW_REF, $args);
     unset($exe);
     $lines = explode("\n", $ret);
     foreach ($lines as $line) {
         if (preg_match('/^([0-9a-fA-F]{40}) refs\\/tags\\/' . preg_quote($this->refName) . '(\\^{})$/', $line, $regs)) {
             $this->commit = $this->GetProject()->GetCommit($regs[1]);
             return;
         }
     }
     GitPHP_Cache::GetObjectCacheInstance()->Set($this->GetCacheKey(), $this);
 }
Beispiel #8
0
 /**
  * ReadHashPaths
  *
  * Read hash to path mappings
  *
  * @access private
  */
 private function ReadHashPaths()
 {
     $this->hashPathsRead = true;
     if ($this->GetProject()->GetCompat()) {
         $this->ReadHashPathsGit();
     } else {
         $this->ReadHashPathsRaw($this->GetTree());
     }
     GitPHP_Cache::GetObjectCacheInstance()->Set($this->GetCacheKey(), $this);
 }
Beispiel #9
0
 /**
  * Get diff data
  *
  * @param integer $context number of context lines
  * @param boolean $header true to include file header
  * @param string $file override file name
  * @return string diff data
  */
 private function GetDiffData($context = 3, $header = true, $file = null)
 {
     $fromData = '';
     $toData = '';
     if (empty($this->status) || $this->status == 'M' || $this->status == 'D') {
         $fromBlob = $this->GetFromBlob();
         $fromData = $fromBlob->GetData(false);
     }
     if (empty($this->status) || $this->status == 'M' || $this->status == 'A') {
         $toBlob = $this->GetToBlob();
         $toData = $toBlob->GetData(false);
     }
     $output = '';
     if ($header) {
         $output = '--- ' . $this->GetFromLabel($file) . "\n" . '+++ ' . $this->GetToLabel($file) . "\n";
     }
     $diffOutput = false;
     $cacheKey = null;
     if ($this->cache) {
         $cacheKey = 'project|' . $this->project->GetProject() . '|diff|' . $context . '|' . $this->fromHash . '|' . $this->toHash;
         $diffOutput = $this->cache->Get($cacheKey);
     }
     if ($diffOutput === false) {
         if ($this->UseXDiff()) {
             $diffOutput = $this->GetXDiff($fromData, $toData, $context);
         } else {
             $diffOutput = $this->GetPhpDiff($fromData, $toData, $context);
         }
         if ($this->cache) {
             $this->cache->Set($cacheKey, $diffOutput);
         }
     }
     $output .= $diffOutput;
     return $output;
 }
Beispiel #10
0
 /**
  * ReadData
  *
  * Reads the blob data
  *
  * @access private
  */
 private function ReadData()
 {
     $this->dataRead = true;
     if ($this->GetProject()->GetCompat()) {
         $exe = new GitPHP_GitExe($this->GetProject());
         $args = array();
         $args[] = 'blob';
         $args[] = $this->hash;
         $this->data = $exe->Execute(GIT_CAT_FILE, $args);
     } else {
         $this->data = $this->GetProject()->GetObject($this->hash);
     }
     GitPHP_Cache::GetObjectCacheInstance()->Set($this->GetCacheKey(), $this);
 }
 /**
  * Initialize project list
  */
 protected function InitializeProjectList()
 {
     if (file_exists(GITPHP_CONFIGDIR . 'projects.conf.php')) {
         $this->projectList = GitPHP_ProjectList::Instantiate($this->config, GITPHP_CONFIGDIR . 'projects.conf.php', false);
     } else {
         $this->projectList = GitPHP_ProjectList::Instantiate($this->config, GITPHP_CONFIGDIR . 'gitphp.conf.php', true);
     }
     $this->projectList->SetMemoryCache(new GitPHP_MemoryCache($this->config->GetValue('objectmemory')));
     if ($this->config->GetValue('objectcache')) {
         $strategy = null;
         $servers = $this->config->GetValue('memcache');
         if ($servers) {
             if (class_exists('Memcached')) {
                 $strategy = new GitPHP_Cache_Memcached($servers);
             } else {
                 if (class_exists('Memcache')) {
                     $strategy = new GitPHP_Cache_Memcache($servers);
                 } else {
                     throw new GitPHP_MissingMemcacheException();
                 }
             }
         } else {
             $strategy = new GitPHP_Cache_File(GITPHP_CACHEDIR . 'objects', $this->config->GetValue('objectcachecompress'));
         }
         $cache = new GitPHP_Cache($strategy);
         $cache->SetLifetime($this->config->GetValue('objectcachelifetime'));
         $this->projectList->SetCache($cache);
     }
     $this->projectList->SetExe($this->exe);
     if ($this->log) {
         $this->projectList->AddObserver($this->log);
     }
 }