Path: blob/master/src/applications/differential/customfield/DifferentialBranchField.php
12256 views
<?php12final class DifferentialBranchField3extends DifferentialCustomField {45public function getFieldKey() {6return 'differential:branch';7}89public function getFieldName() {10return pht('Branch');11}1213public function getFieldDescription() {14return pht('Shows the branch a diff came from.');15}1617public function shouldAppearInPropertyView() {18return true;19}2021public function renderPropertyViewValue(array $handles) {22return null;23}2425public function shouldAppearInDiffPropertyView() {26return true;27}2829public function renderDiffPropertyViewLabel(DifferentialDiff $diff) {30return $this->getFieldName();31}3233public function renderDiffPropertyViewValue(DifferentialDiff $diff) {34return $this->getBranchDescription($diff);35}3637private function getBranchDescription(DifferentialDiff $diff) {38$branch = $diff->getBranch();39$bookmark = $diff->getBookmark();4041if ($branch === null) {42$branch = '';43}44if ($bookmark === null) {45$bookmark = '';46}4748if (strlen($branch) && strlen($bookmark)) {49return pht('%s (bookmark) on %s (branch)', $bookmark, $branch);50} else if (strlen($bookmark)) {51return pht('%s (bookmark)', $bookmark);52} else if (strlen($branch)) {53$onto = $diff->loadTargetBranch();54if ($onto !== null && strlen($onto) && ($onto !== $branch)) {55return pht(56'%s (branched from %s)',57$branch,58$onto);59} else {60return $branch;61}62} else {63return null;64}65}6667public function getProTips() {68return array(69pht(70'In Git and Mercurial, use a branch like "%s" to automatically '.71'associate changes with the corresponding task.',72'T123'),73);74}7576public function shouldAppearInTransactionMail() {77return true;78}7980public function updateTransactionMailBody(81PhabricatorMetaMTAMailBody $body,82PhabricatorApplicationTransactionEditor $editor,83array $xactions) {8485$revision = $this->getObject();8687// Show the "BRANCH" section only if there's a new diff or the revision88// is "Accepted".89$is_update = (bool)$editor->getDiffUpdateTransaction($xactions);90$is_accepted = $revision->isAccepted();91if (!$is_update && !$is_accepted) {92return;93}9495$branch = $this->getBranchDescription($revision->getActiveDiff());96if ($branch === null) {97return;98}99100$body->addTextSection(pht('BRANCH'), $branch);101}102103}104105106