Example #1
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;
 }
Example #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();
     $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;
 }
Example #3
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;
 }