/**
  * Verify git version
  *
  * Verify hat the version of the installed GIT binary is at least 1.6. 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('env');
     $process->nonZeroExitCodeException = true;
     $process->argument('hg')->argument('--version')->execute();
     if (!preg_match('/\\(version (.*)\\)/', $process->stdoutOutput, $match)) {
         throw new vcsRuntimeException('Could not determine Mercurial version.');
     }
     if (version_compare($match[1], '1.3', '>=')) {
         return self::$checked = true;
     }
     throw new vcsRuntimeException('Mercurial is required in a minimum version of 1.3.');
 }
 /**
  * Returns the complete log for this resource.
  *
  * @return array
  */
 protected function getResourceLog()
 {
     $log = vcsCache::get($this->path, $this->currentVersion, 'log');
     if ($log === false) {
         // Refetch the basic logrmation, and cache it.
         $process = new vcsHgCliProcess();
         $process->workingDirectory($this->root);
         // Fetch for specified version, if set
         if ($this->currentVersion !== null) {
             $process->argument('-r ' . $this->currentVersion);
         }
         // Execute log command
         $process->argument('log');
         $process->argument('--template')->argument('{node}\\t{author|email}\\t{date|isodate}\\t{desc|urlescape}\\n');
         $process->argument(new pbsPathArgument('.' . $this->path));
         $process->execute();
         // Parse commit log
         $lines = explode("\n", $process->stdoutOutput);
         if (!$lines) {
             return array();
         }
         $lineCount = count($lines);
         $log = array();
         $lastCommit = null;
         foreach ($lines as $line) {
             if (!$line) {
                 continue;
             }
             list($node, $author, $date, $desc) = explode("\t", $line, 4);
             $atPosition = strpos($author, '@');
             if ($atPosition) {
                 $author = substr($author, 0, $atPosition);
             }
             $log[$node] = new vcsLogEntry($node, $author, urldecode($desc), strtotime($date));
         }
         $log = array_reverse($log);
         $last = end($log);
         $this->currentVersion = (string) $last->version;
         // Cache extracted data
         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)
 {
     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 vcsHgCliProcess();
         $process->workingDirectory($this->root);
         $process->argument('diff');
         if ($current !== null) {
             $process->argument('-r' . $current);
         }
         $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 vcsHgCliProcess();
     $process->workingDirectory($this->root);
     $process->argument('pull')->argument('default');
     $process->execute();
     $process = new vcsHgCliProcess();
     $process->workingDirectory($this->root);
     $process->argument('update');
     if ($version) {
         $process->argument('-r' . $version);
     }
     $process->execute();
     // Check if an update has happened
     $this->currentVersion = null;
     return $oldVersion !== $this->getVersionString();
 }