1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 06:20:56 +01:00

Remove calls to getCallsign() in bin/repository scripts

Summary:
Ref T4245. Prepare these scripts for a callsign-free world. This also makes them more flexible and easier to use.

The following are now valid ways to identify a repository for these scripts: ID (`3`), PHID (`PHID-REPO-wxyz`), R<ID> (`R3`), r<CALLSIGN> (`rSKYNET`), CALLSIGN (`SKYNET`).

In the future, a human-readable label (`skynet`) may also become valid.

Test Plan:
- Ran `bin/repository reparse --all ...` with `rX`, `X`, `3`, `R3`.
- Ran `bin/repository reparse --change ...` with `rXaaa`, including short versions.
- Ran `bin/repository update ...` with `rX`, `X`, `3`, `R3`.
- Ran `bin/repository refs ...` with various identifiers.
- Ran `bin/repository pull ...` with various identifiers.
- Ran `bin/repository mirror ...` with various identifiers.
- Ran `bin/repository mark-imported ...` with various identifiers.
- Ran `bin/repository list`.
- Ran `bin/repository importing ...` with various identifiers and examined output.
- Ran `bin/repository edit ...` with various identifiers.
- Ran `bin/repository discover ...` with various identifiers.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4245

Differential Revision: https://secure.phabricator.com/D14924
This commit is contained in:
epriestley 2016-01-01 18:39:12 -08:00
parent ff1bfb64dd
commit edcc3232aa
14 changed files with 156 additions and 90 deletions

View file

@ -7,7 +7,7 @@ final class PhabricatorRepositoryManagementDiscoverWorkflow
$this $this
->setName('discover') ->setName('discover')
->setExamples('**discover** [__options__] __repository__ ...') ->setExamples('**discover** [__options__] __repository__ ...')
->setSynopsis(pht('Discover __repository__, named by callsign.')) ->setSynopsis(pht('Discover __repository__.'))
->setArguments( ->setArguments(
array( array(
array( array(
@ -31,14 +31,16 @@ final class PhabricatorRepositoryManagementDiscoverWorkflow
if (!$repos) { if (!$repos) {
throw new PhutilArgumentUsageException( throw new PhutilArgumentUsageException(
pht('Specify one or more repositories to discover, by callsign.')); pht('Specify one or more repositories to discover.'));
} }
$console = PhutilConsole::getConsole(); $console = PhutilConsole::getConsole();
foreach ($repos as $repo) { foreach ($repos as $repo) {
$console->writeOut( $console->writeOut(
"%s\n", "%s\n",
pht("Discovering '%s'...", $repo->getCallsign())); pht(
'Discovering "%s"...',
$repo->getDisplayName()));
id(new PhabricatorRepositoryDiscoveryEngine()) id(new PhabricatorRepositoryDiscoveryEngine())
->setRepository($repo) ->setRepository($repo)

View file

@ -9,8 +9,7 @@ final class PhabricatorRepositoryManagementEditWorkflow
->setExamples('**edit** --as __username__ __repository__ ...') ->setExamples('**edit** --as __username__ __repository__ ...')
->setSynopsis( ->setSynopsis(
pht( pht(
'Edit __repository__, named by callsign '. 'Edit __repository__ (will eventually be deprecated by Conduit).'))
'(will eventually be deprecated by Conduit).'))
->setArguments( ->setArguments(
array( array(
array( array(
@ -45,7 +44,7 @@ final class PhabricatorRepositoryManagementEditWorkflow
if (!$repos) { if (!$repos) {
throw new PhutilArgumentUsageException( throw new PhutilArgumentUsageException(
pht('Specify one or more repositories to edit, by callsign.')); pht('Specify one or more repositories to edit.'));
} }
$console = PhutilConsole::getConsole(); $console = PhutilConsole::getConsole();
@ -76,7 +75,11 @@ final class PhabricatorRepositoryManagementEditWorkflow
} }
foreach ($repos as $repo) { foreach ($repos as $repo) {
$console->writeOut("%s\n", pht("Editing '%s'...", $repo->getCallsign())); $console->writeOut(
"%s\n",
pht(
'Editing "%s"...',
$repo->getDisplayName()));
$xactions = array(); $xactions = array();

View file

@ -9,8 +9,7 @@ final class PhabricatorRepositoryManagementImportingWorkflow
->setExamples('**importing** __repository__ ...') ->setExamples('**importing** __repository__ ...')
->setSynopsis( ->setSynopsis(
pht( pht(
'Show commits in __repository__, named by callsign, which are '. 'Show commits in __repository__ which are still importing.'))
'still importing.'))
->setArguments( ->setArguments(
array( array(
array( array(
@ -30,8 +29,7 @@ final class PhabricatorRepositoryManagementImportingWorkflow
if (!$repos) { if (!$repos) {
throw new PhutilArgumentUsageException( throw new PhutilArgumentUsageException(
pht( pht(
'Specify one or more repositories to find importing commits for, '. 'Specify one or more repositories to find importing commits for.'));
'by callsign.'));
} }
$repos = mpull($repos, null, 'getID'); $repos = mpull($repos, null, 'getID');
@ -54,7 +52,7 @@ final class PhabricatorRepositoryManagementImportingWorkflow
$repo = $repos[$row['repositoryID']]; $repo = $repos[$row['repositoryID']];
$identifier = $row['commitIdentifier']; $identifier = $row['commitIdentifier'];
$console->writeOut('%s', 'r'.$repo->getCallsign().$identifier); $console->writeOut('%s', $repo->formatCommitName($identifier));
if (!$args->getArg('simple')) { if (!$args->getArg('simple')) {
$status = $row['importStatus']; $status = $row['importStatus'];

View file

@ -18,7 +18,7 @@ final class PhabricatorRepositoryManagementListWorkflow
->execute(); ->execute();
if ($repos) { if ($repos) {
foreach ($repos as $repo) { foreach ($repos as $repo) {
$console->writeOut("%s\n", $repo->getCallsign()); $console->writeOut("%s\n", $repo->getMonogram());
} }
} else { } else {
$console->writeErr("%s\n", pht('There are no repositories.')); $console->writeErr("%s\n", pht('There are no repositories.'));

View file

@ -7,7 +7,7 @@ final class PhabricatorRepositoryManagementMarkImportedWorkflow
$this $this
->setName('mark-imported') ->setName('mark-imported')
->setExamples('**mark-imported** __repository__ ...') ->setExamples('**mark-imported** __repository__ ...')
->setSynopsis(pht('Mark __repository__, named by callsign, as imported.')) ->setSynopsis(pht('Mark __repository__ as imported.'))
->setArguments( ->setArguments(
array( array(
array( array(
@ -26,32 +26,40 @@ final class PhabricatorRepositoryManagementMarkImportedWorkflow
if (!$repos) { if (!$repos) {
throw new PhutilArgumentUsageException( throw new PhutilArgumentUsageException(
pht('Specify one or more repositories to mark imported, by callsign.')); pht('Specify one or more repositories to mark imported.'));
} }
$new_importing_value = (bool)$args->getArg('mark-not-imported'); $new_importing_value = (bool)$args->getArg('mark-not-imported');
$console = PhutilConsole::getConsole(); $console = PhutilConsole::getConsole();
foreach ($repos as $repo) { foreach ($repos as $repo) {
$callsign = $repo->getCallsign(); $name = $repo->getDisplayName();
if ($repo->isImporting() && $new_importing_value) { if ($repo->isImporting() && $new_importing_value) {
$console->writeOut( $console->writeOut(
"%s\n", "%s\n",
pht("Repository '%s' is already importing.", $callsign)); pht(
'Repository "%s" is already importing.',
$name));
} else if (!$repo->isImporting() && !$new_importing_value) { } else if (!$repo->isImporting() && !$new_importing_value) {
$console->writeOut( $console->writeOut(
"%s\n", "%s\n",
pht("Repository '%s' is already imported.", $callsign)); pht(
'Repository "%s" is already imported.',
$name));
} else { } else {
if ($new_importing_value) { if ($new_importing_value) {
$console->writeOut( $console->writeOut(
"%s\n", "%s\n",
pht("Marking repository '%s' as importing.", $callsign)); pht(
'Marking repository "%s" as importing.',
$name));
} else { } else {
$console->writeOut( $console->writeOut(
"%s\n", "%s\n",
pht("Marking repository '%s' as imported.", $callsign)); pht(
'Marking repository "%s" as imported.',
$name));
} }
$repo->setDetail('importing', $new_importing_value); $repo->setDetail('importing', $new_importing_value);

View file

@ -8,7 +8,7 @@ final class PhabricatorRepositoryManagementMirrorWorkflow
->setName('mirror') ->setName('mirror')
->setExamples('**mirror** [__options__] __repository__ ...') ->setExamples('**mirror** [__options__] __repository__ ...')
->setSynopsis( ->setSynopsis(
pht('Push __repository__, named by callsign, to mirrors.')) pht('Push __repository__ to mirrors.'))
->setArguments( ->setArguments(
array( array(
array( array(
@ -28,14 +28,16 @@ final class PhabricatorRepositoryManagementMirrorWorkflow
if (!$repos) { if (!$repos) {
throw new PhutilArgumentUsageException( throw new PhutilArgumentUsageException(
pht( pht(
'Specify one or more repositories to push to mirrors, by callsign.')); 'Specify one or more repositories to push to mirrors.'));
} }
$console = PhutilConsole::getConsole(); $console = PhutilConsole::getConsole();
foreach ($repos as $repo) { foreach ($repos as $repo) {
$console->writeOut( $console->writeOut(
"%s\n", "%s\n",
pht('Pushing "%s" to mirrors...', $repo->getCallsign())); pht(
"Pushing '%s' to mirrors...",
$repo->getDisplayName()));
$engine = id(new PhabricatorRepositoryMirrorEngine()) $engine = id(new PhabricatorRepositoryMirrorEngine())
->setRepository($repo) ->setRepository($repo)
@ -43,7 +45,7 @@ final class PhabricatorRepositoryManagementMirrorWorkflow
->pushToMirrors(); ->pushToMirrors();
} }
$console->writeOut('%s\b', pht('Done.')); $console->writeOut("%s\n", pht('Done.'));
return 0; return 0;
} }

View file

@ -7,7 +7,7 @@ final class PhabricatorRepositoryManagementPullWorkflow
$this $this
->setName('pull') ->setName('pull')
->setExamples('**pull** __repository__ ...') ->setExamples('**pull** __repository__ ...')
->setSynopsis(pht('Pull __repository__, named by callsign.')) ->setSynopsis(pht('Pull __repository__.'))
->setArguments( ->setArguments(
array( array(
array( array(
@ -26,12 +26,16 @@ final class PhabricatorRepositoryManagementPullWorkflow
if (!$repos) { if (!$repos) {
throw new PhutilArgumentUsageException( throw new PhutilArgumentUsageException(
pht('Specify one or more repositories to pull, by callsign.')); pht('Specify one or more repositories to pull.'));
} }
$console = PhutilConsole::getConsole(); $console = PhutilConsole::getConsole();
foreach ($repos as $repo) { foreach ($repos as $repo) {
$console->writeOut("%s\n", pht("Pulling '%s'...", $repo->getCallsign())); $console->writeOut(
"%s\n",
pht(
'Pulling "%s"...',
$repo->getDisplayName()));
id(new PhabricatorRepositoryPullEngine()) id(new PhabricatorRepositoryPullEngine())
->setRepository($repo) ->setRepository($repo)

View file

@ -7,7 +7,7 @@ final class PhabricatorRepositoryManagementRefsWorkflow
$this $this
->setName('refs') ->setName('refs')
->setExamples('**refs** [__options__] __repository__ ...') ->setExamples('**refs** [__options__] __repository__ ...')
->setSynopsis(pht('Update refs in __repository__, named by callsign.')) ->setSynopsis(pht('Update refs in __repository__.'))
->setArguments( ->setArguments(
array( array(
array( array(
@ -27,15 +27,16 @@ final class PhabricatorRepositoryManagementRefsWorkflow
if (!$repos) { if (!$repos) {
throw new PhutilArgumentUsageException( throw new PhutilArgumentUsageException(
pht( pht(
'Specify one or more repositories to update refs for, '. 'Specify one or more repositories to update refs for.'));
'by callsign.'));
} }
$console = PhutilConsole::getConsole(); $console = PhutilConsole::getConsole();
foreach ($repos as $repo) { foreach ($repos as $repo) {
$console->writeOut( $console->writeOut(
"%s\n", "%s\n",
pht("Updating refs in '%s'...", $repo->getCallsign())); pht(
'Updating refs in "%s"...',
$repo->getDisplayName()));
$engine = id(new PhabricatorRepositoryRefEngine()) $engine = id(new PhabricatorRepositoryRefEngine())
->setRepository($repo) ->setRepository($repo)

View file

@ -28,7 +28,7 @@ final class PhabricatorRepositoryManagementReparseWorkflow
), ),
array( array(
'name' => 'all', 'name' => 'all',
'param' => 'callsign or phid', 'param' => 'repository',
'help' => pht( 'help' => pht(
'Reparse all commits in the specified repository. This mode '. 'Reparse all commits in the specified repository. This mode '.
'queues parsers into the task queue; you must run taskmasters '. 'queues parsers into the task queue; you must run taskmasters '.
@ -192,16 +192,16 @@ final class PhabricatorRepositoryManagementReparseWorkflow
$commits = array(); $commits = array();
if ($all_from_repo) { if ($all_from_repo) {
$repository = id(new PhabricatorRepository())->loadOneWhere( $repository = id(new PhabricatorRepositoryQuery())
'callsign = %s OR phid = %s', ->setViewer(PhabricatorUser::getOmnipotentUser())
$all_from_repo, ->withIdentifiers(array($all_from_repo))
$all_from_repo); ->executeOne();
if (!$repository) { if (!$repository) {
throw new PhutilArgumentUsageException( throw new PhutilArgumentUsageException(
pht('Unknown repository %s!', $all_from_repo)); pht('Unknown repository "%s"!', $all_from_repo));
} }
$query = id(new DiffusionCommitQuery()) $query = id(new DiffusionCommitQuery())
->setViewer(PhabricatorUser::getOmnipotentUser()) ->setViewer(PhabricatorUser::getOmnipotentUser())
->withRepository($repository); ->withRepository($repository);
@ -216,46 +216,14 @@ final class PhabricatorRepositoryManagementReparseWorkflow
$commits = $query->execute(); $commits = $query->execute();
$callsign = $repository->getCallsign();
if (!$commits) { if (!$commits) {
throw new PhutilArgumentUsageException( throw new PhutilArgumentUsageException(
pht( pht(
'No commits have been discovered in %s repository!', 'No commits have been discovered in the "%s" repository!',
$callsign)); $repository->getDisplayName()));
} }
} else { } else {
$commits = array(); $commits = $this->loadNamedCommits($reparse_what);
foreach ($reparse_what as $identifier) {
$matches = null;
if (!preg_match('/r([A-Z]+)([a-z0-9]+)/', $identifier, $matches)) {
throw new PhutilArgumentUsageException(pht(
"Can't parse commit identifier: %s",
$identifier));
}
$callsign = $matches[1];
$commit_identifier = $matches[2];
$repository = id(new PhabricatorRepository())->loadOneWhere(
'callsign = %s',
$callsign);
if (!$repository) {
throw new PhutilArgumentUsageException(pht(
"No repository with callsign '%s'!",
$callsign));
}
$commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
'repositoryID = %d AND commitIdentifier = %s',
$repository->getID(),
$commit_identifier);
if (!$commit) {
throw new PhutilArgumentUsageException(pht(
"No matching commit '%s' in repository '%s'. ".
"(For git and mercurial repositories, you must specify the entire ".
"commit hash.)",
$commit_identifier,
$callsign));
}
$commits[] = $commit;
}
} }
if ($all_from_repo && !$force_local) { if ($all_from_repo && !$force_local) {
@ -273,6 +241,8 @@ final class PhabricatorRepositoryManagementReparseWorkflow
$tasks = array(); $tasks = array();
foreach ($commits as $commit) { foreach ($commits as $commit) {
$repository = $commit->getRepository();
if ($importing) { if ($importing) {
$status = $commit->getImportStatus(); $status = $commit->getImportStatus();
// Find the first missing import step and queue that up. // Find the first missing import step and queue that up.

View file

@ -20,9 +20,9 @@ final class PhabricatorRepositoryManagementUpdateWorkflow
->setExamples('**update** [options] __repository__') ->setExamples('**update** [options] __repository__')
->setSynopsis( ->setSynopsis(
pht( pht(
'Update __repository__, named by callsign. '. 'Update __repository__. This performs the __pull__, __discover__, '.
'This performs the __pull__, __discover__, __ref__ and __mirror__ '. '__ref__ and __mirror__ operations and is primarily an internal '.
'operations and is primarily an internal workflow.')) 'workflow.'))
->setArguments( ->setArguments(
array( array(
array( array(
@ -47,7 +47,7 @@ final class PhabricatorRepositoryManagementUpdateWorkflow
$repos = $this->loadRepositories($args, 'repos'); $repos = $this->loadRepositories($args, 'repos');
if (count($repos) !== 1) { if (count($repos) !== 1) {
throw new PhutilArgumentUsageException( throw new PhutilArgumentUsageException(
pht('Specify exactly one repository to update, by callsign.')); pht('Specify exactly one repository to update.'));
} }
$repository = head($repos); $repository = head($repos);

View file

@ -4,26 +4,32 @@ abstract class PhabricatorRepositoryManagementWorkflow
extends PhabricatorManagementWorkflow { extends PhabricatorManagementWorkflow {
protected function loadRepositories(PhutilArgumentParser $args, $param) { protected function loadRepositories(PhutilArgumentParser $args, $param) {
$callsigns = $args->getArg($param); $identifiers = $args->getArg($param);
if (!$callsigns) { if (!$identifiers) {
return null; return null;
} }
$repos = id(new PhabricatorRepositoryQuery()) $query = id(new PhabricatorRepositoryQuery())
->setViewer($this->getViewer()) ->setViewer($this->getViewer())
->withCallsigns($callsigns) ->withIdentifiers($identifiers);
->execute();
$repos = mpull($repos, null, 'getCallsign'); $query->execute();
foreach ($callsigns as $callsign) {
if (empty($repos[$callsign])) { $map = $query->getIdentifierMap();
foreach ($identifiers as $identifier) {
if (empty($map[$identifier])) {
throw new PhutilArgumentUsageException( throw new PhutilArgumentUsageException(
pht("No repository with callsign '%s' exists!", $callsign)); pht(
'Repository "%s" does not exist!',
$identifier));
} }
} }
return $repos; // Reorder repositories according to argument order.
$repositories = array_select_keys($map, $identifiers);
return array_values($repositories);
} }
protected function loadCommits(PhutilArgumentParser $args, $param) { protected function loadCommits(PhutilArgumentParser $args, $param) {

View file

@ -49,7 +49,7 @@ final class PhabricatorRepositoryRepositoryPHIDType
} }
public function canLoadNamedObject($name) { public function canLoadNamedObject($name) {
return preg_match('/^r[A-Z]+|R[0-9]+$/', $name); return preg_match('/^r[A-Z]+|R[1-9]\d*\z/', $name);
} }
public function loadNamedObjects( public function loadNamedObjects(

View file

@ -15,6 +15,7 @@ final class PhabricatorRepositoryQuery
private $numericIdentifiers; private $numericIdentifiers;
private $callsignIdentifiers; private $callsignIdentifiers;
private $phidIdentifiers; private $phidIdentifiers;
private $monogramIdentifiers;
private $identifierMap; private $identifierMap;
@ -48,10 +49,16 @@ final class PhabricatorRepositoryQuery
} }
public function withIdentifiers(array $identifiers) { public function withIdentifiers(array $identifiers) {
$ids = array(); $callsigns = array(); $phids = array(); $ids = array();
$callsigns = array();
$phids = array();
$monograms = array();
foreach ($identifiers as $identifier) { foreach ($identifiers as $identifier) {
if (ctype_digit($identifier)) { if (ctype_digit($identifier)) {
$ids[$identifier] = $identifier; $ids[$identifier] = $identifier;
} else if (preg_match('/^(r[A-Z]+)|(R[1-9]\d*)\z/', $identifier)) {
$monograms[$identifier] = $identifier;
} else { } else {
$repository_type = PhabricatorRepositoryRepositoryPHIDType::TYPECONST; $repository_type = PhabricatorRepositoryRepositoryPHIDType::TYPECONST;
if (phid_get_type($identifier) === $repository_type) { if (phid_get_type($identifier) === $repository_type) {
@ -65,6 +72,8 @@ final class PhabricatorRepositoryQuery
$this->numericIdentifiers = $ids; $this->numericIdentifiers = $ids;
$this->callsignIdentifiers = $callsigns; $this->callsignIdentifiers = $callsigns;
$this->phidIdentifiers = $phids; $this->phidIdentifiers = $phids;
$this->monogramIdentifiers = $monograms;
return $this; return $this;
} }
@ -273,6 +282,21 @@ final class PhabricatorRepositoryQuery
} }
} }
if ($this->monogramIdentifiers) {
$monogram_map = array();
foreach ($repositories as $repository) {
foreach ($repository->getAllMonograms() as $monogram) {
$monogram_map[$monogram] = $repository;
}
}
foreach ($this->monogramIdentifiers as $monogram) {
if (isset($monogram_map[$monogram])) {
$this->identifierMap[$monogram] = $monogram_map[$monogram];
}
}
}
return $repositories; return $repositories;
} }
@ -447,7 +471,8 @@ final class PhabricatorRepositoryQuery
if ($this->numericIdentifiers || if ($this->numericIdentifiers ||
$this->callsignIdentifiers || $this->callsignIdentifiers ||
$this->phidIdentifiers) { $this->phidIdentifiers ||
$this->monogramIdentifiers) {
$identifier_clause = array(); $identifier_clause = array();
if ($this->numericIdentifiers) { if ($this->numericIdentifiers) {
@ -471,6 +496,33 @@ final class PhabricatorRepositoryQuery
$this->phidIdentifiers); $this->phidIdentifiers);
} }
if ($this->monogramIdentifiers) {
$monogram_callsigns = array();
$monogram_ids = array();
foreach ($this->monogramIdentifiers as $identifier) {
if ($identifier[0] == 'r') {
$monogram_callsigns[] = substr($identifier, 1);
} else {
$monogram_ids[] = substr($identifier, 1);
}
}
if ($monogram_ids) {
$identifier_clause[] = qsprintf(
$conn,
'r.id IN (%Ld)',
$monogram_ids);
}
if ($monogram_callsigns) {
$identifier_clause[] = qsprintf(
$conn,
'r.callsign IN (%Ls)',
$monogram_callsigns);
}
}
$where = array('('.implode(' OR ', $identifier_clause).')'); $where = array('('.implode(' OR ', $identifier_clause).')');
} }

View file

@ -151,6 +151,26 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
return 'r'.$this->getCallsign(); return 'r'.$this->getCallsign();
} }
public function getDisplayName() {
// TODO: This is intended to produce a human-readable name that is not
// necessarily a global, unique identifier. Eventually, it may just return
// a string like "skynet" instead of "rSKYNET".
return $this->getMonogram();
}
public function getAllMonograms() {
$monograms = array();
$monograms[] = 'R'.$this->getID();
$callsign = $this->getCallsign();
if (strlen($callsign)) {
$monograms[] = 'r'.$callsign;
}
return $monograms;
}
public function getDetail($key, $default = null) { public function getDetail($key, $default = null) {
return idx($this->details, $key, $default); return idx($this->details, $key, $default);
} }