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

Add a "commits" attachment to "differential.diff.search" for retrieving local commit information

Summary:
Ref T13124. See PHI593.

When you `arc diff` in a Git or Mercurial repository, we upload some information about the local commits in your working copy which the change was generated from.

In the future (for example, with T1508) we may increase the prominence of this feature.

Provide a stable way to read this information back via the API. This roughly mirrors the information we provide about commits in "diffusion.commit.search", although the latter is less fleshed-out today.

Test Plan: Used `differential.diff.search` to retrieve commit information about Git, Mercurial, and Subversion diffs. (There's no info for Subversion, but it doesn't crash or anything.)

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13124

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

+87 -1
+2
src/__phutil_library_map__.php
··· 455 455 'DifferentialCommitMessageParser' => 'applications/differential/parser/DifferentialCommitMessageParser.php', 456 456 'DifferentialCommitMessageParserTestCase' => 'applications/differential/parser/__tests__/DifferentialCommitMessageParserTestCase.php', 457 457 'DifferentialCommitsField' => 'applications/differential/customfield/DifferentialCommitsField.php', 458 + 'DifferentialCommitsSearchEngineAttachment' => 'applications/differential/engineextension/DifferentialCommitsSearchEngineAttachment.php', 458 459 'DifferentialConduitAPIMethod' => 'applications/differential/conduit/DifferentialConduitAPIMethod.php', 459 460 'DifferentialConflictsCommitMessageField' => 'applications/differential/field/DifferentialConflictsCommitMessageField.php', 460 461 'DifferentialController' => 'applications/differential/controller/DifferentialController.php', ··· 5733 5734 'DifferentialCommitMessageParser' => 'Phobject', 5734 5735 'DifferentialCommitMessageParserTestCase' => 'PhabricatorTestCase', 5735 5736 'DifferentialCommitsField' => 'DifferentialCustomField', 5737 + 'DifferentialCommitsSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment', 5736 5738 'DifferentialConduitAPIMethod' => 'ConduitAPIMethod', 5737 5739 'DifferentialConflictsCommitMessageField' => 'DifferentialCommitMessageField', 5738 5740 'DifferentialController' => 'PhabricatorController',
+77
src/applications/differential/engineextension/DifferentialCommitsSearchEngineAttachment.php
··· 1 + <?php 2 + 3 + final class DifferentialCommitsSearchEngineAttachment 4 + extends PhabricatorSearchEngineAttachment { 5 + 6 + public function getAttachmentName() { 7 + return pht('Diff Commits'); 8 + } 9 + 10 + public function getAttachmentDescription() { 11 + return pht('Get the local commits (if any) for each diff.'); 12 + } 13 + 14 + public function loadAttachmentData(array $objects, $spec) { 15 + $properties = id(new DifferentialDiffProperty())->loadAllWhere( 16 + 'diffID IN (%Ld) AND name = %s', 17 + mpull($objects, 'getID'), 18 + 'local:commits'); 19 + 20 + $map = array(); 21 + foreach ($properties as $property) { 22 + $map[$property->getDiffID()] = $property->getData(); 23 + } 24 + 25 + return $map; 26 + } 27 + 28 + public function getAttachmentForObject($object, $data, $spec) { 29 + $diff_id = $object->getID(); 30 + $info = idx($data, $diff_id, array()); 31 + 32 + // NOTE: This should be similar to the information returned about commits 33 + // by "diffusion.commit.search". 34 + 35 + $list = array(); 36 + foreach ($info as $commit) { 37 + $author_epoch = idx($commit, 'time'); 38 + if ($author_epoch) { 39 + $author_epoch = (int)$author_epoch; 40 + } 41 + 42 + // TODO: Currently, we don't upload the raw author string from "arc". 43 + // Reconstruct a plausible version of it until we begin uploading this 44 + // information. 45 + 46 + $author_name = idx($commit, 'author'); 47 + $author_email = idx($commit, 'authorEmail'); 48 + if (strlen($author_name) && strlen($author_email)) { 49 + $author_raw = (string)id(new PhutilEmailAddress()) 50 + ->setDisplayName($author_name) 51 + ->setAddress($author_email); 52 + } else if (strlen($author_email)) { 53 + $author_raw = $author_email; 54 + } else { 55 + $author_raw = $author_name; 56 + } 57 + 58 + $list[] = array( 59 + 'identifier' => $commit['commit'], 60 + 'tree' => idx($commit, 'tree'), 61 + 'parents' => idx($commit, 'parents', array()), 62 + 'author' => array( 63 + 'name' => $author_name, 64 + 'email' => $author_email, 65 + 'raw' => $author_raw, 66 + 'epoch' => $author_epoch, 67 + ), 68 + 'message' => idx($commit, 'message'), 69 + ); 70 + } 71 + 72 + return array( 73 + 'commits' => $list, 74 + ); 75 + } 76 + 77 + }
+4 -1
src/applications/differential/storage/DifferentialDiff.php
··· 815 815 } 816 816 817 817 public function getConduitSearchAttachments() { 818 - return array(); 818 + return array( 819 + id(new DifferentialCommitsSearchEngineAttachment()) 820 + ->setAttachmentKey('commits'), 821 + ); 819 822 } 820 823 821 824
+4
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 716 716 } 717 717 718 718 public function getFieldValuesForConduit() { 719 + 720 + // NOTE: This data should be similar to the information returned about 721 + // commmits by "differential.diff.search" with the "commits" attachment. 722 + 719 723 return array( 720 724 'identifier' => $this->getCommitIdentifier(), 721 725 );