@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.

Add workflow to create repository identities

Summary:
Depends on D19443. Creates a workflow for populating the new identity table by iterating over commits, either one repo at a time or all at once. Locally caches identities to avoid fetching them `inf` times. An actual migration that invokes this workflow will come in another revision that won't land until at least next week.

Performance is ~2k commits in 4.9s on my local machine.

Test Plan: Ran locally a few times with a few different states of the `repository_identity` table.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: jcox, Korvin, PHID-OPKG-gm6ozazyms6q6i22gyam

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

+104 -1
+2
src/__phutil_library_map__.php
··· 4118 4118 'PhabricatorRepositoryManagementMovePathsWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementMovePathsWorkflow.php', 4119 4119 'PhabricatorRepositoryManagementParentsWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementParentsWorkflow.php', 4120 4120 'PhabricatorRepositoryManagementPullWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php', 4121 + 'PhabricatorRepositoryManagementRebuildIdentitiesWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementRebuildIdentitiesWorkflow.php', 4121 4122 'PhabricatorRepositoryManagementRefsWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementRefsWorkflow.php', 4122 4123 'PhabricatorRepositoryManagementReparseWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementReparseWorkflow.php', 4123 4124 'PhabricatorRepositoryManagementThawWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementThawWorkflow.php', ··· 10031 10032 'PhabricatorRepositoryManagementMovePathsWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 10032 10033 'PhabricatorRepositoryManagementParentsWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 10033 10034 'PhabricatorRepositoryManagementPullWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 10035 + 'PhabricatorRepositoryManagementRebuildIdentitiesWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 10034 10036 'PhabricatorRepositoryManagementRefsWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 10035 10037 'PhabricatorRepositoryManagementReparseWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 10036 10038 'PhabricatorRepositoryManagementThawWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
+101
src/applications/repository/management/PhabricatorRepositoryManagementRebuildIdentitiesWorkflow.php
··· 1 + <?php 2 + 3 + final class PhabricatorRepositoryManagementRebuildIdentitiesWorkflow 4 + extends PhabricatorRepositoryManagementWorkflow { 5 + 6 + protected function didConstruct() { 7 + $this 8 + ->setName('rebuild-identities') 9 + ->setExamples( 10 + '**rebuild-identities** [__options__] __repository__') 11 + ->setSynopsis(pht('Rebuild repository identities from commits.')) 12 + ->setArguments( 13 + array( 14 + array( 15 + 'name' => 'repositories', 16 + 'wildcard' => true, 17 + ), 18 + array( 19 + 'name' => 'all', 20 + 'help' => pht('Rebuild identities across all repositories.'), 21 + ), 22 + )); 23 + } 24 + 25 + public function execute(PhutilArgumentParser $args) { 26 + $console = PhutilConsole::getConsole(); 27 + 28 + $all = $args->getArg('all'); 29 + $repositories = $args->getArg('repositories'); 30 + 31 + if ($all xor empty($repositories)) { 32 + throw new PhutilArgumentUsageException( 33 + pht('Specify --all or a list of repositories, but not both.')); 34 + } 35 + 36 + $query = id(new DiffusionCommitQuery()) 37 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 38 + ->needCommitData(true); 39 + 40 + if ($repositories) { 41 + $repos = $this->loadRepositories($args, 'repositories'); 42 + $query->withRepositoryIDs(mpull($repos, 'getID')); 43 + } 44 + 45 + $iterator = new PhabricatorQueryIterator($query); 46 + foreach ($iterator as $commit) { 47 + $data = $commit->getCommitData(); 48 + $author_name = $data->getAuthorName(); 49 + $author_identity = $this->getIdentityForCommit( 50 + $commit, $author_name); 51 + 52 + $commit->setAuthorIdentityPHID($author_identity->getPHID()); 53 + $data->setCommitDetail( 54 + 'authorIdentityPHID', $author_identity->getPHID()); 55 + 56 + $committer_name = $data->getCommitDetail('committer', null); 57 + if ($committer_name) { 58 + $committer_identity = $this->getIdentityForCommit( 59 + $commit, $committer_name); 60 + 61 + $commit->setCommitterIdentityPHID($committer_identity->getPHID()); 62 + $data->setCommitDetail( 63 + 'committerIdentityPHID', $committer_identity->getPHID()); 64 + } 65 + 66 + $commit->save(); 67 + $data->save(); 68 + } 69 + 70 + } 71 + 72 + private function getIdentityForCommit( 73 + PhabricatorRepositoryCommit $commit, $identity_name) { 74 + 75 + static $seen = array(); 76 + $identity_key = PhabricatorHash::digestForIndex($identity_name); 77 + if (empty($seen[$identity_key])) { 78 + try { 79 + $user_phid = id(new DiffusionResolveUserQuery()) 80 + ->withCommit($commit) 81 + ->withName($identity_name) 82 + ->execute(); 83 + 84 + $identity = id(new PhabricatorRepositoryIdentity()) 85 + ->setAuthorPHID($commit->getPHID()) 86 + ->setIdentityName($identity_name) 87 + ->setAutomaticGuessedUserPHID($user_phid) 88 + ->save(); 89 + } catch (AphrontDuplicateKeyQueryException $ex) { 90 + // Somehow this identity already exists? 91 + $identity = id(new PhabricatorRepositoryIdentityQuery()) 92 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 93 + ->withIdentityNames(array($identity_name)) 94 + ->executeOne(); 95 + } 96 + $seen[$identity_key] = $identity; 97 + } 98 + 99 + return $seen[$identity_key]; 100 + } 101 + }
+1 -1
src/applications/repository/management/PhabricatorRepositoryManagementReparseWorkflow.php
··· 6 6 protected function didConstruct() { 7 7 $this 8 8 ->setName('reparse') 9 - ->setExamples('**reparse** [options] __repository__') 9 + ->setExamples('**reparse** [options] __commit__') 10 10 ->setSynopsis( 11 11 pht( 12 12 '**reparse** __what__ __which_parts__ [--trace] [--force]'."\n\n".