[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/repository/daemon/ -> PhabricatorGitGraphStream.php (source)

   1  <?php
   2  
   3  final class PhabricatorGitGraphStream
   4    extends PhabricatorRepositoryGraphStream {
   5  
   6    private $repository;
   7    private $iterator;
   8  
   9    private $parents        = array();
  10    private $dates          = array();
  11  
  12    public function __construct(
  13      PhabricatorRepository $repository,
  14      $start_commit) {
  15  
  16      $this->repository = $repository;
  17  
  18      $future = $repository->getLocalCommandFuture(
  19        'log --format=%s %s --',
  20        '%H%x01%P%x01%ct',
  21        $start_commit);
  22  
  23      $this->iterator = new LinesOfALargeExecFuture($future);
  24      $this->iterator->setDelimiter("\n");
  25      $this->iterator->rewind();
  26    }
  27  
  28    public function getParents($commit) {
  29      if (!isset($this->parents[$commit])) {
  30        $this->parseUntil($commit);
  31      }
  32      $parents = $this->parents[$commit];
  33  
  34      // NOTE: In Git, it is possible for a commit to list the same parent more
  35      // than once. See T5226. Discard duplicate parents.
  36  
  37      return array_unique($parents);
  38    }
  39  
  40    public function getCommitDate($commit) {
  41      if (!isset($this->dates[$commit])) {
  42        $this->parseUntil($commit);
  43      }
  44      return $this->dates[$commit];
  45    }
  46  
  47    private function parseUntil($commit) {
  48      if ($this->isParsed($commit)) {
  49        return;
  50      }
  51  
  52      $gitlog = $this->iterator;
  53  
  54      while ($gitlog->valid()) {
  55        $line = $gitlog->current();
  56        $gitlog->next();
  57  
  58        $line = trim($line);
  59        if (!strlen($line)) {
  60          break;
  61        }
  62        list($hash, $parents, $epoch) = explode("\1", $line);
  63  
  64        if ($parents) {
  65          $parents = explode(' ', $parents);
  66        } else {
  67          // First commit.
  68          $parents = array();
  69        }
  70  
  71        $this->dates[$hash] = $epoch;
  72        $this->parents[$hash] = $parents;
  73  
  74        if ($this->isParsed($commit)) {
  75          return;
  76        }
  77      }
  78  
  79      throw new Exception("No such commit '{$commit}' in repository!");
  80    }
  81  
  82    private function isParsed($commit) {
  83      return isset($this->dates[$commit]);
  84    }
  85  
  86  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1