]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Support 'arc:exec(command)' in base-commit DSL
authorepriestley <git@epriestley.com>
Fri, 22 Jun 2012 15:13:06 +0000 (08:13 -0700)
committerepriestley <git@epriestley.com>
Fri, 22 Jun 2012 15:13:06 +0000 (08:13 -0700)
Summary: Allow users to run a command to determine the base revision of the commit range.

Test Plan: Ran stuff like `arc which --show-base --base 'arc:exec(ls)'` and got the expected results.

Reviewers: dschleimer, csilvers, btrahan, vrana

Reviewed By: csilvers

CC: aran
Maniphest Tasks: T1233

Differential Revision: https://secure.phabricator.com/D2830

src/parser/ArcanistBaseCommitParser.php

index d1d41f395b3b810d682519e56e02505ba2ee0a38..046810779f144e05f905d1241f2ea48c7d5c1ed8 100644 (file)
@@ -32,7 +32,7 @@ final class ArcanistBaseCommitParser {
       return array();
     }
 
-    $spec = preg_split('/[ ,]/', $raw_spec);
+    $spec = preg_split('/\s*,\s*/', $raw_spec);
     $spec = array_filter($spec);
 
     foreach ($spec as $rule) {
@@ -164,6 +164,19 @@ final class ArcanistBaseCommitParser {
       case 'outgoing':
         return $this->api->resolveBaseCommitRule($rule, $source);
       default:
+        $matches = null;
+        if (preg_match('/^exec\((.*)\)$/', $name, $matches)) {
+          $root = $this->api->getWorkingCopyIdentity()->getProjectRoot();
+          $future = new ExecFuture($matches[1]);
+          $future->setCWD($root);
+          list($err, $stdout) = $future->resolve();
+          if (!$err) {
+            return trim($stdout);
+          } else {
+            return null;
+          }
+        }
+
         throw new ArcanistUsageException(
           "Base commit rule '{$rule}' (from source '{$source}') ".
           "is not a recognized rule.");