2011-01-27 23:55:52 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialRevisionUpdateHistoryView extends AphrontView {
|
|
|
|
|
|
|
|
private $diffs = array();
|
2011-02-03 22:20:43 +01:00
|
|
|
private $selectedVersusDiffID;
|
|
|
|
private $selectedDiffID;
|
2011-04-18 22:38:54 +02:00
|
|
|
private $selectedWhitespace;
|
2011-12-04 01:36:19 +01:00
|
|
|
private $user;
|
2011-01-27 23:55:52 +01:00
|
|
|
|
2012-05-22 02:55:35 +02:00
|
|
|
public function setDiffs(array $diffs) {
|
|
|
|
assert_instances_of($diffs, 'DifferentialDiff');
|
2011-01-27 23:55:52 +01:00
|
|
|
$this->diffs = $diffs;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-03 22:20:43 +01:00
|
|
|
public function setSelectedVersusDiffID($id) {
|
|
|
|
$this->selectedVersusDiffID = $id;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setSelectedDiffID($id) {
|
|
|
|
$this->selectedDiffID = $id;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-04-18 22:38:54 +02:00
|
|
|
public function setSelectedWhitespace($whitespace) {
|
|
|
|
$this->selectedWhitespace = $whitespace;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-12-04 01:36:19 +01:00
|
|
|
public function setUser($user) {
|
|
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUser() {
|
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
|
2011-01-27 23:55:52 +01:00
|
|
|
public function render() {
|
|
|
|
|
|
|
|
require_celerity_resource('differential-core-view-css');
|
|
|
|
require_celerity_resource('differential-revision-history-css');
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
array(
|
|
|
|
'name' => 'Base',
|
|
|
|
'id' => null,
|
|
|
|
'desc' => 'Base',
|
|
|
|
'age' => null,
|
2011-02-05 02:53:14 +01:00
|
|
|
'obj' => null,
|
2011-01-27 23:55:52 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
$seq = 0;
|
|
|
|
foreach ($this->diffs as $diff) {
|
|
|
|
$data[] = array(
|
|
|
|
'name' => 'Diff '.(++$seq),
|
|
|
|
'id' => $diff->getID(),
|
2011-02-05 02:53:14 +01:00
|
|
|
'desc' => $diff->getDescription(),
|
2011-01-27 23:55:52 +01:00
|
|
|
'age' => $diff->getDateCreated(),
|
2011-02-05 02:53:14 +01:00
|
|
|
'obj' => $diff,
|
2011-01-27 23:55:52 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-02-03 22:20:43 +01:00
|
|
|
$max_id = $diff->getID();
|
|
|
|
|
2011-01-27 23:55:52 +01:00
|
|
|
$idx = 0;
|
|
|
|
$rows = array();
|
2011-02-04 00:41:58 +01:00
|
|
|
$disable = false;
|
|
|
|
$radios = array();
|
2011-07-17 03:44:48 +02:00
|
|
|
$last_base = null;
|
2011-01-27 23:55:52 +01:00
|
|
|
foreach ($data as $row) {
|
|
|
|
|
2012-01-31 21:07:41 +01:00
|
|
|
$diff = $row['obj'];
|
2012-02-06 19:55:55 +01:00
|
|
|
$name = $row['name'];
|
|
|
|
$id = $row['id'];
|
2011-01-27 23:55:52 +01:00
|
|
|
|
2011-02-03 22:20:43 +01:00
|
|
|
$old_class = null;
|
|
|
|
$new_class = null;
|
|
|
|
|
2011-02-04 00:41:58 +01:00
|
|
|
if ($id) {
|
|
|
|
$new_checked = ($this->selectedDiffID == $id);
|
|
|
|
$new = javelin_render_tag(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'radio',
|
|
|
|
'name' => 'id',
|
|
|
|
'value' => $id,
|
|
|
|
'checked' => $new_checked ? 'checked' : null,
|
|
|
|
'sigil' => 'differential-new-radio',
|
|
|
|
));
|
|
|
|
if ($new_checked) {
|
|
|
|
$new_class = " revhistory-new-now";
|
|
|
|
$disable = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$new = null;
|
|
|
|
}
|
|
|
|
|
2011-02-03 22:20:43 +01:00
|
|
|
if ($max_id != $id) {
|
|
|
|
$uniq = celerity_generate_unique_node_id();
|
|
|
|
$old_checked = ($this->selectedVersusDiffID == $id);
|
|
|
|
$old = phutil_render_tag(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'radio',
|
|
|
|
'name' => 'vs',
|
2011-02-04 00:41:58 +01:00
|
|
|
'value' => $id,
|
2011-02-03 22:20:43 +01:00
|
|
|
'id' => $uniq,
|
|
|
|
'checked' => $old_checked ? 'checked' : null,
|
2011-02-04 00:41:58 +01:00
|
|
|
'disabled' => $disable ? 'disabled' : null,
|
2011-02-03 22:20:43 +01:00
|
|
|
));
|
|
|
|
$radios[] = $uniq;
|
|
|
|
if ($old_checked) {
|
|
|
|
$old_class = " revhistory-old-now";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$old = null;
|
|
|
|
}
|
|
|
|
|
2011-07-17 03:44:48 +02:00
|
|
|
$desc = $row['desc'];
|
|
|
|
|
2011-02-05 02:53:14 +01:00
|
|
|
if ($row['age']) {
|
2011-12-04 01:36:19 +01:00
|
|
|
$age = phabricator_datetime($row['age'], $this->getUser());
|
2011-02-05 02:53:14 +01:00
|
|
|
} else {
|
|
|
|
$age = null;
|
|
|
|
}
|
2011-01-27 23:55:52 +01:00
|
|
|
|
|
|
|
if (++$idx % 2) {
|
|
|
|
$class = ' class="alt"';
|
|
|
|
} else {
|
|
|
|
$class = null;
|
|
|
|
}
|
|
|
|
|
2012-01-31 21:07:41 +01:00
|
|
|
if ($diff) {
|
2011-02-05 02:53:14 +01:00
|
|
|
$lint = self::renderDiffLintStar($row['obj']);
|
|
|
|
$unit = self::renderDiffUnitStar($row['obj']);
|
2012-01-24 08:28:46 +01:00
|
|
|
$lint_message = self::getDiffLintMessage($diff);
|
|
|
|
$unit_message = self::getDiffUnitMessage($diff);
|
|
|
|
$lint_title = ' title="'.phutil_escape_html($lint_message).'"';
|
|
|
|
$unit_title = ' title="'.phutil_escape_html($unit_message).'"';
|
2012-01-31 21:07:41 +01:00
|
|
|
$base = $this->renderBaseRevision($diff);
|
2011-02-05 02:53:14 +01:00
|
|
|
} else {
|
|
|
|
$lint = null;
|
|
|
|
$unit = null;
|
2012-01-24 08:28:46 +01:00
|
|
|
$lint_title = null;
|
|
|
|
$unit_title = null;
|
2012-01-31 21:07:41 +01:00
|
|
|
$base = null;
|
2011-02-05 02:53:14 +01:00
|
|
|
}
|
|
|
|
|
2011-07-17 03:44:48 +02:00
|
|
|
if ($last_base !== null && $base !== $last_base) {
|
|
|
|
// TODO: Render some kind of notice about rebases.
|
|
|
|
}
|
|
|
|
$last_base = $base;
|
|
|
|
|
2011-01-27 23:55:52 +01:00
|
|
|
$rows[] =
|
|
|
|
'<tr'.$class.'>'.
|
2012-02-06 19:55:55 +01:00
|
|
|
'<td class="revhistory-name">'.phutil_escape_html($name).'</td>'.
|
|
|
|
'<td class="revhistory-id">'.phutil_escape_html($id).'</td>'.
|
2011-07-17 03:44:48 +02:00
|
|
|
'<td class="revhistory-base">'.phutil_escape_html($base).'</td>'.
|
|
|
|
'<td class="revhistory-desc">'.phutil_escape_html($desc).'</td>'.
|
2011-01-27 23:55:52 +01:00
|
|
|
'<td class="revhistory-age">'.$age.'</td>'.
|
2012-01-24 08:28:46 +01:00
|
|
|
'<td class="revhistory-star"'.$lint_title.'>'.$lint.'</td>'.
|
|
|
|
'<td class="revhistory-star"'.$unit_title.'>'.$unit.'</td>'.
|
2011-02-03 22:20:43 +01:00
|
|
|
'<td class="revhistory-old'.$old_class.'">'.$old.'</td>'.
|
|
|
|
'<td class="revhistory-new'.$new_class.'">'.$new.'</td>'.
|
2011-01-27 23:55:52 +01:00
|
|
|
'</tr>';
|
|
|
|
}
|
|
|
|
|
2011-07-17 03:44:48 +02:00
|
|
|
Javelin::initBehavior(
|
|
|
|
'differential-diff-radios',
|
|
|
|
array(
|
|
|
|
'radios' => $radios,
|
|
|
|
));
|
2011-02-04 00:41:58 +01:00
|
|
|
|
2011-07-17 03:44:48 +02:00
|
|
|
$options = array(
|
2012-03-13 01:06:36 +01:00
|
|
|
DifferentialChangesetParser::WHITESPACE_IGNORE_FORCE => 'Ignore All',
|
2012-02-06 20:13:45 +01:00
|
|
|
DifferentialChangesetParser::WHITESPACE_IGNORE_ALL => 'Ignore Most',
|
|
|
|
DifferentialChangesetParser::WHITESPACE_IGNORE_TRAILING =>
|
|
|
|
'Ignore Trailing',
|
|
|
|
DifferentialChangesetParser::WHITESPACE_SHOW_ALL => 'Show All',
|
2011-07-17 03:44:48 +02:00
|
|
|
);
|
2011-04-18 22:38:54 +02:00
|
|
|
|
2011-07-17 03:44:48 +02:00
|
|
|
$select = '<select name="whitespace">';
|
|
|
|
foreach ($options as $value => $label) {
|
|
|
|
$select .= phutil_render_tag(
|
|
|
|
'option',
|
|
|
|
array(
|
|
|
|
'value' => $value,
|
|
|
|
'selected' => ($value == $this->selectedWhitespace)
|
|
|
|
? 'selected'
|
|
|
|
: null,
|
|
|
|
),
|
|
|
|
phutil_escape_html($label));
|
|
|
|
}
|
|
|
|
$select .= '</select>';
|
2011-01-27 23:55:52 +01:00
|
|
|
|
|
|
|
return
|
|
|
|
'<div class="differential-revision-history differential-panel">'.
|
|
|
|
'<h1>Revision Update History</h1>'.
|
2012-08-22 00:01:20 +02:00
|
|
|
'<form action="#toc">'.
|
2011-01-27 23:55:52 +01:00
|
|
|
'<table class="differential-revision-history-table">'.
|
|
|
|
'<tr>'.
|
|
|
|
'<th>Diff</th>'.
|
|
|
|
'<th>ID</th>'.
|
2011-07-17 03:44:48 +02:00
|
|
|
'<th>Base</th>'.
|
2011-01-27 23:55:52 +01:00
|
|
|
'<th>Description</th>'.
|
2011-02-05 02:53:14 +01:00
|
|
|
'<th>Created</th>'.
|
2011-01-27 23:55:52 +01:00
|
|
|
'<th>Lint</th>'.
|
|
|
|
'<th>Unit</th>'.
|
|
|
|
'</tr>'.
|
|
|
|
implode("\n", $rows).
|
|
|
|
'<tr>'.
|
|
|
|
'<td colspan="8" class="diff-differ-submit">'.
|
|
|
|
'<label>Whitespace Changes: '.$select.'</label>'.
|
2011-02-03 22:20:43 +01:00
|
|
|
'<button>Show Diff</button>'.
|
2011-01-27 23:55:52 +01:00
|
|
|
'</td>'.
|
|
|
|
'</tr>'.
|
|
|
|
'</table>'.
|
|
|
|
'</form>'.
|
|
|
|
'</div>';
|
|
|
|
}
|
2011-02-05 02:53:14 +01:00
|
|
|
|
|
|
|
const STAR_NONE = 'none';
|
|
|
|
const STAR_OKAY = 'okay';
|
|
|
|
const STAR_WARN = 'warn';
|
|
|
|
const STAR_FAIL = 'fail';
|
|
|
|
const STAR_SKIP = 'skip';
|
|
|
|
|
|
|
|
public static function renderDiffLintStar(DifferentialDiff $diff) {
|
|
|
|
static $map = array(
|
|
|
|
DifferentialLintStatus::LINT_NONE => self::STAR_NONE,
|
|
|
|
DifferentialLintStatus::LINT_OKAY => self::STAR_OKAY,
|
|
|
|
DifferentialLintStatus::LINT_WARN => self::STAR_WARN,
|
|
|
|
DifferentialLintStatus::LINT_FAIL => self::STAR_FAIL,
|
|
|
|
DifferentialLintStatus::LINT_SKIP => self::STAR_SKIP,
|
2012-06-15 02:09:24 +02:00
|
|
|
DifferentialLintStatus::LINT_POSTPONED => self::STAR_SKIP
|
2011-02-05 02:53:14 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$star = idx($map, $diff->getLintStatus(), self::STAR_FAIL);
|
|
|
|
|
|
|
|
return self::renderDiffStar($star);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function renderDiffUnitStar(DifferentialDiff $diff) {
|
|
|
|
static $map = array(
|
|
|
|
DifferentialUnitStatus::UNIT_NONE => self::STAR_NONE,
|
|
|
|
DifferentialUnitStatus::UNIT_OKAY => self::STAR_OKAY,
|
|
|
|
DifferentialUnitStatus::UNIT_WARN => self::STAR_WARN,
|
|
|
|
DifferentialUnitStatus::UNIT_FAIL => self::STAR_FAIL,
|
|
|
|
DifferentialUnitStatus::UNIT_SKIP => self::STAR_SKIP,
|
2011-06-09 01:16:59 +02:00
|
|
|
DifferentialUnitStatus::UNIT_POSTPONED => self::STAR_SKIP,
|
2011-02-05 02:53:14 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$star = idx($map, $diff->getUnitStatus(), self::STAR_FAIL);
|
|
|
|
|
|
|
|
return self::renderDiffStar($star);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getDiffLintMessage(DifferentialDiff $diff) {
|
|
|
|
switch ($diff->getLintStatus()) {
|
|
|
|
case DifferentialLintStatus::LINT_NONE:
|
|
|
|
return 'No Linters Available';
|
|
|
|
case DifferentialLintStatus::LINT_OKAY:
|
|
|
|
return 'Lint OK';
|
|
|
|
case DifferentialLintStatus::LINT_WARN:
|
|
|
|
return 'Lint Warnings';
|
|
|
|
case DifferentialLintStatus::LINT_FAIL:
|
|
|
|
return 'Lint Errors';
|
|
|
|
case DifferentialLintStatus::LINT_SKIP:
|
|
|
|
return 'Lint Skipped';
|
2012-06-15 02:09:24 +02:00
|
|
|
case DifferentialLintStatus::LINT_POSTPONED:
|
|
|
|
return 'Lint Postponed';
|
2011-02-05 02:53:14 +01:00
|
|
|
}
|
|
|
|
return '???';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getDiffUnitMessage(DifferentialDiff $diff) {
|
|
|
|
switch ($diff->getUnitStatus()) {
|
|
|
|
case DifferentialUnitStatus::UNIT_NONE:
|
|
|
|
return 'No Unit Test Coverage';
|
|
|
|
case DifferentialUnitStatus::UNIT_OKAY:
|
|
|
|
return 'Unit Tests OK';
|
|
|
|
case DifferentialUnitStatus::UNIT_WARN:
|
|
|
|
return 'Unit Test Warnings';
|
|
|
|
case DifferentialUnitStatus::UNIT_FAIL:
|
|
|
|
return 'Unit Test Errors';
|
|
|
|
case DifferentialUnitStatus::UNIT_SKIP:
|
|
|
|
return 'Unit Tests Skipped';
|
2011-06-09 01:16:59 +02:00
|
|
|
case DifferentialUnitStatus::UNIT_POSTPONED:
|
|
|
|
return 'Unit Tests Postponed';
|
2011-02-05 02:53:14 +01:00
|
|
|
}
|
|
|
|
return '???';
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function renderDiffStar($star) {
|
|
|
|
$class = 'diff-star-'.$star;
|
|
|
|
return
|
|
|
|
'<span class="'.$class.'">'.
|
|
|
|
"\xE2\x98\x85".
|
|
|
|
'</span>';
|
|
|
|
}
|
|
|
|
|
2011-07-17 03:44:48 +02:00
|
|
|
private function renderBaseRevision(DifferentialDiff $diff) {
|
|
|
|
switch ($diff->getSourceControlSystem()) {
|
|
|
|
case 'git':
|
2012-01-08 10:39:35 +01:00
|
|
|
$base = $diff->getSourceControlBaseRevision();
|
|
|
|
if (strpos($base, '@') === false) {
|
|
|
|
return substr($base, 0, 7);
|
|
|
|
} else {
|
|
|
|
// The diff is from git-svn
|
|
|
|
$base = explode('@', $base);
|
|
|
|
$base = last($base);
|
|
|
|
return $base;
|
|
|
|
}
|
2011-07-17 03:44:48 +02:00
|
|
|
case 'svn':
|
|
|
|
$base = $diff->getSourceControlBaseRevision();
|
|
|
|
$base = explode('@', $base);
|
2012-01-08 10:39:35 +01:00
|
|
|
$base = last($base);
|
2011-07-17 03:44:48 +02:00
|
|
|
return $base;
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2011-01-27 23:55:52 +01:00
|
|
|
}
|