Esempio n. 1
0
 /**
  * Gets a tree
  *
  * @param string $hash tree hash
  * @return GitPHP_Tree tree object
  */
 public function GetTree($hash)
 {
     if (empty($hash)) {
         return null;
     }
     if (preg_match('/^[0-9A-Fa-f]{4,39}$/', $hash) && !$this->compat) {
         $fullHash = $this->project->ExpandHash($hash);
         if ($fullHash == $hash) {
             throw new GitPHP_InvalidHashException($hash);
         }
         $hash = $fullHash;
     }
     if (!preg_match('/^[0-9A-Fa-f]{40}$/', $hash)) {
         return null;
     }
     $key = GitPHP_Tree::CacheKey($this->project->GetProject(), $hash);
     $tree = null;
     if ($this->memoryCache) {
         $tree = $this->memoryCache->Get($key);
     }
     if (!$tree) {
         if ($this->cache) {
             $tree = $this->cache->Get($key);
         }
         $strategy = null;
         if ($this->compat) {
             $strategy = new GitPHP_TreeLoad_Git($this->exe);
         } else {
             $strategy = new GitPHP_TreeLoad_Raw($this->objectLoader, $this->exe);
         }
         if ($tree) {
             $tree->SetProject($this->project);
             $tree->SetStrategy($strategy);
         } else {
             $tree = new GitPHP_Tree($this->project, $hash, $strategy);
         }
         $tree->AddObserver($this);
         if ($this->memoryCache) {
             $this->memoryCache->Set($key, $tree);
         }
     }
     return $tree;
 }
Esempio n. 2
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'));
 }
Esempio n. 3
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;
 }