Differential D15986 Diff 38488 src/applications/repository/engine/PhabricatorRepositoryDiscoveryEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/engine/PhabricatorRepositoryDiscoveryEngine.php
| Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | public function discoverCommits() { | ||||
| $lock->unlock(); | $lock->unlock(); | ||||
| return $result; | return $result; | ||||
| } | } | ||||
| private function discoverCommitsWithLock() { | private function discoverCommitsWithLock() { | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| $viewer = $this->getViewer(); | |||||
| $vcs = $repository->getVersionControlSystem(); | $vcs = $repository->getVersionControlSystem(); | ||||
| switch ($vcs) { | switch ($vcs) { | ||||
| case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: | case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: | ||||
| $refs = $this->discoverSubversionCommits(); | $refs = $this->discoverSubversionCommits(); | ||||
| break; | break; | ||||
| case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: | case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: | ||||
| $refs = $this->discoverMercurialCommits(); | $refs = $this->discoverMercurialCommits(); | ||||
| Show All 25 Lines | foreach ($refs as $ref) { | ||||
| $ref->getIdentifier(), | $ref->getIdentifier(), | ||||
| $ref->getEpoch(), | $ref->getEpoch(), | ||||
| $ref->getCanCloseImmediately(), | $ref->getCanCloseImmediately(), | ||||
| $ref->getParents()); | $ref->getParents()); | ||||
| $this->commitCache[$ref->getIdentifier()] = true; | $this->commitCache[$ref->getIdentifier()] = true; | ||||
| } | } | ||||
| $version = $this->getObservedVersion($repository); | |||||
| if ($version !== null) { | |||||
| id(new DiffusionRepositoryClusterEngine()) | |||||
| ->setViewer($viewer) | |||||
| ->setRepository($repository) | |||||
| ->synchronizeWorkingCopyAfterDiscovery($version); | |||||
| } | |||||
| return $refs; | return $refs; | ||||
| } | } | ||||
| /* -( Discovering Git Repositories )--------------------------------------- */ | /* -( Discovering Git Repositories )--------------------------------------- */ | ||||
| /** | /** | ||||
| * @task git | * @task git | ||||
| */ | */ | ||||
| private function discoverGitCommits() { | private function discoverGitCommits() { | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| if (!$repository->isHosted()) { | if (!$repository->isHosted()) { | ||||
| $this->verifyGitOrigin($repository); | $this->verifyGitOrigin($repository); | ||||
| } | } | ||||
| // TODO: This should also import tags, but some of the logic is still | |||||
| // branch-specific today. | |||||
| $branches = id(new DiffusionLowLevelGitRefQuery()) | $branches = id(new DiffusionLowLevelGitRefQuery()) | ||||
| ->setRepository($repository) | ->setRepository($repository) | ||||
| ->withIsOriginBranch(true) | ->withRefTypes( | ||||
| array( | |||||
| PhabricatorRepositoryRefCursor::TYPE_BRANCH, | |||||
| )) | |||||
| ->execute(); | ->execute(); | ||||
| if (!$branches) { | if (!$branches) { | ||||
| // This repository has no branches at all, so we don't need to do | // This repository has no branches at all, so we don't need to do | ||||
| // anything. Generally, this means the repository is empty. | // anything. Generally, this means the repository is empty. | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 502 Lines • ▼ Show 20 Lines | private function isInitialImport(array $refs) { | ||||
| if ($any_commits) { | if ($any_commits) { | ||||
| // If the repository already has commits, this isn't an import. | // If the repository already has commits, this isn't an import. | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| private function getObservedVersion(PhabricatorRepository $repository) { | |||||
| if ($repository->isHosted()) { | |||||
| return null; | |||||
| } | |||||
| if ($repository->isGit()) { | |||||
| return $this->getGitObservedVersion($repository); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private function getGitObservedVersion(PhabricatorRepository $repository) { | |||||
| $refs = id(new DiffusionLowLevelGitRefQuery()) | |||||
| ->setRepository($repository) | |||||
| ->execute(); | |||||
| if (!$refs) { | |||||
| return null; | |||||
| } | |||||
| // In Git, the observed version is the most recently discovered commit | |||||
| // at any repository HEAD. It's possible for this to regress temporarily | |||||
| // if a branch is pushed and then deleted. This is acceptable because it | |||||
| // doesn't do anything meaningfully bad and will fix itself on the next | |||||
| // push. | |||||
| $ref_identifiers = mpull($refs, 'getCommitIdentifier'); | |||||
| $ref_identifiers = array_fuse($ref_identifiers); | |||||
| $version = queryfx_one( | |||||
| $repository->establishConnection('w'), | |||||
| 'SELECT MAX(id) version FROM %T WHERE repositoryID = %d | |||||
| AND commitIdentifier IN (%Ls)', | |||||
| id(new PhabricatorRepositoryCommit())->getTableName(), | |||||
| $repository->getID(), | |||||
| $ref_identifiers); | |||||
| if (!$version) { | |||||
| return null; | |||||
| } | |||||
| return (int)$version['version']; | |||||
| } | |||||
| } | } | ||||