Exemplo n.º 1
0
 /**
  * @dataProvider outputVerbosityDataProvider
  */
 public function testIsVerbose($verbosity_level)
 {
     $this->output->getVerbosity()->willReturn($verbosity_level)->shouldBeCalled();
     $actual = $this->io->isVerbose();
     if ($verbosity_level >= OutputInterface::VERBOSITY_VERBOSE) {
         $this->assertTrue($actual, 'Output should be verbose.');
     } else {
         $this->assertFalse($actual, 'Output should not be verbose.');
     }
 }
Exemplo n.º 2
0
 /**
  * Queries missing revision data.
  *
  * @param integer $from_revision From revision.
  * @param integer $to_revision   To revision.
  *
  * @return void
  */
 private function _queryRevisionData($from_revision, $to_revision)
 {
     $range_start = $from_revision;
     // The "io" isn't set during autocomplete.
     if (isset($this->_io)) {
         // Create progress bar for repository plugins, where data amount is known upfront.
         $progress_bar = $this->_io->createProgressBar(ceil(($to_revision - $from_revision) / 200) + 1);
         $progress_bar->setMessage(' * Reading missing revisions:');
         $progress_bar->setFormat('%message% %current%/%max% [%bar%] <info>%percent:3s%%</info> %elapsed:6s%/%estimated:-6s% <info>%memory:-10s%</info>');
         $progress_bar->start();
     }
     $log_command_arguments = $this->_getLogCommandArguments();
     $is_verbose = isset($this->_io) && $this->_io->isVerbose();
     while ($range_start <= $to_revision) {
         $range_end = min($range_start + 199, $to_revision);
         $command = $this->_repositoryConnector->getCommand('log', sprintf($log_command_arguments, $range_start, $range_end, $this->_repositoryRootUrl));
         $command->setCacheDuration('10 years');
         $svn_log = $command->run();
         $this->_parseLog($svn_log);
         $range_start = $range_end + 1;
         if (isset($progress_bar)) {
             $progress_bar->advance();
         }
     }
     if (isset($progress_bar)) {
         // Remove progress bar of repository plugins.
         $progress_bar->clear();
         unset($progress_bar);
         // Create progress bar for database plugins, where data amount isn't known upfront.
         $progress_bar = $this->_io->createProgressBar();
         $progress_bar->setMessage(' * Reading missing revisions:');
         $progress_bar->setFormat('%message% %current% [%bar%] %elapsed:6s% <info>%memory:-10s%</info>');
         $progress_bar->start();
         foreach ($this->getDatabaseCollectorPlugins() as $plugin) {
             $plugin->process($from_revision, $to_revision, $progress_bar);
         }
     } else {
         foreach ($this->getDatabaseCollectorPlugins() as $plugin) {
             $plugin->process($from_revision, $to_revision);
         }
     }
     if (isset($progress_bar)) {
         $progress_bar->finish();
         $this->_io->writeln('');
     }
     if ($is_verbose) {
         $this->_displayPluginActivityStatistics();
     }
 }
Exemplo n.º 3
0
 /**
  * Returns file-based cache storage.
  *
  * @param string  $name     Cache name.
  * @param integer $duration Duration in seconds.
  *
  * @return ICacheStorage
  * @throws \InvalidArgumentException When namespace is missing in the name.
  */
 private function _getStorage($name, $duration = null)
 {
     $name_parts = explode(':', $name, 2);
     if (count($name_parts) != 2) {
         throw new \InvalidArgumentException('The $name parameter must be in "namespace:name" format.');
     }
     $filename_parts = array($name_parts[0], substr(hash_hmac('sha1', $name_parts[1], 'svn-buddy'), 0, 8), 'D' . (isset($duration) ? $duration : 'INF'));
     $cache_filename = $this->_workingDirectory . DIRECTORY_SEPARATOR . implode('_', $filename_parts) . '.cache';
     if (isset($this->_io) && $this->_io->isVerbose()) {
         $message = $cache_filename;
         if (file_exists($cache_filename)) {
             $message .= ' (hit: ' . $this->_sizeHelper->formatSize(filesize($cache_filename)) . ')';
         } else {
             $message .= ' (miss)';
         }
         $this->_io->writeln(array('', '<debug>[cache]: ' . $message . '</debug>'));
     }
     return new FileCacheStorage($cache_filename);
 }
Exemplo n.º 4
0
 /**
  * Runs the command.
  *
  * @param callable|null $callback Callback.
  *
  * @return string
  * @throws RepositoryCommandException When command execution failed.
  */
 private function _doRun($callback = null)
 {
     $process = $this->_processFactory->createProcess($this->_commandLine, 1200);
     try {
         $start = microtime(true);
         $process->mustRun($callback);
         if ($this->_io->isVerbose()) {
             $runtime = sprintf('%01.2f', microtime(true) - $start);
             $this->_io->writeln(array('', '<debug>[svn, ' . round($runtime, 2) . 's]: ' . $this->_commandLine . '</debug>'));
         }
         $output = (string) $process->getOutput();
         if ($this->_io->isDebug()) {
             $this->_io->writeln($output, OutputInterface::OUTPUT_RAW);
         }
         return $output;
     } catch (ProcessFailedException $e) {
         throw new RepositoryCommandException($this->_commandLine, $process->getErrorOutput());
     }
 }
Exemplo n.º 5
0
 /**
  * Runs the command.
  *
  * @param callable|null $callback Callback.
  *
  * @return string
  * @throws RepositoryCommandException When command execution failed.
  */
 private function _doRun($callback = null)
 {
     try {
         $start = microtime(true);
         $this->_process->mustRun($callback);
         if ($this->_io->isVerbose()) {
             $runtime = sprintf('%01.2f', microtime(true) - $start);
             $command_line = $this->_process->getCommandLine();
             $this->_io->writeln(PHP_EOL . '<fg=white;bg=magenta>[svn, ' . round($runtime, 2) . 's]: ' . $command_line . '</>');
         }
     } catch (ProcessFailedException $e) {
         $process = $e->getProcess();
         throw new RepositoryCommandException($process->getCommandLine(), $process->getErrorOutput());
     }
     $output = (string) $this->_process->getOutput();
     if ($this->_io->isDebug()) {
         $this->_io->writeln($output, OutputInterface::OUTPUT_RAW);
     }
     return $output;
 }
 /**
  * Sets IO.
  *
  * @param ConsoleIO $io Console IO.
  *
  * @return void
  */
 public function setIO(ConsoleIO $io = null)
 {
     $this->_io = $io;
     $this->_debugMode = isset($io) && $io->isVerbose();
 }