2011-08-30 20:34:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialLocalCommitsView extends AphrontView {
|
|
|
|
|
|
|
|
private $localCommits;
|
|
|
|
|
|
|
|
public function setLocalCommits($local_commits) {
|
|
|
|
$this->localCommits = $local_commits;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
$user = $this->user;
|
|
|
|
if (!$user) {
|
|
|
|
throw new Exception("Call setUser() before render()-ing this view.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$local = $this->localCommits;
|
|
|
|
if (!$local) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
require_celerity_resource('differential-local-commits-view-css');
|
|
|
|
|
|
|
|
$has_tree = false;
|
|
|
|
$has_local = false;
|
|
|
|
|
|
|
|
foreach ($local as $commit) {
|
|
|
|
if (idx($commit, 'tree')) {
|
|
|
|
$has_tree = true;
|
|
|
|
}
|
|
|
|
if (idx($commit, 'local')) {
|
|
|
|
$has_local = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$rows = array();
|
2012-12-13 19:46:41 +01:00
|
|
|
$highlight = true;
|
2011-08-30 20:34:07 +02:00
|
|
|
foreach ($local as $commit) {
|
2012-12-13 19:46:41 +01:00
|
|
|
if ($highlight) {
|
|
|
|
$class = 'alt';
|
|
|
|
$highlight = false;
|
|
|
|
} else {
|
|
|
|
$class = '';
|
|
|
|
$highlight = true;
|
|
|
|
}
|
|
|
|
|
2011-08-30 20:34:07 +02:00
|
|
|
|
|
|
|
$row = array();
|
|
|
|
if (idx($commit, 'commit')) {
|
|
|
|
$commit_hash = substr($commit['commit'], 0, 16);
|
|
|
|
} else if (isset($commit['rev'])) {
|
|
|
|
$commit_hash = substr($commit['rev'], 0, 16);
|
|
|
|
} else {
|
|
|
|
$commit_hash = null;
|
|
|
|
}
|
2013-02-08 21:07:44 +01:00
|
|
|
$row[] = phutil_tag('td', array(), $commit_hash);
|
2011-08-30 20:34:07 +02:00
|
|
|
|
|
|
|
if ($has_tree) {
|
|
|
|
$tree = idx($commit, 'tree');
|
|
|
|
$tree = substr($tree, 0, 16);
|
2013-02-08 21:07:44 +01:00
|
|
|
$row[] = phutil_tag('td', array(), $tree);
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($has_local) {
|
|
|
|
$local_rev = idx($commit, 'local', null);
|
2013-02-08 21:07:44 +01:00
|
|
|
$row[] = phutil_tag('td', array(), $local_rev);
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$parents = idx($commit, 'parents', array());
|
|
|
|
foreach ($parents as $k => $parent) {
|
|
|
|
if (is_array($parent)) {
|
|
|
|
$parent = idx($parent, 'rev');
|
|
|
|
}
|
2013-02-08 21:07:44 +01:00
|
|
|
$parents[$k] = substr($parent, 0, 16);
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|
2013-02-11 20:17:14 +01:00
|
|
|
$parents = phutil_implode_html(phutil_tag('br'), $parents);
|
2013-02-08 21:07:44 +01:00
|
|
|
$row[] = phutil_tag('td', array(), $parents);
|
2011-08-30 20:34:07 +02:00
|
|
|
|
|
|
|
$author = nonempty(
|
|
|
|
idx($commit, 'user'),
|
|
|
|
idx($commit, 'author'));
|
2013-02-08 21:07:44 +01:00
|
|
|
$row[] = phutil_tag('td', array(), $author);
|
2011-08-30 20:34:07 +02:00
|
|
|
|
2012-05-10 00:56:37 +02:00
|
|
|
$message = idx($commit, 'message');
|
|
|
|
|
2011-08-30 20:34:07 +02:00
|
|
|
$summary = idx($commit, 'summary');
|
2012-05-10 00:56:37 +02:00
|
|
|
$summary = phutil_utf8_shorten($summary, 80);
|
|
|
|
|
|
|
|
$view = new AphrontMoreView();
|
2013-01-31 18:08:02 +01:00
|
|
|
$view->setSome($summary);
|
2012-05-10 00:56:37 +02:00
|
|
|
|
|
|
|
if ($message && (trim($summary) != trim($message))) {
|
2013-01-31 18:08:02 +01:00
|
|
|
$view->setMore(phutil_escape_html_newlines($message));
|
2012-05-10 00:56:37 +02:00
|
|
|
}
|
|
|
|
|
2013-01-31 18:08:02 +01:00
|
|
|
$row[] = phutil_tag(
|
2012-05-10 00:56:37 +02:00
|
|
|
'td',
|
|
|
|
array(
|
|
|
|
'class' => 'summary',
|
|
|
|
),
|
|
|
|
$view->render());
|
2011-08-30 20:34:07 +02:00
|
|
|
|
|
|
|
$date = nonempty(
|
|
|
|
idx($commit, 'date'),
|
|
|
|
idx($commit, 'time'));
|
|
|
|
if ($date) {
|
|
|
|
$date = phabricator_datetime($date, $user);
|
|
|
|
}
|
2013-02-08 21:07:44 +01:00
|
|
|
$row[] = phutil_tag('td', array(), $date);
|
2011-08-30 20:34:07 +02:00
|
|
|
|
2013-02-08 21:07:44 +01:00
|
|
|
$rows[] = phutil_tag('tr', array('class' => $class), $row);
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$headers = array();
|
2013-01-24 22:18:44 +01:00
|
|
|
$headers[] = '<th>'.pht('Commit').'</th>';
|
2011-08-30 20:34:07 +02:00
|
|
|
if ($has_tree) {
|
2013-01-24 22:18:44 +01:00
|
|
|
$headers[] = '<th>'.pht('Tree').'</th>';
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|
|
|
|
if ($has_local) {
|
2013-01-24 22:18:44 +01:00
|
|
|
$headers[] = '<th>'.pht('Local').'</th>';
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|
2013-01-24 22:18:44 +01:00
|
|
|
$headers[] = '<th>'.pht('Parents').'</th>';
|
|
|
|
$headers[] = '<th>'.pht('Author').'</th>';
|
|
|
|
$headers[] = '<th>'.pht('Summary').'</th>';
|
|
|
|
$headers[] = '<th>'.pht('Date').'</th>';
|
2011-08-30 20:34:07 +02:00
|
|
|
|
|
|
|
$headers = '<tr>'.implode('', $headers).'</tr>';
|
|
|
|
|
|
|
|
return
|
2012-12-13 06:00:35 +01:00
|
|
|
id(new PhabricatorHeaderView())
|
|
|
|
->setHeader(pht('Local Commits'))
|
|
|
|
->render().
|
2011-08-30 20:34:07 +02:00
|
|
|
'<div class="differential-panel">'.
|
|
|
|
'<table class="differential-local-commits-table">'.
|
|
|
|
$headers.
|
|
|
|
implode("\n", $rows).
|
|
|
|
'</table>'.
|
|
|
|
'</div>';
|
|
|
|
}
|
|
|
|
}
|