コード例 #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;
 }
コード例 #2
0
ファイル: FileDiff.class.php プロジェクト: fboender/gitphp
 /**
  * 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;
 }
コード例 #3
0
 /**
  * Applies global config settings to a project
  *
  * @param GitPHP_Project $project project
  */
 protected function ApplyGlobalConfig($project)
 {
     if (!$project) {
         return;
     }
     if (!$this->config) {
         return;
     }
     if ($this->config->GetValue('cloneurl')) {
         $project->SetCloneUrl(GitPHP_Util::AddSlash($this->config->GetValue('cloneurl'), false) . $project->GetProject());
     }
     if ($this->config->GetValue('pushurl')) {
         $project->SetPushUrl(GitPHP_Util::AddSlash($this->config->GetValue('pushurl'), false) . $project->GetProject());
     }
     if ($this->config->GetValue('bugpattern')) {
         $project->SetBugPattern($this->config->GetValue('bugpattern'));
     }
     if ($this->config->GetValue('bugurl')) {
         $project->SetBugUrl($this->config->GetValue('bugurl'));
     }
     if ($this->config->HasKey('compat')) {
         $project->SetCompat($this->config->GetValue('compat'));
     }
     if ($this->config->HasKey('uniqueabbrev')) {
         $project->SetUniqueAbbreviation($this->config->GetValue('uniqueabbrev'));
     }
     if ($this->config->GetValue('abbreviateurl')) {
         $project->SetUniqueAbbreviation(true);
     }
 }
コード例 #4
0
ファイル: Project.class.php プロジェクト: fboender/gitphp
 /**
  * Compares two projects by project name
  *
  * @param GitPHP_Project $a first project
  * @param GitPHP_Project $b second project
  * @return integer comparison result
  */
 public static function CompareProject($a, $b)
 {
     $catCmp = strcmp($a->GetCategory(), $b->GetCategory());
     if ($catCmp !== 0) {
         return $catCmp;
     }
     return strcmp($a->GetProject(), $b->GetProject());
 }
コード例 #5
0
ファイル: Router.class.php プロジェクト: fboender/gitphp
 /**
  * Gets a project identifier for a project
  *
  * @param string|GitPHP_Project $value string or project
  * @return string identifier
  */
 private static function GetProject($value)
 {
     if ($value instanceof GitPHP_Project) {
         return $value->GetProject();
     } else {
         if (is_string($value)) {
             return $value;
         }
     }
 }