Esempio n. 1
0
 /**
  * Gets the hash paths for a tree
  *
  * @param GitPHP_Tree $tree tre
  * @return array array of treepath and hashpath arrays
  */
 public function LoadHashPaths($tree)
 {
     if (!$tree) {
         return;
     }
     $treePaths = array();
     $blobPaths = array();
     $args = array();
     $args[] = '--full-name';
     $args[] = '-r';
     $args[] = '-t';
     $args[] = $tree->GetHash();
     $lines = explode("\n", $this->exe->Execute($tree->GetProject()->GetPath(), GIT_LS_TREE, $args));
     foreach ($lines as $line) {
         if (preg_match("/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)\$/", $line, $regs)) {
             switch ($regs[2]) {
                 case 'tree':
                     $treePaths[trim($regs[4])] = $regs[3];
                     break;
                 case 'blob':
                     $blobPaths[trim($regs[4])] = $regs[3];
                     break;
             }
         }
     }
     return array($treePaths, $blobPaths);
 }
Esempio n. 2
0
 /**
  * Gets the data for a tree
  *
  * @param GitPHP_Tree $tree tree
  * @return array array of tree contents
  */
 public function Load($tree)
 {
     if (!$tree) {
         return;
     }
     $contents = array();
     $treePath = $tree->GetPath();
     $args = array();
     $args[] = '--full-name';
     if ($this->exe->CanShowSizeInTree()) {
         $args[] = '-l';
     }
     $args[] = '-t';
     $args[] = $tree->GetHash();
     $lines = explode("\n", $this->exe->Execute($tree->GetProject()->GetPath(), GIT_LS_TREE, $args));
     foreach ($lines as $line) {
         if (preg_match("/^([0-9]+) (.+) ([0-9a-fA-F]{40})(\\s+[0-9]+|\\s+-)?\t(.+)\$/", $line, $regs)) {
             switch ($regs[2]) {
                 case 'tree':
                     $data = array();
                     $data['type'] = 'tree';
                     $data['hash'] = $regs[3];
                     $data['mode'] = $regs[1];
                     $path = $regs[5];
                     if (!empty($treePath)) {
                         $path = $treePath . '/' . $path;
                     }
                     $data['path'] = $path;
                     $contents[] = $data;
                     break;
                 case 'blob':
                     $data = array();
                     $data['type'] = 'blob';
                     $data['hash'] = $regs[3];
                     $data['mode'] = $regs[1];
                     $path = $regs[5];
                     if (!empty($treePath)) {
                         $path = $treePath . '/' . $path;
                     }
                     $data['path'] = $path;
                     $size = trim($regs[4]);
                     if (!empty($size)) {
                         $data['size'] = $size;
                     }
                     $contents[] = $data;
                     break;
             }
         }
     }
     return $contents;
 }
Esempio n. 3
0
 /**
  * Gets the data for a tree
  *
  * @param GitPHP_Tree $tree tree
  * @return array array of tree contents
  */
 public function Load($tree)
 {
     if (!$tree) {
         return;
     }
     $contents = array();
     $treePath = $tree->GetPath();
     $treeData = $this->objectLoader->GetObject($tree->GetHash());
     $start = 0;
     $len = strlen($treeData);
     while ($start < $len) {
         $pos = strpos($treeData, "", $start);
         list($mode, $path) = explode(' ', substr($treeData, $start, $pos - $start), 2);
         $mode = str_pad($mode, 6, '0', STR_PAD_LEFT);
         $hash = bin2hex(substr($treeData, $pos + 1, 20));
         $start = $pos + 21;
         $octmode = octdec($mode);
         if ($octmode == 57344) {
             // submodules not currently supported
             continue;
         }
         if (!empty($treePath)) {
             $path = $treePath . '/' . $path;
         }
         $data = array();
         $data['hash'] = $hash;
         if ($octmode & 0x4000) {
             // tree
             $data['type'] = 'tree';
         } else {
             // blob
             $data['type'] = 'blob';
         }
         $data['mode'] = $mode;
         $data['path'] = $path;
         $contents[] = $data;
     }
     return $contents;
 }
Esempio n. 4
0
 /**
  * Sets the matching object
  *
  * @param GitPHP_Tree|GitPHP_Blob $object matching object
  */
 public function SetObject($object)
 {
     if ($object instanceof GitPHP_Tree) {
         $this->objectType = 'tree';
         $this->objectHash = $object->GetHash();
     } else {
         if ($object instanceof GitPHP_Blob) {
             $this->objectType = 'blob';
             $this->objectHash = $object->GetHash();
         } else {
             throw new Exception('Invalid file search result object');
         }
     }
 }
Esempio n. 5
0
 /**
  * Constructor
  *
  * @param GitPHP_Project $project project
  * @param GitPHP_Tree $tree tree to search
  * @param string $search string to search
  * @param GitPHP_GitExe $exe git executable
  * @param int $limit limit of results to return
  * @param int $skip number of results to skip
  */
 public function __construct($project, $tree, $search, $exe, $limit = 50, $skip = 0)
 {
     if (!$project) {
         throw new Exception('Project is required');
     }
     if (!$tree) {
         throw new Exception('Tree is required');
     }
     if (empty($search)) {
         throw new Exception('Search is required');
     }
     if (!$exe) {
         throw new Exception('Git exe is required');
     }
     $this->project = $project;
     $this->treeHash = $tree->GetHash();
     $this->treePath = $tree->GetPath();
     $this->search = $search;
     $this->exe = $exe;
     $this->limit = $limit;
     $this->skip = $skip;
 }
Esempio n. 6
0
 /**
  * Gets the cache key to use for this object
  *
  * @return string cache key
  */
 public function GetCacheKey()
 {
     return GitPHP_Tree::CacheKey($this->project->GetProject(), $this->hash);
 }
Esempio n. 7
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. 8
0
 /**
  * Sets the object for this archive
  *
  * @param GitPHP_Commit|GitPHP_Tree|null $object the git object
  */
 public function SetObject($object)
 {
     // Archive only works for commits and trees
     if ($object == null) {
         $this->objectHash = '';
         $this->objectType = '';
         return;
     }
     if ($object instanceof GitPHP_Commit) {
         $this->objectType = 'commit';
         $this->objectHash = $object->GetHash();
         return;
     }
     if ($object instanceof GitPHP_Tree) {
         $this->objectType = 'tree';
         $this->objectHash = $object->GetHash();
         return;
     }
     throw new Exception('Invalid source object for archive');
 }