@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
at upstream/main 154 lines 3.7 kB view raw
1<?php 2 3final class DifferentialLocalCommitsView extends AphrontView { 4 5 private $localCommits; 6 private $commitsForLinks = array(); 7 8 public function setLocalCommits($local_commits) { 9 $this->localCommits = $local_commits; 10 return $this; 11 } 12 13 /** 14 * @param array<PhabricatorRepositoryCommit> $commits 15 */ 16 public function setCommitsForLinks(array $commits) { 17 assert_instances_of($commits, PhabricatorRepositoryCommit::class); 18 $this->commitsForLinks = $commits; 19 return $this; 20 } 21 22 public function render() { 23 $viewer = $this->getViewer(); 24 25 $local = $this->localCommits; 26 if (!$local) { 27 return null; 28 } 29 30 $has_tree = false; 31 $has_local = false; 32 33 foreach ($local as $commit) { 34 if (idx($commit, 'tree')) { 35 $has_tree = true; 36 } 37 if (idx($commit, 'local')) { 38 $has_local = true; 39 } 40 } 41 42 $rows = array(); 43 foreach ($local as $commit) { 44 $row = array(); 45 if (idx($commit, 'commit')) { 46 $commit_link = $this->buildCommitLink($commit['commit']); 47 } else if (isset($commit['rev'])) { 48 $commit_link = $this->buildCommitLink($commit['rev']); 49 } else { 50 $commit_link = null; 51 } 52 $row[] = $commit_link; 53 54 if ($has_tree) { 55 $row[] = $this->buildCommitLink($commit['tree']); 56 } 57 58 if ($has_local) { 59 $row[] = $this->buildCommitLink($commit['local']); 60 } 61 62 $parents = idx($commit, 'parents', array()); 63 foreach ($parents as $k => $parent) { 64 if (is_array($parent)) { 65 $parent = idx($parent, 'rev'); 66 } 67 $parents[$k] = $this->buildCommitLink($parent); 68 } 69 $parents = phutil_implode_html(phutil_tag('br'), $parents); 70 $row[] = $parents; 71 72 $author = nonempty( 73 idx($commit, 'user'), 74 idx($commit, 'author')); 75 $row[] = $author; 76 77 $message = idx($commit, 'message'); 78 79 $summary = idx($commit, 'summary'); 80 $summary = id(new PhutilUTF8StringTruncator()) 81 ->setMaximumGlyphs(80) 82 ->truncateString($summary); 83 84 $view = new AphrontMoreView(); 85 $view->setSome($summary); 86 87 if ($message && (trim($summary) != trim($message))) { 88 $view->setMore(phutil_escape_html_newlines($message)); 89 } 90 91 $row[] = $view->render(); 92 93 $date = nonempty( 94 idx($commit, 'date'), 95 idx($commit, 'time')); 96 if ($date) { 97 $date = phabricator_datetime($date, $viewer); 98 } 99 $row[] = $date; 100 101 $rows[] = $row; 102 } 103 104 $column_classes = array(''); 105 if ($has_tree) { 106 $column_classes[] = ''; 107 } 108 if ($has_local) { 109 $column_classes[] = ''; 110 } 111 $column_classes[] = ''; 112 $column_classes[] = ''; 113 $column_classes[] = 'wide'; 114 $column_classes[] = 'date'; 115 $table = id(new AphrontTableView($rows)) 116 ->setColumnClasses($column_classes); 117 $headers = array(); 118 $headers[] = pht('Commit'); 119 if ($has_tree) { 120 $headers[] = pht('Tree'); 121 } 122 if ($has_local) { 123 $headers[] = pht('Local'); 124 } 125 $headers[] = pht('Parents'); 126 $headers[] = pht('Author'); 127 $headers[] = pht('Summary'); 128 $headers[] = pht('Date'); 129 $table->setHeaders($headers); 130 131 return $table; 132 } 133 134 private static function formatCommit($commit) { 135 return substr($commit, 0, 12); 136 } 137 138 private function buildCommitLink($hash) { 139 $commit_for_link = idx($this->commitsForLinks, $hash); 140 $commit_hash = self::formatCommit($hash); 141 if ($commit_for_link) { 142 $link = phutil_tag( 143 'a', 144 array( 145 'href' => $commit_for_link->getURI(), 146 ), 147 $commit_hash); 148 } else { 149 $link = $commit_hash; 150 } 151 return $link; 152 } 153 154}