Differential D21514 Diff 51213 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 95 Lines • ▼ Show 20 Lines | private function discoverCommitsWithLock() { | ||||
$task_priority = $this->getImportTaskPriority($repository, $refs); | $task_priority = $this->getImportTaskPriority($repository, $refs); | ||||
// Record discovered commits and mark them in the cache. | // Record discovered commits and mark them in the cache. | ||||
foreach ($refs as $ref) { | foreach ($refs as $ref) { | ||||
$this->recordCommit( | $this->recordCommit( | ||||
$repository, | $repository, | ||||
$ref->getIdentifier(), | $ref->getIdentifier(), | ||||
$ref->getEpoch(), | $ref->getEpoch(), | ||||
$ref->getCanCloseImmediately(), | $ref->getIsPermanent(), | ||||
$ref->getParents(), | $ref->getParents(), | ||||
$task_priority); | $task_priority); | ||||
$this->commitCache[$ref->getIdentifier()] = true; | $this->commitCache[$ref->getIdentifier()] = true; | ||||
} | } | ||||
$this->markUnreachableCommits($repository); | $this->markUnreachableCommits($repository); | ||||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | do { | ||||
$xml = phutil_utf8ize($xml); | $xml = phutil_utf8ize($xml); | ||||
$log = new SimpleXMLElement($xml); | $log = new SimpleXMLElement($xml); | ||||
foreach ($log->logentry as $entry) { | foreach ($log->logentry as $entry) { | ||||
$identifier = (int)$entry['revision']; | $identifier = (int)$entry['revision']; | ||||
$epoch = (int)strtotime((string)$entry->date[0]); | $epoch = (int)strtotime((string)$entry->date[0]); | ||||
$refs[$identifier] = id(new PhabricatorRepositoryCommitRef()) | $refs[$identifier] = id(new PhabricatorRepositoryCommitRef()) | ||||
->setIdentifier($identifier) | ->setIdentifier($identifier) | ||||
->setEpoch($epoch) | ->setEpoch($epoch) | ||||
->setCanCloseImmediately(true); | ->setIsPermanent(true); | ||||
if ($upper_bound === null) { | if ($upper_bound === null) { | ||||
$upper_bound = $identifier; | $upper_bound = $identifier; | ||||
} else { | } else { | ||||
$upper_bound = min($upper_bound, $identifier); | $upper_bound = min($upper_bound, $identifier); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | foreach ($branches as $branch) { | ||||
continue; | continue; | ||||
} | } | ||||
$this->log(pht('Looking for new commits.')); | $this->log(pht('Looking for new commits.')); | ||||
$branch_refs = $this->discoverStreamAncestry( | $branch_refs = $this->discoverStreamAncestry( | ||||
new PhabricatorMercurialGraphStream($repository, $commit), | new PhabricatorMercurialGraphStream($repository, $commit), | ||||
$commit, | $commit, | ||||
$close_immediately = true); | $is_permanent = true); | ||||
$this->didDiscoverRefs($branch_refs); | $this->didDiscoverRefs($branch_refs); | ||||
$refs[] = $branch_refs; | $refs[] = $branch_refs; | ||||
} | } | ||||
return array_mergev($refs); | return array_mergev($refs); | ||||
} | } | ||||
/* -( Internals )---------------------------------------------------------- */ | /* -( Internals )---------------------------------------------------------- */ | ||||
private function discoverStreamAncestry( | private function discoverStreamAncestry( | ||||
PhabricatorRepositoryGraphStream $stream, | PhabricatorRepositoryGraphStream $stream, | ||||
$commit, | $commit, | ||||
$close_immediately) { | $is_permanent) { | ||||
$discover = array($commit); | $discover = array($commit); | ||||
$graph = array(); | $graph = array(); | ||||
$seen = array(); | $seen = array(); | ||||
// Find all the reachable, undiscovered commits. Build a graph of the | // Find all the reachable, undiscovered commits. Build a graph of the | ||||
// edges. | // edges. | ||||
while ($discover) { | while ($discover) { | ||||
Show All 36 Lines | foreach ($commits as $commit) { | ||||
// with the behavior of "git show". | // with the behavior of "git show". | ||||
if (!strlen($epoch)) { | if (!strlen($epoch)) { | ||||
$epoch = 0; | $epoch = 0; | ||||
} | } | ||||
$refs[] = id(new PhabricatorRepositoryCommitRef()) | $refs[] = id(new PhabricatorRepositoryCommitRef()) | ||||
->setIdentifier($commit) | ->setIdentifier($commit) | ||||
->setEpoch($epoch) | ->setEpoch($epoch) | ||||
->setCanCloseImmediately($close_immediately) | ->setIsPermanent($is_permanent) | ||||
->setParents($stream->getParents($commit)); | ->setParents($stream->getParents($commit)); | ||||
} | } | ||||
return $refs; | return $refs; | ||||
} | } | ||||
private function reduceGraph(array $edges) { | private function reduceGraph(array $edges) { | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | private function fillCommitCache(array $identifiers) { | ||||
} | } | ||||
while (count($this->commitCache) > $max_size) { | while (count($this->commitCache) > $max_size) { | ||||
array_shift($this->commitCache); | array_shift($this->commitCache); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Sort branches so we process closeable branches first. This makes the | * Sort branches so we process permanent 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 publish 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 refs. | * @param list<DiffusionRepositoryRef> List of refs. | ||||
* @return list<DiffusionRepositoryRef> Sorted list of refs. | * @return list<DiffusionRepositoryRef> Sorted list of refs. | ||||
*/ | */ | ||||
private function sortRefs(array $refs) { | private function sortRefs(array $refs) { | ||||
Show All 13 Lines | private function sortRefs(array $refs) { | ||||
return array_merge($head_refs, $tail_refs); | return array_merge($head_refs, $tail_refs); | ||||
} | } | ||||
private function recordCommit( | private function recordCommit( | ||||
PhabricatorRepository $repository, | PhabricatorRepository $repository, | ||||
$commit_identifier, | $commit_identifier, | ||||
$epoch, | $epoch, | ||||
$close_immediately, | $is_permanent, | ||||
array $parents, | array $parents, | ||||
$task_priority) { | $task_priority) { | ||||
$commit = new PhabricatorRepositoryCommit(); | $commit = new PhabricatorRepositoryCommit(); | ||||
$conn_w = $repository->establishConnection('w'); | $conn_w = $repository->establishConnection('w'); | ||||
// First, try to revive an existing unreachable commit (if one exists) by | // 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 | // removing the "unreachable" flag. If we succeed, we don't need to do | ||||
Show All 15 Lines | if ($conn_w->getAffectedRows()) { | ||||
// After reviving a commit, schedule new daemons for it. | // After reviving a commit, schedule new daemons for it. | ||||
$this->didDiscoverCommit($repository, $commit, $epoch, $task_priority); | $this->didDiscoverCommit($repository, $commit, $epoch, $task_priority); | ||||
return; | return; | ||||
} | } | ||||
$commit->setRepositoryID($repository->getID()); | $commit->setRepositoryID($repository->getID()); | ||||
$commit->setCommitIdentifier($commit_identifier); | $commit->setCommitIdentifier($commit_identifier); | ||||
$commit->setEpoch($epoch); | $commit->setEpoch($epoch); | ||||
if ($close_immediately) { | if ($is_permanent) { | ||||
$commit->setImportStatus(PhabricatorRepositoryCommit::IMPORTED_CLOSEABLE); | $commit->setImportStatus(PhabricatorRepositoryCommit::IMPORTED_PERMANENT); | ||||
} | } | ||||
$data = new PhabricatorRepositoryCommitData(); | $data = new PhabricatorRepositoryCommitData(); | ||||
try { | try { | ||||
// If this commit has parents, look up their IDs. The parent commits | // If this commit has parents, look up their IDs. The parent commits | ||||
// should always exist already. | // should always exist already. | ||||
▲ Show 20 Lines • Show All 414 Lines • Show Last 20 Lines |