1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-28 17:52:42 +01:00

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
This commit is contained in:
epriestley 2020-04-08 10:24:46 -07:00
parent f56c6bde2b
commit 391c164313
4 changed files with 120 additions and 114 deletions

View file

@ -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',

View file

@ -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(<<<EOTEXT
**browse** [__options__] __path__ ...
**browse** [__options__] __object__ ...
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: git, hg, svn
Open a file or object (like a task or revision) in your web browser.
public function getWorkflowInformation() {
$help = pht(<<<EOTEXT
Open a file or object (like a task or revision) in a local web browser.
$ arc browse README # Open a file in Diffusion.
$ arc browse T123 # View a task.
$ arc browse HEAD # View a symbolic commit.
Set the 'browser' value using 'arc set-config' to select a browser. If
no browser is set, the command will try to guess which browser to use.
To choose a browser binary to invoke, use:
$ arc set-config browser __browser-binary__
If no browser is set, the command will try to guess which browser to use.
EOTEXT
);
return $this->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 getArguments() {
public function getWorkflowArguments() {
return array(
'branch' => array(
'param' => 'branch_name',
'help' => pht(
$this->newWorkflowArgument('branch')
->setParameter('branch-name')
->setHelp(
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',
'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);

View file

@ -1,11 +1,7 @@
<?php
/**
* Displays user's Git branches or Mercurial bookmarks.
*
* @concrete-extensible
*/
class ArcanistFeatureWorkflow extends ArcanistWorkflow {
class ArcanistFeatureWorkflow
extends ArcanistArcWorkflow {
private $branches;
@ -13,62 +9,51 @@ class ArcanistFeatureWorkflow extends ArcanistWorkflow {
return 'feature';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**feature** [__options__]
**feature** __name__ [__start__]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: git, hg
A wrapper on 'git branch' or 'hg bookmark'.
Without __name__, it lists the available branches and their revision
status.
With __name__, it creates or checks out a branch. If the branch
__name__ doesn't exist and is in format D123 then the branch of
revision D123 is checked out. Use __start__ to specify where the new
branch will start. Use 'arc.feature.start.default' to set the default
feature start location.
EOTEXT
);
}
public function requiresRepositoryAPI() {
return true;
}
public function getArguments() {
public function getWorkflowArguments() {
return array(
'view-all' => 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(<<<EOHELP
A wrapper on 'git branch' or 'hg bookmark'.
Without __name__, it lists the available branches and their revision status.
With __name__, it creates or checks out a branch. If the branch __name__
doesn't exist and is in format D123 then the branch of revision D123 is
checked out. Use __start__ to specify where the new branch will start. Use
'arc.feature.start.default' to set the default feature start location.
EOHELP
));
}
public function run() {
public function runWorkflow() {
$working_copy = $this->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) {

View file

@ -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,6 +2266,10 @@ abstract class ArcanistWorkflow extends Phobject {
}
final public function getRepositoryRef() {
$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;
}
@ -2249,6 +2277,7 @@ abstract class ArcanistWorkflow extends Phobject {
if (!$this->repositoryAPI) {
return null;
}
}
if (!$this->repositoryRef) {
$ref = id(new ArcanistRepositoryRef())