From 391c1643134a64abae53f800f4a87b9340683a07 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 8 Apr 2020 10:24:46 -0700 Subject: [PATCH] Trivially update "arc branch/feature" and "arc browse" for Toolsets Summary: Ref T11968. Ref T13490. These are the workflows which currently use the intermediate-level hardpoint code (which made hardpoints formal, but didn't do the yield stuff). Move toward updating them by doing some basic bookkeeping, with a few compatibility adjustments to the parent Workflow class. Test Plan: Ran "arc branch" and "arc browse" with various arguments. Maniphest Tasks: T13490, T11968 Differential Revision: https://secure.phabricator.com/D21074 --- src/__phutil_library_map__.php | 4 +- .../workflow/ArcanistBrowseWorkflow.php | 94 +++++++++--------- src/workflow/ArcanistFeatureWorkflow.php | 95 ++++++++----------- src/workflow/ArcanistWorkflow.php | 41 ++++++-- 4 files changed, 120 insertions(+), 114 deletions(-) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index b7a66041..c39e766e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1019,7 +1019,7 @@ phutil_register_library_map(array( 'ArcanistBrowseRevisionURIHardpointLoader' => 'ArcanistBrowseURIHardpointLoader', 'ArcanistBrowseURIHardpointLoader' => 'ArcanistHardpointLoader', 'ArcanistBrowseURIRef' => 'ArcanistRef', - 'ArcanistBrowseWorkflow' => 'ArcanistWorkflow', + 'ArcanistBrowseWorkflow' => 'ArcanistArcWorkflow', 'ArcanistBuildPlanRef' => 'Phobject', 'ArcanistBuildRef' => 'Phobject', 'ArcanistBundle' => 'Phobject', @@ -1137,7 +1137,7 @@ phutil_register_library_map(array( 'ArcanistExternalLinterTestCase' => 'ArcanistLinterTestCase', 'ArcanistExtractUseXHPASTLinterRule' => 'ArcanistXHPASTLinterRule', 'ArcanistExtractUseXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase', - 'ArcanistFeatureWorkflow' => 'ArcanistWorkflow', + 'ArcanistFeatureWorkflow' => 'ArcanistArcWorkflow', 'ArcanistFileConfigurationSource' => 'ArcanistFilesystemConfigurationSource', 'ArcanistFileDataRef' => 'Phobject', 'ArcanistFileUploader' => 'Phobject', diff --git a/src/browse/workflow/ArcanistBrowseWorkflow.php b/src/browse/workflow/ArcanistBrowseWorkflow.php index 1b0f3221..331c06d0 100644 --- a/src/browse/workflow/ArcanistBrowseWorkflow.php +++ b/src/browse/workflow/ArcanistBrowseWorkflow.php @@ -3,70 +3,62 @@ /** * Browse files or objects in the Phabricator web interface. */ -final class ArcanistBrowseWorkflow extends ArcanistWorkflow { +final class ArcanistBrowseWorkflow + extends ArcanistArcWorkflow { public function getWorkflowName() { return 'browse'; } - public function getCommandSynopses() { - return phutil_console_format(<<newWorkflowInformation() + ->setSynopsis(pht('Open a file or object in a local web browser.')) + ->addExample('**browse** [options] -- __target__ ...') + ->addExample('**browse** -- __file-name__') + ->addExample('**browse** -- __object-name__') + ->setHelp($help); } - public function getCommandHelp() { - return phutil_console_format(<< array( - 'param' => 'branch_name', - 'help' => pht( - 'Default branch name to view on server. Defaults to "%s".', - 'master'), - ), - 'types' => array( - 'param' => 'types', - 'aliases' => array('type'), - 'help' => pht( - 'Parse arguments with particular types.'), - ), - 'force' => array( - 'help' => pht( - '(DEPRECATED) Obsolete, use "--types path" instead.'), - ), - '*' => 'targets', + $this->newWorkflowArgument('branch') + ->setParameter('branch-name') + ->setHelp( + pht( + 'Default branch name to view on server. Defaults to "%s".', + 'master')), + $this->newWorkflowArgument('types') + ->setParameter('type-list') + ->setHelp( + pht( + 'Force targets to be interpreted as naming particular types of '. + 'resources.')), + $this->newWorkflowArgument('force') + ->setHelp( + pht( + '(DEPRECATED) Obsolete, use "--types path" instead.')), + $this->newWorkflowArgument('targets') + ->setIsPathArgument(true) + ->setWildcard(true), ); } - public function desiresWorkingCopy() { - return true; - } - - public function desiresRepositoryAPI() { - return true; - } - - public function run() { - $conduit = $this->getConduitEngine(); - - $console = PhutilConsole::getConsole(); - + public function runWorkflow() { $targets = $this->getArgument('targets'); $targets = array_fuse($targets); diff --git a/src/workflow/ArcanistFeatureWorkflow.php b/src/workflow/ArcanistFeatureWorkflow.php index 53d5772f..a382cf9b 100644 --- a/src/workflow/ArcanistFeatureWorkflow.php +++ b/src/workflow/ArcanistFeatureWorkflow.php @@ -1,11 +1,7 @@ array( - 'help' => pht('Include closed and abandoned revisions.'), - ), - 'by-status' => array( - 'help' => pht('Sort branches by status instead of time.'), - ), - 'output' => array( - 'param' => 'format', - 'support' => array( - 'json', - ), - 'help' => pht( - "With '%s', show features in machine-readable JSON format.", - 'json'), - ), - '*' => 'branch', + $this->newWorkflowArgument('view-all') + ->setHelp(pht('Include closed and abandoned revisions.')), + $this->newWorkflowArgument('by-status') + ->setParameter('status') + ->setHelp(pht('Sort branches by status instead of time.')), + $this->newWorkflowArgument('output') + ->setParameter('format') + ->setHelp( + pht( + 'With "json", show features in machine-readable JSON format.')), + $this->newWorkflowArgument('branch') + ->setWildcard(true), ); } - public function getSupportedRevisionControlSystems() { - return array('git', 'hg'); + public function getWorkflowInformation() { + return $this->newWorkflowInformation() + ->setSynopsis(pht('Wrapper on "git branch" or "hg bookmark".')) + ->addExample(pht('**feature** [__options__]')) + ->addExample(pht('**feature** __name__ [__start__]')) + ->setHelp( + pht(<<getWorkingCopy(); + $repository_api = $this->getRepositoryAPI(); + if (!$repository_api) { + throw new PhutilArgumentUsageException( + pht( + 'This command must be run in a Git or Mercurial working copy.')); + } $names = $this->getArgument('branch'); if ($names) { diff --git a/src/workflow/ArcanistWorkflow.php b/src/workflow/ArcanistWorkflow.php index ca9c9f43..907968a1 100644 --- a/src/workflow/ArcanistWorkflow.php +++ b/src/workflow/ArcanistWorkflow.php @@ -336,6 +336,16 @@ abstract class ArcanistWorkflow extends Phobject { } final public function getConfigFromAnySource($key) { + $source_list = $this->getConfigurationSourceList(); + if ($source_list) { + $value_list = $source_list->getStorageValueList($key); + if ($value_list) { + return last($value_list)->getValue(); + } + + return null; + } + return $this->configurationManager->getConfigFromAnySource($key); } @@ -884,6 +894,14 @@ abstract class ArcanistWorkflow extends Phobject { } final public function getWorkingCopy() { + $configuration_engine = $this->getConfigurationEngine(); + if ($configuration_engine) { + $working_copy = $configuration_engine->getWorkingCopy(); + $working_path = $working_copy->getWorkingDirectory(); + + return ArcanistWorkingCopyIdentity::newFromPath($working_path); + } + $working_copy = $this->getConfigurationManager()->getWorkingCopyIdentity(); if (!$working_copy) { $workflow = get_class($this); @@ -911,6 +929,12 @@ abstract class ArcanistWorkflow extends Phobject { } final public function getRepositoryAPI() { + $configuration_engine = $this->getConfigurationEngine(); + if ($configuration_engine) { + $working_copy = $configuration_engine->getWorkingCopy(); + return $working_copy->getRepositoryAPI(); + } + if (!$this->repositoryAPI) { $workflow = get_class($this); throw new Exception( @@ -2232,7 +2256,7 @@ abstract class ArcanistWorkflow extends Phobject { $query->setRepositoryRef($repository_ref); } - $working_copy = $this->getConfigurationManager()->getWorkingCopyIdentity(); + $working_copy = $this->getWorkingCopy(); if ($working_copy) { $working_ref = $this->newWorkingCopyStateRef(); $query->setWorkingCopyRef($working_ref); @@ -2242,12 +2266,17 @@ abstract class ArcanistWorkflow extends Phobject { } final public function getRepositoryRef() { - if (!$this->getConfigurationManager()->getWorkingCopyIdentity()) { - return null; - } + $configuration_engine = $this->getConfigurationEngine(); + if ($configuration_engine) { + // This is a toolset workflow and can always build a repository ref. + } else { + if (!$this->getConfigurationManager()->getWorkingCopyIdentity()) { + return null; + } - if (!$this->repositoryAPI) { - return null; + if (!$this->repositoryAPI) { + return null; + } } if (!$this->repositoryRef) {