Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/parser/DifferentialChangesetParser.php
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | final class DifferentialChangesetParser extends Phobject { | ||||
private $offsetMode; | private $offsetMode; | ||||
private $rangeStart; | private $rangeStart; | ||||
private $rangeEnd; | private $rangeEnd; | ||||
private $mask; | private $mask; | ||||
private $linesOfContext = 8; | private $linesOfContext = 8; | ||||
private $highlightEngine; | private $highlightEngine; | ||||
private $viewer; | |||||
public function setRange($start, $end) { | public function setRange($start, $end) { | ||||
$this->rangeStart = $start; | $this->rangeStart = $start; | ||||
$this->rangeEnd = $end; | $this->rangeEnd = $end; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setMask(array $mask) { | public function setMask(array $mask) { | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | public function setOffsetMode($offset_mode) { | ||||
$this->offsetMode = $offset_mode; | $this->offsetMode = $offset_mode; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getOffsetMode() { | public function getOffsetMode() { | ||||
return $this->offsetMode; | return $this->offsetMode; | ||||
} | } | ||||
public function setViewer(PhabricatorUser $viewer) { | |||||
$this->viewer = $viewer; | |||||
return $this; | |||||
} | |||||
public function getViewer() { | |||||
return $this->viewer; | |||||
} | |||||
public static function getDefaultRendererForViewer(PhabricatorUser $viewer) { | public static function getDefaultRendererForViewer(PhabricatorUser $viewer) { | ||||
$is_unified = $viewer->compareUserSetting( | $is_unified = $viewer->compareUserSetting( | ||||
PhabricatorUnifiedDiffsSetting::SETTINGKEY, | PhabricatorUnifiedDiffsSetting::SETTINGKEY, | ||||
PhabricatorUnifiedDiffsSetting::VALUE_ALWAYS_UNIFIED); | PhabricatorUnifiedDiffsSetting::VALUE_ALWAYS_UNIFIED); | ||||
if ($is_unified) { | if ($is_unified) { | ||||
return '1up'; | return '1up'; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 838 Lines • ▼ Show 20 Lines | if ($this->comments) { | ||||
$old_comments[$final][] = $comment; | $old_comments[$final][] = $comment; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
$renderer | $renderer | ||||
->setOldComments($old_comments) | ->setOldComments($old_comments) | ||||
->setNewComments($new_comments); | ->setNewComments($new_comments); | ||||
$engine_view = $this->newDocumentEngineChangesetView(); | |||||
if ($engine_view !== null) { | |||||
return $engine_view; | |||||
} | |||||
switch ($this->changeset->getFileType()) { | switch ($this->changeset->getFileType()) { | ||||
case DifferentialChangeType::FILE_IMAGE: | case DifferentialChangeType::FILE_IMAGE: | ||||
$old = null; | $old = null; | ||||
$new = null; | $new = null; | ||||
// TODO: Improve the architectural issue as discussed in D955 | // TODO: Improve the architectural issue as discussed in D955 | ||||
// https://secure.phabricator.com/D955 | // https://secure.phabricator.com/D955 | ||||
$reference = $this->getRenderingReference(); | $reference = $this->getRenderingReference(); | ||||
$parts = explode('/', $reference); | $parts = explode('/', $reference); | ||||
▲ Show 20 Lines • Show All 656 Lines • ▼ Show 20 Lines | if ($fast_path) { | ||||
} | } | ||||
$line = implode('', $line); | $line = implode('', $line); | ||||
} | } | ||||
return $prefix.$line; | return $prefix.$line; | ||||
} | } | ||||
private function newDocumentEngineChangesetView() { | |||||
$changeset = $this->changeset; | |||||
$viewer = $this->getViewer(); | |||||
// TODO: This should probably be made non-optional in the future. | |||||
if (!$viewer) { | |||||
return null; | |||||
} | |||||
$old_data = $this->old; | |||||
$old_data = ipull($old_data, 'text'); | |||||
$old_data = implode('', $old_data); | |||||
$new_data = $this->new; | |||||
$new_data = ipull($new_data, 'text'); | |||||
$new_data = implode('', $new_data); | |||||
$old_ref = id(new PhabricatorDocumentRef()) | |||||
->setName($changeset->getOldFile()) | |||||
->setData($old_data); | |||||
$new_ref = id(new PhabricatorDocumentRef()) | |||||
->setName($changeset->getFilename()) | |||||
->setData($new_data); | |||||
$old_engines = PhabricatorDocumentEngine::getEnginesForRef( | |||||
$viewer, | |||||
$old_ref); | |||||
$new_engines = PhabricatorDocumentEngine::getEnginesForRef( | |||||
$viewer, | |||||
$new_ref); | |||||
$shared_engines = array_intersect_key($old_engines, $new_engines); | |||||
$document_engine = null; | |||||
foreach ($shared_engines as $shared_engine) { | |||||
if ($shared_engine->canDiffDocuments($old_ref, $new_ref)) { | |||||
$document_engine = $shared_engine; | |||||
break; | |||||
} | |||||
} | |||||
if ($document_engine) { | |||||
return $document_engine->newDiffView( | |||||
$old_ref, | |||||
$new_ref); | |||||
} | |||||
return null; | |||||
} | |||||
} | } |