mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 03:50:54 +01:00
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
This commit is contained in:
parent
2949905c04
commit
ec89c7d63e
3 changed files with 38 additions and 7 deletions
|
@ -129,6 +129,12 @@ final class DiffusionCommitController extends DiffusionController {
|
|||
),
|
||||
$message));
|
||||
|
||||
if ($commit->isUnreachable()) {
|
||||
$this->commitErrors[] = pht(
|
||||
'This commit has been deleted in the repository: it is no longer '.
|
||||
'reachable from any branch, tag, or ref.');
|
||||
}
|
||||
|
||||
if ($this->getCommitErrors()) {
|
||||
$error_panel = id(new PHUIInfoView())
|
||||
->appendChild($this->getCommitErrors())
|
||||
|
|
|
@ -444,10 +444,17 @@ final class PhabricatorRepositoryDiscoveryEngine
|
|||
return;
|
||||
}
|
||||
|
||||
// When filling the cache we ignore commits which have been marked as
|
||||
// unreachable, treating them as though they do not exist. When recording
|
||||
// commits later we'll revive commits that exist but are unreachable.
|
||||
|
||||
$commits = id(new PhabricatorRepositoryCommit())->loadAllWhere(
|
||||
'repositoryID = %d AND commitIdentifier IN (%Ls)',
|
||||
'repositoryID = %d AND commitIdentifier IN (%Ls)
|
||||
AND (importStatus & %d) != %d',
|
||||
$this->getRepository()->getID(),
|
||||
$identifiers);
|
||||
$identifiers,
|
||||
PhabricatorRepositoryCommit::IMPORTED_UNREACHABLE,
|
||||
PhabricatorRepositoryCommit::IMPORTED_UNREACHABLE);
|
||||
|
||||
foreach ($commits as $commit) {
|
||||
$this->commitCache[$commit->getCommitIdentifier()] = true;
|
||||
|
@ -493,6 +500,24 @@ final class PhabricatorRepositoryDiscoveryEngine
|
|||
array $parents) {
|
||||
|
||||
$commit = new PhabricatorRepositoryCommit();
|
||||
$conn_w = $repository->establishConnection('w');
|
||||
|
||||
// First, try to revive an existing unreachable commit (if one exists) by
|
||||
// removing the "unreachable" flag. If we succeed, we don't need to do
|
||||
// anything else: we already discovered this commit some time ago.
|
||||
queryfx(
|
||||
$conn_w,
|
||||
'UPDATE %T SET importStatus = (importStatus & ~%d)
|
||||
WHERE repositoryID = %d AND commitIdentifier = %s',
|
||||
$commit->getTableName(),
|
||||
PhabricatorRepositoryCommit::IMPORTED_UNREACHABLE,
|
||||
$repository->getID(),
|
||||
$commit_identifier);
|
||||
if ($conn_w->getAffectedRows()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$commit->setRepositoryID($repository->getID());
|
||||
$commit->setCommitIdentifier($commit_identifier);
|
||||
$commit->setEpoch($epoch);
|
||||
|
@ -502,10 +527,7 @@ final class PhabricatorRepositoryDiscoveryEngine
|
|||
|
||||
$data = new PhabricatorRepositoryCommitData();
|
||||
|
||||
$conn_w = $repository->establishConnection('w');
|
||||
|
||||
try {
|
||||
|
||||
// If this commit has parents, look up their IDs. The parent commits
|
||||
// should always exist already.
|
||||
|
||||
|
@ -583,8 +605,6 @@ final class PhabricatorRepositoryDiscoveryEngine
|
|||
'commit' => $commit,
|
||||
)));
|
||||
|
||||
|
||||
|
||||
} catch (AphrontDuplicateKeyQueryException $ex) {
|
||||
$commit->killTransaction();
|
||||
// Ignore. This can happen because we discover the same new commit
|
||||
|
|
|
@ -32,6 +32,7 @@ final class PhabricatorRepositoryCommit
|
|||
const IMPORTED_ALL = 15;
|
||||
|
||||
const IMPORTED_CLOSEABLE = 1024;
|
||||
const IMPORTED_UNREACHABLE = 2048;
|
||||
|
||||
private $commitData = self::ATTACHABLE;
|
||||
private $audits = self::ATTACHABLE;
|
||||
|
@ -58,6 +59,10 @@ final class PhabricatorRepositoryCommit
|
|||
return $this->isPartiallyImported(self::IMPORTED_ALL);
|
||||
}
|
||||
|
||||
public function isUnreachable() {
|
||||
return $this->isPartiallyImported(self::IMPORTED_UNREACHABLE);
|
||||
}
|
||||
|
||||
public function writeImportStatusFlag($flag) {
|
||||
queryfx(
|
||||
$this->establishConnection('w'),
|
||||
|
|
Loading…
Reference in a new issue