@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.

Move more hunk loads into DifferentialHunkQuery

Summary: Ref T5179. Ref T4045. I want to move all hunk loads into DifferentialHunkQuery so I can make it do magical things where hunks come from multiple places, handle non-utf8 encodings properly, handle compression, archive into Files, and so on.

Test Plan: Viewed some revisions. Called `differential.getrawdiff`.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4045, T5179

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

+75 -33
+5 -1
src/__phutil_library_map__.php
··· 3007 3007 'DifferentialBranchField' => 'DifferentialCustomField', 3008 3008 'DifferentialCapabilityDefaultView' => 'PhabricatorPolicyCapability', 3009 3009 'DifferentialChangesSinceLastUpdateField' => 'DifferentialCustomField', 3010 - 'DifferentialChangeset' => 'DifferentialDAO', 3010 + 'DifferentialChangeset' => 3011 + array( 3012 + 0 => 'DifferentialDAO', 3013 + 1 => 'PhabricatorPolicyInterface', 3014 + ), 3011 3015 'DifferentialChangesetDetailView' => 'AphrontView', 3012 3016 'DifferentialChangesetHTMLRenderer' => 'DifferentialChangesetRenderer', 3013 3017 'DifferentialChangesetListView' => 'AphrontView',
+6 -10
src/applications/differential/conduit/ConduitAPI_differential_getrawdiff_Method.php
··· 31 31 $diff = id(new DifferentialDiffQuery()) 32 32 ->withIDs(array($diff_id)) 33 33 ->setViewer($viewer) 34 + ->needChangesets(true) 34 35 ->executeOne(); 35 36 36 37 if (!$diff) { 37 38 throw new ConduitException('ERR_NOT_FOUND'); 38 39 } 39 40 40 - $changesets = $diff->loadChangesets(); 41 - foreach ($changesets as $changeset) { 42 - $changeset->attachHunks( 43 - $changeset->loadHunks()); 44 - } 41 + $renderer = id(new DifferentialRawDiffRenderer()) 42 + ->setChangesets($diff->getChangesets()) 43 + ->setViewer($viewer) 44 + ->setFormat('git'); 45 45 46 - $renderer = new DifferentialRawDiffRenderer(); 47 - $renderer->setChangesets($changesets); 48 - $renderer->setViewer($viewer); 49 - $renderer->setFormat('git'); 50 46 return $renderer->buildPatch(); 51 - 52 47 } 48 + 53 49 }
+14 -7
src/applications/differential/parser/__tests__/DifferentialHunkParserTestCase.php
··· 1 1 <?php 2 2 3 3 final class DifferentialHunkParserTestCase extends PhabricatorTestCase { 4 + 4 5 private function createComment() { 5 6 $comment = new DifferentialInlineComment(); 6 7 return $comment; 7 8 } 8 9 10 + private function createHunk( 11 + $old_offset, 12 + $old_len, 13 + $new_offset, 14 + $new_len, 15 + $changes) { 9 16 17 + $hunk = id(new DifferentialHunk()) 18 + ->setOldOffset($old_offset) 19 + ->setOldLen($old_len) 20 + ->setNewOffset($new_offset) 21 + ->setNewLen($new_len) 22 + ->setChanges($changes); 10 23 11 - private function createHunk($oldOffset, $oldLen, $newOffset, $newLen, $changes) { 12 - $hunk = new DifferentialHunk(); 13 - $hunk->setOldOffset($oldOffset); 14 - $hunk->setOldLen($oldLen); 15 - $hunk->setNewOffset($newOffset); 16 - $hunk->setNewLen($newLen); 17 - $hunk->setChanges($changes); 18 24 return $hunk; 19 25 } 26 + 20 27 // Returns a change that consists of a single hunk, starting at line 1. 21 28 private function createSingleChange($old_lines, $new_lines, $changes) { 22 29 return array(
+23 -10
src/applications/differential/query/DifferentialDiffQuery.php
··· 76 76 } 77 77 78 78 79 - if ($this->needChangesets) { 80 - $this->loadChangesets($diffs); 79 + if ($diffs && $this->needChangesets) { 80 + $diffs = $this->loadChangesets($diffs); 81 81 } 82 82 83 - if ($this->needArcanistProjects) { 84 - $this->loadArcanistProjects($diffs); 83 + if ($diffs && $this->needArcanistProjects) { 84 + $diffs = $this->loadArcanistProjects($diffs); 85 85 } 86 86 87 87 return $diffs; 88 88 } 89 89 90 90 private function loadChangesets(array $diffs) { 91 + $diff_ids = mpull($diffs, 'getID'); 92 + 93 + $changesets = id(new DifferentialChangeset())->loadAllWhere( 94 + 'diffID IN (%Ld)', 95 + $diff_ids); 96 + 97 + if ($changesets) { 98 + id(new DifferentialHunkQuery()) 99 + ->setViewer($this->getViewer()) 100 + ->setParentQuery($this) 101 + ->withChangesets($changesets) 102 + ->needAttachToChangesets(true) 103 + ->execute(); 104 + } 105 + 106 + $changeset_groups = mgroup($changesets, 'getDiffID'); 91 107 foreach ($diffs as $diff) { 92 - $diff->attachChangesets( 93 - $diff->loadRelatives(new DifferentialChangeset(), 'diffID')); 94 - foreach ($diff->getChangesets() as $changeset) { 95 - $changeset->attachHunks( 96 - $changeset->loadRelatives(new DifferentialHunk(), 'changesetID')); 97 - } 108 + $diff_changesets = idx($changeset_groups, $diff->getID(), array()); 109 + $diff->attachChangesets($diff_changesets); 98 110 } 111 + 99 112 return $diffs; 100 113 } 101 114
-4
src/applications/differential/render/DifferentialRawDiffRenderer.php
··· 37 37 public function buildPatch() { 38 38 $diff = new DifferentialDiff(); 39 39 $diff->attachChangesets($this->getChangesets()); 40 - foreach ($diff->getChangesets() as $changeset) { 41 - $changeset->attachHunks( 42 - $changeset->loadRelatives(new DifferentialHunk(), 'changesetID')); 43 - } 44 40 45 41 $raw_changes = $diff->buildChangesList(); 46 42 $changes = array();
+27 -1
src/applications/differential/storage/DifferentialChangeset.php
··· 1 1 <?php 2 2 3 - final class DifferentialChangeset extends DifferentialDAO { 3 + final class DifferentialChangeset extends DifferentialDAO 4 + implements PhabricatorPolicyInterface { 4 5 5 6 protected $diffID; 6 7 protected $oldFile; ··· 16 17 17 18 private $unsavedHunks = array(); 18 19 private $hunks = self::ATTACHABLE; 20 + private $diff = self::ATTACHABLE; 19 21 20 22 const TABLE_CACHE = 'differential_changeset_parse_cache'; 21 23 ··· 170 172 } 171 173 172 174 return false; 175 + } 176 + 177 + 178 + /* -( PhabricatorPolicyInterface )----------------------------------------- */ 179 + 180 + 181 + public function getCapabilities() { 182 + return array( 183 + PhabricatorPolicyCapability::CAN_VIEW, 184 + ); 185 + } 186 + 187 + public function getPolicy($capability) { 188 + // TODO: For now, these are never queried directly through the policy 189 + // framework. Fix that up. 190 + return PhabricatorPolicies::getMostOpenPolicy(); 191 + } 192 + 193 + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 194 + return false; 195 + } 196 + 197 + public function describeAutomaticCapability($capability) { 198 + return null; 173 199 } 174 200 175 201 }