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

When observing a repository, switch to "importing" mode on a large discovery in an empty repository

Summary:
Ref T10923. Fixes T9554.

When hosting a repository, we currently have a heuristic that tries to detect when you're doing an initial import: if you push more than 7 commits to an empty repository, it counts as an import and we disable mail/feed/etc.

Do something similar for observed repositories: if the repository is empty and we discover more than 7 commits, switch to import mode until we catch up.

This should align behavior with user expectation more often when juggling hosted vs imported repositories.

Test Plan:
- Created a new hosted repository.
- Activated it and allowed it to fully import.
- Added an "Observe URI".
- Saw it automatically drop into "Importing" mode until the import completed.
- Swapped it back to hosted mode.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9554, T10923

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

+56 -11
+2 -9
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
··· 172 172 173 173 if ($this->isInitialImport($all_updates)) { 174 174 $repository = $this->getRepository(); 175 - 176 - $repository->openTransaction(); 177 - $repository->beginReadLocking(); 178 - $repository = $repository->reload(); 179 - $repository->setDetail('importing', true); 180 - $repository->save(); 181 - $repository->endReadLocking(); 182 - $repository->saveTransaction(); 175 + $repository->markImporting(); 183 176 } 184 177 185 178 if ($this->emailPHIDs) { ··· 1244 1237 $commit_count++; 1245 1238 } 1246 1239 1247 - if ($commit_count <= 7) { 1240 + if ($commit_count <= PhabricatorRepository::IMPORT_THRESHOLD) { 1248 1241 // If this pushes a very small number of commits, assume it's an 1249 1242 // initial commit or stack of a few initial commits. 1250 1243 return false;
+36
src/applications/repository/engine/PhabricatorRepositoryDiscoveryEngine.php
··· 52 52 throw new Exception(pht("Unknown VCS '%s'!", $vcs)); 53 53 } 54 54 55 + if ($this->isInitialImport($refs)) { 56 + $this->log( 57 + pht( 58 + 'Discovered more than %s commit(s) in an empty repository, '. 59 + 'marking repository as importing.', 60 + new PhutilNumber(PhabricatorRepository::IMPORT_THRESHOLD))); 61 + 62 + $repository->markImporting(); 63 + } 64 + 55 65 // Clear the working set cache. 56 66 $this->workingSet = array(); 57 67 ··· 577 587 $data['commitID'] = $commit->getID(); 578 588 579 589 PhabricatorWorker::scheduleTask($class, $data); 590 + } 591 + 592 + private function isInitialImport(array $refs) { 593 + $commit_count = count($refs); 594 + 595 + if ($commit_count <= PhabricatorRepository::IMPORT_THRESHOLD) { 596 + // If we fetched a small number of commits, assume it's an initial 597 + // commit or a stack of a few initial commits. 598 + return false; 599 + } 600 + 601 + $viewer = $this->getViewer(); 602 + $repository = $this->getRepository(); 603 + 604 + $any_commits = id(new DiffusionCommitQuery()) 605 + ->setViewer($viewer) 606 + ->withRepository($repository) 607 + ->setLimit(1) 608 + ->execute(); 609 + 610 + if ($any_commits) { 611 + // If the repository already has commits, this isn't an import. 612 + return false; 613 + } 614 + 615 + return true; 580 616 } 581 617 582 618 }
-1
src/applications/repository/engine/__tests__/PhabricatorWorkingCopyTestCase.php
··· 71 71 $this->didConstructRepository($repo); 72 72 73 73 $repo->save(); 74 - $repo->makeEphemeral(); 75 74 76 75 // Keep the disk resources around until we exit. 77 76 $this->dirs[] = $dir;
+18 -1
src/applications/repository/storage/PhabricatorRepository.php
··· 26 26 */ 27 27 const MINIMUM_QUALIFIED_HASH = 5; 28 28 29 + /** 30 + * Minimum number of commits to an empty repository to trigger "import" mode. 31 + */ 32 + const IMPORT_THRESHOLD = 7; 33 + 29 34 const TABLE_PATH = 'repository_path'; 30 35 const TABLE_PATHCHANGE = 'repository_pathchange'; 31 36 const TABLE_FILESYSTEM = 'repository_filesystem'; ··· 354 359 if (!strlen($name)) { 355 360 $name = $this->getName(); 356 361 $name = phutil_utf8_strtolower($name); 357 - $name = preg_replace('@[/ -:]+@', '-', $name); 362 + $name = preg_replace('@[/ -:<>]+@', '-', $name); 358 363 $name = trim($name, '-'); 359 364 if (!strlen($name)) { 360 365 $name = $this->getCallsign(); ··· 2153 2158 } 2154 2159 2155 2160 return $service; 2161 + } 2162 + 2163 + public function markImporting() { 2164 + $this->openTransaction(); 2165 + $this->beginReadLocking(); 2166 + $repository = $this->reload(); 2167 + $repository->setDetail('importing', true); 2168 + $repository->save(); 2169 + $this->endReadLocking(); 2170 + $this->saveTransaction(); 2171 + 2172 + return $repository; 2156 2173 } 2157 2174 2158 2175