[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/herald/adapter/ -> HeraldDifferentialAdapter.php (source)

   1  <?php
   2  
   3  abstract class HeraldDifferentialAdapter extends HeraldAdapter {
   4  
   5    private $repository = false;
   6    private $diff;
   7  
   8    abstract protected function loadChangesets();
   9    abstract protected function loadChangesetsWithHunks();
  10  
  11    public function getDiff() {
  12      return $this->diff;
  13    }
  14  
  15    public function setDiff(DifferentialDiff $diff) {
  16      $this->diff = $diff;
  17      return $this;
  18    }
  19  
  20    public function loadRepository() {
  21      if ($this->repository === false) {
  22        $repository_phid = $this->getObject()->getRepositoryPHID();
  23  
  24        if ($repository_phid) {
  25          $repository = id(new PhabricatorRepositoryQuery())
  26            ->setViewer(PhabricatorUser::getOmnipotentUser())
  27            ->withPHIDs(array($repository_phid))
  28            ->needProjectPHIDs(true)
  29            ->executeOne();
  30        } else {
  31          $repository = null;
  32        }
  33  
  34        $this->repository = $repository;
  35      }
  36  
  37      return $this->repository;
  38    }
  39  
  40  
  41    protected function loadAffectedPaths() {
  42      $changesets = $this->loadChangesets();
  43  
  44      $paths = array();
  45      foreach ($changesets as $changeset) {
  46        $paths[] = $this->getAbsoluteRepositoryPathForChangeset($changeset);
  47      }
  48  
  49      return $paths;
  50    }
  51  
  52    protected function getAbsoluteRepositoryPathForChangeset(
  53      DifferentialChangeset $changeset) {
  54  
  55      $repository = $this->loadRepository();
  56      if (!$repository) {
  57        return '/'.ltrim($changeset->getFilename(), '/');
  58      }
  59  
  60      $diff = $this->getDiff();
  61  
  62      return $changeset->getAbsoluteRepositoryPath($repository, $diff);
  63    }
  64  
  65    protected function loadContentDictionary() {
  66      $add_lines = DifferentialHunk::FLAG_LINES_ADDED;
  67      $rem_lines = DifferentialHunk::FLAG_LINES_REMOVED;
  68      $mask = ($add_lines | $rem_lines);
  69      return $this->loadContentWithMask($mask);
  70    }
  71  
  72    protected function loadAddedContentDictionary() {
  73      return $this->loadContentWithMask(DifferentialHunk::FLAG_LINES_ADDED);
  74    }
  75  
  76    protected function loadRemovedContentDictionary() {
  77      return $this->loadContentWithMask(DifferentialHunk::FLAG_LINES_REMOVED);
  78    }
  79  
  80    protected function loadContentWithMask($mask) {
  81      $changesets = $this->loadChangesetsWithHunks();
  82  
  83      $dict = array();
  84      foreach ($changesets as $changeset) {
  85        $content = array();
  86        foreach ($changeset->getHunks() as $hunk) {
  87          $content[] = $hunk->getContentWithMask($mask);
  88        }
  89  
  90        $path = $this->getAbsoluteRepositoryPathForChangeset($changeset);
  91        $dict[$path] = implode("\n", $content);
  92      }
  93  
  94      return $dict;
  95    }
  96  
  97  }


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