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