2012-06-26 00:21:48 +02:00
|
|
|
<?php
|
|
|
|
|
2014-01-17 00:31:52 +01:00
|
|
|
final class PhabricatorGitGraphStream
|
|
|
|
extends PhabricatorRepositoryGraphStream {
|
2012-06-26 00:21:48 +02:00
|
|
|
|
|
|
|
private $repository;
|
|
|
|
private $iterator;
|
|
|
|
|
|
|
|
private $parents = array();
|
|
|
|
private $dates = array();
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
PhabricatorRepository $repository,
|
|
|
|
$start_commit) {
|
|
|
|
|
|
|
|
$this->repository = $repository;
|
|
|
|
|
|
|
|
$future = $repository->getLocalCommandFuture(
|
2014-06-09 20:36:49 +02:00
|
|
|
'log --format=%s %s --',
|
2012-06-26 00:21:48 +02:00
|
|
|
'%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);
|
|
|
|
}
|
2014-06-03 00:25:28 +02:00
|
|
|
$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);
|
2012-06-26 00:21:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|