/** * Verify bzr version * * Verify that the version of the installed bzr binary is at least 1.1. Will * throw an exception, if the binary is not available or too old. * * @return void */ protected static function checkVersion() { if (self::$checked === true) { return true; } $process = new pbsSystemProcess('bzr'); $process->nonZeroExitCodeException = true; $process->argument('--version')->execute(); if (!preg_match('/\\Bazaar \\(bzr\\) ([0-9.]*)/', $process->stdoutOutput, $match)) { throw new vcsRuntimeException('Could not determine Bazaar version.'); } if (version_compare($match[1], '1.1', '<')) { throw new vcsRuntimeException('Bazaar is required in a minimum version of 1.1.'); } $process = new pbsSystemProcess('bzr'); $process->nonZeroExitCodeException = true; $process->argument('plugins')->execute(); if (strpos($process->stdoutOutput, 'xmloutput') === false) { throw new vcsRuntimeException('Missing required bazaar pluging "xmloutput".'); } return self::$checked = true; }
/** * Get blame information for resource * * The method should return author and revision information for each line, * describing who when last changed the current resource. The returned * array should look like: * <code> * array( * T_LINE_NUMBER => array( * 'author' => T_STRING, * 'version' => T_STRING, * ), * ... * ); * </code> * * If some file in the repository has no blame information associated, like * binary files, the method should return false. * * Optionally a version may be specified which defines a later version of * the resource for which the blame information should be returned. * * @param mixed $version * @return mixed */ public function blame($version = null) { $version = $version === null ? $this->getVersionString() : $version; if (!in_array($version, $this->getVersions(), true)) { throw new vcsNoSuchVersionException($this->path, $version); } $blame = vcsCache::get($this->path, $version, 'blame'); if ($blame === false) { $shortHashCache = array(); // Refetch the basic blamermation, and cache it. $process = new vcsBzrCliProcess(); $process->workingDirectory($this->root); // Execute command $process->argument('xmlannotate'); if ($version !== null) { $process->argument('-r' . $version); } $process->argument(new pbsPathArgument('.' . $this->path)); $return = $process->execute(); $blame = array(); libxml_use_internal_errors(true); try { $xmlDoc = new SimpleXMLElement($process->stdoutOutput); // Convert returned lines into diff structures foreach ($xmlDoc->entry as $line) { $blame[] = new vcsBlameStruct($line, $line['revno'], $line['author'], strtotime($line['date'])); } } catch (Exception $e) { return false; } vcsCache::cache($this->path, $version, 'blame', $blame); } return $blame; }
/** * Returns the diff between two different versions. * * @param string $version * @param string $current * @return vcsDiff */ public function getDiff($version, $current = null) { if (!in_array($version, $this->getVersions(), true)) { throw new vcsNoSuchVersionException($this->path, $version); } $diff = vcsCache::get($this->path, $version, 'diff'); if ($diff === false) { // Refetch the basic content information, and cache it. $process = new vcsBzrCliProcess(); $process->workingDirectory($this->root); $process->argument('diff'); if ($current !== null) { $process->argument('-r' . $version . ".." . $current); } else { $process->argument("-r" . $version); } $process->argument(new pbsPathArgument('.' . $this->path)); $process->execute(); // Parse resulting unified diff $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) { // Remember version before update try $oldVersion = $this->getVersionString(); $process = new vcsBzrCliProcess(); $process->workingDirectory($this->root); $process->argument('update'); $process->execute(); if ($version !== null) { $process = new vcsBzrCliProcess(); $process->workingDirectory($this->root); $process->argument('revert')->argument('-r' . $version); $process->execute(); } // Check if an update has happened $this->currentVersion = null; return $oldVersion !== $this->getVersionString(); }