Path: blob/master/src/applications/differential/view/DifferentialLocalCommitsView.php
12256 views
<?php12final class DifferentialLocalCommitsView extends AphrontView {34private $localCommits;5private $commitsForLinks = array();67public function setLocalCommits($local_commits) {8$this->localCommits = $local_commits;9return $this;10}1112public function setCommitsForLinks(array $commits) {13assert_instances_of($commits, 'PhabricatorRepositoryCommit');14$this->commitsForLinks = $commits;15return $this;16}1718public function render() {19$viewer = $this->getViewer();2021$local = $this->localCommits;22if (!$local) {23return null;24}2526$has_tree = false;27$has_local = false;2829foreach ($local as $commit) {30if (idx($commit, 'tree')) {31$has_tree = true;32}33if (idx($commit, 'local')) {34$has_local = true;35}36}3738$rows = array();39foreach ($local as $commit) {40$row = array();41if (idx($commit, 'commit')) {42$commit_link = $this->buildCommitLink($commit['commit']);43} else if (isset($commit['rev'])) {44$commit_link = $this->buildCommitLink($commit['rev']);45} else {46$commit_link = null;47}48$row[] = $commit_link;4950if ($has_tree) {51$row[] = $this->buildCommitLink($commit['tree']);52}5354if ($has_local) {55$row[] = $this->buildCommitLink($commit['local']);56}5758$parents = idx($commit, 'parents', array());59foreach ($parents as $k => $parent) {60if (is_array($parent)) {61$parent = idx($parent, 'rev');62}63$parents[$k] = $this->buildCommitLink($parent);64}65$parents = phutil_implode_html(phutil_tag('br'), $parents);66$row[] = $parents;6768$author = nonempty(69idx($commit, 'user'),70idx($commit, 'author'));71$row[] = $author;7273$message = idx($commit, 'message');7475$summary = idx($commit, 'summary');76$summary = id(new PhutilUTF8StringTruncator())77->setMaximumGlyphs(80)78->truncateString($summary);7980$view = new AphrontMoreView();81$view->setSome($summary);8283if ($message && (trim($summary) != trim($message))) {84$view->setMore(phutil_escape_html_newlines($message));85}8687$row[] = $view->render();8889$date = nonempty(90idx($commit, 'date'),91idx($commit, 'time'));92if ($date) {93$date = phabricator_datetime($date, $viewer);94}95$row[] = $date;9697$rows[] = $row;98}99100$column_classes = array('');101if ($has_tree) {102$column_classes[] = '';103}104if ($has_local) {105$column_classes[] = '';106}107$column_classes[] = '';108$column_classes[] = '';109$column_classes[] = 'wide';110$column_classes[] = 'date';111$table = id(new AphrontTableView($rows))112->setColumnClasses($column_classes);113$headers = array();114$headers[] = pht('Commit');115if ($has_tree) {116$headers[] = pht('Tree');117}118if ($has_local) {119$headers[] = pht('Local');120}121$headers[] = pht('Parents');122$headers[] = pht('Author');123$headers[] = pht('Summary');124$headers[] = pht('Date');125$table->setHeaders($headers);126127return $table;128}129130private static function formatCommit($commit) {131return substr($commit, 0, 12);132}133134private function buildCommitLink($hash) {135$commit_for_link = idx($this->commitsForLinks, $hash);136$commit_hash = self::formatCommit($hash);137if ($commit_for_link) {138$link = phutil_tag(139'a',140array(141'href' => $commit_for_link->getURI(),142),143$commit_hash);144} else {145$link = $commit_hash;146}147return $link;148}149150}151152153