2011-03-08 18:54:55 +01:00
|
|
|
<?php
|
|
|
|
|
Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
final class DiffusionBrowseFileController extends DiffusionBrowseController {
|
2011-03-08 18:54:55 +01:00
|
|
|
|
2012-11-07 07:46:23 +01:00
|
|
|
private $lintCommit;
|
|
|
|
private $lintMessages;
|
Provide a rough, unstable API for reporting coverage into Diffusion
Summary:
Ref T4994. This stuff works:
- You can dump a blob of coverage information into `diffusion.updatecoverage`. This wipes existing coverage information and replaces it.
- It shows up when viewing files.
- It shows up when viewing commits.
This stuff does not work:
- When viewing files, the Javascript hover interaction isn't tied in yet.
- We always show this information, even if you're behind the commit where it was generated.
- You can't do incremental updates.
- There's no aggregation at the file (this file has 90% coverage), diff (the changes in this commit are 90% covered), or directory (the code in this directory has 90% coverage) levels yet.
- This is probably not the final form of the UI, storage, or API, so you should expect occasional changes over time. I've marked the method as "Unstable" for now.
Test Plan:
- Ran `save_lint.php` to check for collateral damage; it worked fine.
- Ran `save_lint.php` on a new branch to check creation.
- Published some fake coverage information.
- Viewed an affected commit.
- Viewed an affected file.
{F151915}
{F151916}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: jhurwitz, epriestley, zeeg
Maniphest Tasks: T5044, T4994
Differential Revision: https://secure.phabricator.com/D9022
2014-05-18 01:10:54 +02:00
|
|
|
private $coverage;
|
2012-11-07 07:46:23 +01:00
|
|
|
|
2011-03-08 18:54:55 +01:00
|
|
|
public function processRequest() {
|
2011-03-23 03:34:47 +01:00
|
|
|
$request = $this->getRequest();
|
Allow Diffusion to display PDF files
Summary:
When Diffusion encounters an image file, it displays it as an
image, but when it encounters a PDF file, it currently shows only some
gibberish. This fixes that.
Test Plan:
I tried it. Embedding a large PDF in a data URL is a little
bit slow, but it works.
Reviewers: tuomaspelkonen, epriestley, gc3, waltermundt, jungejason, nh
Reviewed By: epriestley
CC: aran, tuomaspelkonen, epriestley, jaapweel
Differential Revision: 915
2011-09-09 00:23:58 +02:00
|
|
|
$drequest = $this->getDiffusionRequest();
|
2012-04-08 02:24:35 +02:00
|
|
|
|
|
|
|
$before = $request->getStr('before');
|
|
|
|
if ($before) {
|
|
|
|
return $this->buildBeforeResponse($before);
|
|
|
|
}
|
|
|
|
|
Allow Diffusion to display PDF files
Summary:
When Diffusion encounters an image file, it displays it as an
image, but when it encounters a PDF file, it currently shows only some
gibberish. This fixes that.
Test Plan:
I tried it. Embedding a large PDF in a data URL is a little
bit slow, but it works.
Reviewers: tuomaspelkonen, epriestley, gc3, waltermundt, jungejason, nh
Reviewed By: epriestley
CC: aran, tuomaspelkonen, epriestley, jaapweel
Differential Revision: 915
2011-09-09 00:23:58 +02:00
|
|
|
$path = $drequest->getPath();
|
2012-07-18 02:13:03 +02:00
|
|
|
|
|
|
|
$preferences = $request->getUser()->loadPreferences();
|
2013-09-20 01:01:58 +02:00
|
|
|
|
|
|
|
$show_blame = $request->getBool(
|
|
|
|
'blame',
|
|
|
|
$preferences->getPreference(
|
|
|
|
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_BLAME,
|
|
|
|
false));
|
|
|
|
$show_color = $request->getBool(
|
|
|
|
'color',
|
|
|
|
$preferences->getPreference(
|
|
|
|
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_COLOR,
|
|
|
|
true));
|
|
|
|
|
|
|
|
$view = $request->getStr('view');
|
|
|
|
if ($request->isFormPost() && $view != 'raw') {
|
|
|
|
$preferences->setPreference(
|
|
|
|
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_BLAME,
|
|
|
|
$show_blame);
|
2012-07-18 02:13:03 +02:00
|
|
|
$preferences->setPreference(
|
2013-09-20 01:01:58 +02:00
|
|
|
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_COLOR,
|
|
|
|
$show_color);
|
2012-07-18 02:13:03 +02:00
|
|
|
$preferences->save();
|
2012-07-19 19:15:06 +02:00
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
$uri = $request->getRequestURI()
|
|
|
|
->alter('blame', null)
|
|
|
|
->alter('color', null);
|
2012-07-18 02:13:03 +02:00
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
return id(new AphrontRedirectResponse())->setURI($uri);
|
2013-03-05 23:31:20 +01:00
|
|
|
}
|
2012-04-08 02:24:35 +02:00
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
// We need the blame information if blame is on and we're building plain
|
|
|
|
// text, or blame is on and this is an Ajax request. If blame is on and
|
|
|
|
// this is a colorized request, we don't show blame at first (we ajax it
|
|
|
|
// in afterward) so we don't need to query for it.
|
|
|
|
$needs_blame = ($show_blame && !$show_color) ||
|
|
|
|
($show_blame && $request->isAjax());
|
|
|
|
|
2013-05-07 23:57:08 +02:00
|
|
|
$file_content = DiffusionFileContent::newFromConduit(
|
|
|
|
$this->callConduitWithDiffusionRequest(
|
|
|
|
'diffusion.filecontentquery',
|
|
|
|
array(
|
|
|
|
'commit' => $drequest->getCommit(),
|
|
|
|
'path' => $drequest->getPath(),
|
|
|
|
'needsBlame' => $needs_blame,
|
|
|
|
)));
|
|
|
|
$data = $file_content->getCorpus();
|
2011-03-22 07:57:32 +01:00
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
if ($view === 'raw') {
|
2012-03-20 03:52:24 +01:00
|
|
|
return $this->buildRawResponse($path, $data);
|
2012-03-14 07:50:34 +01:00
|
|
|
}
|
|
|
|
|
2012-11-07 07:46:23 +01:00
|
|
|
$this->loadLintMessages();
|
Provide a rough, unstable API for reporting coverage into Diffusion
Summary:
Ref T4994. This stuff works:
- You can dump a blob of coverage information into `diffusion.updatecoverage`. This wipes existing coverage information and replaces it.
- It shows up when viewing files.
- It shows up when viewing commits.
This stuff does not work:
- When viewing files, the Javascript hover interaction isn't tied in yet.
- We always show this information, even if you're behind the commit where it was generated.
- You can't do incremental updates.
- There's no aggregation at the file (this file has 90% coverage), diff (the changes in this commit are 90% covered), or directory (the code in this directory has 90% coverage) levels yet.
- This is probably not the final form of the UI, storage, or API, so you should expect occasional changes over time. I've marked the method as "Unstable" for now.
Test Plan:
- Ran `save_lint.php` to check for collateral damage; it worked fine.
- Ran `save_lint.php` on a new branch to check creation.
- Published some fake coverage information.
- Viewed an affected commit.
- Viewed an affected file.
{F151915}
{F151916}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: jhurwitz, epriestley, zeeg
Maniphest Tasks: T5044, T4994
Differential Revision: https://secure.phabricator.com/D9022
2014-05-18 01:10:54 +02:00
|
|
|
$this->coverage = $drequest->loadCoverage();
|
2012-11-07 07:46:23 +01:00
|
|
|
|
2013-09-20 23:43:15 +02:00
|
|
|
$binary_uri = null;
|
|
|
|
if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) {
|
|
|
|
$file = $this->loadFileForData($path, $data);
|
|
|
|
$file_uri = $file->getBestURI();
|
|
|
|
|
|
|
|
if ($file->isViewableImage()) {
|
|
|
|
$corpus = $this->buildImageCorpus($file_uri);
|
|
|
|
} else {
|
|
|
|
$corpus = $this->buildBinaryCorpus($file_uri, $data);
|
|
|
|
$binary_uri = $file_uri;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Build the content of the file.
|
|
|
|
$corpus = $this->buildCorpus(
|
|
|
|
$show_blame,
|
|
|
|
$show_color,
|
|
|
|
$file_content,
|
|
|
|
$needs_blame,
|
|
|
|
$drequest,
|
|
|
|
$path,
|
|
|
|
$data);
|
|
|
|
}
|
2012-03-20 03:52:24 +01:00
|
|
|
|
2013-03-05 23:31:20 +01:00
|
|
|
if ($request->isAjax()) {
|
|
|
|
return id(new AphrontAjaxResponse())->setContent($corpus);
|
|
|
|
}
|
|
|
|
|
2012-03-20 03:52:24 +01:00
|
|
|
require_celerity_resource('diffusion-source-css');
|
|
|
|
|
2011-03-26 20:42:12 +01:00
|
|
|
// Render the page.
|
Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
$view = $this->buildActionView($drequest);
|
2013-10-01 23:35:31 +02:00
|
|
|
$action_list = $this->enrichActionView(
|
2013-09-20 01:01:58 +02:00
|
|
|
$view,
|
|
|
|
$drequest,
|
|
|
|
$show_blame,
|
2014-02-22 00:21:38 +01:00
|
|
|
$show_color);
|
2013-10-01 23:35:31 +02:00
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$properties = $this->buildPropertyView($drequest, $action_list);
|
2013-10-01 23:35:31 +02:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($this->buildHeaderView($drequest))
|
2013-10-11 16:53:56 +02:00
|
|
|
->addPropertyList($properties);
|
2013-10-01 23:35:31 +02:00
|
|
|
|
|
|
|
$content = array();
|
|
|
|
$content[] = $object_box;
|
2013-09-20 01:01:04 +02:00
|
|
|
|
2012-04-24 03:16:38 +02:00
|
|
|
$follow = $request->getStr('follow');
|
|
|
|
if ($follow) {
|
|
|
|
$notice = new AphrontErrorView();
|
|
|
|
$notice->setSeverity(AphrontErrorView::SEVERITY_WARNING);
|
2013-05-11 17:23:19 +02:00
|
|
|
$notice->setTitle(pht('Unable to Continue'));
|
2012-04-24 03:16:38 +02:00
|
|
|
switch ($follow) {
|
|
|
|
case 'first':
|
|
|
|
$notice->appendChild(
|
2013-05-11 17:23:19 +02:00
|
|
|
pht("Unable to continue tracing the history of this file because ".
|
|
|
|
"this commit is the first commit in the repository."));
|
2012-04-24 03:16:38 +02:00
|
|
|
break;
|
|
|
|
case 'created':
|
|
|
|
$notice->appendChild(
|
2013-05-11 17:23:19 +02:00
|
|
|
pht("Unable to continue tracing the history of this file because ".
|
|
|
|
"this commit created the file."));
|
2012-04-24 03:16:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
$content[] = $notice;
|
|
|
|
}
|
|
|
|
|
|
|
|
$renamed = $request->getStr('renamed');
|
|
|
|
if ($renamed) {
|
|
|
|
$notice = new AphrontErrorView();
|
|
|
|
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
2013-05-11 17:23:19 +02:00
|
|
|
$notice->setTitle(pht('File Renamed'));
|
2012-04-24 03:16:38 +02:00
|
|
|
$notice->appendChild(
|
2013-05-11 17:23:19 +02:00
|
|
|
pht("File history passes through a rename from '%s' to '%s'.",
|
|
|
|
$drequest->getPath(), $renamed));
|
2012-04-24 03:16:38 +02:00
|
|
|
$content[] = $notice;
|
|
|
|
}
|
|
|
|
|
2011-03-26 20:42:12 +01:00
|
|
|
$content[] = $corpus;
|
2011-10-02 21:52:54 +02:00
|
|
|
$content[] = $this->buildOpenRevisions();
|
2011-03-26 20:42:12 +01:00
|
|
|
|
upgrade diffusion to use modern header UI and fix a few quirks
Summary:
upgrades are CrumbsView, HeaderView, PropertyListView, and ActionListView. I had to modify CrumbsView stuff a bit to handle the "advanced" diffusion crumbs.
Quirks fixed include making file tree view show up in diffusion, the page not have extra space when the file tree is hidden, links no longer breaking once you visit files (since without the change the files always got "/" appended and thus 404'd), and a differential quirk where it read "next step:" and that colon is a no no,
Test Plan: played around in diffusion and differential
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin, chad
Maniphest Tasks: T2048, T2178
Differential Revision: https://secure.phabricator.com/D4169
2012-12-13 02:50:42 +01:00
|
|
|
$crumbs = $this->buildCrumbs(
|
|
|
|
array(
|
|
|
|
'branch' => true,
|
|
|
|
'path' => true,
|
|
|
|
'view' => 'browse',
|
|
|
|
));
|
2011-03-26 20:42:12 +01:00
|
|
|
|
2011-04-19 06:21:08 +02:00
|
|
|
$basename = basename($this->getDiffusionRequest()->getPath());
|
|
|
|
|
upgrade diffusion to use modern header UI and fix a few quirks
Summary:
upgrades are CrumbsView, HeaderView, PropertyListView, and ActionListView. I had to modify CrumbsView stuff a bit to handle the "advanced" diffusion crumbs.
Quirks fixed include making file tree view show up in diffusion, the page not have extra space when the file tree is hidden, links no longer breaking once you visit files (since without the change the files always got "/" appended and thus 404'd), and a differential quirk where it read "next step:" and that colon is a no no,
Test Plan: played around in diffusion and differential
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin, chad
Maniphest Tasks: T2048, T2178
Differential Revision: https://secure.phabricator.com/D4169
2012-12-13 02:50:42 +01:00
|
|
|
return $this->buildApplicationPage(
|
2013-09-20 01:01:04 +02:00
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$content,
|
|
|
|
),
|
2011-03-26 20:42:12 +01:00
|
|
|
array(
|
2011-04-19 06:21:08 +02:00
|
|
|
'title' => $basename,
|
2011-03-26 20:42:12 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2012-11-07 07:46:23 +01:00
|
|
|
private function loadLintMessages() {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$branch = $drequest->loadBranch();
|
|
|
|
|
|
|
|
if (!$branch || !$branch->getLintCommit()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-14 22:22:02 +01:00
|
|
|
$this->lintCommit = $branch->getLintCommit();
|
2012-11-07 07:46:23 +01:00
|
|
|
|
2012-11-09 00:14:44 +01:00
|
|
|
$conn = id(new PhabricatorRepository())->establishConnection('r');
|
|
|
|
|
|
|
|
$where = '';
|
|
|
|
if ($drequest->getLint()) {
|
|
|
|
$where = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'AND code = %s',
|
|
|
|
$drequest->getLint());
|
|
|
|
}
|
|
|
|
|
2012-11-07 07:46:23 +01:00
|
|
|
$this->lintMessages = queryfx_all(
|
2012-11-09 00:14:44 +01:00
|
|
|
$conn,
|
|
|
|
'SELECT * FROM %T WHERE branchID = %d %Q AND path = %s',
|
2012-11-07 07:46:23 +01:00
|
|
|
PhabricatorRepository::TABLE_LINTMESSAGE,
|
|
|
|
$branch->getID(),
|
2012-11-09 00:14:44 +01:00
|
|
|
$where,
|
2012-11-07 07:46:23 +01:00
|
|
|
'/'.$drequest->getPath());
|
|
|
|
}
|
|
|
|
|
2013-05-07 23:57:08 +02:00
|
|
|
private function buildCorpus(
|
2013-09-20 01:01:58 +02:00
|
|
|
$show_blame,
|
|
|
|
$show_color,
|
2013-05-07 23:57:08 +02:00
|
|
|
DiffusionFileContent $file_content,
|
|
|
|
$needs_blame,
|
|
|
|
DiffusionRequest $drequest,
|
|
|
|
$path,
|
|
|
|
$data) {
|
2011-04-01 22:42:00 +02:00
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
if (!$show_color) {
|
|
|
|
$style =
|
2014-02-21 23:43:24 +01:00
|
|
|
"border: none; width: 100%; height: 80em; font-family: monospace";
|
2013-09-20 01:01:58 +02:00
|
|
|
if (!$show_blame) {
|
2013-01-18 03:43:35 +01:00
|
|
|
$corpus = phutil_tag(
|
2011-03-23 03:34:47 +01:00
|
|
|
'textarea',
|
|
|
|
array(
|
|
|
|
'style' => $style,
|
|
|
|
),
|
2013-05-07 23:57:08 +02:00
|
|
|
$file_content->getCorpus());
|
2013-09-20 01:01:58 +02:00
|
|
|
} else {
|
2013-05-07 23:57:08 +02:00
|
|
|
$text_list = $file_content->getTextList();
|
|
|
|
$rev_list = $file_content->getRevList();
|
|
|
|
$blame_dict = $file_content->getBlameDict();
|
2011-04-01 03:28:24 +02:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($text_list as $k => $line) {
|
|
|
|
$rev = $rev_list[$k];
|
2013-03-05 01:22:30 +01:00
|
|
|
$author = $blame_dict[$rev]['author'];
|
2011-04-01 03:28:24 +02:00
|
|
|
$rows[] =
|
2011-06-07 01:08:49 +02:00
|
|
|
sprintf("%-10s %-20s %s", substr($rev, 0, 7), $author, $line);
|
2011-04-01 03:28:24 +02:00
|
|
|
}
|
|
|
|
|
2013-01-18 03:43:35 +01:00
|
|
|
$corpus = phutil_tag(
|
2011-04-01 03:28:24 +02:00
|
|
|
'textarea',
|
|
|
|
array(
|
|
|
|
'style' => $style,
|
|
|
|
),
|
2013-01-18 03:43:35 +01:00
|
|
|
implode("\n", $rows));
|
2013-09-20 01:01:58 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
require_celerity_resource('syntax-highlighting-css');
|
|
|
|
$text_list = $file_content->getTextList();
|
|
|
|
$rev_list = $file_content->getRevList();
|
|
|
|
$blame_dict = $file_content->getBlameDict();
|
|
|
|
|
|
|
|
$text_list = implode("\n", $text_list);
|
|
|
|
$text_list = PhabricatorSyntaxHighlighter::highlightWithFilename(
|
|
|
|
$path,
|
|
|
|
$text_list);
|
|
|
|
$text_list = explode("\n", $text_list);
|
|
|
|
|
|
|
|
$rows = $this->buildDisplayRows($text_list, $rev_list, $blame_dict,
|
|
|
|
$needs_blame, $drequest, $show_blame, $show_color);
|
|
|
|
|
|
|
|
$corpus_table = javelin_tag(
|
|
|
|
'table',
|
|
|
|
array(
|
|
|
|
'class' => "diffusion-source remarkup-code PhabricatorMonospaced",
|
|
|
|
'sigil' => 'phabricator-source',
|
|
|
|
),
|
|
|
|
$rows);
|
2011-03-23 03:34:47 +01:00
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
if ($this->getRequest()->isAjax()) {
|
|
|
|
return $corpus_table;
|
|
|
|
}
|
2011-03-23 03:34:47 +01:00
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
$id = celerity_generate_unique_node_id();
|
2013-03-05 23:31:20 +01:00
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
$projects = $drequest->loadArcanistProjects();
|
|
|
|
$langs = array();
|
|
|
|
foreach ($projects as $project) {
|
|
|
|
$ls = $project->getSymbolIndexLanguages();
|
|
|
|
if (!$ls) {
|
|
|
|
continue;
|
2013-03-05 23:31:20 +01:00
|
|
|
}
|
2013-09-20 01:01:58 +02:00
|
|
|
$dep_projects = $project->getSymbolIndexProjects();
|
|
|
|
$dep_projects[] = $project->getPHID();
|
|
|
|
foreach ($ls as $lang) {
|
|
|
|
if (!isset($langs[$lang])) {
|
|
|
|
$langs[$lang] = array();
|
2012-07-20 07:01:31 +02:00
|
|
|
}
|
2013-09-20 01:01:58 +02:00
|
|
|
$langs[$lang] += $dep_projects + array($project);
|
2012-07-20 07:01:31 +02:00
|
|
|
}
|
2013-09-20 01:01:58 +02:00
|
|
|
}
|
2012-07-20 07:01:31 +02:00
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
$lang = last(explode('.', $drequest->getPath()));
|
2012-07-20 07:01:31 +02:00
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
if (isset($langs[$lang])) {
|
|
|
|
Javelin::initBehavior(
|
|
|
|
'repository-crossreference',
|
2011-03-23 03:34:47 +01:00
|
|
|
array(
|
2013-09-20 01:01:58 +02:00
|
|
|
'container' => $id,
|
|
|
|
'lang' => $lang,
|
|
|
|
'projects' => $langs[$lang],
|
|
|
|
));
|
|
|
|
}
|
2011-03-23 03:34:47 +01:00
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
$corpus = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'id' => $id,
|
|
|
|
),
|
|
|
|
$corpus_table);
|
2013-03-05 23:31:20 +01:00
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
Javelin::initBehavior('load-blame', array('id' => $id));
|
2011-03-23 03:34:47 +01:00
|
|
|
}
|
|
|
|
|
2014-02-22 00:21:38 +01:00
|
|
|
$edit = $this->renderEditButton();
|
|
|
|
$file = $this->renderFileButton();
|
2014-02-21 23:43:24 +01:00
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht('File Contents'))
|
2014-02-22 00:21:38 +01:00
|
|
|
->addActionLink($edit)
|
|
|
|
->addActionLink($file);
|
2014-02-21 23:43:24 +01:00
|
|
|
|
|
|
|
$corpus = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->appendChild($corpus);
|
|
|
|
|
2011-03-26 20:42:12 +01:00
|
|
|
return $corpus;
|
|
|
|
}
|
2011-03-13 01:17:34 +01:00
|
|
|
|
2013-09-20 01:01:04 +02:00
|
|
|
private function enrichActionView(
|
|
|
|
PhabricatorActionListView $view,
|
|
|
|
DiffusionRequest $drequest,
|
2013-09-20 01:01:58 +02:00
|
|
|
$show_blame,
|
2014-02-22 00:21:38 +01:00
|
|
|
$show_color) {
|
2013-09-20 01:01:04 +02:00
|
|
|
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
$base_uri = $this->getRequest()->getRequestURI();
|
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Show Last Change'))
|
|
|
|
->setHref(
|
|
|
|
$drequest->generateURI(
|
|
|
|
array(
|
|
|
|
'action' => 'change',
|
|
|
|
)))
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-backward'));
|
2013-09-20 01:01:58 +02:00
|
|
|
|
|
|
|
if ($show_blame) {
|
2012-10-03 19:58:56 +02:00
|
|
|
$blame_text = pht('Disable Blame');
|
2014-05-12 19:08:32 +02:00
|
|
|
$blame_icon = 'fa-exclamation-circle lightgreytext';
|
2013-09-20 01:01:58 +02:00
|
|
|
$blame_value = 0;
|
2012-10-03 19:58:56 +02:00
|
|
|
} else {
|
|
|
|
$blame_text = pht('Enable Blame');
|
2014-05-12 19:08:32 +02:00
|
|
|
$blame_icon = 'fa-exclamation-circle';
|
2013-09-20 01:01:58 +02:00
|
|
|
$blame_value = 1;
|
2012-10-03 19:58:56 +02:00
|
|
|
}
|
2012-03-20 03:52:24 +01:00
|
|
|
|
2013-09-20 01:01:04 +02:00
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName($blame_text)
|
2013-09-20 01:01:58 +02:00
|
|
|
->setHref($base_uri->alter('blame', $blame_value))
|
2013-09-20 01:01:04 +02:00
|
|
|
->setIcon($blame_icon)
|
|
|
|
->setUser($viewer)
|
|
|
|
->setRenderAsForm(true));
|
2012-03-20 03:52:24 +01:00
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
if ($show_color) {
|
2012-10-03 19:58:56 +02:00
|
|
|
$highlight_text = pht('Disable Highlighting');
|
2014-05-12 19:08:32 +02:00
|
|
|
$highlight_icon = 'fa-star-o grey';
|
2013-09-20 01:01:58 +02:00
|
|
|
$highlight_value = 0;
|
2012-10-03 19:58:56 +02:00
|
|
|
} else {
|
|
|
|
$highlight_text = pht('Enable Highlighting');
|
2014-05-12 19:08:32 +02:00
|
|
|
$highlight_icon = 'fa-star';
|
2013-09-20 01:01:58 +02:00
|
|
|
$highlight_value = 1;
|
2012-10-03 19:58:56 +02:00
|
|
|
}
|
2013-09-20 01:01:04 +02:00
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName($highlight_text)
|
2013-09-20 01:01:58 +02:00
|
|
|
->setHref($base_uri->alter('color', $highlight_value))
|
2013-09-20 01:01:04 +02:00
|
|
|
->setIcon($highlight_icon)
|
|
|
|
->setUser($viewer)
|
|
|
|
->setRenderAsForm(true));
|
2012-11-07 07:46:23 +01:00
|
|
|
|
|
|
|
$href = null;
|
2012-11-09 00:14:44 +01:00
|
|
|
if ($this->getRequest()->getStr('lint') !== null) {
|
2012-11-09 01:13:21 +01:00
|
|
|
$lint_text = pht('Hide %d Lint Message(s)', count($this->lintMessages));
|
2012-11-07 07:46:23 +01:00
|
|
|
$href = $base_uri->alter('lint', null);
|
|
|
|
|
|
|
|
} else if ($this->lintCommit === null) {
|
|
|
|
$lint_text = pht('Lint not Available');
|
2013-01-14 22:22:02 +01:00
|
|
|
} else {
|
2012-11-07 07:46:23 +01:00
|
|
|
$lint_text = pht(
|
2013-01-14 22:22:02 +01:00
|
|
|
'Show %d Lint Message(s)',
|
2012-11-07 07:46:23 +01:00
|
|
|
count($this->lintMessages));
|
|
|
|
$href = $this->getDiffusionRequest()->generateURI(array(
|
|
|
|
'action' => 'browse',
|
|
|
|
'commit' => $this->lintCommit,
|
2012-11-09 00:14:44 +01:00
|
|
|
))->alter('lint', '');
|
2012-11-07 07:46:23 +01:00
|
|
|
}
|
|
|
|
|
2013-09-20 01:01:04 +02:00
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName($lint_text)
|
|
|
|
->setHref($href)
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-exclamation-triangle')
|
2013-09-20 01:01:04 +02:00
|
|
|
->setDisabled(!$href));
|
2012-10-03 19:58:56 +02:00
|
|
|
|
2013-09-20 01:01:04 +02:00
|
|
|
return $view;
|
2012-03-20 03:52:24 +01:00
|
|
|
}
|
|
|
|
|
2014-02-22 00:21:38 +01:00
|
|
|
private function renderEditButton() {
|
2012-03-20 03:52:24 +01:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
$path = $drequest->getPath();
|
2012-09-13 20:01:41 +02:00
|
|
|
$line = nonempty((int)$drequest->getLine(), 1);
|
2012-03-20 03:52:24 +01:00
|
|
|
|
2012-04-05 02:53:16 +02:00
|
|
|
$callsign = $repository->getCallsign();
|
|
|
|
$editor_link = $user->loadEditorLink($path, $line, $callsign);
|
2014-05-23 00:33:21 +02:00
|
|
|
$template = $user->loadEditorLink($path, '%l', $callsign);
|
2012-03-20 03:52:24 +01:00
|
|
|
|
2014-02-21 23:43:24 +01:00
|
|
|
$icon_edit = id(new PHUIIconView())
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIconFont('fa-pencil');
|
2014-02-21 23:43:24 +01:00
|
|
|
$button = id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setText(pht('Open in Editor'))
|
|
|
|
->setHref($editor_link)
|
|
|
|
->setIcon($icon_edit)
|
2014-05-23 00:33:21 +02:00
|
|
|
->setID('editor_link')
|
|
|
|
->setMetadata(array('link_template' => $template))
|
2014-02-21 23:43:24 +01:00
|
|
|
->setDisabled(!$editor_link);
|
|
|
|
|
|
|
|
return $button;
|
2012-03-20 03:52:24 +01:00
|
|
|
}
|
2011-03-13 01:17:34 +01:00
|
|
|
|
2014-02-22 00:21:38 +01:00
|
|
|
private function renderFileButton($file_uri = null) {
|
|
|
|
|
|
|
|
$base_uri = $this->getRequest()->getRequestURI();
|
|
|
|
|
|
|
|
if ($file_uri) {
|
|
|
|
$text = pht('Download Raw File');
|
|
|
|
$href = $file_uri;
|
2014-05-12 19:08:32 +02:00
|
|
|
$icon = 'fa-download';
|
2014-02-22 00:21:38 +01:00
|
|
|
} else {
|
|
|
|
$text = pht('View Raw File');
|
|
|
|
$href = $base_uri->alter('view', 'raw');
|
2014-05-12 19:08:32 +02:00
|
|
|
$icon = 'fa-file-text';
|
2014-02-22 00:21:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$iconview = id(new PHUIIconView())
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIconFont($icon);
|
2014-02-22 00:21:38 +01:00
|
|
|
$button = id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setText($text)
|
|
|
|
->setHref($href)
|
|
|
|
->setIcon($iconview);
|
|
|
|
|
|
|
|
return $button;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-07 21:01:25 +02:00
|
|
|
private function buildDisplayRows(
|
|
|
|
array $text_list,
|
|
|
|
array $rev_list,
|
|
|
|
array $blame_dict,
|
|
|
|
$needs_blame,
|
|
|
|
DiffusionRequest $drequest,
|
2013-09-20 01:01:58 +02:00
|
|
|
$show_blame,
|
|
|
|
$show_color) {
|
2012-04-07 21:01:25 +02:00
|
|
|
|
2013-03-05 01:22:30 +01:00
|
|
|
$handles = array();
|
2011-05-18 16:44:53 +02:00
|
|
|
if ($blame_dict) {
|
2012-04-09 08:08:26 +02:00
|
|
|
$epoch_list = ipull(ifilter($blame_dict, 'epoch'), 'epoch');
|
2012-04-08 02:24:35 +02:00
|
|
|
$epoch_min = min($epoch_list);
|
|
|
|
$epoch_max = max($epoch_list);
|
|
|
|
$epoch_range = ($epoch_max - $epoch_min) + 1;
|
2013-04-19 05:20:43 +02:00
|
|
|
|
|
|
|
$author_phids = ipull(ifilter($blame_dict, 'authorPHID'), 'authorPHID');
|
|
|
|
$handles = $this->loadViewerHandles($author_phids);
|
2011-05-18 16:44:53 +02:00
|
|
|
}
|
2011-04-01 03:28:24 +02:00
|
|
|
|
2012-07-04 23:04:45 +02:00
|
|
|
$line_arr = array();
|
|
|
|
$line_str = $drequest->getLine();
|
|
|
|
$ranges = explode(',', $line_str);
|
|
|
|
foreach ($ranges as $range) {
|
|
|
|
if (strpos($range, '-') !== false) {
|
|
|
|
list($min, $max) = explode('-', $range, 2);
|
|
|
|
$line_arr[] = array(
|
|
|
|
'min' => min($min, $max),
|
|
|
|
'max' => max($min, $max),
|
|
|
|
);
|
|
|
|
} else if (strlen($range)) {
|
|
|
|
$line_arr[] = array(
|
|
|
|
'min' => $range,
|
|
|
|
'max' => $range,
|
|
|
|
);
|
|
|
|
}
|
2012-02-25 20:45:51 +01:00
|
|
|
}
|
|
|
|
|
2012-04-08 02:24:35 +02:00
|
|
|
$display = array();
|
|
|
|
|
|
|
|
$line_number = 1;
|
|
|
|
$last_rev = null;
|
|
|
|
$color = null;
|
2011-04-01 03:28:24 +02:00
|
|
|
foreach ($text_list as $k => $line) {
|
2012-04-08 02:24:35 +02:00
|
|
|
$display_line = array(
|
|
|
|
'epoch' => null,
|
|
|
|
'commit' => null,
|
|
|
|
'author' => null,
|
|
|
|
'target' => null,
|
|
|
|
'highlighted' => null,
|
|
|
|
'line' => $line_number,
|
|
|
|
'data' => $line,
|
|
|
|
);
|
|
|
|
|
2013-09-20 01:01:58 +02:00
|
|
|
if ($show_blame) {
|
2011-04-01 03:28:24 +02:00
|
|
|
// If the line's rev is same as the line above, show empty content
|
|
|
|
// with same color; otherwise generate blame info. The newer a change
|
2012-04-08 02:24:35 +02:00
|
|
|
// is, the more saturated the color.
|
|
|
|
|
|
|
|
$rev = idx($rev_list, $k, $last_rev);
|
|
|
|
|
2011-04-01 03:28:24 +02:00
|
|
|
if ($last_rev == $rev) {
|
2012-04-08 02:24:35 +02:00
|
|
|
$display_line['color'] = $color;
|
2011-03-26 20:42:12 +01:00
|
|
|
} else {
|
2012-04-08 02:24:35 +02:00
|
|
|
$blame = $blame_dict[$rev];
|
2011-04-01 03:28:24 +02:00
|
|
|
|
2012-04-09 08:08:26 +02:00
|
|
|
if (!isset($blame['epoch'])) {
|
|
|
|
$color = '#ffd'; // Render as warning.
|
|
|
|
} else {
|
|
|
|
$color_ratio = ($blame['epoch'] - $epoch_min) / $epoch_range;
|
2013-03-08 07:38:08 +01:00
|
|
|
$color_value = 0xE6 * (1.0 - $color_ratio);
|
2012-04-09 08:08:26 +02:00
|
|
|
$color = sprintf(
|
|
|
|
'#%02x%02x%02x',
|
|
|
|
$color_value,
|
|
|
|
0xF6,
|
|
|
|
$color_value);
|
|
|
|
}
|
2011-03-26 20:42:12 +01:00
|
|
|
|
2012-04-09 08:08:26 +02:00
|
|
|
$display_line['epoch'] = idx($blame, 'epoch');
|
2012-04-08 02:24:35 +02:00
|
|
|
$display_line['color'] = $color;
|
|
|
|
$display_line['commit'] = $rev;
|
2011-04-02 00:34:45 +02:00
|
|
|
|
2013-03-05 01:22:30 +01:00
|
|
|
$author_phid = idx($blame, 'authorPHID');
|
|
|
|
if ($author_phid && $handles[$author_phid]) {
|
|
|
|
$author_link = $handles[$author_phid]->renderLink();
|
2011-10-18 21:58:45 +02:00
|
|
|
} else {
|
2014-04-26 21:51:47 +02:00
|
|
|
$author_link = $blame['author'];
|
2011-10-18 21:58:45 +02:00
|
|
|
}
|
2012-04-08 02:24:35 +02:00
|
|
|
$display_line['author'] = $author_link;
|
|
|
|
|
2011-04-01 03:28:24 +02:00
|
|
|
$last_rev = $rev;
|
2011-03-26 20:42:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-04 23:04:45 +02:00
|
|
|
if ($line_arr) {
|
|
|
|
if ($line_number == $line_arr[0]['min']) {
|
2012-04-08 02:24:35 +02:00
|
|
|
$display_line['target'] = true;
|
|
|
|
}
|
2012-07-04 23:04:45 +02:00
|
|
|
foreach ($line_arr as $range) {
|
|
|
|
if ($line_number >= $range['min'] &&
|
|
|
|
$line_number <= $range['max']) {
|
|
|
|
$display_line['highlighted'] = true;
|
|
|
|
}
|
2012-02-25 20:45:51 +01:00
|
|
|
}
|
2011-03-26 20:42:12 +01:00
|
|
|
}
|
|
|
|
|
2012-04-08 02:24:35 +02:00
|
|
|
$display[] = $display_line;
|
|
|
|
++$line_number;
|
|
|
|
}
|
|
|
|
|
2013-10-30 21:15:26 +01:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
2012-04-10 10:32:47 +02:00
|
|
|
$commits = array_filter(ipull($display, 'commit'));
|
|
|
|
if ($commits) {
|
2013-10-30 21:15:26 +01:00
|
|
|
$commits = id(new DiffusionCommitQuery())
|
|
|
|
->setViewer($viewer)
|
2013-11-07 21:10:43 +01:00
|
|
|
->withRepository($drequest->getRepository())
|
2013-10-30 21:15:26 +01:00
|
|
|
->withIdentifiers($commits)
|
2012-04-10 10:32:47 +02:00
|
|
|
->execute();
|
|
|
|
$commits = mpull($commits, null, 'getCommitIdentifier');
|
|
|
|
}
|
2012-04-08 02:24:35 +02:00
|
|
|
|
2012-06-23 01:52:08 +02:00
|
|
|
$revision_ids = id(new DifferentialRevision())
|
|
|
|
->loadIDsByCommitPHIDs(mpull($commits, 'getPHID'));
|
2012-06-21 21:48:45 +02:00
|
|
|
$revisions = array();
|
2012-06-23 01:52:08 +02:00
|
|
|
if ($revision_ids) {
|
2013-09-26 21:37:19 +02:00
|
|
|
$revisions = id(new DifferentialRevisionQuery())
|
2013-10-30 21:15:26 +01:00
|
|
|
->setViewer($viewer)
|
2013-09-26 21:37:19 +02:00
|
|
|
->withIDs($revision_ids)
|
|
|
|
->execute();
|
2012-06-21 21:48:45 +02:00
|
|
|
}
|
|
|
|
|
2013-10-30 21:15:26 +01:00
|
|
|
$phids = array();
|
|
|
|
foreach ($commits as $commit) {
|
|
|
|
if ($commit->getAuthorPHID()) {
|
|
|
|
$phids[] = $commit->getAuthorPHID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($revisions as $revision) {
|
|
|
|
if ($revision->getAuthorPHID()) {
|
|
|
|
$phids[] = $revision->getAuthorPHID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$handles = $this->loadViewerHandles($phids);
|
|
|
|
|
Use "user-select: none" to provide a visual cue about copy/paste JS magic
Summary:
- For line numbers, use "user-select: none" to make them unselectable. This provides a stronger visual cue that copy/paste is enchanted.
- In Paste, make it look sensible again after the blame-on-blame refactor in Diffusion. See also TODO to share this code formally.
- In Diffusion, use the "phabricator-oncopy" behavior.
NOTE: I left blame/commit columns selectable in Diffusion, since you might reasonably want to copy/paste them?
NOTE: In Differential, the left side of the diff still highlights, even though it will be copied only if you select part of a line on the left and nothing else. But this seemed like a reasonable behavior, so I left it.
Test Plan:
- Looked at Paste. Saw a nice line number column. Selected text, got the expected selection. Copied text, got the expected copy.
- Looked at Diffusion. Saw a nice line number column, still. Selected text, got expected selection. Copied text, got expected copy.
- Looked at Differential. Highlighted stuff, got expected results. Copied stuff, got expected results.
Reviewers: btrahan, vrana, jungejason
Reviewed By: vrana
CC: aran
Maniphest Tasks: T1123
Differential Revision: https://secure.phabricator.com/D2242
2012-04-17 00:55:16 +02:00
|
|
|
Javelin::initBehavior('phabricator-oncopy', array());
|
|
|
|
|
2012-11-07 07:46:23 +01:00
|
|
|
$engine = null;
|
|
|
|
$inlines = array();
|
2012-11-09 00:14:44 +01:00
|
|
|
if ($this->getRequest()->getStr('lint') !== null && $this->lintMessages) {
|
2012-11-07 07:46:23 +01:00
|
|
|
$engine = new PhabricatorMarkupEngine();
|
2013-10-30 21:15:26 +01:00
|
|
|
$engine->setViewer($viewer);
|
2012-11-07 07:46:23 +01:00
|
|
|
|
|
|
|
foreach ($this->lintMessages as $message) {
|
|
|
|
$inline = id(new PhabricatorAuditInlineComment())
|
2012-11-10 02:45:19 +01:00
|
|
|
->setID($message['id'])
|
2012-11-09 01:13:21 +01:00
|
|
|
->setSyntheticAuthor(
|
|
|
|
ArcanistLintSeverity::getStringForSeverity($message['severity']).
|
|
|
|
' '.$message['code'].' ('.$message['name'].')')
|
2012-11-07 07:46:23 +01:00
|
|
|
->setLineNumber($message['line'])
|
|
|
|
->setContent($message['description']);
|
|
|
|
$inlines[$message['line']][] = $inline;
|
|
|
|
|
|
|
|
$engine->addObject(
|
|
|
|
$inline,
|
|
|
|
PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY);
|
|
|
|
}
|
|
|
|
|
|
|
|
$engine->process();
|
|
|
|
require_celerity_resource('differential-changeset-view-css');
|
|
|
|
}
|
|
|
|
|
|
|
|
$rows = $this->renderInlines(
|
|
|
|
idx($inlines, 0, array()),
|
Provide a rough, unstable API for reporting coverage into Diffusion
Summary:
Ref T4994. This stuff works:
- You can dump a blob of coverage information into `diffusion.updatecoverage`. This wipes existing coverage information and replaces it.
- It shows up when viewing files.
- It shows up when viewing commits.
This stuff does not work:
- When viewing files, the Javascript hover interaction isn't tied in yet.
- We always show this information, even if you're behind the commit where it was generated.
- You can't do incremental updates.
- There's no aggregation at the file (this file has 90% coverage), diff (the changes in this commit are 90% covered), or directory (the code in this directory has 90% coverage) levels yet.
- This is probably not the final form of the UI, storage, or API, so you should expect occasional changes over time. I've marked the method as "Unstable" for now.
Test Plan:
- Ran `save_lint.php` to check for collateral damage; it worked fine.
- Ran `save_lint.php` on a new branch to check creation.
- Published some fake coverage information.
- Viewed an affected commit.
- Viewed an affected file.
{F151915}
{F151916}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: jhurwitz, epriestley, zeeg
Maniphest Tasks: T5044, T4994
Differential Revision: https://secure.phabricator.com/D9022
2014-05-18 01:10:54 +02:00
|
|
|
$show_blame,
|
|
|
|
(bool)$this->coverage,
|
2012-11-07 07:46:23 +01:00
|
|
|
$engine);
|
|
|
|
|
2012-04-08 02:24:35 +02:00
|
|
|
foreach ($display as $line) {
|
|
|
|
|
|
|
|
$line_href = $drequest->generateURI(
|
Fix many encoding and architecture problems in Diffusion request and URI handling
Summary:
Diffusion request/uri handling is currently a big, hastily ported mess. In particular, it has:
- Tons and tons of duplicated code.
- Bugs with handling unusual branch and file names.
- An excessively large (and yet insufficiently expressive) API on DiffusionRequest, including a nonsensical concrete base class.
- Other tools were doing hacky things like passing ":" branch names.
This diff attempts to fix these issues.
- Make the base class abstract (it was concrete ONLY for "/diffusion/").
- Move all URI generation to DiffusionRequest. Make the core static. Add unit tests.
- Delete the 300 copies of URI generation code throughout Diffusion.
- Move all URI parsing to DiffusionRequest. Make the core static. Add unit tests.
- Add an appropriate static initializer for other callers.
- Convert all code calling `newFromAphrontRequestDictionary` outside of Diffusion to the new `newFromDictionary` API.
- Refactor static initializers to be sensibly-sized.
- Refactor derived DiffusionRequest classes to remove duplicated code.
- Properly encode branch names (fixes branches with "/", see <https://github.com/facebook/phabricator/issues/100>).
- Properly encode path names (fixes issues in D1742).
- Properly escape delimiter characters ";" and "$" in path names so files like "$100" are not interpreted as "line 100".
- Fix a couple warnings.
- Fix a couple lint issues.
- Fix a bug where we would not parse filenames with spaces in them correctly in the Git browse query.
- Fix a bug where Git change queries would fail unnecessarily.
- Provide or improve some documentation.
This thing is pretty gigantic but also kind of hard to split up. If it's unreasonably difficult to review, let me know and I can take a stab at it though.
This supplants D1742.
Test Plan:
- Used home, repository, branch, browse, change, history, diff (ajax), lastmodified (ajax) views of Diffusion.
- Used Owners typeaheads and search.
- Used diffusion.getrecentcommitsbypath method.
- Pushed a change to an absurdly-named file on an absurdly-named branch, everything worked properly.
{F9185}
Reviewers: nh, vrana, btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1921
2012-03-20 03:52:14 +01:00
|
|
|
array(
|
2012-04-08 02:24:35 +02:00
|
|
|
'action' => 'browse',
|
|
|
|
'line' => $line['line'],
|
|
|
|
'stable' => true,
|
Fix many encoding and architecture problems in Diffusion request and URI handling
Summary:
Diffusion request/uri handling is currently a big, hastily ported mess. In particular, it has:
- Tons and tons of duplicated code.
- Bugs with handling unusual branch and file names.
- An excessively large (and yet insufficiently expressive) API on DiffusionRequest, including a nonsensical concrete base class.
- Other tools were doing hacky things like passing ":" branch names.
This diff attempts to fix these issues.
- Make the base class abstract (it was concrete ONLY for "/diffusion/").
- Move all URI generation to DiffusionRequest. Make the core static. Add unit tests.
- Delete the 300 copies of URI generation code throughout Diffusion.
- Move all URI parsing to DiffusionRequest. Make the core static. Add unit tests.
- Add an appropriate static initializer for other callers.
- Convert all code calling `newFromAphrontRequestDictionary` outside of Diffusion to the new `newFromDictionary` API.
- Refactor static initializers to be sensibly-sized.
- Refactor derived DiffusionRequest classes to remove duplicated code.
- Properly encode branch names (fixes branches with "/", see <https://github.com/facebook/phabricator/issues/100>).
- Properly encode path names (fixes issues in D1742).
- Properly escape delimiter characters ";" and "$" in path names so files like "$100" are not interpreted as "line 100".
- Fix a couple warnings.
- Fix a couple lint issues.
- Fix a bug where we would not parse filenames with spaces in them correctly in the Git browse query.
- Fix a bug where Git change queries would fail unnecessarily.
- Provide or improve some documentation.
This thing is pretty gigantic but also kind of hard to split up. If it's unreasonably difficult to review, let me know and I can take a stab at it though.
This supplants D1742.
Test Plan:
- Used home, repository, branch, browse, change, history, diff (ajax), lastmodified (ajax) views of Diffusion.
- Used Owners typeaheads and search.
- Used diffusion.getrecentcommitsbypath method.
- Pushed a change to an absurdly-named file on an absurdly-named branch, everything worked properly.
{F9185}
Reviewers: nh, vrana, btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1921
2012-03-20 03:52:14 +01:00
|
|
|
));
|
|
|
|
|
2012-04-08 02:24:35 +02:00
|
|
|
$blame = array();
|
2013-03-05 23:31:20 +01:00
|
|
|
$style = null;
|
|
|
|
if (array_key_exists('color', $line)) {
|
|
|
|
if ($line['color']) {
|
|
|
|
$style = 'background: '.$line['color'].';';
|
|
|
|
}
|
2012-04-08 02:24:35 +02:00
|
|
|
|
|
|
|
$before_link = null;
|
|
|
|
$commit_link = null;
|
2012-06-21 21:48:45 +02:00
|
|
|
$revision_link = null;
|
2012-04-08 02:24:35 +02:00
|
|
|
if (idx($line, 'commit')) {
|
|
|
|
$commit = $line['commit'];
|
|
|
|
|
|
|
|
if (idx($commits, $commit)) {
|
2013-10-30 21:15:26 +01:00
|
|
|
$tooltip = $this->renderCommitTooltip(
|
|
|
|
$commits[$commit],
|
|
|
|
$handles,
|
|
|
|
$line['author']);
|
|
|
|
} else {
|
|
|
|
$tooltip = null;
|
2012-04-08 02:24:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Javelin::initBehavior('phabricator-tooltips', array());
|
|
|
|
require_celerity_resource('aphront-tooltip-css');
|
|
|
|
|
2013-01-25 21:57:17 +01:00
|
|
|
$commit_link = javelin_tag(
|
2012-04-08 02:24:35 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $drequest->generateURI(
|
|
|
|
array(
|
|
|
|
'action' => 'commit',
|
|
|
|
'commit' => $line['commit'],
|
|
|
|
)),
|
|
|
|
'sigil' => 'has-tooltip',
|
|
|
|
'meta' => array(
|
|
|
|
'tip' => $tooltip,
|
|
|
|
'align' => 'E',
|
|
|
|
'size' => 600,
|
|
|
|
),
|
|
|
|
),
|
2013-01-25 21:57:17 +01:00
|
|
|
phutil_utf8_shorten($line['commit'], 9, ''));
|
2012-04-08 02:24:35 +02:00
|
|
|
|
2012-07-12 02:02:15 +02:00
|
|
|
$revision_id = null;
|
|
|
|
if (idx($commits, $commit)) {
|
|
|
|
$revision_id = idx($revision_ids, $commits[$commit]->getPHID());
|
|
|
|
}
|
|
|
|
|
2012-06-21 21:48:45 +02:00
|
|
|
if ($revision_id) {
|
|
|
|
$revision = idx($revisions, $revision_id);
|
2013-10-30 21:15:26 +01:00
|
|
|
if ($revision) {
|
|
|
|
$tooltip = $this->renderRevisionTooltip($revision, $handles);
|
|
|
|
$revision_link = javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/D'.$revision->getID(),
|
|
|
|
'sigil' => 'has-tooltip',
|
|
|
|
'meta' => array(
|
|
|
|
'tip' => $tooltip,
|
|
|
|
'align' => 'E',
|
|
|
|
'size' => 600,
|
|
|
|
),
|
2012-06-21 21:48:45 +02:00
|
|
|
),
|
2013-10-30 21:15:26 +01:00
|
|
|
'D'.$revision->getID());
|
|
|
|
}
|
2012-06-21 21:48:45 +02:00
|
|
|
}
|
|
|
|
|
2012-09-29 01:41:39 +02:00
|
|
|
$uri = $line_href->alter('before', $commit);
|
2013-01-25 21:57:17 +01:00
|
|
|
$before_link = javelin_tag(
|
2012-04-08 02:24:35 +02:00
|
|
|
'a',
|
|
|
|
array(
|
2012-09-29 01:41:39 +02:00
|
|
|
'href' => $uri->setQueryParam('view', 'blame'),
|
2012-04-08 02:24:35 +02:00
|
|
|
'sigil' => 'has-tooltip',
|
|
|
|
'meta' => array(
|
2013-05-11 17:23:19 +02:00
|
|
|
'tip' => pht('Skip Past This Commit'),
|
2012-04-08 02:24:35 +02:00
|
|
|
'align' => 'E',
|
|
|
|
'size' => 300,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
"\xC2\xAB");
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:32:58 +01:00
|
|
|
$blame[] = phutil_tag(
|
2012-04-08 02:24:35 +02:00
|
|
|
'th',
|
|
|
|
array(
|
|
|
|
'class' => 'diffusion-blame-link',
|
|
|
|
),
|
|
|
|
$before_link);
|
|
|
|
|
2013-10-30 21:15:26 +01:00
|
|
|
$object_links = array();
|
|
|
|
$object_links[] = $commit_link;
|
|
|
|
if ($revision_link) {
|
|
|
|
$object_links[] = phutil_tag('span', array(), '/');
|
|
|
|
$object_links[] = $revision_link;
|
|
|
|
}
|
2012-04-08 02:24:35 +02:00
|
|
|
|
2013-01-18 09:32:58 +01:00
|
|
|
$blame[] = phutil_tag(
|
2012-06-21 21:48:45 +02:00
|
|
|
'th',
|
|
|
|
array(
|
|
|
|
'class' => 'diffusion-rev-link',
|
2012-04-08 02:24:35 +02:00
|
|
|
),
|
2013-10-30 21:15:26 +01:00
|
|
|
$object_links);
|
Fix many encoding and architecture problems in Diffusion request and URI handling
Summary:
Diffusion request/uri handling is currently a big, hastily ported mess. In particular, it has:
- Tons and tons of duplicated code.
- Bugs with handling unusual branch and file names.
- An excessively large (and yet insufficiently expressive) API on DiffusionRequest, including a nonsensical concrete base class.
- Other tools were doing hacky things like passing ":" branch names.
This diff attempts to fix these issues.
- Make the base class abstract (it was concrete ONLY for "/diffusion/").
- Move all URI generation to DiffusionRequest. Make the core static. Add unit tests.
- Delete the 300 copies of URI generation code throughout Diffusion.
- Move all URI parsing to DiffusionRequest. Make the core static. Add unit tests.
- Add an appropriate static initializer for other callers.
- Convert all code calling `newFromAphrontRequestDictionary` outside of Diffusion to the new `newFromDictionary` API.
- Refactor static initializers to be sensibly-sized.
- Refactor derived DiffusionRequest classes to remove duplicated code.
- Properly encode branch names (fixes branches with "/", see <https://github.com/facebook/phabricator/issues/100>).
- Properly encode path names (fixes issues in D1742).
- Properly escape delimiter characters ";" and "$" in path names so files like "$100" are not interpreted as "line 100".
- Fix a couple warnings.
- Fix a couple lint issues.
- Fix a bug where we would not parse filenames with spaces in them correctly in the Git browse query.
- Fix a bug where Git change queries would fail unnecessarily.
- Provide or improve some documentation.
This thing is pretty gigantic but also kind of hard to split up. If it's unreasonably difficult to review, let me know and I can take a stab at it though.
This supplants D1742.
Test Plan:
- Used home, repository, branch, browse, change, history, diff (ajax), lastmodified (ajax) views of Diffusion.
- Used Owners typeaheads and search.
- Used diffusion.getrecentcommitsbypath method.
- Pushed a change to an absurdly-named file on an absurdly-named branch, everything worked properly.
{F9185}
Reviewers: nh, vrana, btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1921
2012-03-20 03:52:14 +01:00
|
|
|
}
|
|
|
|
|
2013-01-18 03:43:35 +01:00
|
|
|
$line_link = phutil_tag(
|
2011-03-26 20:42:12 +01:00
|
|
|
'a',
|
|
|
|
array(
|
2012-04-08 02:24:35 +02:00
|
|
|
'href' => $line_href,
|
2013-10-30 21:15:26 +01:00
|
|
|
'style' => $style,
|
2012-04-08 02:24:35 +02:00
|
|
|
),
|
2013-01-18 03:43:35 +01:00
|
|
|
$line['line']);
|
2012-04-08 02:24:35 +02:00
|
|
|
|
2013-01-25 21:57:17 +01:00
|
|
|
$blame[] = javelin_tag(
|
2012-04-08 02:24:35 +02:00
|
|
|
'th',
|
|
|
|
array(
|
|
|
|
'class' => 'diffusion-line-link',
|
2013-08-04 21:11:10 +02:00
|
|
|
'sigil' => 'phabricator-source-line',
|
2013-03-05 23:31:20 +01:00
|
|
|
'style' => $style,
|
2012-04-08 02:24:35 +02:00
|
|
|
),
|
|
|
|
$line_link);
|
|
|
|
|
2013-08-04 21:11:10 +02:00
|
|
|
Javelin::initBehavior('phabricator-line-linker');
|
2012-08-04 18:47:51 +02:00
|
|
|
|
2012-04-08 02:24:35 +02:00
|
|
|
if ($line['target']) {
|
|
|
|
Javelin::initBehavior(
|
|
|
|
'diffusion-jump-to',
|
|
|
|
array(
|
|
|
|
'target' => 'scroll_target',
|
|
|
|
));
|
2013-01-31 18:08:02 +01:00
|
|
|
$anchor_text = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'id' => 'scroll_target',
|
|
|
|
),
|
|
|
|
'');
|
2012-04-08 02:24:35 +02:00
|
|
|
} else {
|
|
|
|
$anchor_text = null;
|
|
|
|
}
|
|
|
|
|
2013-01-31 18:08:02 +01:00
|
|
|
$blame[] = phutil_tag(
|
2012-04-08 02:24:35 +02:00
|
|
|
'td',
|
|
|
|
array(
|
2011-03-26 20:42:12 +01:00
|
|
|
),
|
2013-01-31 18:08:02 +01:00
|
|
|
array(
|
|
|
|
$anchor_text,
|
|
|
|
|
|
|
|
// NOTE: See phabricator-oncopy behavior.
|
2014-04-09 02:55:48 +02:00
|
|
|
"\xE2\x80\x8B",
|
2013-01-31 18:08:02 +01:00
|
|
|
|
|
|
|
// TODO: [HTML] Not ideal.
|
2014-01-17 12:05:14 +01:00
|
|
|
phutil_safe_html(str_replace("\t", ' ', $line['data'])),
|
2013-01-31 18:08:02 +01:00
|
|
|
));
|
2011-03-26 20:42:12 +01:00
|
|
|
|
Provide a rough, unstable API for reporting coverage into Diffusion
Summary:
Ref T4994. This stuff works:
- You can dump a blob of coverage information into `diffusion.updatecoverage`. This wipes existing coverage information and replaces it.
- It shows up when viewing files.
- It shows up when viewing commits.
This stuff does not work:
- When viewing files, the Javascript hover interaction isn't tied in yet.
- We always show this information, even if you're behind the commit where it was generated.
- You can't do incremental updates.
- There's no aggregation at the file (this file has 90% coverage), diff (the changes in this commit are 90% covered), or directory (the code in this directory has 90% coverage) levels yet.
- This is probably not the final form of the UI, storage, or API, so you should expect occasional changes over time. I've marked the method as "Unstable" for now.
Test Plan:
- Ran `save_lint.php` to check for collateral damage; it worked fine.
- Ran `save_lint.php` on a new branch to check creation.
- Published some fake coverage information.
- Viewed an affected commit.
- Viewed an affected file.
{F151915}
{F151916}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: jhurwitz, epriestley, zeeg
Maniphest Tasks: T5044, T4994
Differential Revision: https://secure.phabricator.com/D9022
2014-05-18 01:10:54 +02:00
|
|
|
if ($this->coverage) {
|
|
|
|
require_celerity_resource('differential-changeset-view-css');
|
|
|
|
$cov_index = $line['line'] - 1;
|
|
|
|
|
|
|
|
if (isset($this->coverage[$cov_index])) {
|
|
|
|
$cov_class = $this->coverage[$cov_index];
|
|
|
|
} else {
|
|
|
|
$cov_class = 'N';
|
|
|
|
}
|
|
|
|
|
|
|
|
$blame[] = phutil_tag(
|
|
|
|
'td',
|
|
|
|
array(
|
|
|
|
'class' => 'cov cov-'.$cov_class,
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:32:58 +01:00
|
|
|
$rows[] = phutil_tag(
|
2012-04-08 02:24:35 +02:00
|
|
|
'tr',
|
|
|
|
array(
|
2013-08-04 21:11:10 +02:00
|
|
|
'class' => ($line['highlighted'] ?
|
|
|
|
'phabricator-source-highlight' :
|
|
|
|
null),
|
2012-04-08 02:24:35 +02:00
|
|
|
),
|
2013-01-18 09:32:58 +01:00
|
|
|
$blame);
|
2012-11-07 07:46:23 +01:00
|
|
|
|
2014-05-10 03:06:29 +02:00
|
|
|
$cur_inlines = $this->renderInlines(
|
2012-11-07 07:46:23 +01:00
|
|
|
idx($inlines, $line['line'], array()),
|
Provide a rough, unstable API for reporting coverage into Diffusion
Summary:
Ref T4994. This stuff works:
- You can dump a blob of coverage information into `diffusion.updatecoverage`. This wipes existing coverage information and replaces it.
- It shows up when viewing files.
- It shows up when viewing commits.
This stuff does not work:
- When viewing files, the Javascript hover interaction isn't tied in yet.
- We always show this information, even if you're behind the commit where it was generated.
- You can't do incremental updates.
- There's no aggregation at the file (this file has 90% coverage), diff (the changes in this commit are 90% covered), or directory (the code in this directory has 90% coverage) levels yet.
- This is probably not the final form of the UI, storage, or API, so you should expect occasional changes over time. I've marked the method as "Unstable" for now.
Test Plan:
- Ran `save_lint.php` to check for collateral damage; it worked fine.
- Ran `save_lint.php` on a new branch to check creation.
- Published some fake coverage information.
- Viewed an affected commit.
- Viewed an affected file.
{F151915}
{F151916}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: jhurwitz, epriestley, zeeg
Maniphest Tasks: T5044, T4994
Differential Revision: https://secure.phabricator.com/D9022
2014-05-18 01:10:54 +02:00
|
|
|
$show_blame,
|
|
|
|
$this->coverage,
|
2014-05-10 03:06:29 +02:00
|
|
|
$engine);
|
|
|
|
foreach ($cur_inlines as $cur_inline) {
|
|
|
|
$rows[] = $cur_inline;
|
|
|
|
}
|
2011-03-26 20:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $rows;
|
2011-03-08 18:54:55 +01:00
|
|
|
}
|
2011-04-01 03:28:24 +02:00
|
|
|
|
Provide a rough, unstable API for reporting coverage into Diffusion
Summary:
Ref T4994. This stuff works:
- You can dump a blob of coverage information into `diffusion.updatecoverage`. This wipes existing coverage information and replaces it.
- It shows up when viewing files.
- It shows up when viewing commits.
This stuff does not work:
- When viewing files, the Javascript hover interaction isn't tied in yet.
- We always show this information, even if you're behind the commit where it was generated.
- You can't do incremental updates.
- There's no aggregation at the file (this file has 90% coverage), diff (the changes in this commit are 90% covered), or directory (the code in this directory has 90% coverage) levels yet.
- This is probably not the final form of the UI, storage, or API, so you should expect occasional changes over time. I've marked the method as "Unstable" for now.
Test Plan:
- Ran `save_lint.php` to check for collateral damage; it worked fine.
- Ran `save_lint.php` on a new branch to check creation.
- Published some fake coverage information.
- Viewed an affected commit.
- Viewed an affected file.
{F151915}
{F151916}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: jhurwitz, epriestley, zeeg
Maniphest Tasks: T5044, T4994
Differential Revision: https://secure.phabricator.com/D9022
2014-05-18 01:10:54 +02:00
|
|
|
private function renderInlines(
|
|
|
|
array $inlines,
|
|
|
|
$needs_blame,
|
|
|
|
$has_coverage,
|
|
|
|
$engine) {
|
|
|
|
|
2012-11-07 07:46:23 +01:00
|
|
|
$rows = array();
|
|
|
|
foreach ($inlines as $inline) {
|
|
|
|
$inline_view = id(new DifferentialInlineCommentView())
|
|
|
|
->setMarkupEngine($engine)
|
|
|
|
->setInlineComment($inline)
|
|
|
|
->render();
|
Provide a rough, unstable API for reporting coverage into Diffusion
Summary:
Ref T4994. This stuff works:
- You can dump a blob of coverage information into `diffusion.updatecoverage`. This wipes existing coverage information and replaces it.
- It shows up when viewing files.
- It shows up when viewing commits.
This stuff does not work:
- When viewing files, the Javascript hover interaction isn't tied in yet.
- We always show this information, even if you're behind the commit where it was generated.
- You can't do incremental updates.
- There's no aggregation at the file (this file has 90% coverage), diff (the changes in this commit are 90% covered), or directory (the code in this directory has 90% coverage) levels yet.
- This is probably not the final form of the UI, storage, or API, so you should expect occasional changes over time. I've marked the method as "Unstable" for now.
Test Plan:
- Ran `save_lint.php` to check for collateral damage; it worked fine.
- Ran `save_lint.php` on a new branch to check creation.
- Published some fake coverage information.
- Viewed an affected commit.
- Viewed an affected file.
{F151915}
{F151916}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: jhurwitz, epriestley, zeeg
Maniphest Tasks: T5044, T4994
Differential Revision: https://secure.phabricator.com/D9022
2014-05-18 01:10:54 +02:00
|
|
|
|
|
|
|
$row = array_fill(0, ($needs_blame ? 3 : 1), phutil_tag('th'));
|
|
|
|
|
2013-02-02 14:15:30 +01:00
|
|
|
$row[] = phutil_tag('td', array(), $inline_view);
|
Provide a rough, unstable API for reporting coverage into Diffusion
Summary:
Ref T4994. This stuff works:
- You can dump a blob of coverage information into `diffusion.updatecoverage`. This wipes existing coverage information and replaces it.
- It shows up when viewing files.
- It shows up when viewing commits.
This stuff does not work:
- When viewing files, the Javascript hover interaction isn't tied in yet.
- We always show this information, even if you're behind the commit where it was generated.
- You can't do incremental updates.
- There's no aggregation at the file (this file has 90% coverage), diff (the changes in this commit are 90% covered), or directory (the code in this directory has 90% coverage) levels yet.
- This is probably not the final form of the UI, storage, or API, so you should expect occasional changes over time. I've marked the method as "Unstable" for now.
Test Plan:
- Ran `save_lint.php` to check for collateral damage; it worked fine.
- Ran `save_lint.php` on a new branch to check creation.
- Published some fake coverage information.
- Viewed an affected commit.
- Viewed an affected file.
{F151915}
{F151916}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: jhurwitz, epriestley, zeeg
Maniphest Tasks: T5044, T4994
Differential Revision: https://secure.phabricator.com/D9022
2014-05-18 01:10:54 +02:00
|
|
|
|
|
|
|
if ($has_coverage) {
|
|
|
|
$row[] = phutil_tag(
|
|
|
|
'td',
|
|
|
|
array(
|
|
|
|
'class' => 'cov cov-I',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2013-02-02 14:15:30 +01:00
|
|
|
$rows[] = phutil_tag('tr', array('class' => 'inline'), $row);
|
2012-11-07 07:46:23 +01:00
|
|
|
}
|
Provide a rough, unstable API for reporting coverage into Diffusion
Summary:
Ref T4994. This stuff works:
- You can dump a blob of coverage information into `diffusion.updatecoverage`. This wipes existing coverage information and replaces it.
- It shows up when viewing files.
- It shows up when viewing commits.
This stuff does not work:
- When viewing files, the Javascript hover interaction isn't tied in yet.
- We always show this information, even if you're behind the commit where it was generated.
- You can't do incremental updates.
- There's no aggregation at the file (this file has 90% coverage), diff (the changes in this commit are 90% covered), or directory (the code in this directory has 90% coverage) levels yet.
- This is probably not the final form of the UI, storage, or API, so you should expect occasional changes over time. I've marked the method as "Unstable" for now.
Test Plan:
- Ran `save_lint.php` to check for collateral damage; it worked fine.
- Ran `save_lint.php` on a new branch to check creation.
- Published some fake coverage information.
- Viewed an affected commit.
- Viewed an affected file.
{F151915}
{F151916}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: jhurwitz, epriestley, zeeg
Maniphest Tasks: T5044, T4994
Differential Revision: https://secure.phabricator.com/D9022
2014-05-18 01:10:54 +02:00
|
|
|
|
2012-11-07 07:46:23 +01:00
|
|
|
return $rows;
|
|
|
|
}
|
2011-04-01 03:28:24 +02:00
|
|
|
|
2012-03-20 03:52:24 +01:00
|
|
|
private function loadFileForData($path, $data) {
|
2013-12-30 20:27:02 +01:00
|
|
|
$file = PhabricatorFile::buildFromFileDataOrHash(
|
2012-07-09 19:38:25 +02:00
|
|
|
$data,
|
|
|
|
array(
|
|
|
|
'name' => basename($path),
|
2013-02-20 22:33:47 +01:00
|
|
|
'ttl' => time() + 60 * 60 * 24,
|
2013-12-30 20:27:02 +01:00
|
|
|
'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
|
2012-07-09 19:38:25 +02:00
|
|
|
));
|
2013-12-30 20:27:02 +01:00
|
|
|
|
|
|
|
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
|
|
|
$file->attachToObject(
|
|
|
|
$this->getRequest()->getUser(),
|
|
|
|
$this->getDiffusionRequest()->getRepository()->getPHID());
|
|
|
|
unset($unguarded);
|
|
|
|
|
|
|
|
return $file;
|
2012-03-20 03:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function buildRawResponse($path, $data) {
|
|
|
|
$file = $this->loadFileForData($path, $data);
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($file->getBestURI());
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildImageCorpus($file_uri) {
|
2013-10-11 16:53:56 +02:00
|
|
|
$properties = new PHUIPropertyListView();
|
2012-10-31 19:43:17 +01:00
|
|
|
|
2013-10-14 20:40:19 +02:00
|
|
|
$properties->addImageContent(
|
2013-01-18 03:39:02 +01:00
|
|
|
phutil_tag(
|
2012-03-20 03:52:24 +01:00
|
|
|
'img',
|
|
|
|
array(
|
|
|
|
'src' => $file_uri,
|
|
|
|
)));
|
2012-10-31 19:43:17 +01:00
|
|
|
|
2014-02-22 00:21:38 +01:00
|
|
|
$file = $this->renderFileButton($file_uri);
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht('Image'))
|
|
|
|
->addActionLink($file);
|
|
|
|
|
2013-10-14 20:40:19 +02:00
|
|
|
return id(new PHUIObjectBoxView())
|
2014-02-22 00:21:38 +01:00
|
|
|
->setHeader($header)
|
2013-10-14 20:40:19 +02:00
|
|
|
->addPropertyList($properties);
|
2012-03-20 03:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function buildBinaryCorpus($file_uri, $data) {
|
2012-10-31 19:43:17 +01:00
|
|
|
|
2014-02-22 23:08:04 +01:00
|
|
|
$size = new PhutilNumber(strlen($data));
|
|
|
|
$text = pht('This is a binary file. It is %s byte(s) in length.', $size);
|
|
|
|
$text = id(new PHUIBoxView())
|
|
|
|
->addPadding(PHUI::PADDING_LARGE)
|
|
|
|
->appendChild($text);
|
|
|
|
|
|
|
|
$file = $this->renderFileButton($file_uri);
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht('Details'))
|
|
|
|
->addActionLink($file);
|
|
|
|
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->appendChild($text);
|
2012-10-31 19:43:17 +01:00
|
|
|
|
2014-02-22 23:08:04 +01:00
|
|
|
return $box;
|
2012-03-20 03:52:24 +01:00
|
|
|
}
|
|
|
|
|
2012-04-08 02:24:35 +02:00
|
|
|
private function buildBeforeResponse($before) {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
|
2012-04-24 03:16:38 +02:00
|
|
|
// NOTE: We need to get the grandparent so we can capture filename changes
|
|
|
|
// in the parent.
|
|
|
|
|
2013-12-20 21:39:21 +01:00
|
|
|
$parent = $this->loadParentCommitOf($before);
|
2012-04-24 03:16:38 +02:00
|
|
|
$old_filename = null;
|
|
|
|
$was_created = false;
|
|
|
|
if ($parent) {
|
2013-12-20 21:39:21 +01:00
|
|
|
$grandparent = $this->loadParentCommitOf($parent);
|
2012-04-24 03:16:38 +02:00
|
|
|
|
|
|
|
if ($grandparent) {
|
2012-09-28 23:36:47 +02:00
|
|
|
$rename_query = new DiffusionRenameHistoryQuery();
|
|
|
|
$rename_query->setRequest($drequest);
|
2013-12-20 21:39:21 +01:00
|
|
|
$rename_query->setOldCommit($grandparent);
|
Diffusion - move commit parents query to conduit
Summary:
Ref T2784. Relatively complicated one as this bad boy is used in a repository daemon.
While testing, I noticed bugs in the expandshortname query stuff. Those variables are private to the parent class so they need some setX love.
Also, was unable to find links to the "before" stuff, but made them by hand by looking at some of these T2784 diffs, browsing a file at a specific revision, then hacking the "before" variable to be some known commit that also touched the file. This produced sensical results. On the process of doing that I upgraded a query to use the proper policy query.
Test Plan: In git, mercurial, svn, verified on a commit page the "parents" showed up correctly. played around with ?before parameter on specific file browse page, with commits known to have interesting history and stuff looked good
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T2784
Differential Revision: https://secure.phabricator.com/D5988
2013-05-22 01:22:49 +02:00
|
|
|
$rename_query->setViewer($request->getUser());
|
2012-04-24 03:16:38 +02:00
|
|
|
$old_filename = $rename_query->loadOldFilename();
|
|
|
|
$was_created = $rename_query->getWasCreated();
|
|
|
|
}
|
|
|
|
}
|
2012-04-08 02:24:35 +02:00
|
|
|
|
2012-04-24 03:16:38 +02:00
|
|
|
$follow = null;
|
|
|
|
if ($was_created) {
|
|
|
|
// If the file was created in history, that means older commits won't
|
|
|
|
// have it. Since we know it existed at 'before', it must have been
|
|
|
|
// created then; jump there.
|
|
|
|
$target_commit = $before;
|
|
|
|
$follow = 'created';
|
|
|
|
} else if ($parent) {
|
|
|
|
// If we found a parent, jump to it. This is the normal case.
|
2014-02-11 19:38:27 +01:00
|
|
|
$target_commit = $parent;
|
2012-04-24 03:16:38 +02:00
|
|
|
} else {
|
|
|
|
// If there's no parent, this was probably created in the initial commit?
|
|
|
|
// And the "was_created" check will fail because we can't identify the
|
|
|
|
// grandparent. Keep the user at 'before'.
|
|
|
|
$target_commit = $before;
|
|
|
|
$follow = 'first';
|
|
|
|
}
|
2012-04-08 02:24:35 +02:00
|
|
|
|
2012-04-24 03:16:38 +02:00
|
|
|
$path = $drequest->getPath();
|
|
|
|
$renamed = null;
|
|
|
|
if ($old_filename !== null &&
|
2012-09-28 23:36:47 +02:00
|
|
|
$old_filename !== '/'.$path) {
|
2012-04-24 03:16:38 +02:00
|
|
|
$renamed = $path;
|
|
|
|
$path = $old_filename;
|
|
|
|
}
|
2012-04-08 02:24:35 +02:00
|
|
|
|
2012-07-27 00:39:13 +02:00
|
|
|
$line = null;
|
|
|
|
// If there's a follow error, drop the line so the user sees the message.
|
|
|
|
if (!$follow) {
|
|
|
|
$line = $this->getBeforeLineNumber($target_commit);
|
|
|
|
}
|
|
|
|
|
2012-04-08 02:24:35 +02:00
|
|
|
$before_uri = $drequest->generateURI(
|
|
|
|
array(
|
|
|
|
'action' => 'browse',
|
2012-04-24 03:16:38 +02:00
|
|
|
'commit' => $target_commit,
|
2012-07-27 00:39:13 +02:00
|
|
|
'line' => $line,
|
2012-04-24 03:16:38 +02:00
|
|
|
'path' => $path,
|
2012-04-08 02:24:35 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
$before_uri->setQueryParams($request->getRequestURI()->getQueryParams());
|
|
|
|
$before_uri = $before_uri->alter('before', null);
|
2012-04-24 03:16:38 +02:00
|
|
|
$before_uri = $before_uri->alter('renamed', $renamed);
|
|
|
|
$before_uri = $before_uri->alter('follow', $follow);
|
2012-04-08 02:24:35 +02:00
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($before_uri);
|
|
|
|
}
|
2011-04-02 00:34:45 +02:00
|
|
|
|
2012-07-27 00:39:13 +02:00
|
|
|
private function getBeforeLineNumber($target_commit) {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
|
|
|
|
$line = $drequest->getLine();
|
|
|
|
if (!$line) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-05-14 22:53:32 +02:00
|
|
|
$raw_diff = $this->callConduitWithDiffusionRequest(
|
|
|
|
'diffusion.rawdiffquery',
|
|
|
|
array(
|
|
|
|
'commit' => $drequest->getCommit(),
|
|
|
|
'path' => $drequest->getPath(),
|
|
|
|
'againstCommit' => $target_commit));
|
|
|
|
$old_line = 0;
|
|
|
|
$new_line = 0;
|
|
|
|
|
|
|
|
foreach (explode("\n", $raw_diff) as $text) {
|
|
|
|
if ($text[0] == '-' || $text[0] == ' ') {
|
|
|
|
$old_line++;
|
|
|
|
}
|
|
|
|
if ($text[0] == '+' || $text[0] == ' ') {
|
|
|
|
$new_line++;
|
|
|
|
}
|
|
|
|
if ($new_line == $line) {
|
|
|
|
return $old_line;
|
2012-07-27 00:39:13 +02:00
|
|
|
}
|
|
|
|
}
|
2013-05-14 22:53:32 +02:00
|
|
|
|
|
|
|
// We didn't find the target line.
|
|
|
|
return $line;
|
2012-07-27 00:39:13 +02:00
|
|
|
}
|
|
|
|
|
2013-12-20 21:39:21 +01:00
|
|
|
private function loadParentCommitOf($commit) {
|
2012-04-24 03:16:38 +02:00
|
|
|
$drequest = $this->getDiffusionRequest();
|
Diffusion - move commit parents query to conduit
Summary:
Ref T2784. Relatively complicated one as this bad boy is used in a repository daemon.
While testing, I noticed bugs in the expandshortname query stuff. Those variables are private to the parent class so they need some setX love.
Also, was unable to find links to the "before" stuff, but made them by hand by looking at some of these T2784 diffs, browsing a file at a specific revision, then hacking the "before" variable to be some known commit that also touched the file. This produced sensical results. On the process of doing that I upgraded a query to use the proper policy query.
Test Plan: In git, mercurial, svn, verified on a commit page the "parents" showed up correctly. played around with ?before parameter on specific file browse page, with commits known to have interesting history and stuff looked good
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T2784
Differential Revision: https://secure.phabricator.com/D5988
2013-05-22 01:22:49 +02:00
|
|
|
$user = $this->getRequest()->getUser();
|
2012-04-24 03:16:38 +02:00
|
|
|
|
|
|
|
$before_req = DiffusionRequest::newFromDictionary(
|
|
|
|
array(
|
Diffusion - move commit parents query to conduit
Summary:
Ref T2784. Relatively complicated one as this bad boy is used in a repository daemon.
While testing, I noticed bugs in the expandshortname query stuff. Those variables are private to the parent class so they need some setX love.
Also, was unable to find links to the "before" stuff, but made them by hand by looking at some of these T2784 diffs, browsing a file at a specific revision, then hacking the "before" variable to be some known commit that also touched the file. This produced sensical results. On the process of doing that I upgraded a query to use the proper policy query.
Test Plan: In git, mercurial, svn, verified on a commit page the "parents" showed up correctly. played around with ?before parameter on specific file browse page, with commits known to have interesting history and stuff looked good
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T2784
Differential Revision: https://secure.phabricator.com/D5988
2013-05-22 01:22:49 +02:00
|
|
|
'user' => $user,
|
2012-04-24 03:16:38 +02:00
|
|
|
'repository' => $drequest->getRepository(),
|
2013-12-20 21:39:21 +01:00
|
|
|
'commit' => $commit,
|
2012-04-24 03:16:38 +02:00
|
|
|
));
|
|
|
|
|
Diffusion - move commit parents query to conduit
Summary:
Ref T2784. Relatively complicated one as this bad boy is used in a repository daemon.
While testing, I noticed bugs in the expandshortname query stuff. Those variables are private to the parent class so they need some setX love.
Also, was unable to find links to the "before" stuff, but made them by hand by looking at some of these T2784 diffs, browsing a file at a specific revision, then hacking the "before" variable to be some known commit that also touched the file. This produced sensical results. On the process of doing that I upgraded a query to use the proper policy query.
Test Plan: In git, mercurial, svn, verified on a commit page the "parents" showed up correctly. played around with ?before parameter on specific file browse page, with commits known to have interesting history and stuff looked good
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T2784
Differential Revision: https://secure.phabricator.com/D5988
2013-05-22 01:22:49 +02:00
|
|
|
$parents = DiffusionQuery::callConduitWithDiffusionRequest(
|
|
|
|
$user,
|
|
|
|
$before_req,
|
|
|
|
'diffusion.commitparentsquery',
|
|
|
|
array(
|
2013-12-20 21:39:21 +01:00
|
|
|
'commit' => $commit,
|
|
|
|
));
|
2012-04-24 03:16:38 +02:00
|
|
|
|
|
|
|
return head($parents);
|
|
|
|
}
|
|
|
|
|
2013-10-30 21:15:26 +01:00
|
|
|
private function renderRevisionTooltip(
|
|
|
|
DifferentialRevision $revision,
|
|
|
|
array $handles) {
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$date = phabricator_date($revision->getDateModified(), $viewer);
|
|
|
|
$id = $revision->getID();
|
|
|
|
$title = $revision->getTitle();
|
|
|
|
$header = "D{$id} {$title}";
|
|
|
|
|
|
|
|
$author = $handles[$revision->getAuthorPHID()]->getName();
|
|
|
|
|
|
|
|
return "{$header}\n{$date} \xC2\xB7 {$author}";
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderCommitTooltip(
|
|
|
|
PhabricatorRepositoryCommit $commit,
|
|
|
|
array $handles,
|
|
|
|
$author) {
|
|
|
|
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$date = phabricator_date($commit->getEpoch(), $viewer);
|
|
|
|
$summary = trim($commit->getSummary());
|
|
|
|
|
|
|
|
if ($commit->getAuthorPHID()) {
|
|
|
|
$author = $handles[$commit->getAuthorPHID()]->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return "{$summary}\n{$date} \xC2\xB7 {$author}";
|
|
|
|
}
|
|
|
|
|
2011-03-08 18:54:55 +01:00
|
|
|
}
|