Differential D8781 Diff 20858 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 96 Lines • ▼ Show 20 Lines | private function discoverGitCommits() { | ||||
| $branches = $this->sortBranches($branches); | $branches = $this->sortBranches($branches); | ||||
| $branches = mpull($branches, 'getCommitIdentifier', 'getShortName'); | $branches = mpull($branches, 'getCommitIdentifier', 'getShortName'); | ||||
| $this->log( | $this->log( | ||||
| pht( | pht( | ||||
| 'Discovering commits in repository %s.', | 'Discovering commits in repository %s.', | ||||
| $repository->getCallsign())); | $repository->getCallsign())); | ||||
| $this->fillCommitCache(array_values($branches)); | |||||
| $refs = array(); | $refs = array(); | ||||
| foreach ($branches as $name => $commit) { | foreach ($branches as $name => $commit) { | ||||
| $this->log(pht('Examining branch "%s", at "%s".', $name, $commit)); | $this->log(pht('Examining branch "%s", at "%s".', $name, $commit)); | ||||
| if (!$repository->shouldTrackBranch($name)) { | if (!$repository->shouldTrackBranch($name)) { | ||||
| $this->log(pht("Skipping, branch is untracked.")); | $this->log(pht("Skipping, branch is untracked.")); | ||||
| continue; | continue; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 236 Lines • ▼ Show 20 Lines | /* -( Discovering Mercurial Repositories )--------------------------------- */ | ||||
| */ | */ | ||||
| private function discoverMercurialCommits() { | private function discoverMercurialCommits() { | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| $branches = id(new DiffusionLowLevelMercurialBranchesQuery()) | $branches = id(new DiffusionLowLevelMercurialBranchesQuery()) | ||||
| ->setRepository($repository) | ->setRepository($repository) | ||||
| ->execute(); | ->execute(); | ||||
| $this->fillCommitCache(mpull($branches, 'getCommitIdentifier')); | |||||
| $refs = array(); | $refs = array(); | ||||
| foreach ($branches as $branch) { | foreach ($branches as $branch) { | ||||
| // NOTE: Mercurial branches may have multiple heads, so the names may | // NOTE: Mercurial branches may have multiple heads, so the names may | ||||
| // not be unique. | // not be unique. | ||||
| $name = $branch->getShortName(); | $name = $branch->getShortName(); | ||||
| $commit = $branch->getCommitIdentifier(); | $commit = $branch->getCommitIdentifier(); | ||||
| $this->log(pht('Examining branch "%s" head "%s".', $name, $commit)); | $this->log(pht('Examining branch "%s" head "%s".', $name, $commit)); | ||||
| ▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | private function isKnownCommit($identifier) { | ||||
| if ($this->repairMode) { | if ($this->repairMode) { | ||||
| // In repair mode, rediscover the entire repository, ignoring the | // In repair mode, rediscover the entire repository, ignoring the | ||||
| // database state. We can hit the local cache above, but if we miss it | // database state. We can hit the local cache above, but if we miss it | ||||
| // stop the script from going to the database cache. | // stop the script from going to the database cache. | ||||
| return false; | return false; | ||||
| } | } | ||||
| $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( | $this->fillCommitCache(array($identifier)); | ||||
| 'repositoryID = %d AND commitIdentifier = %s', | |||||
| return isset($this->commitCache[$identifier]); | |||||
| } | |||||
| private function fillCommitCache(array $identifiers) { | |||||
| if (!$identifiers) { | |||||
| return; | |||||
| } | |||||
| $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere( | |||||
| 'repositoryID = %d AND commitIdentifier IN (%Ls)', | |||||
| $this->getRepository()->getID(), | $this->getRepository()->getID(), | ||||
| $identifier); | $identifiers); | ||||
| if (!$commit) { | foreach ($commits as $commit) { | ||||
| return false; | $this->commitCache[$commit->getCommitIdentifier()] = true; | ||||
| } | } | ||||
| $this->commitCache[$identifier] = true; | |||||
| while (count($this->commitCache) > self::MAX_COMMIT_CACHE_SIZE) { | while (count($this->commitCache) > self::MAX_COMMIT_CACHE_SIZE) { | ||||
| array_shift($this->commitCache); | array_shift($this->commitCache); | ||||
| } | } | ||||
| return true; | |||||
| } | } | ||||
| /** | /** | ||||
| * Sort branches so we process closeable branches first. This makes the | * Sort branches so we process closeable branches first. This makes the | ||||
| * whole import process a little cheaper, since we can close these commits | * whole import process a little cheaper, since we can close these commits | ||||
| * the first time through rather than catching them in the refs step. | * the first time through rather than catching them in the refs step. | ||||
| * | * | ||||
| * @task internal | * @task internal | ||||
| * | * | ||||
| * @param list<DiffusionRepositoryRef> List of branch heads. | * @param list<DiffusionRepositoryRef> List of branch heads. | ||||
| ▲ Show 20 Lines • Show All 115 Lines • Show Last 20 Lines | |||||