Example #1
0
File: SVN.php Project: rsms/phpab
 /**
  * Register data to be cached at end of request/response-session
  *
  * @param  string
  * @param  mixed
  * @return void
  */
 public static function scheduleCacheWrite($k, &$v)
 {
     if (!self::$hasSchCacheTrig) {
         register_shutdown_function(array('SVN', 'finalize'));
         self::$hasSchCacheTrig = true;
     }
     self::$scheduledCacheWrites[$k] =& $v;
 }
 function canCheckout()
 {
     $errors = array();
     if (!SVN::available()) {
         $errors[] = "Subversion is not available.";
     }
     return $errors;
 }
Example #3
0
 /**
  * Read data from file
  *
  * @param  int     Specific revision. 0 = youngest
  * @param  bool    Disable memory-based cache
  * @return string  contents
  * @throws IOException
  */
 public function getContents($revision = 0, $noCache = false)
 {
     if (!$this->rep) {
         return null;
     }
     if (SVN::$apcEnabled && !$noCache) {
         $cKey = $this->rep->getCacheKey($this->getPath() . '-CONTENTS', $this->getRevision());
         # try load cache
         if (($dat = apc_fetch($cKey)) !== false) {
             #print 'cache hit';
             return $dat;
         }
         # load data
         $dat = $this->rep->look('cat', $this->getPath(), $revision ? "-r {$revision}" : '');
         # schedule cache write
         SVN::scheduleCacheWrite($cKey, $dat);
         return $dat;
     } else {
         return $this->rep->look('cat', $this->getPath(), $revision ? "-r {$revision}" : '');
     }
 }
Example #4
0
 /**
  * Get all files and directories in a directory for one level down
  *
  * The results of this method is cached using APC in memory.
  * 
  * @param  string
  * @param  int           Show files for a specific revision. 0 = newest revision
  * @param  bool
  * @return SVNDirectory  Returns null if the directory specified does not exist
  */
 public function getFiles($path = '/', $revision = 0, $noCache = false)
 {
     $path = rtrim($path, '/') . '/';
     # Load mem cached data
     if (SVN::$apcEnabled && !$noCache) {
         $apcKey = $this->getCacheKey($path, $revision);
         if (($root = apc_fetch($apcKey)) !== false) {
             #print 'cache hit';
             return $root;
         }
     }
     # Query
     $tree = trim(SVN::look("tree --full-paths --show-ids" . ($revision ? " -r {$revision}" : '') . " '" . $this->path . "' '{$path}'" . '|' . SVN::grepBin() . " -E '^" . str_replace(array('?', '+'), array('\\?', '\\+'), $path) . "[^/]+/? *<'"));
     if (!$tree) {
         return null;
     }
     # Generate data
     $tree = explode("\n", $tree);
     $len = count($tree);
     $root = null;
     for ($i = 0; $i < $len; $i++) {
         $rev = 0;
         $inode = 0;
         $line = self::parseTreeFileInfo($tree[$i], $rev, $inode);
         if (!$root) {
             $root = SVNDirectory::fromData($line, $rev, $inode, $this);
         } elseif (substr($line, -1) == '/') {
             $root->appendChild(SVNDirectory::fromData($line, $rev, $inode));
         } else {
             $root->appendChild(SVNFile::fromData($line, $rev, $inode));
         }
     }
     # Save cache at request/response-session end
     if (SVN::$apcEnabled && !$noCache) {
         SVN::scheduleCacheWrite($apcKey, $root);
     }
     return $root;
 }