Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13975344
D8765.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D8765.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
@@ -380,6 +380,7 @@
'DifferentialHunk' => 'applications/differential/storage/DifferentialHunk.php',
'DifferentialHunkParser' => 'applications/differential/parser/DifferentialHunkParser.php',
'DifferentialHunkParserTestCase' => 'applications/differential/parser/__tests__/DifferentialHunkParserTestCase.php',
+ 'DifferentialHunkQuery' => 'applications/differential/query/DifferentialHunkQuery.php',
'DifferentialHunkTestCase' => 'applications/differential/storage/__tests__/DifferentialHunkTestCase.php',
'DifferentialInlineComment' => 'applications/differential/storage/DifferentialInlineComment.php',
'DifferentialInlineCommentEditController' => 'applications/differential/controller/DifferentialInlineCommentEditController.php',
@@ -2958,8 +2959,13 @@
'DifferentialGitSVNIDField' => 'DifferentialCustomField',
'DifferentialHostField' => 'DifferentialCustomField',
'DifferentialHovercardEventListener' => 'PhabricatorEventListener',
- 'DifferentialHunk' => 'DifferentialDAO',
+ 'DifferentialHunk' =>
+ array(
+ 0 => 'DifferentialDAO',
+ 1 => 'PhabricatorPolicyInterface',
+ ),
'DifferentialHunkParserTestCase' => 'PhabricatorTestCase',
+ 'DifferentialHunkQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'DifferentialHunkTestCase' => 'ArcanistPhutilTestCase',
'DifferentialInlineComment' => 'PhabricatorInlineCommentInterface',
'DifferentialInlineCommentEditController' => 'PhabricatorInlineCommentController',
diff --git a/src/applications/differential/query/DifferentialHunkQuery.php b/src/applications/differential/query/DifferentialHunkQuery.php
new file mode 100644
--- /dev/null
+++ b/src/applications/differential/query/DifferentialHunkQuery.php
@@ -0,0 +1,87 @@
+<?php
+
+final class DifferentialHunkQuery
+ extends PhabricatorCursorPagedPolicyAwareQuery {
+
+ private $changesets;
+ private $shouldAttachToChangesets;
+
+ public function withChangesets(array $changesets) {
+ assert_instances_of($changesets, 'DifferentialChangeset');
+ $this->changesets = $changesets;
+ return $this;
+ }
+
+ public function needAttachToChangesets($attach) {
+ $this->shouldAttachToChangesets = $attach;
+ return $this;
+ }
+
+ public function loadPage() {
+ $table = new DifferentialHunk();
+ $conn_r = $table->establishConnection('r');
+
+ $data = queryfx_all(
+ $conn_r,
+ 'SELECT * FROM %T %Q %Q %Q',
+ $table->getTableName(),
+ $this->buildWhereClause($conn_r),
+ $this->buildOrderClause($conn_r),
+ $this->buildLimitClause($conn_r));
+
+ return $table->loadAllFromArray($data);
+ }
+
+ public function willFilterPage(array $hunks) {
+
+ $changesets = mpull($this->changesets, null, 'getID');
+ foreach ($hunks as $key => $hunk) {
+ $changeset = idx($changesets, $hunk->getChangesetID());
+ if (!$changeset) {
+ unset($hunks[$key]);
+ }
+ $hunk->attachChangeset($changeset);
+ }
+
+ return $hunks;
+ }
+
+ public function didFilterPage(array $hunks) {
+ if ($this->shouldAttachToChangesets) {
+ $hunk_groups = mgroup($hunks, 'getChangesetID');
+ foreach ($this->changesets as $changeset) {
+ $hunks = idx($hunk_groups, $changeset->getID(), array());
+ $changeset->attachHunks($hunks);
+ }
+ }
+
+ return $hunks;
+ }
+
+ private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
+ $where = array();
+
+ if (!$this->changesets) {
+ throw new Exception(
+ pht('You must load hunks via changesets, with withChangesets()!'));
+ }
+
+ $where[] = qsprintf(
+ $conn_r,
+ 'changesetID IN (%Ld)',
+ mpull($this->changesets, 'getID'));
+
+ $where[] = $this->buildPagingClause($conn_r);
+
+ return $this->formatWhereClause($where);
+ }
+
+ public function getQueryApplicationClass() {
+ return 'PhabricatorApplicationDifferential';
+ }
+
+ protected function getReversePaging() {
+ return true;
+ }
+
+}
diff --git a/src/applications/differential/storage/DifferentialHunk.php b/src/applications/differential/storage/DifferentialHunk.php
--- a/src/applications/differential/storage/DifferentialHunk.php
+++ b/src/applications/differential/storage/DifferentialHunk.php
@@ -1,6 +1,7 @@
<?php
-final class DifferentialHunk extends DifferentialDAO {
+final class DifferentialHunk extends DifferentialDAO
+ implements PhabricatorPolicyInterface {
protected $changesetID;
protected $changes;
@@ -9,6 +10,8 @@
protected $newOffset;
protected $newLen;
+ private $changeset;
+
const FLAG_LINES_ADDED = 1;
const FLAG_LINES_REMOVED = 2;
const FLAG_LINES_STABLE = 4;
@@ -101,4 +104,35 @@
return $results;
}
+ public function getChangeset() {
+ return $this->assertAttached($this->changeset);
+ }
+
+ public function attachChangeset(DifferentialChangeset $changeset) {
+ $this->changeset = $changeset;
+ return $this;
+ }
+
+
+/* -( PhabricatorPolicyInterface )----------------------------------------- */
+
+
+ public function getCapabilities() {
+ return array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ );
+ }
+
+ public function getPolicy($capability) {
+ return $this->getChangeset()->getPolicy($capability);
+ }
+
+ public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
+ return $this->getChangeset()->hasAutomaticCapability($capability, $viewer);
+ }
+
+ public function describeAutomaticCapability($capability) {
+ return null;
+ }
+
}
diff --git a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php
--- a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php
+++ b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php
@@ -19,6 +19,7 @@
protected $repository;
protected $affectedPackages;
protected $changesets;
+ private $haveHunks;
public function getAdapterApplicationClass() {
return 'PhabricatorApplicationDifferential';
@@ -180,6 +181,22 @@
return $this->changesets;
}
+ private function loadChangesetsWithHunks() {
+ $changesets = $this->loadChangesets();
+
+ if ($changesets && !$this->haveHunks) {
+ $this->haveHunks = true;
+
+ id(new DifferentialHunkQuery())
+ ->setViewer(PhabricatorUser::getOmnipotentUser())
+ ->withChangesets($changesets)
+ ->needAttachToChangesets(true)
+ ->execute();
+ }
+
+ return $changesets;
+ }
+
protected function loadAffectedPaths() {
$changesets = $this->loadChangesets();
@@ -219,24 +236,16 @@
}
private function loadContentWithMask($mask) {
- $changesets = $this->loadChangesets();
-
- $hunks = array();
- if ($changesets) {
- $hunks = id(new DifferentialHunk())->loadAllWhere(
- 'changesetID in (%Ld)',
- mpull($changesets, 'getID'));
- }
+ $changesets = $this->loadChangesetsWithHunks();
$dict = array();
- $hunks = mgroup($hunks, 'getChangesetID');
- $changesets = mpull($changesets, null, 'getID');
- foreach ($changesets as $id => $changeset) {
- $path = $this->getAbsoluteRepositoryPathForChangeset($changeset);
+ foreach ($changesets as $changeset) {
$content = array();
- foreach (idx($hunks, $id, array()) as $hunk) {
+ foreach ($changeset->getHunks() as $hunk) {
$content[] = $hunk->getContentWithMask($mask);
}
+
+ $path = $this->getAbsoluteRepositoryPathForChangeset($changeset);
$dict[$path] = implode("\n", $content);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Oct 19 2024, 9:45 AM (4 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6731520
Default Alt Text
D8765.diff (7 KB)
Attached To
Mode
D8765: Add DifferentialHunkQuery to start hiding hunk storage details
Attached
Detach File
Event Timeline
Log In to Comment