1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-28 09:42:41 +01:00
phorge-phorge/src/applications/repository/daemon/PhabricatorGitGraphStream.php

87 lines
1.9 KiB
PHP
Raw Normal View History

<?php
Move Git discovery into DiscoveryEngine Summary: Ref T4327. Consolidates and simplifies infrastructure: - Moves Git discovery into DiscoveryEngine. - Collapses a bunch of the Git and Mercurial code related to stream discovery. - Removes all cach code from PullLocal daemon (it's no longer called). - Adds basic unit tests for Git and Mercurial discovery. Various cleanup: - Makes GitStream and MercurialStream extend a common base. - Improves performance of MercurialStream in some cases, by requiring fewer commits be output and parsed. - Makes mirroring exceptions easier to debug. - Fixes discovery of Mercurial repositories with multiple branch heads. - Adds some missing `pht()`. Test Plan: I tested this fairly throughly because I think this phase is complete: - Made new repositories in multiple VCSes and did full imports. - Particularly, I reimported Arcanist to make sure that TODO was resolved. I think it was related to the toposort stuff. - Pushed commits to multiple VCSes. - Pushed commits to a non-close branch, then pushed a merge commit. Observed commits import initially as non-close, then get flagged for close. - Started full daemons and resolved various minor issues that showed up in the daemon log until everything ran cleanly. - Basically spent about 30 minutes banging on this in every way I could think of to try to break it. I found and fixed some minor stuff, but it seems solid. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4327 Differential Revision: https://secure.phabricator.com/D7987
2014-01-17 00:31:52 +01:00
final class PhabricatorGitGraphStream
extends PhabricatorRepositoryGraphStream {
private $repository;
private $iterator;
private $parents = array();
private $dates = array();
public function __construct(
PhabricatorRepository $repository,
$start_commit) {
$this->repository = $repository;
$future = $repository->getLocalCommandFuture(
'log --format=%s %s --',
'%H%x01%P%x01%ct',
$start_commit);
$this->iterator = new LinesOfALargeExecFuture($future);
$this->iterator->setDelimiter("\n");
$this->iterator->rewind();
}
public function getParents($commit) {
if (!isset($this->parents[$commit])) {
$this->parseUntil($commit);
}
$parents = $this->parents[$commit];
// NOTE: In Git, it is possible for a commit to list the same parent more
// than once. See T5226. Discard duplicate parents.
return array_unique($parents);
}
public function getCommitDate($commit) {
if (!isset($this->dates[$commit])) {
$this->parseUntil($commit);
}
return $this->dates[$commit];
}
private function parseUntil($commit) {
if ($this->isParsed($commit)) {
return;
}
$gitlog = $this->iterator;
while ($gitlog->valid()) {
$line = $gitlog->current();
$gitlog->next();
$line = trim($line);
if (!strlen($line)) {
break;
}
list($hash, $parents, $epoch) = explode("\1", $line);
if ($parents) {
$parents = explode(' ', $parents);
} else {
// First commit.
$parents = array();
}
$this->dates[$hash] = $epoch;
$this->parents[$hash] = $parents;
if ($this->isParsed($commit)) {
return;
}
}
throw new Exception("No such commit '{$commit}' in repository!");
}
private function isParsed($commit) {
return isset($this->dates[$commit]);
}
}