Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15395037
D9287.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D9287.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -3007,7 +3007,11 @@
'DifferentialBranchField' => 'DifferentialCustomField',
'DifferentialCapabilityDefaultView' => 'PhabricatorPolicyCapability',
'DifferentialChangesSinceLastUpdateField' => 'DifferentialCustomField',
- 'DifferentialChangeset' => 'DifferentialDAO',
+ 'DifferentialChangeset' =>
+ array(
+ 0 => 'DifferentialDAO',
+ 1 => 'PhabricatorPolicyInterface',
+ ),
'DifferentialChangesetDetailView' => 'AphrontView',
'DifferentialChangesetHTMLRenderer' => 'DifferentialChangesetRenderer',
'DifferentialChangesetListView' => 'AphrontView',
diff --git a/src/applications/differential/conduit/ConduitAPI_differential_getrawdiff_Method.php b/src/applications/differential/conduit/ConduitAPI_differential_getrawdiff_Method.php
--- a/src/applications/differential/conduit/ConduitAPI_differential_getrawdiff_Method.php
+++ b/src/applications/differential/conduit/ConduitAPI_differential_getrawdiff_Method.php
@@ -31,23 +31,19 @@
$diff = id(new DifferentialDiffQuery())
->withIDs(array($diff_id))
->setViewer($viewer)
+ ->needChangesets(true)
->executeOne();
if (!$diff) {
throw new ConduitException('ERR_NOT_FOUND');
}
- $changesets = $diff->loadChangesets();
- foreach ($changesets as $changeset) {
- $changeset->attachHunks(
- $changeset->loadHunks());
- }
+ $renderer = id(new DifferentialRawDiffRenderer())
+ ->setChangesets($diff->getChangesets())
+ ->setViewer($viewer)
+ ->setFormat('git');
- $renderer = new DifferentialRawDiffRenderer();
- $renderer->setChangesets($changesets);
- $renderer->setViewer($viewer);
- $renderer->setFormat('git');
return $renderer->buildPatch();
-
}
+
}
diff --git a/src/applications/differential/parser/__tests__/DifferentialHunkParserTestCase.php b/src/applications/differential/parser/__tests__/DifferentialHunkParserTestCase.php
--- a/src/applications/differential/parser/__tests__/DifferentialHunkParserTestCase.php
+++ b/src/applications/differential/parser/__tests__/DifferentialHunkParserTestCase.php
@@ -1,22 +1,29 @@
<?php
final class DifferentialHunkParserTestCase extends PhabricatorTestCase {
+
private function createComment() {
$comment = new DifferentialInlineComment();
return $comment;
}
+ private function createHunk(
+ $old_offset,
+ $old_len,
+ $new_offset,
+ $new_len,
+ $changes) {
+ $hunk = id(new DifferentialHunk())
+ ->setOldOffset($old_offset)
+ ->setOldLen($old_len)
+ ->setNewOffset($new_offset)
+ ->setNewLen($new_len)
+ ->setChanges($changes);
- private function createHunk($oldOffset, $oldLen, $newOffset, $newLen, $changes) {
- $hunk = new DifferentialHunk();
- $hunk->setOldOffset($oldOffset);
- $hunk->setOldLen($oldLen);
- $hunk->setNewOffset($newOffset);
- $hunk->setNewLen($newLen);
- $hunk->setChanges($changes);
return $hunk;
}
+
// Returns a change that consists of a single hunk, starting at line 1.
private function createSingleChange($old_lines, $new_lines, $changes) {
return array(
diff --git a/src/applications/differential/query/DifferentialDiffQuery.php b/src/applications/differential/query/DifferentialDiffQuery.php
--- a/src/applications/differential/query/DifferentialDiffQuery.php
+++ b/src/applications/differential/query/DifferentialDiffQuery.php
@@ -76,26 +76,39 @@
}
- if ($this->needChangesets) {
- $this->loadChangesets($diffs);
+ if ($diffs && $this->needChangesets) {
+ $diffs = $this->loadChangesets($diffs);
}
- if ($this->needArcanistProjects) {
- $this->loadArcanistProjects($diffs);
+ if ($diffs && $this->needArcanistProjects) {
+ $diffs = $this->loadArcanistProjects($diffs);
}
return $diffs;
}
private function loadChangesets(array $diffs) {
+ $diff_ids = mpull($diffs, 'getID');
+
+ $changesets = id(new DifferentialChangeset())->loadAllWhere(
+ 'diffID IN (%Ld)',
+ $diff_ids);
+
+ if ($changesets) {
+ id(new DifferentialHunkQuery())
+ ->setViewer($this->getViewer())
+ ->setParentQuery($this)
+ ->withChangesets($changesets)
+ ->needAttachToChangesets(true)
+ ->execute();
+ }
+
+ $changeset_groups = mgroup($changesets, 'getDiffID');
foreach ($diffs as $diff) {
- $diff->attachChangesets(
- $diff->loadRelatives(new DifferentialChangeset(), 'diffID'));
- foreach ($diff->getChangesets() as $changeset) {
- $changeset->attachHunks(
- $changeset->loadRelatives(new DifferentialHunk(), 'changesetID'));
- }
+ $diff_changesets = idx($changeset_groups, $diff->getID(), array());
+ $diff->attachChangesets($diff_changesets);
}
+
return $diffs;
}
diff --git a/src/applications/differential/render/DifferentialRawDiffRenderer.php b/src/applications/differential/render/DifferentialRawDiffRenderer.php
--- a/src/applications/differential/render/DifferentialRawDiffRenderer.php
+++ b/src/applications/differential/render/DifferentialRawDiffRenderer.php
@@ -37,10 +37,6 @@
public function buildPatch() {
$diff = new DifferentialDiff();
$diff->attachChangesets($this->getChangesets());
- foreach ($diff->getChangesets() as $changeset) {
- $changeset->attachHunks(
- $changeset->loadRelatives(new DifferentialHunk(), 'changesetID'));
- }
$raw_changes = $diff->buildChangesList();
$changes = array();
diff --git a/src/applications/differential/storage/DifferentialChangeset.php b/src/applications/differential/storage/DifferentialChangeset.php
--- a/src/applications/differential/storage/DifferentialChangeset.php
+++ b/src/applications/differential/storage/DifferentialChangeset.php
@@ -1,6 +1,7 @@
<?php
-final class DifferentialChangeset extends DifferentialDAO {
+final class DifferentialChangeset extends DifferentialDAO
+ implements PhabricatorPolicyInterface {
protected $diffID;
protected $oldFile;
@@ -16,6 +17,7 @@
private $unsavedHunks = array();
private $hunks = self::ATTACHABLE;
+ private $diff = self::ATTACHABLE;
const TABLE_CACHE = 'differential_changeset_parse_cache';
@@ -172,4 +174,28 @@
return false;
}
+
+/* -( PhabricatorPolicyInterface )----------------------------------------- */
+
+
+ public function getCapabilities() {
+ return array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ );
+ }
+
+ public function getPolicy($capability) {
+ // TODO: For now, these are never queried directly through the policy
+ // framework. Fix that up.
+ return PhabricatorPolicies::getMostOpenPolicy();
+ }
+
+ public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
+ return false;
+ }
+
+ public function describeAutomaticCapability($capability) {
+ return null;
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Mar 17, 2:55 AM (2 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7224895
Default Alt Text
D9287.diff (6 KB)
Attached To
Mode
D9287: Move more hunk loads into DifferentialHunkQuery
Attached
Detach File
Event Timeline
Log In to Comment