Path: blob/master/src/applications/differential/herald/HeraldDifferentialAdapter.php
12256 views
<?php12abstract class HeraldDifferentialAdapter extends HeraldAdapter {34private $repository = false;5private $diff;67abstract protected function loadChangesets();8abstract protected function loadChangesetsWithHunks();910public function getDiff() {11return $this->diff;12}1314public function setDiff(DifferentialDiff $diff) {15$this->diff = $diff;16return $this;17}1819public function loadRepository() {20if ($this->repository === false) {21$repository_phid = $this->getObject()->getRepositoryPHID();2223if ($repository_phid) {24$repository = id(new PhabricatorRepositoryQuery())25->setViewer(PhabricatorUser::getOmnipotentUser())26->withPHIDs(array($repository_phid))27->executeOne();28} else {29$repository = null;30}3132$this->repository = $repository;33}3435return $this->repository;36}373839public function loadAffectedPaths() {40$changesets = $this->loadChangesets();4142$paths = array();43foreach ($changesets as $changeset) {44$paths[] = $this->getAbsoluteRepositoryPathForChangeset($changeset);45}4647return $paths;48}4950protected function getAbsoluteRepositoryPathForChangeset(51DifferentialChangeset $changeset) {5253$repository = $this->loadRepository();54if (!$repository) {55return '/'.ltrim($changeset->getFilename(), '/');56}5758$diff = $this->getDiff();5960return $changeset->getAbsoluteRepositoryPath($repository, $diff);61}6263public function loadContentDictionary() {64$add_lines = DifferentialHunk::FLAG_LINES_ADDED;65$rem_lines = DifferentialHunk::FLAG_LINES_REMOVED;66$mask = ($add_lines | $rem_lines);67return $this->loadContentWithMask($mask);68}6970public function loadAddedContentDictionary() {71return $this->loadContentWithMask(DifferentialHunk::FLAG_LINES_ADDED);72}7374public function loadRemovedContentDictionary() {75return $this->loadContentWithMask(DifferentialHunk::FLAG_LINES_REMOVED);76}7778protected function loadContentWithMask($mask) {79$changesets = $this->loadChangesetsWithHunks();8081$dict = array();82foreach ($changesets as $changeset) {83$content = array();84foreach ($changeset->getHunks() as $hunk) {85$content[] = $hunk->getContentWithMask($mask);86}8788$path = $this->getAbsoluteRepositoryPathForChangeset($changeset);89$dict[$path] = implode("\n", $content);90}9192return $dict;93}9495}969798