From 76ac8b4196b2b210b265acef181f7f78ac89bb0b Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 30 Aug 2011 11:34:07 -0700 Subject: [PATCH] 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 --- src/__celerity_resource_map__.php | 9 ++ src/__phutil_library_map__.php | 2 + .../DifferentialRevisionViewController.php | 29 +++- .../controller/revisionview/__init__.php | 1 + .../DifferentialLocalCommitsView.php | 138 ++++++++++++++++++ .../view/localcommits/__init__.php | 17 +++ .../differential/local-commits-view.css | 30 ++++ 7 files changed, 221 insertions(+), 5 deletions(-) create mode 100644 src/applications/differential/view/localcommits/DifferentialLocalCommitsView.php create mode 100644 src/applications/differential/view/localcommits/__init__.php create mode 100644 webroot/rsrc/css/application/differential/local-commits-view.css diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index f7ef9ef48a..7ecff1e3cd 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -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', diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 3c94cef8d3..b487f2a6aa 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php b/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php index 28646f5143..f09b7ae649 100644 --- a/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php +++ b/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php @@ -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)); } diff --git a/src/applications/differential/controller/revisionview/__init__.php b/src/applications/differential/controller/revisionview/__init__.php index 4347f9d231..dee7918034 100644 --- a/src/applications/differential/controller/revisionview/__init__.php +++ b/src/applications/differential/controller/revisionview/__init__.php @@ -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'); diff --git a/src/applications/differential/view/localcommits/DifferentialLocalCommitsView.php b/src/applications/differential/view/localcommits/DifferentialLocalCommitsView.php new file mode 100644 index 0000000000..03f21bf2dc --- /dev/null +++ b/src/applications/differential/view/localcommits/DifferentialLocalCommitsView.php @@ -0,0 +1,138 @@ +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[] = ''.phutil_escape_html($commit_hash).''; + + if ($has_tree) { + $tree = idx($commit, 'tree'); + $tree = substr($tree, 0, 16); + $row[] = ''.phutil_escape_html($tree).''; + } + + if ($has_local) { + $local_rev = idx($commit, 'local', null); + $row[] = ''.phutil_escape_html($local_rev).''; + } + + $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('
', $parents); + $row[] = ''.$parents.''; + + $author = nonempty( + idx($commit, 'user'), + idx($commit, 'author')); + $row[] = ''.phutil_escape_html($author).''; + + $summary = idx($commit, 'summary'); + $summary = phutil_utf8_shorten($summary, 60); + $row[] = ''.phutil_escape_html($summary).''; + + $date = nonempty( + idx($commit, 'date'), + idx($commit, 'time')); + if ($date) { + $date = phabricator_datetime($date, $user); + } + $row[] = ''.$date.''; + + $rows[] = ''.implode('', $row).''; + } + + + $headers = array(); + $headers[] = 'Commit'; + if ($has_tree) { + $headers[] = 'Tree'; + } + if ($has_local) { + $headers[] = 'Local'; + } + $headers[] = 'Parents'; + $headers[] = 'Author'; + $headers[] = 'Summary'; + $headers[] = 'Date'; + + $headers = ''.implode('', $headers).''; + + return + '
'. + '

Local Commits

'. + ''. + $headers. + implode("\n", $rows). + '
'. + '
'; + } +} diff --git a/src/applications/differential/view/localcommits/__init__.php b/src/applications/differential/view/localcommits/__init__.php new file mode 100644 index 0000000000..b92836ef23 --- /dev/null +++ b/src/applications/differential/view/localcommits/__init__.php @@ -0,0 +1,17 @@ +