Path: blob/master/src/applications/differential/engineextension/DifferentialCommitsSearchEngineAttachment.php
12256 views
<?php12final class DifferentialCommitsSearchEngineAttachment3extends PhabricatorSearchEngineAttachment {45public function getAttachmentName() {6return pht('Diff Commits');7}89public function getAttachmentDescription() {10return pht('Get the local commits (if any) for each diff.');11}1213public function loadAttachmentData(array $objects, $spec) {14$properties = id(new DifferentialDiffProperty())->loadAllWhere(15'diffID IN (%Ld) AND name = %s',16mpull($objects, 'getID'),17'local:commits');1819$map = array();20foreach ($properties as $property) {21$map[$property->getDiffID()] = $property->getData();22}2324return $map;25}2627public function getAttachmentForObject($object, $data, $spec) {28$diff_id = $object->getID();29$info = idx($data, $diff_id, array());3031// NOTE: This should be similar to the information returned about commits32// by "diffusion.commit.search".3334$list = array();35foreach ($info as $commit) {36$author_epoch = idx($commit, 'time');37if ($author_epoch) {38$author_epoch = (int)$author_epoch;39}4041// TODO: Currently, we don't upload the raw author string from "arc".42// Reconstruct a plausible version of it until we begin uploading this43// information.4445$author_name = idx($commit, 'author');46$author_email = idx($commit, 'authorEmail');47if (strlen($author_name) && strlen($author_email)) {48$author_raw = (string)id(new PhutilEmailAddress())49->setDisplayName($author_name)50->setAddress($author_email);51} else if (strlen($author_email)) {52$author_raw = $author_email;53} else {54$author_raw = $author_name;55}5657$list[] = array(58'identifier' => $commit['commit'],59'tree' => idx($commit, 'tree'),60'parents' => idx($commit, 'parents', array()),61'author' => array(62'name' => $author_name,63'email' => $author_email,64'raw' => $author_raw,65'epoch' => $author_epoch,66),67'message' => idx($commit, 'message'),68);69}7071return array(72'commits' => $list,73);74}7576}777879