From d8967290e9535ee8f9a6a42a0588e717a37cd3fd Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 12 Mar 2012 17:04:20 -0700 Subject: [PATCH] Improve "arc cover" parameters Summary: Give "arc cover" --rev and paths parameters like "arc lint" and "arc unit". Test Plan: Ran 'arc cover' with various rev/path things. Ran in SVN to verify it works/fails correctly. Reviewers: btrahan, vrana Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T707 Differential Revision: https://secure.phabricator.com/D1860 --- src/workflow/base/ArcanistBaseWorkflow.php | 14 +++++- src/workflow/cover/ArcanistCoverWorkflow.php | 52 ++++++++++++++------ 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/src/workflow/base/ArcanistBaseWorkflow.php b/src/workflow/base/ArcanistBaseWorkflow.php index 3d1b1e1f..9cc5a18f 100644 --- a/src/workflow/base/ArcanistBaseWorkflow.php +++ b/src/workflow/base/ArcanistBaseWorkflow.php @@ -950,9 +950,19 @@ abstract class ArcanistBaseWorkflow { * * @param list List of explicitly provided paths. * @param string|null Revision name, if provided. + * @param mask Mask of ArcanistRepositoryAPI flags to exclude. + * Defaults to ArcanistRepositoryAPI::FLAG_UNTRACKED. * @return list List of paths the workflow should act on. */ - protected function selectPathsForWorkflow(array $paths, $rev) { + protected function selectPathsForWorkflow( + array $paths, + $rev, + $omit_mask = null) { + + if ($omit_mask === null) { + $omit_mask = ArcanistRepositoryAPI::FLAG_UNTRACKED; + } + if ($paths) { $working_copy = $this->getWorkingCopy(); foreach ($paths as $key => $path) { @@ -973,7 +983,7 @@ abstract class ArcanistBaseWorkflow { $paths = $repository_api->getWorkingCopyStatus(); foreach ($paths as $path => $flags) { - if ($flags & ArcanistRepositoryAPI::FLAG_UNTRACKED) { + if ($flags & $omit_mask) { unset($paths[$path]); } } diff --git a/src/workflow/cover/ArcanistCoverWorkflow.php b/src/workflow/cover/ArcanistCoverWorkflow.php index 69afd21a..53c95f02 100644 --- a/src/workflow/cover/ArcanistCoverWorkflow.php +++ b/src/workflow/cover/ArcanistCoverWorkflow.php @@ -25,7 +25,7 @@ final class ArcanistCoverWorkflow extends ArcanistBaseWorkflow { public function getCommandSynopses() { return phutil_console_format(<< array( + 'param' => 'revision', + 'help' => 'Cover changes since a specific revision.', + 'supports' => array( + 'git', + 'hg', + ), + 'nosupport' => array( + 'svn' => "cover does not currently support --rev in svn.", + ), + ), + '*' => 'paths', + ); + } + public function requiresWorkingCopy() { return true; } @@ -60,21 +78,20 @@ EOTEXT $repository_api = $this->getRepositoryAPI(); - $paths = $repository_api->getWorkingCopyStatus(); + $in_paths = $this->getArgument('paths'); + $in_rev = $this->getArgument('rev'); - foreach ($paths as $path => $status) { - if (is_dir($path)) { - unset($paths[$path]); - } - if ($status & ArcanistRepositoryAPI::FLAG_UNTRACKED) { - unset($paths[$path]); - } - if ($status & ArcanistRepositoryAPI::FLAG_ADDED) { - unset($paths[$path]); - } + if ($in_rev) { + // Although selectPathsForWorkflow() may set this, we want to set it + // explicitly so we blame against the correct relative commit. + $repository_api->parseRelativeLocalCommit(array($in_rev)); } - $paths = array_keys($paths); + $paths = $this->selectPathsForWorkflow( + $in_paths, + $in_rev, + ArcanistRepositoryAPI::FLAG_UNTRACKED | + ArcanistRepositoryAPI::FLAG_ADDED); if (!$paths) { throw new ArcanistNoEffectException( @@ -83,10 +100,15 @@ EOTEXT $covers = array(); foreach ($paths as $path) { + if (is_dir($repository_api->getPath($path))) { + continue; + } + $lines = $this->getChangedLines($path, 'cover'); if (!$lines) { continue; } + $blame = $repository_api->getBlame($path); foreach ($lines as $line) { list($author, $revision) = idx($blame, $line, array(null, null));