mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
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
This commit is contained in:
parent
19403fdb8e
commit
843bfb4fd8
4 changed files with 87 additions and 1 deletions
|
@ -455,6 +455,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialCommitMessageParser' => 'applications/differential/parser/DifferentialCommitMessageParser.php',
|
||||
'DifferentialCommitMessageParserTestCase' => 'applications/differential/parser/__tests__/DifferentialCommitMessageParserTestCase.php',
|
||||
'DifferentialCommitsField' => 'applications/differential/customfield/DifferentialCommitsField.php',
|
||||
'DifferentialCommitsSearchEngineAttachment' => 'applications/differential/engineextension/DifferentialCommitsSearchEngineAttachment.php',
|
||||
'DifferentialConduitAPIMethod' => 'applications/differential/conduit/DifferentialConduitAPIMethod.php',
|
||||
'DifferentialConflictsCommitMessageField' => 'applications/differential/field/DifferentialConflictsCommitMessageField.php',
|
||||
'DifferentialController' => 'applications/differential/controller/DifferentialController.php',
|
||||
|
@ -5733,6 +5734,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialCommitMessageParser' => 'Phobject',
|
||||
'DifferentialCommitMessageParserTestCase' => 'PhabricatorTestCase',
|
||||
'DifferentialCommitsField' => 'DifferentialCustomField',
|
||||
'DifferentialCommitsSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
|
||||
'DifferentialConduitAPIMethod' => 'ConduitAPIMethod',
|
||||
'DifferentialConflictsCommitMessageField' => 'DifferentialCommitMessageField',
|
||||
'DifferentialController' => 'PhabricatorController',
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialCommitsSearchEngineAttachment
|
||||
extends PhabricatorSearchEngineAttachment {
|
||||
|
||||
public function getAttachmentName() {
|
||||
return pht('Diff Commits');
|
||||
}
|
||||
|
||||
public function getAttachmentDescription() {
|
||||
return pht('Get the local commits (if any) for each diff.');
|
||||
}
|
||||
|
||||
public function loadAttachmentData(array $objects, $spec) {
|
||||
$properties = id(new DifferentialDiffProperty())->loadAllWhere(
|
||||
'diffID IN (%Ld) AND name = %s',
|
||||
mpull($objects, 'getID'),
|
||||
'local:commits');
|
||||
|
||||
$map = array();
|
||||
foreach ($properties as $property) {
|
||||
$map[$property->getDiffID()] = $property->getData();
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
public function getAttachmentForObject($object, $data, $spec) {
|
||||
$diff_id = $object->getID();
|
||||
$info = idx($data, $diff_id, array());
|
||||
|
||||
// NOTE: This should be similar to the information returned about commits
|
||||
// by "diffusion.commit.search".
|
||||
|
||||
$list = array();
|
||||
foreach ($info as $commit) {
|
||||
$author_epoch = idx($commit, 'time');
|
||||
if ($author_epoch) {
|
||||
$author_epoch = (int)$author_epoch;
|
||||
}
|
||||
|
||||
// TODO: Currently, we don't upload the raw author string from "arc".
|
||||
// Reconstruct a plausible version of it until we begin uploading this
|
||||
// information.
|
||||
|
||||
$author_name = idx($commit, 'author');
|
||||
$author_email = idx($commit, 'authorEmail');
|
||||
if (strlen($author_name) && strlen($author_email)) {
|
||||
$author_raw = (string)id(new PhutilEmailAddress())
|
||||
->setDisplayName($author_name)
|
||||
->setAddress($author_email);
|
||||
} else if (strlen($author_email)) {
|
||||
$author_raw = $author_email;
|
||||
} else {
|
||||
$author_raw = $author_name;
|
||||
}
|
||||
|
||||
$list[] = array(
|
||||
'identifier' => $commit['commit'],
|
||||
'tree' => idx($commit, 'tree'),
|
||||
'parents' => idx($commit, 'parents', array()),
|
||||
'author' => array(
|
||||
'name' => $author_name,
|
||||
'email' => $author_email,
|
||||
'raw' => $author_raw,
|
||||
'epoch' => $author_epoch,
|
||||
),
|
||||
'message' => idx($commit, 'message'),
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'commits' => $list,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -815,7 +815,10 @@ final class DifferentialDiff
|
|||
}
|
||||
|
||||
public function getConduitSearchAttachments() {
|
||||
return array();
|
||||
return array(
|
||||
id(new DifferentialCommitsSearchEngineAttachment())
|
||||
->setAttachmentKey('commits'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -716,6 +716,10 @@ final class PhabricatorRepositoryCommit
|
|||
}
|
||||
|
||||
public function getFieldValuesForConduit() {
|
||||
|
||||
// NOTE: This data should be similar to the information returned about
|
||||
// commmits by "differential.diff.search" with the "commits" attachment.
|
||||
|
||||
return array(
|
||||
'identifier' => $this->getCommitIdentifier(),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue