Differential D21521 Diff 51224 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 136 Lines • ▼ Show 20 Lines | $heads = id(new DiffusionLowLevelGitRefQuery()) | ||||
| ->execute(); | ->execute(); | ||||
| if (!$heads) { | if (!$heads) { | ||||
| // This repository has no heads at all, so we don't need to do | // This repository has no heads 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(); | ||||
| } | } | ||||
| $heads = $this->sortRefs($heads); | |||||
| $head_commits = mpull($heads, 'getCommitIdentifier'); | |||||
| $this->log( | $this->log( | ||||
| pht( | pht( | ||||
| 'Discovering commits in repository "%s".', | 'Discovering commits in repository "%s".', | ||||
| $repository->getDisplayName())); | $repository->getDisplayName())); | ||||
| $this->fillCommitCache($head_commits); | $ref_lists = array(); | ||||
| $refs = array(); | $head_groups = $this->getRefGroupsForDiscovery($heads); | ||||
| foreach ($heads as $ref) { | foreach ($head_groups as $head_group) { | ||||
| $group_identifiers = mpull($head_group, 'getCommitIdentifier'); | |||||
| $group_identifiers = array_fuse($group_identifiers); | |||||
| $this->fillCommitCache($group_identifiers); | |||||
| foreach ($head_group as $ref) { | |||||
| $name = $ref->getShortName(); | $name = $ref->getShortName(); | ||||
| $commit = $ref->getCommitIdentifier(); | $commit = $ref->getCommitIdentifier(); | ||||
| $this->log( | $this->log( | ||||
| pht( | pht( | ||||
| 'Examining "%s" (%s) at "%s".', | 'Examining "%s" (%s) at "%s".', | ||||
| $name, | $name, | ||||
| $ref->getRefType(), | $ref->getRefType(), | ||||
| $commit)); | $commit)); | ||||
| if (!$repository->shouldTrackRef($ref)) { | if (!$repository->shouldTrackRef($ref)) { | ||||
| $this->log(pht('Skipping, ref is untracked.')); | $this->log(pht('Skipping, ref is untracked.')); | ||||
| continue; | continue; | ||||
| } | } | ||||
| if ($this->isKnownCommit($commit)) { | if ($this->isKnownCommit($commit)) { | ||||
| $this->log(pht('Skipping, HEAD is known.')); | $this->log(pht('Skipping, HEAD is known.')); | ||||
| continue; | continue; | ||||
| } | } | ||||
| // In Git, it's possible to tag anything. We just skip tags that don't | // In Git, it's possible to tag anything. We just skip tags that don't | ||||
| // point to a commit. See T11301. | // point to a commit. See T11301. | ||||
| $fields = $ref->getRawFields(); | $fields = $ref->getRawFields(); | ||||
| $ref_type = idx($fields, 'objecttype'); | $ref_type = idx($fields, 'objecttype'); | ||||
| $tag_type = idx($fields, '*objecttype'); | $tag_type = idx($fields, '*objecttype'); | ||||
| if ($ref_type != 'commit' && $tag_type != 'commit') { | if ($ref_type != 'commit' && $tag_type != 'commit') { | ||||
| $this->log(pht('Skipping, this is not a commit.')); | $this->log(pht('Skipping, this is not a commit.')); | ||||
| continue; | continue; | ||||
| } | } | ||||
| $this->log(pht('Looking for new commits.')); | $this->log(pht('Looking for new commits.')); | ||||
| $head_refs = $this->discoverStreamAncestry( | $head_refs = $this->discoverStreamAncestry( | ||||
| new PhabricatorGitGraphStream($repository, $commit), | new PhabricatorGitGraphStream($repository, $commit), | ||||
| $commit, | $commit, | ||||
| $publisher->isPermanentRef($ref)); | $publisher->isPermanentRef($ref)); | ||||
| $this->didDiscoverRefs($head_refs); | $this->didDiscoverRefs($head_refs); | ||||
| $refs[] = $head_refs; | $ref_lists[] = $head_refs; | ||||
| } | |||||
| } | } | ||||
| return array_mergev($refs); | $refs = array_mergev($ref_lists); | ||||
| return $refs; | |||||
| } | |||||
| /** | |||||
| * @task git | |||||
| */ | |||||
| private function getRefGroupsForDiscovery(array $heads) { | |||||
| $heads = $this->sortRefs($heads); | |||||
| // See T13593. We hold a commit cache with a fixed maximum size. Split the | |||||
| // refs into chunks no larger than the cache size, so we don't overflow the | |||||
| // cache when testing them. | |||||
| $array_iterator = new ArrayIterator($heads); | |||||
| $chunk_iterator = new PhutilChunkedIterator( | |||||
| $array_iterator, | |||||
| self::MAX_COMMIT_CACHE_SIZE); | |||||
| return $chunk_iterator; | |||||
| } | } | ||||
| /* -( Discovering Subversion Repositories )-------------------------------- */ | /* -( Discovering Subversion Repositories )-------------------------------- */ | ||||
| /** | /** | ||||
| * @task svn | * @task svn | ||||
| ▲ Show 20 Lines • Show All 697 Lines • Show Last 20 Lines | |||||