/** * 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}" : ''); } }
/** * 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; }