Exemplo n.º 1
0
 public function testListDir()
 {
     $datadir = dirname(__FILE__) . '/resources/testdir';
     $listed = GitPHP_Util::ListDir($datadir);
     $this->assertCount(5, $listed);
     $expected = array($datadir . '/.hiddentestfile', $datadir . '/testfile1.txt', $datadir . '/testdir2/testfile2.txt', $datadir . '/testdir2/testdir4/testfile4.txt', $datadir . '/testdir3/testfile3.txt');
     $this->assertCount(0, array_diff($listed, $expected));
     $this->assertCount(0, array_diff($expected, $listed));
 }
Exemplo n.º 2
0
 /**
  * Loads the ref list for a ref type
  *
  * @param GitPHP_RefList $refList ref list
  * @param string $type ref type
  * @return array array of refs
  */
 protected function GetRefs(GitPHP_RefList $refList, $type)
 {
     if (!$refList) {
         return;
     }
     if (empty($type)) {
         return;
     }
     if (GitPHP_DebugLog::GetInstance()->GetEnabled()) {
         $autotimer = new GitPHP_DebugAutoLog();
     }
     $refs = array();
     $prefix = 'refs/' . $type;
     $fullPath = $refList->GetProject()->GetPath() . '/' . $prefix;
     $fullPathLen = strlen($fullPath) + 1;
     /* loose files */
     $refFiles = GitPHP_Util::ListDir($fullPath);
     for ($i = 0; $i < count($refFiles); ++$i) {
         $ref = substr($refFiles[$i], $fullPathLen);
         if (empty($ref) || isset($refs[$ref])) {
             continue;
         }
         $hash = trim(file_get_contents($refFiles[$i]));
         if (preg_match('/^[0-9A-Fa-f]{40}$/', $hash)) {
             $refs[$ref] = $hash;
         }
     }
     /* packed refs */
     if (file_exists($refList->GetProject()->GetPath() . '/packed-refs')) {
         $packedRefs = explode("\n", file_get_contents($refList->GetProject()->GetPath() . '/packed-refs'));
         foreach ($packedRefs as $ref) {
             if (preg_match('/^([0-9A-Fa-f]{40}) refs\\/' . $type . '\\/(.+)$/', $ref, $regs)) {
                 if (!isset($refs[$regs[2]])) {
                     $refs[$regs[2]] = $regs[1];
                 }
             }
         }
     }
     return $refs;
 }
Exemplo n.º 3
0
 /**
  * Recurses into a directory and lists files inside
  *
  * @param string $dir directory
  * @return string[] array of filenames
  */
 public static function ListDir($dir)
 {
     $files = array();
     if ($dh = opendir($dir)) {
         while (($file = readdir($dh)) !== false) {
             if ($file == '.' || $file == '..') {
                 continue;
             }
             $fullFile = $dir . '/' . $file;
             if (is_dir($fullFile)) {
                 $subFiles = GitPHP_Util::ListDir($fullFile);
                 if (count($subFiles) > 0) {
                     $files = array_merge($files, $subFiles);
                 }
             } else {
                 $files[] = $fullFile;
             }
         }
     }
     return $files;
 }