@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+156 -90
+5 -3
src/applications/repository/management/PhabricatorRepositoryManagementDiscoverWorkflow.php
··· 7 7 $this 8 8 ->setName('discover') 9 9 ->setExamples('**discover** [__options__] __repository__ ...') 10 - ->setSynopsis(pht('Discover __repository__, named by callsign.')) 10 + ->setSynopsis(pht('Discover __repository__.')) 11 11 ->setArguments( 12 12 array( 13 13 array( ··· 31 31 32 32 if (!$repos) { 33 33 throw new PhutilArgumentUsageException( 34 - pht('Specify one or more repositories to discover, by callsign.')); 34 + pht('Specify one or more repositories to discover.')); 35 35 } 36 36 37 37 $console = PhutilConsole::getConsole(); 38 38 foreach ($repos as $repo) { 39 39 $console->writeOut( 40 40 "%s\n", 41 - pht("Discovering '%s'...", $repo->getCallsign())); 41 + pht( 42 + 'Discovering "%s"...', 43 + $repo->getDisplayName())); 42 44 43 45 id(new PhabricatorRepositoryDiscoveryEngine()) 44 46 ->setRepository($repo)
+7 -4
src/applications/repository/management/PhabricatorRepositoryManagementEditWorkflow.php
··· 9 9 ->setExamples('**edit** --as __username__ __repository__ ...') 10 10 ->setSynopsis( 11 11 pht( 12 - 'Edit __repository__, named by callsign '. 13 - '(will eventually be deprecated by Conduit).')) 12 + 'Edit __repository__ (will eventually be deprecated by Conduit).')) 14 13 ->setArguments( 15 14 array( 16 15 array( ··· 45 44 46 45 if (!$repos) { 47 46 throw new PhutilArgumentUsageException( 48 - pht('Specify one or more repositories to edit, by callsign.')); 47 + pht('Specify one or more repositories to edit.')); 49 48 } 50 49 51 50 $console = PhutilConsole::getConsole(); ··· 76 75 } 77 76 78 77 foreach ($repos as $repo) { 79 - $console->writeOut("%s\n", pht("Editing '%s'...", $repo->getCallsign())); 78 + $console->writeOut( 79 + "%s\n", 80 + pht( 81 + 'Editing "%s"...', 82 + $repo->getDisplayName())); 80 83 81 84 $xactions = array(); 82 85
+3 -5
src/applications/repository/management/PhabricatorRepositoryManagementImportingWorkflow.php
··· 9 9 ->setExamples('**importing** __repository__ ...') 10 10 ->setSynopsis( 11 11 pht( 12 - 'Show commits in __repository__, named by callsign, which are '. 13 - 'still importing.')) 12 + 'Show commits in __repository__ which are still importing.')) 14 13 ->setArguments( 15 14 array( 16 15 array( ··· 30 29 if (!$repos) { 31 30 throw new PhutilArgumentUsageException( 32 31 pht( 33 - 'Specify one or more repositories to find importing commits for, '. 34 - 'by callsign.')); 32 + 'Specify one or more repositories to find importing commits for.')); 35 33 } 36 34 37 35 $repos = mpull($repos, null, 'getID'); ··· 54 52 $repo = $repos[$row['repositoryID']]; 55 53 $identifier = $row['commitIdentifier']; 56 54 57 - $console->writeOut('%s', 'r'.$repo->getCallsign().$identifier); 55 + $console->writeOut('%s', $repo->formatCommitName($identifier)); 58 56 59 57 if (!$args->getArg('simple')) { 60 58 $status = $row['importStatus'];
+1 -1
src/applications/repository/management/PhabricatorRepositoryManagementListWorkflow.php
··· 18 18 ->execute(); 19 19 if ($repos) { 20 20 foreach ($repos as $repo) { 21 - $console->writeOut("%s\n", $repo->getCallsign()); 21 + $console->writeOut("%s\n", $repo->getMonogram()); 22 22 } 23 23 } else { 24 24 $console->writeErr("%s\n", pht('There are no repositories.'));
+15 -7
src/applications/repository/management/PhabricatorRepositoryManagementMarkImportedWorkflow.php
··· 7 7 $this 8 8 ->setName('mark-imported') 9 9 ->setExamples('**mark-imported** __repository__ ...') 10 - ->setSynopsis(pht('Mark __repository__, named by callsign, as imported.')) 10 + ->setSynopsis(pht('Mark __repository__ as imported.')) 11 11 ->setArguments( 12 12 array( 13 13 array( ··· 26 26 27 27 if (!$repos) { 28 28 throw new PhutilArgumentUsageException( 29 - pht('Specify one or more repositories to mark imported, by callsign.')); 29 + pht('Specify one or more repositories to mark imported.')); 30 30 } 31 31 32 32 $new_importing_value = (bool)$args->getArg('mark-not-imported'); 33 33 34 34 $console = PhutilConsole::getConsole(); 35 35 foreach ($repos as $repo) { 36 - $callsign = $repo->getCallsign(); 36 + $name = $repo->getDisplayName(); 37 37 38 38 if ($repo->isImporting() && $new_importing_value) { 39 39 $console->writeOut( 40 40 "%s\n", 41 - pht("Repository '%s' is already importing.", $callsign)); 41 + pht( 42 + 'Repository "%s" is already importing.', 43 + $name)); 42 44 } else if (!$repo->isImporting() && !$new_importing_value) { 43 45 $console->writeOut( 44 46 "%s\n", 45 - pht("Repository '%s' is already imported.", $callsign)); 47 + pht( 48 + 'Repository "%s" is already imported.', 49 + $name)); 46 50 } else { 47 51 if ($new_importing_value) { 48 52 $console->writeOut( 49 53 "%s\n", 50 - pht("Marking repository '%s' as importing.", $callsign)); 54 + pht( 55 + 'Marking repository "%s" as importing.', 56 + $name)); 51 57 } else { 52 58 $console->writeOut( 53 59 "%s\n", 54 - pht("Marking repository '%s' as imported.", $callsign)); 60 + pht( 61 + 'Marking repository "%s" as imported.', 62 + $name)); 55 63 } 56 64 57 65 $repo->setDetail('importing', $new_importing_value);
+6 -4
src/applications/repository/management/PhabricatorRepositoryManagementMirrorWorkflow.php
··· 8 8 ->setName('mirror') 9 9 ->setExamples('**mirror** [__options__] __repository__ ...') 10 10 ->setSynopsis( 11 - pht('Push __repository__, named by callsign, to mirrors.')) 11 + pht('Push __repository__ to mirrors.')) 12 12 ->setArguments( 13 13 array( 14 14 array( ··· 28 28 if (!$repos) { 29 29 throw new PhutilArgumentUsageException( 30 30 pht( 31 - 'Specify one or more repositories to push to mirrors, by callsign.')); 31 + 'Specify one or more repositories to push to mirrors.')); 32 32 } 33 33 34 34 $console = PhutilConsole::getConsole(); 35 35 foreach ($repos as $repo) { 36 36 $console->writeOut( 37 37 "%s\n", 38 - pht('Pushing "%s" to mirrors...', $repo->getCallsign())); 38 + pht( 39 + "Pushing '%s' to mirrors...", 40 + $repo->getDisplayName())); 39 41 40 42 $engine = id(new PhabricatorRepositoryMirrorEngine()) 41 43 ->setRepository($repo) ··· 43 45 ->pushToMirrors(); 44 46 } 45 47 46 - $console->writeOut('%s\b', pht('Done.')); 48 + $console->writeOut("%s\n", pht('Done.')); 47 49 48 50 return 0; 49 51 }
+7 -3
src/applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php
··· 7 7 $this 8 8 ->setName('pull') 9 9 ->setExamples('**pull** __repository__ ...') 10 - ->setSynopsis(pht('Pull __repository__, named by callsign.')) 10 + ->setSynopsis(pht('Pull __repository__.')) 11 11 ->setArguments( 12 12 array( 13 13 array( ··· 26 26 27 27 if (!$repos) { 28 28 throw new PhutilArgumentUsageException( 29 - pht('Specify one or more repositories to pull, by callsign.')); 29 + pht('Specify one or more repositories to pull.')); 30 30 } 31 31 32 32 $console = PhutilConsole::getConsole(); 33 33 foreach ($repos as $repo) { 34 - $console->writeOut("%s\n", pht("Pulling '%s'...", $repo->getCallsign())); 34 + $console->writeOut( 35 + "%s\n", 36 + pht( 37 + 'Pulling "%s"...', 38 + $repo->getDisplayName())); 35 39 36 40 id(new PhabricatorRepositoryPullEngine()) 37 41 ->setRepository($repo)
+5 -4
src/applications/repository/management/PhabricatorRepositoryManagementRefsWorkflow.php
··· 7 7 $this 8 8 ->setName('refs') 9 9 ->setExamples('**refs** [__options__] __repository__ ...') 10 - ->setSynopsis(pht('Update refs in __repository__, named by callsign.')) 10 + ->setSynopsis(pht('Update refs in __repository__.')) 11 11 ->setArguments( 12 12 array( 13 13 array( ··· 27 27 if (!$repos) { 28 28 throw new PhutilArgumentUsageException( 29 29 pht( 30 - 'Specify one or more repositories to update refs for, '. 31 - 'by callsign.')); 30 + 'Specify one or more repositories to update refs for.')); 32 31 } 33 32 34 33 $console = PhutilConsole::getConsole(); 35 34 foreach ($repos as $repo) { 36 35 $console->writeOut( 37 36 "%s\n", 38 - pht("Updating refs in '%s'...", $repo->getCallsign())); 37 + pht( 38 + 'Updating refs in "%s"...', 39 + $repo->getDisplayName())); 39 40 40 41 $engine = id(new PhabricatorRepositoryRefEngine()) 41 42 ->setRepository($repo)
+12 -42
src/applications/repository/management/PhabricatorRepositoryManagementReparseWorkflow.php
··· 28 28 ), 29 29 array( 30 30 'name' => 'all', 31 - 'param' => 'callsign or phid', 31 + 'param' => 'repository', 32 32 'help' => pht( 33 33 'Reparse all commits in the specified repository. This mode '. 34 34 'queues parsers into the task queue; you must run taskmasters '. ··· 192 192 193 193 $commits = array(); 194 194 if ($all_from_repo) { 195 - $repository = id(new PhabricatorRepository())->loadOneWhere( 196 - 'callsign = %s OR phid = %s', 197 - $all_from_repo, 198 - $all_from_repo); 195 + $repository = id(new PhabricatorRepositoryQuery()) 196 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 197 + ->withIdentifiers(array($all_from_repo)) 198 + ->executeOne(); 199 + 199 200 if (!$repository) { 200 201 throw new PhutilArgumentUsageException( 201 - pht('Unknown repository %s!', $all_from_repo)); 202 + pht('Unknown repository "%s"!', $all_from_repo)); 202 203 } 203 - 204 204 205 205 $query = id(new DiffusionCommitQuery()) 206 206 ->setViewer(PhabricatorUser::getOmnipotentUser()) ··· 216 216 217 217 $commits = $query->execute(); 218 218 219 - $callsign = $repository->getCallsign(); 220 219 if (!$commits) { 221 220 throw new PhutilArgumentUsageException( 222 221 pht( 223 - 'No commits have been discovered in %s repository!', 224 - $callsign)); 222 + 'No commits have been discovered in the "%s" repository!', 223 + $repository->getDisplayName())); 225 224 } 226 225 } else { 227 - $commits = array(); 228 - foreach ($reparse_what as $identifier) { 229 - $matches = null; 230 - if (!preg_match('/r([A-Z]+)([a-z0-9]+)/', $identifier, $matches)) { 231 - throw new PhutilArgumentUsageException(pht( 232 - "Can't parse commit identifier: %s", 233 - $identifier)); 234 - } 235 - $callsign = $matches[1]; 236 - $commit_identifier = $matches[2]; 237 - $repository = id(new PhabricatorRepository())->loadOneWhere( 238 - 'callsign = %s', 239 - $callsign); 240 - if (!$repository) { 241 - throw new PhutilArgumentUsageException(pht( 242 - "No repository with callsign '%s'!", 243 - $callsign)); 244 - } 245 - $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( 246 - 'repositoryID = %d AND commitIdentifier = %s', 247 - $repository->getID(), 248 - $commit_identifier); 249 - if (!$commit) { 250 - throw new PhutilArgumentUsageException(pht( 251 - "No matching commit '%s' in repository '%s'. ". 252 - "(For git and mercurial repositories, you must specify the entire ". 253 - "commit hash.)", 254 - $commit_identifier, 255 - $callsign)); 256 - } 257 - $commits[] = $commit; 258 - } 226 + $commits = $this->loadNamedCommits($reparse_what); 259 227 } 260 228 261 229 if ($all_from_repo && !$force_local) { ··· 273 241 274 242 $tasks = array(); 275 243 foreach ($commits as $commit) { 244 + $repository = $commit->getRepository(); 245 + 276 246 if ($importing) { 277 247 $status = $commit->getImportStatus(); 278 248 // Find the first missing import step and queue that up.
+4 -4
src/applications/repository/management/PhabricatorRepositoryManagementUpdateWorkflow.php
··· 20 20 ->setExamples('**update** [options] __repository__') 21 21 ->setSynopsis( 22 22 pht( 23 - 'Update __repository__, named by callsign. '. 24 - 'This performs the __pull__, __discover__, __ref__ and __mirror__ '. 25 - 'operations and is primarily an internal workflow.')) 23 + 'Update __repository__. This performs the __pull__, __discover__, '. 24 + '__ref__ and __mirror__ operations and is primarily an internal '. 25 + 'workflow.')) 26 26 ->setArguments( 27 27 array( 28 28 array( ··· 47 47 $repos = $this->loadRepositories($args, 'repos'); 48 48 if (count($repos) !== 1) { 49 49 throw new PhutilArgumentUsageException( 50 - pht('Specify exactly one repository to update, by callsign.')); 50 + pht('Specify exactly one repository to update.')); 51 51 } 52 52 53 53 $repository = head($repos);
+16 -10
src/applications/repository/management/PhabricatorRepositoryManagementWorkflow.php
··· 4 4 extends PhabricatorManagementWorkflow { 5 5 6 6 protected function loadRepositories(PhutilArgumentParser $args, $param) { 7 - $callsigns = $args->getArg($param); 7 + $identifiers = $args->getArg($param); 8 8 9 - if (!$callsigns) { 9 + if (!$identifiers) { 10 10 return null; 11 11 } 12 12 13 - $repos = id(new PhabricatorRepositoryQuery()) 13 + $query = id(new PhabricatorRepositoryQuery()) 14 14 ->setViewer($this->getViewer()) 15 - ->withCallsigns($callsigns) 16 - ->execute(); 15 + ->withIdentifiers($identifiers); 17 16 18 - $repos = mpull($repos, null, 'getCallsign'); 19 - foreach ($callsigns as $callsign) { 20 - if (empty($repos[$callsign])) { 17 + $query->execute(); 18 + 19 + $map = $query->getIdentifierMap(); 20 + foreach ($identifiers as $identifier) { 21 + if (empty($map[$identifier])) { 21 22 throw new PhutilArgumentUsageException( 22 - pht("No repository with callsign '%s' exists!", $callsign)); 23 + pht( 24 + 'Repository "%s" does not exist!', 25 + $identifier)); 23 26 } 24 27 } 25 28 26 - return $repos; 29 + // Reorder repositories according to argument order. 30 + $repositories = array_select_keys($map, $identifiers); 31 + 32 + return array_values($repositories); 27 33 } 28 34 29 35 protected function loadCommits(PhutilArgumentParser $args, $param) {
+1 -1
src/applications/repository/phid/PhabricatorRepositoryRepositoryPHIDType.php
··· 49 49 } 50 50 51 51 public function canLoadNamedObject($name) { 52 - return preg_match('/^r[A-Z]+|R[0-9]+$/', $name); 52 + return preg_match('/^r[A-Z]+|R[1-9]\d*\z/', $name); 53 53 } 54 54 55 55 public function loadNamedObjects(
+54 -2
src/applications/repository/query/PhabricatorRepositoryQuery.php
··· 15 15 private $numericIdentifiers; 16 16 private $callsignIdentifiers; 17 17 private $phidIdentifiers; 18 + private $monogramIdentifiers; 18 19 19 20 private $identifierMap; 20 21 ··· 48 49 } 49 50 50 51 public function withIdentifiers(array $identifiers) { 51 - $ids = array(); $callsigns = array(); $phids = array(); 52 + $ids = array(); 53 + $callsigns = array(); 54 + $phids = array(); 55 + $monograms = array(); 56 + 52 57 foreach ($identifiers as $identifier) { 53 58 if (ctype_digit($identifier)) { 54 59 $ids[$identifier] = $identifier; 60 + } else if (preg_match('/^(r[A-Z]+)|(R[1-9]\d*)\z/', $identifier)) { 61 + $monograms[$identifier] = $identifier; 55 62 } else { 56 63 $repository_type = PhabricatorRepositoryRepositoryPHIDType::TYPECONST; 57 64 if (phid_get_type($identifier) === $repository_type) { ··· 65 72 $this->numericIdentifiers = $ids; 66 73 $this->callsignIdentifiers = $callsigns; 67 74 $this->phidIdentifiers = $phids; 75 + $this->monogramIdentifiers = $monograms; 76 + 68 77 return $this; 69 78 } 70 79 ··· 273 282 } 274 283 } 275 284 285 + if ($this->monogramIdentifiers) { 286 + $monogram_map = array(); 287 + foreach ($repositories as $repository) { 288 + foreach ($repository->getAllMonograms() as $monogram) { 289 + $monogram_map[$monogram] = $repository; 290 + } 291 + } 292 + 293 + foreach ($this->monogramIdentifiers as $monogram) { 294 + if (isset($monogram_map[$monogram])) { 295 + $this->identifierMap[$monogram] = $monogram_map[$monogram]; 296 + } 297 + } 298 + } 299 + 276 300 return $repositories; 277 301 } 278 302 ··· 447 471 448 472 if ($this->numericIdentifiers || 449 473 $this->callsignIdentifiers || 450 - $this->phidIdentifiers) { 474 + $this->phidIdentifiers || 475 + $this->monogramIdentifiers) { 451 476 $identifier_clause = array(); 452 477 453 478 if ($this->numericIdentifiers) { ··· 469 494 $conn, 470 495 'r.phid IN (%Ls)', 471 496 $this->phidIdentifiers); 497 + } 498 + 499 + if ($this->monogramIdentifiers) { 500 + $monogram_callsigns = array(); 501 + $monogram_ids = array(); 502 + 503 + foreach ($this->monogramIdentifiers as $identifier) { 504 + if ($identifier[0] == 'r') { 505 + $monogram_callsigns[] = substr($identifier, 1); 506 + } else { 507 + $monogram_ids[] = substr($identifier, 1); 508 + } 509 + } 510 + 511 + if ($monogram_ids) { 512 + $identifier_clause[] = qsprintf( 513 + $conn, 514 + 'r.id IN (%Ld)', 515 + $monogram_ids); 516 + } 517 + 518 + if ($monogram_callsigns) { 519 + $identifier_clause[] = qsprintf( 520 + $conn, 521 + 'r.callsign IN (%Ls)', 522 + $monogram_callsigns); 523 + } 472 524 } 473 525 474 526 $where = array('('.implode(' OR ', $identifier_clause).')');
+20
src/applications/repository/storage/PhabricatorRepository.php
··· 151 151 return 'r'.$this->getCallsign(); 152 152 } 153 153 154 + public function getDisplayName() { 155 + // TODO: This is intended to produce a human-readable name that is not 156 + // necessarily a global, unique identifier. Eventually, it may just return 157 + // a string like "skynet" instead of "rSKYNET". 158 + return $this->getMonogram(); 159 + } 160 + 161 + public function getAllMonograms() { 162 + $monograms = array(); 163 + 164 + $monograms[] = 'R'.$this->getID(); 165 + 166 + $callsign = $this->getCallsign(); 167 + if (strlen($callsign)) { 168 + $monograms[] = 'r'.$callsign; 169 + } 170 + 171 + return $monograms; 172 + } 173 + 154 174 public function getDetail($key, $default = null) { 155 175 return idx($this->details, $key, $default); 156 176 }