/** * Validates revisions to actually exist. * * @param array $revisions Revisions. * @param string $repository_url Repository url. * * @return array * @throws CommandException When revision doesn't exist. */ protected function getDirectRevisions(array $revisions, $repository_url) { $revision_log = $this->getRevisionLog($repository_url); try { $revisions = $this->_revisionListParser->expandRanges($revisions); $revision_log->getRevisionsData('summary', $revisions); } catch (\InvalidArgumentException $e) { throw new CommandException($e->getMessage()); } return $revisions; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $bugs = $this->getList($this->io->getOption('bugs')); $revisions = $this->getList($this->io->getOption('revisions')); if ($bugs && $revisions) { throw new \RuntimeException('The "--bugs" and "--revisions" options are mutually exclusive.'); } $wc_url = $this->getWorkingCopyUrl(); $missing_revisions = array(); $revision_log = $this->getRevisionLog($wc_url); $revisions_by_path = $revision_log->find('paths', $this->repositoryConnector->getPathFromUrl($wc_url)); if ($revisions) { $revisions = $this->_revisionListParser->expandRanges($revisions); $revisions_by_path = array_intersect($revisions_by_path, $revisions); $missing_revisions = array_diff($revisions, $revisions_by_path); } elseif ($bugs) { // Only show bug-related revisions on given path. The $missing_revisions is always empty. $revisions_from_bugs = $revision_log->find('bugs', $bugs); $revisions_by_path = array_intersect($revisions_by_path, $revisions_from_bugs); } if ($missing_revisions) { throw new CommandException('No information about ' . implode(', ', $missing_revisions) . ' revision(-s).'); } elseif (!$revisions_by_path) { throw new CommandException('No matching revisions found.'); } rsort($revisions_by_path, SORT_NUMERIC); if ($bugs || $revisions) { // Don't limit revisions, when provided explicitly by user. $revisions_by_path_with_limit = $revisions_by_path; } else { // Apply limit only, when no explicit bugs/revisions are set. $revisions_by_path_with_limit = array_slice($revisions_by_path, 0, $this->getLimit()); } $this->printRevisions($revisions_by_path_with_limit, $wc_url, (bool) $this->io->getOption('details')); $revisions_by_path_count = count($revisions_by_path); $revisions_by_path_with_limit_count = count($revisions_by_path_with_limit); if ($revisions_by_path_count > $revisions_by_path_with_limit_count) { $revisions_left = $revisions_by_path_count - $revisions_by_path_with_limit_count; $this->io->writeln($revisions_left . ' revision(-s) not shown'); } }
/** * Returns list of just merged revisions. * * @param string $wc_path Working copy path, where merge happens. * * @return array */ public function getFreshMergedRevisions($wc_path) { $final_paths = array(); $old_paths = $this->getMergedRevisions($wc_path, 'BASE'); $new_paths = $this->getMergedRevisions($wc_path); if ($old_paths === $new_paths) { return array(); } foreach ($new_paths as $new_path => $new_merged_revisions) { if (!isset($old_paths[$new_path])) { // Merge from new path. $final_paths[$new_path] = $this->_revisionListParser->expandRanges(explode(',', $new_merged_revisions)); } elseif ($new_merged_revisions != $old_paths[$new_path]) { // Merge on existing path. $new_merged_revisions_parsed = $this->_revisionListParser->expandRanges(explode(',', $new_merged_revisions)); $old_merged_revisions_parsed = $this->_revisionListParser->expandRanges(explode(',', $old_paths[$new_path])); $final_paths[$new_path] = array_values(array_diff($new_merged_revisions_parsed, $old_merged_revisions_parsed)); } } return $final_paths; }
public function testMultiDigitRevisions() { $expected = array(18, 10, 11, 12); $actual = $this->_revisionListParser->expandRanges(array(18, '10-12')); $this->assertEquals($expected, $actual); }
/** * {@inheritdoc} * * @throws \RuntimeException When both "--bugs" and "--revisions" options were specified. * @throws CommandException When specified revisions are not present in current project. * @throws CommandException When project contains no associated revisions. */ protected function execute(InputInterface $input, OutputInterface $output) { $searching_start = microtime(true); $bugs = $this->getList($this->io->getOption('bugs')); $revisions = $this->getList($this->io->getOption('revisions')); if ($bugs && $revisions) { throw new \RuntimeException('The "--bugs" and "--revisions" options are mutually exclusive.'); } $missing_revisions = array(); $revisions_by_path = $this->getRevisionsByPath(); if ($revisions) { $revisions = $this->_revisionListParser->expandRanges($revisions); $revisions_by_path = array_intersect($revisions_by_path, $revisions); $missing_revisions = array_diff($revisions, $revisions_by_path); } elseif ($bugs) { // Only show bug-related revisions on given path. The $missing_revisions is always empty. $revisions_from_bugs = $this->_revisionLog->find('bugs', $bugs); $revisions_by_path = array_intersect($revisions_by_path, $revisions_from_bugs); } $merged_by = $this->getList($this->io->getOption('merged-by')); if ($merged_by) { $merged_by = $this->_revisionListParser->expandRanges($merged_by); $revisions_by_path = $this->_revisionLog->find('merges', $merged_by); } if ($this->io->getOption('merges')) { $revisions_by_path = array_intersect($revisions_by_path, $this->_revisionLog->find('merges', 'all_merges')); } elseif ($this->io->getOption('no-merges')) { $revisions_by_path = array_diff($revisions_by_path, $this->_revisionLog->find('merges', 'all_merges')); } if ($this->io->getOption('merged')) { $revisions_by_path = array_intersect($revisions_by_path, $this->_revisionLog->find('merges', 'all_merged')); } elseif ($this->io->getOption('not-merged')) { $revisions_by_path = array_diff($revisions_by_path, $this->_revisionLog->find('merges', 'all_merged')); } $action = $this->io->getOption('action'); if ($action) { if (!in_array($action, $this->getAllActions())) { throw new CommandException('The "' . $action . '" action is unknown.'); } $revisions_by_path = array_intersect($revisions_by_path, $this->_revisionLog->find('paths', 'action:' . $action)); } $kind = $this->io->getOption('kind'); if ($kind) { if (!in_array($kind, $this->getAllKinds())) { throw new CommandException('The "' . $kind . '" kind is unknown.'); } $revisions_by_path = array_intersect($revisions_by_path, $this->_revisionLog->find('paths', 'kind:' . $kind)); } if ($missing_revisions) { throw new CommandException($this->getMissingRevisionsErrorMessage($missing_revisions)); } elseif (!$revisions_by_path) { throw new CommandException('No matching revisions found.'); } rsort($revisions_by_path, SORT_NUMERIC); if ($bugs || $revisions) { // Don't limit revisions, when provided explicitly by user. $revisions_by_path_with_limit = $revisions_by_path; } else { // Apply limit only, when no explicit bugs/revisions are set. $revisions_by_path_with_limit = array_slice($revisions_by_path, 0, $this->getMaxCount()); } $revisions_by_path_count = count($revisions_by_path); $revisions_by_path_with_limit_count = count($revisions_by_path_with_limit); if ($revisions_by_path_with_limit_count === $revisions_by_path_count) { $this->io->writeln(sprintf(' * Showing <info>%d</info> revision(-s) in %s:', $revisions_by_path_with_limit_count, $this->getRevisionLogIdentifier())); } else { $this->io->writeln(sprintf(' * Showing <info>%d</info> of <info>%d</info> revision(-s) in %s:', $revisions_by_path_with_limit_count, $revisions_by_path_count, $this->getRevisionLogIdentifier())); } $searching_duration = microtime(true) - $searching_start; $printing_start = microtime(true); $this->printRevisions($revisions_by_path_with_limit); $printing_duration = microtime(true) - $printing_start; $debug_info = 'Generation Time: <info>' . round($searching_duration + $printing_duration, 2) . 's</info>'; $debug_info .= ' ('; $debug_info .= 'searching: <info>' . round($searching_duration, 2) . 's</info>;'; $debug_info .= ' printing: <info>' . round($printing_duration, 2) . 's</info>'; $debug_info .= ').'; $this->io->writeln($debug_info); }