@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow DocumentEngine to elect into diff construction

Summary:
Ref T13425. Allow DocumentEngines to claim they can produce diffs. If both sides of a change can be diffed by the same document engine and it can produce diffs, have it diff them.

This has no impact on runtime behavior because no upstream engine elects into diff generation yet.

Test Plan: Loaded some revisions, nothing broke.

Maniphest Tasks: T13425

Differential Revision: https://secure.phabricator.com/D20830

+105
+1
src/applications/differential/controller/DifferentialChangesetViewController.php
··· 166 166 DifferentialChangesetParser::parseRangeSpecification($spec); 167 167 168 168 $parser = id(new DifferentialChangesetParser()) 169 + ->setViewer($viewer) 169 170 ->setCoverage($coverage) 170 171 ->setChangeset($changeset) 171 172 ->setRenderingReference($rendering_reference)
+68
src/applications/differential/parser/DifferentialChangesetParser.php
··· 58 58 private $linesOfContext = 8; 59 59 60 60 private $highlightEngine; 61 + private $viewer; 61 62 62 63 public function setRange($start, $end) { 63 64 $this->rangeStart = $start; ··· 147 148 148 149 public function getOffsetMode() { 149 150 return $this->offsetMode; 151 + } 152 + 153 + public function setViewer(PhabricatorUser $viewer) { 154 + $this->viewer = $viewer; 155 + return $this; 156 + } 157 + 158 + public function getViewer() { 159 + return $this->viewer; 150 160 } 151 161 152 162 public static function getDefaultRendererForViewer(PhabricatorUser $viewer) { ··· 1003 1013 ->setOldComments($old_comments) 1004 1014 ->setNewComments($new_comments); 1005 1015 1016 + $engine_view = $this->newDocumentEngineChangesetView(); 1017 + if ($engine_view !== null) { 1018 + return $engine_view; 1019 + } 1020 + 1006 1021 switch ($this->changeset->getFileType()) { 1007 1022 case DifferentialChangeType::FILE_IMAGE: 1008 1023 $old = null; ··· 1673 1688 } 1674 1689 1675 1690 return $prefix.$line; 1691 + } 1692 + 1693 + private function newDocumentEngineChangesetView() { 1694 + $changeset = $this->changeset; 1695 + $viewer = $this->getViewer(); 1696 + 1697 + // TODO: This should probably be made non-optional in the future. 1698 + if (!$viewer) { 1699 + return null; 1700 + } 1701 + 1702 + $old_data = $this->old; 1703 + $old_data = ipull($old_data, 'text'); 1704 + $old_data = implode('', $old_data); 1705 + 1706 + $new_data = $this->new; 1707 + $new_data = ipull($new_data, 'text'); 1708 + $new_data = implode('', $new_data); 1709 + 1710 + $old_ref = id(new PhabricatorDocumentRef()) 1711 + ->setName($changeset->getOldFile()) 1712 + ->setData($old_data); 1713 + 1714 + $new_ref = id(new PhabricatorDocumentRef()) 1715 + ->setName($changeset->getFilename()) 1716 + ->setData($new_data); 1717 + 1718 + $old_engines = PhabricatorDocumentEngine::getEnginesForRef( 1719 + $viewer, 1720 + $old_ref); 1721 + 1722 + $new_engines = PhabricatorDocumentEngine::getEnginesForRef( 1723 + $viewer, 1724 + $new_ref); 1725 + 1726 + $shared_engines = array_intersect_key($old_engines, $new_engines); 1727 + 1728 + $document_engine = null; 1729 + foreach ($shared_engines as $shared_engine) { 1730 + if ($shared_engine->canDiffDocuments($old_ref, $new_ref)) { 1731 + $document_engine = $shared_engine; 1732 + break; 1733 + } 1734 + } 1735 + 1736 + 1737 + if ($document_engine) { 1738 + return $document_engine->newDiffView( 1739 + $old_ref, 1740 + $new_ref); 1741 + } 1742 + 1743 + return null; 1676 1744 } 1677 1745 1678 1746 }
+12
src/applications/files/document/PhabricatorDocumentEngine.php
··· 31 31 return $this->canRenderDocumentType($ref); 32 32 } 33 33 34 + public function canDiffDocuments( 35 + PhabricatorDocumentRef $uref, 36 + PhabricatorDocumentRef $vref) { 37 + return false; 38 + } 39 + 40 + public function newDiffView( 41 + PhabricatorDocumentRef $uref, 42 + PhabricatorDocumentRef $vref) { 43 + throw new PhutilMethodNotImplementedException(); 44 + } 45 + 34 46 public function canConfigureEncoding(PhabricatorDocumentRef $ref) { 35 47 return false; 36 48 }
+24
src/applications/files/document/PhabricatorDocumentRef.php
··· 11 11 private $symbolMetadata = array(); 12 12 private $blameURI; 13 13 private $coverage = array(); 14 + private $data; 14 15 15 16 public function setFile(PhabricatorFile $file) { 16 17 $this->file = $file; ··· 65 66 return $this->byteLength; 66 67 } 67 68 69 + if ($this->data !== null) { 70 + return strlen($this->data); 71 + } 72 + 68 73 if ($this->file) { 69 74 return (int)$this->file->getByteSize(); 70 75 } ··· 72 77 return null; 73 78 } 74 79 80 + public function setData($data) { 81 + $this->data = $data; 82 + return $this; 83 + } 84 + 75 85 public function loadData($begin = null, $end = null) { 86 + if ($this->data !== null) { 87 + $data = $this->data; 88 + 89 + if ($begin !== null && $end !== null) { 90 + $data = substr($data, $begin, $end - $begin); 91 + } else if ($begin !== null) { 92 + $data = substr($data, $begin); 93 + } else if ($end !== null) { 94 + $data = substr($data, 0, $end); 95 + } 96 + 97 + return $data; 98 + } 99 + 76 100 if ($this->file) { 77 101 $iterator = $this->file->getFileDataIterator($begin, $end); 78 102