]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve "arc cover" parameters
authorepriestley <git@epriestley.com>
Tue, 13 Mar 2012 00:04:20 +0000 (17:04 -0700)
committerepriestley <git@epriestley.com>
Tue, 13 Mar 2012 00:04:20 +0000 (17:04 -0700)
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
src/workflow/cover/ArcanistCoverWorkflow.php

index 3d1b1e1fe89acb91980315553284ba2feeece15d..9cc5a18f8943d5c90f65aa77a0a5eb043fb98b58 100644 (file)
@@ -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]);
         }
       }
index 69afd21a52c2bce3bc7fdabf22bd7334200150ac..53c95f0214a2195894c3363ec9d0e71d31e1e8ac 100644 (file)
@@ -25,7 +25,7 @@ final class ArcanistCoverWorkflow extends ArcanistBaseWorkflow {
 
   public function getCommandSynopses() {
     return phutil_console_format(<<<EOTEXT
-      **cover**
+      **cover** [--rev __revision__] [__path__ ...]
 EOTEXT
       );
   }
@@ -34,12 +34,30 @@ EOTEXT
     return phutil_console_format(<<<EOTEXT
           Supports: svn, git
           Cover your... professional reputation. Show blame for the lines you
-          changed in your working copy. This will take a minute because blame
-          takes a minute, especially under SVN.
+          changed in your working copy (svn) or since some commit (hg, git).
+          This will take a minute because blame takes a minute, especially under
+          SVN.
 EOTEXT
       );
   }
 
+  public function getArguments() {
+    return array(
+      'rev' => 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));