1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-09 14:21:02 +01:00

Display local commit information in Differential

Summary:
After D857, we try to attach local commit information to revisions. If this
information is available, display it on the revision.

Design on this is a little rough, I might try to combine this into the revision
update view or something like that since we're starting to take up a lot of real
estate for metadata.

Test Plan: Local diffed this and got some commit info.

Reviewers: jungejason, tuomaspelkonen, aran

Reviewed By: jungejason

CC: aran, epriestley, jungejason

Differential Revision: 872
This commit is contained in:
epriestley 2011-08-30 11:34:07 -07:00
parent 5908a63dfe
commit 76ac8b4196
7 changed files with 221 additions and 5 deletions

View file

@ -193,6 +193,15 @@ celerity_register_resource_map(array(
),
'disk' => '/rsrc/js/application/differential/DifferentialInlineCommentEditor.js',
),
'differential-local-commits-view-css' =>
array(
'uri' => '/res/8cdacd82/rsrc/css/application/differential/local-commits-view.css',
'type' => 'css',
'requires' =>
array(
),
'disk' => '/rsrc/css/application/differential/local-commits-view.css',
),
'differential-revision-add-comment-css' =>
array(
'uri' => '/res/849748d3/rsrc/css/application/differential/add-comment.css',

View file

@ -193,6 +193,7 @@ phutil_register_library_map(array(
'DifferentialLinesFieldSpecification' => 'applications/differential/field/specification/lines',
'DifferentialLintFieldSpecification' => 'applications/differential/field/specification/lint',
'DifferentialLintStatus' => 'applications/differential/constants/lintstatus',
'DifferentialLocalCommitsView' => 'applications/differential/view/localcommits',
'DifferentialMail' => 'applications/differential/mail/base',
'DifferentialManiphestTasksFieldSpecification' => 'applications/differential/field/specification/maniphesttasks',
'DifferentialNewDiffMail' => 'applications/differential/mail/newdiff',
@ -860,6 +861,7 @@ phutil_register_library_map(array(
'DifferentialInlineCommentView' => 'AphrontView',
'DifferentialLinesFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialLintFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialLocalCommitsView' => 'AphrontView',
'DifferentialManiphestTasksFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialNewDiffMail' => 'DifferentialReviewRequestMail',
'DifferentialPathFieldSpecification' => 'DifferentialFieldSpecification',

View file

@ -58,7 +58,12 @@ class DifferentialRevisionViewController extends DifferentialController {
$diff_vs = null;
}
$aux_fields = $this->loadAuxiliaryFields($revision, $target);
list($aux_fields, $props) = $this->loadAuxiliaryFieldsAndProperties(
$revision,
$target,
array(
'local:commits',
));
list($changesets, $vs_map, $rendering_references) =
$this->loadChangesetsAndVsMap($diffs, $diff_vs, $target);
@ -204,6 +209,10 @@ class DifferentialRevisionViewController extends DifferentialController {
$diff_history->setSelectedDiffID($target->getID());
$diff_history->setSelectedWhitespace($whitespace);
$local_view = new DifferentialLocalCommitsView();
$local_view->setUser($user);
$local_view->setLocalCommits(idx($props, 'local:commits'));
$toc_view = new DifferentialDiffTableOfContentsView();
$toc_view->setChangesets($changesets);
$toc_view->setStandaloneViewLink(empty($visible_changesets));
@ -211,7 +220,6 @@ class DifferentialRevisionViewController extends DifferentialController {
$toc_view->setRevisionID($revision->getID());
$toc_view->setWhitespace($whitespace);
$draft = id(new PhabricatorDraft())->loadOneWhere(
'authorPHID = %s AND draftKey = %s',
$user->getPHID(),
@ -247,6 +255,7 @@ class DifferentialRevisionViewController extends DifferentialController {
$comment_view->render().
$diff_history->render().
$warning.
$local_view->render().
$toc_view->render().
$changeset_view->render().
$comment_form->render()),
@ -504,9 +513,11 @@ class DifferentialRevisionViewController extends DifferentialController {
->replace();
}
private function loadAuxiliaryFields(
private function loadAuxiliaryFieldsAndProperties(
DifferentialRevision $revision,
DifferentialDiff $diff) {
DifferentialDiff $diff,
array $special_properties) {
$aux_fields = DifferentialFieldSelector::newSelector()
->getFieldSpecifications();
foreach ($aux_fields as $key => $aux_field) {
@ -526,6 +537,10 @@ class DifferentialRevisionViewController extends DifferentialController {
}
$required_properties = array_mergev($aux_props);
$required_properties = array_merge(
$required_properties,
$special_properties);
$property_map = array();
if ($required_properties) {
$properties = id(new DifferentialDiffProperty())->loadAllWhere(
@ -549,7 +564,11 @@ class DifferentialRevisionViewController extends DifferentialController {
$aux_field->setDiffProperties($props);
}
return $aux_fields;
return array(
$aux_fields,
array_select_keys(
$property_map,
$special_properties));
}

View file

@ -23,6 +23,7 @@ phutil_require_module('phabricator', 'applications/differential/storage/viewtime
phutil_require_module('phabricator', 'applications/differential/view/addcomment');
phutil_require_module('phabricator', 'applications/differential/view/changesetlistview');
phutil_require_module('phabricator', 'applications/differential/view/difftableofcontents');
phutil_require_module('phabricator', 'applications/differential/view/localcommits');
phutil_require_module('phabricator', 'applications/differential/view/primarypane');
phutil_require_module('phabricator', 'applications/differential/view/revisioncommentlist');
phutil_require_module('phabricator', 'applications/differential/view/revisiondetail');

View file

@ -0,0 +1,138 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DifferentialLocalCommitsView extends AphrontView {
private $localCommits;
private $user;
public function setLocalCommits($local_commits) {
$this->localCommits = $local_commits;
return $this;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
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();
foreach ($local as $commit) {
$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;
}
$row[] = '<td>'.phutil_escape_html($commit_hash).'</td>';
if ($has_tree) {
$tree = idx($commit, 'tree');
$tree = substr($tree, 0, 16);
$row[] = '<td>'.phutil_escape_html($tree).'</td>';
}
if ($has_local) {
$local_rev = idx($commit, 'local', null);
$row[] = '<td>'.phutil_escape_html($local_rev).'</td>';
}
$parents = idx($commit, 'parents', array());
foreach ($parents as $k => $parent) {
if (is_array($parent)) {
$parent = idx($parent, 'rev');
}
$parents[$k] = phutil_escape_html(substr($parent, 0, 16));
}
$parents = implode('<br />', $parents);
$row[] = '<td>'.$parents.'</td>';
$author = nonempty(
idx($commit, 'user'),
idx($commit, 'author'));
$row[] = '<td>'.phutil_escape_html($author).'</td>';
$summary = idx($commit, 'summary');
$summary = phutil_utf8_shorten($summary, 60);
$row[] = '<td class="summary">'.phutil_escape_html($summary).'</td>';
$date = nonempty(
idx($commit, 'date'),
idx($commit, 'time'));
if ($date) {
$date = phabricator_datetime($date, $user);
}
$row[] = '<td>'.$date.'</td>';
$rows[] = '<tr>'.implode('', $row).'</tr>';
}
$headers = array();
$headers[] = '<th>Commit</th>';
if ($has_tree) {
$headers[] = '<th>Tree</th>';
}
if ($has_local) {
$headers[] = '<th>Local</th>';
}
$headers[] = '<th>Parents</th>';
$headers[] = '<th>Author</th>';
$headers[] = '<th>Summary</th>';
$headers[] = '<th>Date</th>';
$headers = '<tr>'.implode('', $headers).'</tr>';
return
'<div class="differential-panel">'.
'<h1>Local Commits</h1>'.
'<table class="differential-local-commits-table">'.
$headers.
implode("\n", $rows).
'</table>'.
'</div>';
}
}

View file

@ -0,0 +1,17 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'infrastructure/celerity/api');
phutil_require_module('phabricator', 'view/base');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');
phutil_require_source('DifferentialLocalCommitsView.php');

View file

@ -0,0 +1,30 @@
/**
* @provides differential-local-commits-view-css
*/
.differential-local-commits-table {
width: 100%;
font-size: 11px;
border-collapse: separate;
border-spacing: 1px 2px;
}
.differential-local-commits-table th {
color: #666666;
padding: 4px 6px;
}
.differential-local-commits-table tr td {
background: #dcdeca;
}
.differential-local-commits-table td {
padding: 4px 6px;
white-space: nowrap;
vertical-align: top;
}
.differential-local-commits-table td.summary {
white-space: normal;
width: 100%;
}