/** * Get resource log * * Get the full log for the current resource up tu the current revision * * @return array(vcsLogEntry) */ protected function getResourceLog() { if (($log = vcsCache::get($this->path, $this->currentVersion, 'log')) !== false) { return $log; } $version = $this->currentVersion !== null ? $this->currentVersion : 'HEAD'; $process = new vcsCvsCliProcess(); $process->workingDirectory($this->root)->redirect(vcsCvsCliProcess::STDERR, vcsCvsCliProcess::STDOUT)->argument('log')->argument('-r:' . $version)->argument('.' . $this->path)->execute(); $log = array(); $regexp = '((?# Get revision number ) revision\\s+(?P<revision>[\\d\\.]+)(\\r\\n|\\r|\\n) (?# Get commit date ) date:\\s+(?P<date>[^;]+);\\s+ (?# Get commit author ) author:\\s+(?P<author>[^;]+);\\s+ (?# Skip everything else ) [^\\n\\r]+;(\\r\\n|\\r|\\n) (branches:\\s+[^\\n\\r]+;(\\r\\n|\\r|\\n))? (?# Get commit message ) (?P<message>[\\r\\n\\t]*|.*)$)xs'; // Remove closing equal characters $output = rtrim(substr(rtrim($process->stdoutOutput), 0, -77)); // Split all log entries $rawLogs = explode('----------------------------', $output); $rawLogs = array_map('trim', $rawLogs); foreach ($rawLogs as $rawLog) { if (preg_match($regexp, $rawLog, $match) === 0) { continue; } $date = strtotime($match['date']); $revision = $match['revision']; $logEntry = new vcsLogEntry($revision, $match['author'], $match['message'], $date); $log[$revision] = $logEntry; } $log = array_reverse($log); $last = end($log); $this->currentVersion = $last->version; vcsCache::cache($this->path, $this->currentVersion, 'log', $log); return $log; }
/** * Get diff * * Get the diff between the current version and the given version. * Optionally you may specify another version then the current one as the * diff base as the second parameter. * * @param string $version * @param string $current * @return vcsResource */ public function getDiff($version, $current = null) { $current = $current === null ? $this->getVersionString() : $current; if (($diff = vcsCache::get($this->path, $version, 'diff')) !== false) { return $diff; } // Refetch the basic content information, and cache it. $process = new vcsCvsCliProcess(); // WTF: Why is there a non zero exit code? $process->nonZeroExitCodeException = false; // Configure process instance $process->workingDirectory($this->root)->redirect(vcsCvsCliProcess::STDERR, vcsCvsCliProcess::STDOUT)->argument('diff')->argument('-u')->argument('-r')->argument($version)->argument('-r')->argument($current)->argument('.' . $this->path)->execute(); $parser = new vcsUnifiedDiffParser(); $diff = $parser->parseString($process->stdoutOutput); vcsCache::cache($this->path, $version, 'diff', $diff); return $diff; }
/** * Update repository * * Update the repository to the most current state. Method will return * true, if an update happened, and false if no update was available. * * Optionally a version can be specified, in which case the repository * won't be updated to the latest version, but to the specified one. * * @param string $version * @return bool */ public function update($version = null) { if ($version === null) { $version = 'HEAD'; } $process = new vcsCvsCliProcess(); $process->workingDirectory($this->root)->redirect(vcsCvsCliProcess::STDERR, vcsCvsCliProcess::STDOUT)->argument('update')->argument('-Rd')->argument('-r')->argument($version)->execute(); return preg_match('#[\\n\\r]U #', $process->stdoutOutput) > 0; }