@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 an "Unreachable" flag for commits and revive them during discovery

Summary:
Ref T9028. This is the easy part of dealing with deleted commits:

- Add a flag for unreachable commits (nothing sets this flag yet).
- Ignore unreachable commits when querying for known commits during discovery, so we pretend they do not exist.
- When recording a commit, try just reviving an existing unreachable commit first. If that works, bail out.

Test Plan:
- Artificially marked a commit as unreachable with raw SQL.
- Verified it said "deleted: unreachable" in the UI.
- Ran `repository discover --trace --verbose`.
- Saw the discovery process ignore the commit when filling the cache.
- Saw the discovery process revive the commit instead of trying to record it again.
- Web UI now shows the commit as normal.
- Running `repository discover` again doesn't make any further changes.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9028

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

+38 -7
+6
src/applications/diffusion/controller/DiffusionCommitController.php
··· 129 129 ), 130 130 $message)); 131 131 132 + if ($commit->isUnreachable()) { 133 + $this->commitErrors[] = pht( 134 + 'This commit has been deleted in the repository: it is no longer '. 135 + 'reachable from any branch, tag, or ref.'); 136 + } 137 + 132 138 if ($this->getCommitErrors()) { 133 139 $error_panel = id(new PHUIInfoView()) 134 140 ->appendChild($this->getCommitErrors())
+27 -7
src/applications/repository/engine/PhabricatorRepositoryDiscoveryEngine.php
··· 444 444 return; 445 445 } 446 446 447 + // When filling the cache we ignore commits which have been marked as 448 + // unreachable, treating them as though they do not exist. When recording 449 + // commits later we'll revive commits that exist but are unreachable. 450 + 447 451 $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere( 448 - 'repositoryID = %d AND commitIdentifier IN (%Ls)', 452 + 'repositoryID = %d AND commitIdentifier IN (%Ls) 453 + AND (importStatus & %d) != %d', 449 454 $this->getRepository()->getID(), 450 - $identifiers); 455 + $identifiers, 456 + PhabricatorRepositoryCommit::IMPORTED_UNREACHABLE, 457 + PhabricatorRepositoryCommit::IMPORTED_UNREACHABLE); 451 458 452 459 foreach ($commits as $commit) { 453 460 $this->commitCache[$commit->getCommitIdentifier()] = true; ··· 493 500 array $parents) { 494 501 495 502 $commit = new PhabricatorRepositoryCommit(); 503 + $conn_w = $repository->establishConnection('w'); 504 + 505 + // First, try to revive an existing unreachable commit (if one exists) by 506 + // removing the "unreachable" flag. If we succeed, we don't need to do 507 + // anything else: we already discovered this commit some time ago. 508 + queryfx( 509 + $conn_w, 510 + 'UPDATE %T SET importStatus = (importStatus & ~%d) 511 + WHERE repositoryID = %d AND commitIdentifier = %s', 512 + $commit->getTableName(), 513 + PhabricatorRepositoryCommit::IMPORTED_UNREACHABLE, 514 + $repository->getID(), 515 + $commit_identifier); 516 + if ($conn_w->getAffectedRows()) { 517 + return; 518 + } 519 + 520 + 496 521 $commit->setRepositoryID($repository->getID()); 497 522 $commit->setCommitIdentifier($commit_identifier); 498 523 $commit->setEpoch($epoch); ··· 502 527 503 528 $data = new PhabricatorRepositoryCommitData(); 504 529 505 - $conn_w = $repository->establishConnection('w'); 506 - 507 530 try { 508 - 509 531 // If this commit has parents, look up their IDs. The parent commits 510 532 // should always exist already. 511 533 ··· 582 604 'repository' => $repository, 583 605 'commit' => $commit, 584 606 ))); 585 - 586 - 587 607 588 608 } catch (AphrontDuplicateKeyQueryException $ex) { 589 609 $commit->killTransaction();
+5
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 32 32 const IMPORTED_ALL = 15; 33 33 34 34 const IMPORTED_CLOSEABLE = 1024; 35 + const IMPORTED_UNREACHABLE = 2048; 35 36 36 37 private $commitData = self::ATTACHABLE; 37 38 private $audits = self::ATTACHABLE; ··· 56 57 57 58 public function isImported() { 58 59 return $this->isPartiallyImported(self::IMPORTED_ALL); 60 + } 61 + 62 + public function isUnreachable() { 63 + return $this->isPartiallyImported(self::IMPORTED_UNREACHABLE); 59 64 } 60 65 61 66 public function writeImportStatusFlag($flag) {