Page MenuHomePhorge

No OneTemporary

diff --git a/src/applications/diffusion/controller/DiffusionBrowseController.php b/src/applications/diffusion/controller/DiffusionBrowseController.php
index 6d5f320a29..2e1e71201d 100644
--- a/src/applications/diffusion/controller/DiffusionBrowseController.php
+++ b/src/applications/diffusion/controller/DiffusionBrowseController.php
@@ -1,407 +1,315 @@
<?php
final class DiffusionBrowseController extends DiffusionController {
public function processRequest() {
$drequest = $this->diffusionRequest;
$is_file = false;
if ($this->getRequest()->getStr('before')) {
$is_file = true;
} else if ($this->getRequest()->getStr('grep') == '') {
$results = DiffusionBrowseResultSet::newFromConduit(
$this->callConduitWithDiffusionRequest(
'diffusion.browsequery',
array(
'path' => $drequest->getPath(),
'commit' => $drequest->getCommit(),
)));
$reason = $results->getReasonForEmptyResultSet();
$is_file = ($reason == DiffusionBrowseResultSet::REASON_IS_FILE);
}
if ($is_file) {
$controller = new DiffusionBrowseFileController($this->getRequest());
$controller->setDiffusionRequest($drequest);
$controller->setCurrentApplication($this->getCurrentApplication());
return $this->delegateToController($controller);
}
$content = array();
$content[] = $this->buildHeaderView($drequest);
- $content[] = $this->buildActionView($drequest);
+ $content[] = $this->buildBrowseActionView($drequest);
$content[] = $this->buildPropertyView($drequest);
$content[] = $this->renderSearchForm();
if ($this->getRequest()->getStr('grep') != '') {
$content[] = $this->renderSearchResults();
} else {
if (!$results->isValidResults()) {
$empty_result = new DiffusionEmptyResultView();
$empty_result->setDiffusionRequest($drequest);
$empty_result->setDiffusionBrowseResultSet($results);
$empty_result->setView($this->getRequest()->getStr('view'));
$content[] = $empty_result;
} else {
$phids = array();
foreach ($results->getPaths() as $result) {
$data = $result->getLastCommitData();
if ($data) {
if ($data->getCommitDetail('authorPHID')) {
$phids[$data->getCommitDetail('authorPHID')] = true;
}
}
}
$phids = array_keys($phids);
$handles = $this->loadViewerHandles($phids);
$browse_table = new DiffusionBrowseTableView();
$browse_table->setDiffusionRequest($drequest);
$browse_table->setHandles($handles);
$browse_table->setPaths($results->getPaths());
$browse_table->setUser($this->getRequest()->getUser());
$browse_panel = new AphrontPanelView();
$browse_panel->appendChild($browse_table);
$browse_panel->setNoBackground();
$content[] = $browse_panel;
}
$content[] = $this->buildOpenRevisions();
$readme = $this->callConduitWithDiffusionRequest(
'diffusion.readmequery',
array(
'paths' => $results->getPathDicts(),
));
if ($readme) {
$box = new PHUIBoxView();
$box->setShadow(true);
$box->appendChild($readme);
$box->addPadding(PHUI::PADDING_LARGE);
$box->addMargin(PHUI::MARGIN_LARGE);
$header = id(new PHUIHeaderView())
->setHeader(pht('README'));
$content[] = array(
$header,
$box,
);
}
}
$crumbs = $this->buildCrumbs(
array(
'branch' => true,
'path' => true,
'view' => 'browse',
));
return $this->buildApplicationPage(
array(
$crumbs,
$content,
),
array(
'device' => true,
'title' => array(
nonempty(basename($drequest->getPath()), '/'),
$drequest->getRepository()->getCallsign().' Repository',
),
));
}
private function renderSearchForm() {
$drequest = $this->getDiffusionRequest();
$form = id(new AphrontFormView())
->setUser($this->getRequest()->getUser())
->setMethod('GET');
switch ($drequest->getRepository()->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$form->appendChild(pht('Search is not available in Subversion.'));
break;
default:
$form
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Search Here'))
->setName('grep')
->setValue($this->getRequest()->getStr('grep'))
->setCaption(pht('Enter a regular expression.')))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Search File Content')));
break;
}
$filter = new AphrontListFilterView();
$filter->appendChild($form);
if (!strlen($this->getRequest()->getStr('grep'))) {
$filter->setCollapsed(
pht('Show Search'),
pht('Hide Search'),
pht('Search for file content in this directory.'),
'#');
}
return $filter;
}
private function renderSearchResults() {
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$results = array();
$no_data = pht('No results found.');
$limit = 100;
$page = $this->getRequest()->getInt('page', 0);
$pager = new AphrontPagerView();
$pager->setPageSize($limit);
$pager->setOffset($page);
$pager->setURI($this->getRequest()->getRequestURI(), 'page');
try {
$results = $this->callConduitWithDiffusionRequest(
'diffusion.searchquery',
array(
'grep' => $this->getRequest()->getStr('grep'),
'stableCommitName' => $drequest->getStableCommitName(),
'path' => $drequest->getPath(),
'limit' => $limit + 1,
'offset' => $page));
} catch (ConduitException $ex) {
$err = $ex->getErrorDescription();
if ($err != '') {
return id(new AphrontErrorView())
->setTitle(pht('Search Error'))
->appendChild($err);
}
}
$results = $pager->sliceResults($results);
require_celerity_resource('syntax-highlighting-css');
// NOTE: This can be wrong because we may find the string inside the
// comment. But it's correct in most cases and highlighting the whole file
// would be too expensive.
$futures = array();
$engine = PhabricatorSyntaxHighlighter::newEngine();
foreach ($results as $result) {
list($path, $line, $string) = $result;
$futures["{$path}:{$line}"] = $engine->getHighlightFuture(
$engine->getLanguageFromFilename($path),
ltrim($string));
}
try {
Futures($futures)->limit(8)->resolveAll();
} catch (PhutilSyntaxHighlighterException $ex) {
}
$rows = array();
foreach ($results as $result) {
list($path, $line, $string) = $result;
$href = $drequest->generateURI(array(
'action' => 'browse',
'path' => $path,
'line' => $line,
));
try {
$string = $futures["{$path}:{$line}"]->resolve();
} catch (PhutilSyntaxHighlighterException $ex) {
}
$string = phutil_tag(
'pre',
array('class' => 'PhabricatorMonospaced'),
$string);
$path = Filesystem::readablePath($path, $drequest->getPath());
$rows[] = array(
phutil_tag('a', array('href' => $href), $path),
$line,
$string,
);
}
$table = id(new AphrontTableView($rows))
->setClassName('remarkup-code')
->setHeaders(array(pht('Path'), pht('Line'), pht('String')))
->setColumnClasses(array('', 'n', 'wide'))
->setNoDataString($no_data);
return id(new AphrontPanelView())
->setNoBackground(true)
->appendChild($table)
->appendChild($pager);
}
private function markupText($text) {
$engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
$engine->setConfig('viewer', $this->getRequest()->getUser());
$text = $engine->markupText($text);
$text = phutil_tag(
'div',
array(
'class' => 'phabricator-remarkup',
),
$text);
return $text;
}
private function buildHeaderView(DiffusionRequest $drequest) {
$viewer = $this->getRequest()->getUser();
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setHeader($this->renderPathLinks($drequest))
->setPolicyObject($drequest->getRepository());
return $header;
}
- private function buildActionView(DiffusionRequest $drequest) {
- $viewer = $this->getRequest()->getUser();
-
- $view = id(new PhabricatorActionListView())
- ->setUser($viewer);
-
- $history_uri = $drequest->generateURI(
- array(
- 'action' => 'history',
- ));
-
- $view->addAction(
- id(new PhabricatorActionView())
- ->setName(pht('View History'))
- ->setHref($history_uri)
- ->setIcon('perflab'));
-
- $behind_head = $drequest->getRawCommit();
- $head_uri = $drequest->generateURI(
- array(
- 'commit' => '',
- 'action' => 'browse',
- ));
- $view->addAction(
- id(new PhabricatorActionView())
- ->setName(pht('Jump to HEAD'))
- ->setHref($head_uri)
- ->setIcon('home')
- ->setDisabled(!$behind_head));
-
- // TODO: Ideally, this should live in Owners and be event-triggered, but
- // there's no reasonable object for it to react to right now.
-
- $owners_uri = id(new PhutilURI('/owners/view/search/'))
- ->setQueryParams(
- array(
- 'repository' => $drequest->getCallsign(),
- 'path' => '/'.$drequest->getPath(),
- ));
-
- $view->addAction(
- id(new PhabricatorActionView())
- ->setName(pht('Find Owners'))
- ->setHref((string)$owners_uri)
- ->setIcon('preview'));
-
- return $view;
- }
-
private function buildPropertyView(DiffusionRequest $drequest) {
$viewer = $this->getRequest()->getUser();
$view = id(new PhabricatorPropertyListView())
->setUser($viewer);
$stable_commit = $drequest->getStableCommitName();
$callsign = $drequest->getRepository()->getCallsign();
$view->addProperty(
pht('Commit'),
phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'commit',
'commit' => $stable_commit,
)),
),
$drequest->getRepository()->formatCommitName($stable_commit)));
if ($drequest->getTagContent()) {
$view->addProperty(
pht('Tag'),
$drequest->getSymbolicCommit());
$view->addSectionHeader(pht('Tag Content'));
$view->addTextContent($this->markupText($drequest->getTagContent()));
}
return $view;
}
- private function renderPathLinks(DiffusionRequest $drequest) {
- $path = $drequest->getPath();
- $path_parts = array_filter(explode('/', trim($path, '/')));
-
- $links = array();
- if ($path_parts) {
- $links[] = phutil_tag(
- 'a',
- array(
- 'href' => $drequest->generateURI(
- array(
- 'action' => 'browse',
- 'path' => '',
- )),
- ),
- 'r'.$drequest->getRepository()->getCallsign().'/');
- $accum = '';
- $last_key = last_key($path_parts);
- foreach ($path_parts as $key => $part) {
- $links[] = ' ';
- $accum .= '/'.$part;
- if ($key === $last_key) {
- $links[] = $part;
- } else {
- $links[] = phutil_tag(
- 'a',
- array(
- 'href' => $drequest->generateURI(
- array(
- 'action' => 'browse',
- 'path' => $accum,
- )),
- ),
- $part.'/');
- }
- }
- } else {
- $links[] = 'r'.$drequest->getRepository()->getCallsign().'/';
- }
-
- return $links;
- }
-
}
diff --git a/src/applications/diffusion/controller/DiffusionBrowseFileController.php b/src/applications/diffusion/controller/DiffusionBrowseFileController.php
index 3a09039a88..643ac2d3f2 100644
--- a/src/applications/diffusion/controller/DiffusionBrowseFileController.php
+++ b/src/applications/diffusion/controller/DiffusionBrowseFileController.php
@@ -1,982 +1,1007 @@
<?php
final class DiffusionBrowseFileController extends DiffusionController {
private $corpusType = 'text';
private $lintCommit;
private $lintMessages;
public function processRequest() {
$request = $this->getRequest();
$drequest = $this->getDiffusionRequest();
$before = $request->getStr('before');
if ($before) {
return $this->buildBeforeResponse($before);
}
$path = $drequest->getPath();
$selected = $request->getStr('view');
$preferences = $request->getUser()->loadPreferences();
if (!$selected) {
$selected = $preferences->getPreference(
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_VIEW,
'highlighted');
} else if ($request->isFormPost() && $selected != 'raw') {
$preferences->setPreference(
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_VIEW,
$selected);
$preferences->save();
return id(new AphrontRedirectResponse())
->setURI($request->getRequestURI()->alter('view', $selected));
}
$needs_blame = ($selected == 'plainblame');
if ($selected == 'blame' && $request->isAjax()) {
$needs_blame = true;
}
$file_content = DiffusionFileContent::newFromConduit(
$this->callConduitWithDiffusionRequest(
'diffusion.filecontentquery',
array(
'commit' => $drequest->getCommit(),
'path' => $drequest->getPath(),
'needsBlame' => $needs_blame,
)));
$data = $file_content->getCorpus();
if ($selected === 'raw') {
return $this->buildRawResponse($path, $data);
}
$this->loadLintMessages();
// Build the content of the file.
$corpus = $this->buildCorpus(
$selected,
$file_content,
$needs_blame,
$drequest,
$path,
$data);
if ($request->isAjax()) {
return id(new AphrontAjaxResponse())->setContent($corpus);
}
require_celerity_resource('diffusion-source-css');
- if ($this->corpusType == 'text') {
- $view_select_panel = $this->renderViewSelectPanel($selected);
- } else {
- $view_select_panel = null;
- }
-
// Render the page.
$content = array();
+ $content[] = $this->buildHeaderView($drequest);
+ $view = $this->buildBrowseActionView($drequest);
+ $content[] = $this->enrichActionView($view, $drequest, $selected);
+ $content[] = $this->buildPropertyView($drequest);
+
$follow = $request->getStr('follow');
if ($follow) {
$notice = new AphrontErrorView();
$notice->setSeverity(AphrontErrorView::SEVERITY_WARNING);
$notice->setTitle(pht('Unable to Continue'));
switch ($follow) {
case 'first':
$notice->appendChild(
pht("Unable to continue tracing the history of this file because ".
"this commit is the first commit in the repository."));
break;
case 'created':
$notice->appendChild(
pht("Unable to continue tracing the history of this file because ".
"this commit created the file."));
break;
}
$content[] = $notice;
}
$renamed = $request->getStr('renamed');
if ($renamed) {
$notice = new AphrontErrorView();
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
$notice->setTitle(pht('File Renamed'));
$notice->appendChild(
pht("File history passes through a rename from '%s' to '%s'.",
$drequest->getPath(), $renamed));
$content[] = $notice;
}
- $content[] = $view_select_panel;
$content[] = $corpus;
$content[] = $this->buildOpenRevisions();
- $nav = $this->buildSideNav('browse', true);
- $nav->appendChild($content);
$crumbs = $this->buildCrumbs(
array(
'branch' => true,
'path' => true,
'view' => 'browse',
));
- $nav->setCrumbs($crumbs);
$basename = basename($this->getDiffusionRequest()->getPath());
return $this->buildApplicationPage(
- $nav,
+ array(
+ $crumbs,
+ $content,
+ ),
array(
'title' => $basename,
));
}
private function loadLintMessages() {
$drequest = $this->getDiffusionRequest();
$branch = $drequest->loadBranch();
if (!$branch || !$branch->getLintCommit()) {
return;
}
$this->lintCommit = $branch->getLintCommit();
$conn = id(new PhabricatorRepository())->establishConnection('r');
$where = '';
if ($drequest->getLint()) {
$where = qsprintf(
$conn,
'AND code = %s',
$drequest->getLint());
}
$this->lintMessages = queryfx_all(
$conn,
'SELECT * FROM %T WHERE branchID = %d %Q AND path = %s',
PhabricatorRepository::TABLE_LINTMESSAGE,
$branch->getID(),
$where,
'/'.$drequest->getPath());
}
private function buildCorpus(
$selected,
DiffusionFileContent $file_content,
$needs_blame,
DiffusionRequest $drequest,
$path,
$data) {
if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) {
$file = $this->loadFileForData($path, $data);
$file_uri = $file->getBestURI();
if ($file->isViewableImage()) {
$this->corpusType = 'image';
return $this->buildImageCorpus($file_uri);
} else {
$this->corpusType = 'binary';
return $this->buildBinaryCorpus($file_uri, $data);
}
}
switch ($selected) {
case 'plain':
$style =
"margin: 1em 2em; width: 90%; height: 80em; font-family: monospace";
$corpus = phutil_tag(
'textarea',
array(
'style' => $style,
),
$file_content->getCorpus());
break;
case 'plainblame':
$style =
"margin: 1em 2em; width: 90%; height: 80em; font-family: monospace";
$text_list = $file_content->getTextList();
$rev_list = $file_content->getRevList();
$blame_dict = $file_content->getBlameDict();
$rows = array();
foreach ($text_list as $k => $line) {
$rev = $rev_list[$k];
$author = $blame_dict[$rev]['author'];
$rows[] =
sprintf("%-10s %-20s %s", substr($rev, 0, 7), $author, $line);
}
$corpus = phutil_tag(
'textarea',
array(
'style' => $style,
),
implode("\n", $rows));
break;
case 'highlighted':
case 'blame':
default:
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, $selected);
$corpus_table = javelin_tag(
'table',
array(
'class' => "diffusion-source remarkup-code PhabricatorMonospaced",
'sigil' => 'phabricator-source',
),
$rows);
if ($this->getRequest()->isAjax()) {
return $corpus_table;
}
$id = celerity_generate_unique_node_id();
$projects = $drequest->loadArcanistProjects();
$langs = array();
foreach ($projects as $project) {
$ls = $project->getSymbolIndexLanguages();
if (!$ls) {
continue;
}
$dep_projects = $project->getSymbolIndexProjects();
$dep_projects[] = $project->getPHID();
foreach ($ls as $lang) {
if (!isset($langs[$lang])) {
$langs[$lang] = array();
}
$langs[$lang] += $dep_projects + array($project);
}
}
$lang = last(explode('.', $drequest->getPath()));
if (isset($langs[$lang])) {
Javelin::initBehavior(
'repository-crossreference',
array(
'container' => $id,
'lang' => $lang,
'projects' => $langs[$lang],
));
}
$corpus = phutil_tag(
'div',
array(
'style' => 'padding: 0 2em;',
'id' => $id,
),
$corpus_table);
Javelin::initBehavior('load-blame', array('id' => $id));
break;
}
return $corpus;
}
- private function renderViewSelectPanel($selected) {
+ private function enrichActionView(
+ PhabricatorActionListView $view,
+ DiffusionRequest $drequest,
+ $selected) {
+
+ $viewer = $this->getRequest()->getUser();
+ $base_uri = $this->getRequest()->getRequestURI();
+
$toggle_blame = array(
'highlighted' => 'blame',
'blame' => 'highlighted',
'plain' => 'plainblame',
'plainblame' => 'plain',
'raw' => 'raw', // not a real case.
);
+
$toggle_highlight = array(
'highlighted' => 'plain',
'blame' => 'plainblame',
'plain' => 'highlighted',
'plainblame' => 'blame',
'raw' => 'raw', // not a real case.
);
- $user = $this->getRequest()->getUser();
- $base_uri = $this->getRequest()->getRequestURI();
-
$blame_on = ($selected == 'blame' || $selected == 'plainblame');
if ($blame_on) {
$blame_text = pht('Disable Blame');
+ $blame_icon = 'blame-grey';
} else {
$blame_text = pht('Enable Blame');
+ $blame_icon = 'blame';
}
- $blame_button = $this->createViewAction(
- $blame_text,
- $base_uri->alter('view', $toggle_blame[$selected]),
- $user);
+ $view->addAction(
+ id(new PhabricatorActionView())
+ ->setName($blame_text)
+ ->setHref($base_uri->alter('view', $toggle_blame[$selected]))
+ ->setIcon($blame_icon)
+ ->setUser($viewer)
+ ->setRenderAsForm(true));
$highlight_on = ($selected == 'blame' || $selected == 'highlighted');
if ($highlight_on) {
$highlight_text = pht('Disable Highlighting');
+ $highlight_icon = 'highlight-grey';
} else {
$highlight_text = pht('Enable Highlighting');
+ $highlight_icon = 'highlight';
}
- $highlight_button = $this->createViewAction(
- $highlight_text,
- $base_uri->alter('view', $toggle_highlight[$selected]),
- $user);
+
+ $view->addAction(
+ id(new PhabricatorActionView())
+ ->setName($highlight_text)
+ ->setHref($base_uri->alter('view', $toggle_highlight[$selected]))
+ ->setIcon($highlight_icon)
+ ->setUser($viewer)
+ ->setRenderAsForm(true));
$href = null;
if ($this->getRequest()->getStr('lint') !== null) {
$lint_text = pht('Hide %d Lint Message(s)', count($this->lintMessages));
$href = $base_uri->alter('lint', null);
} else if ($this->lintCommit === null) {
$lint_text = pht('Lint not Available');
-
} else {
$lint_text = pht(
'Show %d Lint Message(s)',
count($this->lintMessages));
$href = $this->getDiffusionRequest()->generateURI(array(
'action' => 'browse',
'commit' => $this->lintCommit,
))->alter('lint', '');
}
- $lint_button = $this->createViewAction(
- $lint_text,
- $href,
- $user);
-
- if (!$href) {
- $lint_button->setDisabled(true);
- }
-
+ $view->addAction(
+ id(new PhabricatorActionView())
+ ->setName($lint_text)
+ ->setHref($href)
+ ->setIcon('warning')
+ ->setDisabled(!$href));
- $raw_button = $this->createViewAction(
- pht('View Raw File'),
- $base_uri->alter('view', 'raw'),
- $user,
- 'file');
+ $view->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('View Raw File'))
+ ->setHref($base_uri->alter('view', 'raw'))
+ ->setIcon('file'));
- $edit_button = $this->createEditAction();
+ $view->addAction($this->createEditAction());
- return id(new PhabricatorActionListView())
- ->setUser($user)
- ->setObjectURI($this->getRequest()->getRequestURI())
- ->addAction($blame_button)
- ->addAction($highlight_button)
- ->addAction($lint_button)
- ->addAction($raw_button)
- ->addAction($edit_button);
- }
-
- private function createViewAction(
- $localized_text,
- $href,
- $user,
- $icon = null) {
-
- return id(new PhabricatorActionView())
- ->setName($localized_text)
- ->setIcon($icon)
- ->setUser($user)
- ->setRenderAsForm(true)
- ->setHref($href);
+ return $view;
}
private function createEditAction() {
$request = $this->getRequest();
$user = $request->getUser();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$path = $drequest->getPath();
$line = nonempty((int)$drequest->getLine(), 1);
$callsign = $repository->getCallsign();
$editor_link = $user->loadEditorLink($path, $line, $callsign);
$action = id(new PhabricatorActionView())
->setName(pht('Open in Editor'))
->setIcon('edit');
$action->setHref($editor_link);
$action->setDisabled(!$editor_link);
return $action;
}
private function buildDisplayRows(
array $text_list,
array $rev_list,
array $blame_dict,
$needs_blame,
DiffusionRequest $drequest,
$selected) {
$handles = array();
if ($blame_dict) {
$epoch_list = ipull(ifilter($blame_dict, 'epoch'), 'epoch');
$epoch_min = min($epoch_list);
$epoch_max = max($epoch_list);
$epoch_range = ($epoch_max - $epoch_min) + 1;
$author_phids = ipull(ifilter($blame_dict, 'authorPHID'), 'authorPHID');
$handles = $this->loadViewerHandles($author_phids);
}
$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,
);
}
}
$display = array();
$line_number = 1;
$last_rev = null;
$color = null;
foreach ($text_list as $k => $line) {
$display_line = array(
'epoch' => null,
'commit' => null,
'author' => null,
'target' => null,
'highlighted' => null,
'line' => $line_number,
'data' => $line,
);
if ($selected == 'blame') {
// 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
// is, the more saturated the color.
$rev = idx($rev_list, $k, $last_rev);
if ($last_rev == $rev) {
$display_line['color'] = $color;
} else {
$blame = $blame_dict[$rev];
if (!isset($blame['epoch'])) {
$color = '#ffd'; // Render as warning.
} else {
$color_ratio = ($blame['epoch'] - $epoch_min) / $epoch_range;
$color_value = 0xE6 * (1.0 - $color_ratio);
$color = sprintf(
'#%02x%02x%02x',
$color_value,
0xF6,
$color_value);
}
$display_line['epoch'] = idx($blame, 'epoch');
$display_line['color'] = $color;
$display_line['commit'] = $rev;
$author_phid = idx($blame, 'authorPHID');
if ($author_phid && $handles[$author_phid]) {
$author_link = $handles[$author_phid]->renderLink();
} else {
$author_link = phutil_tag(
'span',
array(
),
$blame['author']);
}
$display_line['author'] = $author_link;
$last_rev = $rev;
}
}
if ($line_arr) {
if ($line_number == $line_arr[0]['min']) {
$display_line['target'] = true;
}
foreach ($line_arr as $range) {
if ($line_number >= $range['min'] &&
$line_number <= $range['max']) {
$display_line['highlighted'] = true;
}
}
}
$display[] = $display_line;
++$line_number;
}
$commits = array_filter(ipull($display, 'commit'));
if ($commits) {
$commits = id(new PhabricatorAuditCommitQuery())
->withIdentifiers($drequest->getRepository()->getID(), $commits)
->needCommitData(true)
->execute();
$commits = mpull($commits, null, 'getCommitIdentifier');
}
$revision_ids = id(new DifferentialRevision())
->loadIDsByCommitPHIDs(mpull($commits, 'getPHID'));
$revisions = array();
if ($revision_ids) {
$revisions = id(new DifferentialRevision())->loadAllWhere(
'id IN (%Ld)',
$revision_ids);
}
$request = $this->getRequest();
$user = $request->getUser();
Javelin::initBehavior('phabricator-oncopy', array());
$engine = null;
$inlines = array();
if ($this->getRequest()->getStr('lint') !== null && $this->lintMessages) {
$engine = new PhabricatorMarkupEngine();
$engine->setViewer($user);
foreach ($this->lintMessages as $message) {
$inline = id(new PhabricatorAuditInlineComment())
->setID($message['id'])
->setSyntheticAuthor(
ArcanistLintSeverity::getStringForSeverity($message['severity']).
' '.$message['code'].' ('.$message['name'].')')
->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()),
($selected == 'blame'),
$engine);
foreach ($display as $line) {
$line_href = $drequest->generateURI(
array(
'action' => 'browse',
'line' => $line['line'],
'stable' => true,
));
$blame = array();
$style = null;
if (array_key_exists('color', $line)) {
if ($line['color']) {
$style = 'background: '.$line['color'].';';
}
$before_link = null;
$commit_link = null;
$revision_link = null;
if (idx($line, 'commit')) {
$commit = $line['commit'];
$summary = 'Unknown';
if (idx($commits, $commit)) {
$summary = $commits[$commit]->getCommitData()->getSummary();
}
$tooltip = phabricator_date(
$line['epoch'],
$user)." \xC2\xB7 ".$summary;
Javelin::initBehavior('phabricator-tooltips', array());
require_celerity_resource('aphront-tooltip-css');
$commit_link = javelin_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'commit',
'commit' => $line['commit'],
)),
'sigil' => 'has-tooltip',
'meta' => array(
'tip' => $tooltip,
'align' => 'E',
'size' => 600,
),
),
phutil_utf8_shorten($line['commit'], 9, ''));
$revision_id = null;
if (idx($commits, $commit)) {
$revision_id = idx($revision_ids, $commits[$commit]->getPHID());
}
if ($revision_id) {
$revision = idx($revisions, $revision_id);
if (!$revision) {
$tooltip = pht('(Invalid revision)');
} else {
$tooltip =
phabricator_date($revision->getDateModified(), $user).
" \xC2\xB7 ".
$revision->getTitle();
}
$revision_link = javelin_tag(
'a',
array(
'href' => '/D'.$revision_id,
'sigil' => 'has-tooltip',
'meta' => array(
'tip' => $tooltip,
'align' => 'E',
'size' => 600,
),
),
'D'.$revision_id);
}
$uri = $line_href->alter('before', $commit);
$before_link = javelin_tag(
'a',
array(
'href' => $uri->setQueryParam('view', 'blame'),
'sigil' => 'has-tooltip',
'meta' => array(
'tip' => pht('Skip Past This Commit'),
'align' => 'E',
'size' => 300,
),
),
"\xC2\xAB");
}
$blame[] = phutil_tag(
'th',
array(
'class' => 'diffusion-blame-link',
'style' => $style,
),
$before_link);
$blame[] = phutil_tag(
'th',
array(
'class' => 'diffusion-rev-link',
'style' => $style,
),
$commit_link);
$blame[] = phutil_tag(
'th',
array(
'class' => 'diffusion-rev-link',
'style' => $style,
),
$revision_link);
$blame[] = phutil_tag(
'th',
array(
'class' => 'diffusion-author-link',
'style' => $style,
),
idx($line, 'author'));
}
$line_link = phutil_tag(
'a',
array(
'href' => $line_href,
),
$line['line']);
$blame[] = javelin_tag(
'th',
array(
'class' => 'diffusion-line-link',
'sigil' => 'phabricator-source-line',
'style' => $style,
),
$line_link);
Javelin::initBehavior('phabricator-line-linker');
if ($line['target']) {
Javelin::initBehavior(
'diffusion-jump-to',
array(
'target' => 'scroll_target',
));
$anchor_text = phutil_tag(
'a',
array(
'id' => 'scroll_target',
),
'');
} else {
$anchor_text = null;
}
$blame[] = phutil_tag(
'td',
array(
),
array(
$anchor_text,
// NOTE: See phabricator-oncopy behavior.
"\xE2\x80\x8B",
// TODO: [HTML] Not ideal.
phutil_safe_html($line['data']),
));
$rows[] = phutil_tag(
'tr',
array(
'class' => ($line['highlighted'] ?
'phabricator-source-highlight' :
null),
),
$blame);
$rows = array_merge($rows, $this->renderInlines(
idx($inlines, $line['line'], array()),
($selected == 'blame'),
$engine));
}
return $rows;
}
private function renderInlines(array $inlines, $needs_blame, $engine) {
$rows = array();
foreach ($inlines as $inline) {
$inline_view = id(new DifferentialInlineCommentView())
->setMarkupEngine($engine)
->setInlineComment($inline)
->render();
$row = array_fill(0, ($needs_blame ? 5 : 1), phutil_tag('th'));
$row[] = phutil_tag('td', array(), $inline_view);
$rows[] = phutil_tag('tr', array('class' => 'inline'), $row);
}
return $rows;
}
private function loadFileForData($path, $data) {
return PhabricatorFile::buildFromFileDataOrHash(
$data,
array(
'name' => basename($path),
'ttl' => time() + 60 * 60 * 24,
));
}
private function buildRawResponse($path, $data) {
$file = $this->loadFileForData($path, $data);
return id(new AphrontRedirectResponse())->setURI($file->getBestURI());
}
private function buildImageCorpus($file_uri) {
$properties = new PhabricatorPropertyListView();
$properties->addProperty(
pht('Image'),
phutil_tag(
'img',
array(
'src' => $file_uri,
)));
$actions = id(new PhabricatorActionListView())
->setUser($this->getRequest()->getUser())
->setObjectURI($this->getRequest()->getRequestURI())
->addAction($this->createEditAction());
return array($actions, $properties);
}
private function buildBinaryCorpus($file_uri, $data) {
$properties = new PhabricatorPropertyListView();
$size = strlen($data);
$properties->addTextContent(
pht(
'This is a binary file. It is %s byte(s) in length.',
new PhutilNumber($size)));
$actions = id(new PhabricatorActionListView())
->setUser($this->getRequest()->getUser())
->setObjectURI($this->getRequest()->getRequestURI())
->addAction($this->createEditAction())
->addAction(
id(new PhabricatorActionView())
->setName(pht('Download Binary File...'))
->setIcon('download')
->setHref($file_uri));
return array($actions, $properties);
}
private function buildBeforeResponse($before) {
$request = $this->getRequest();
$drequest = $this->getDiffusionRequest();
// NOTE: We need to get the grandparent so we can capture filename changes
// in the parent.
$parent = $this->loadParentRevisionOf($before);
$old_filename = null;
$was_created = false;
if ($parent) {
$grandparent = $this->loadParentRevisionOf(
$parent->getCommitIdentifier());
if ($grandparent) {
$rename_query = new DiffusionRenameHistoryQuery();
$rename_query->setRequest($drequest);
$rename_query->setOldCommit($grandparent->getCommitIdentifier());
$rename_query->setViewer($request->getUser());
$old_filename = $rename_query->loadOldFilename();
$was_created = $rename_query->getWasCreated();
}
}
$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.
$target_commit = $parent->getCommitIdentifier();
} 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';
}
$path = $drequest->getPath();
$renamed = null;
if ($old_filename !== null &&
$old_filename !== '/'.$path) {
$renamed = $path;
$path = $old_filename;
}
$line = null;
// If there's a follow error, drop the line so the user sees the message.
if (!$follow) {
$line = $this->getBeforeLineNumber($target_commit);
}
$before_uri = $drequest->generateURI(
array(
'action' => 'browse',
'commit' => $target_commit,
'line' => $line,
'path' => $path,
));
$before_uri->setQueryParams($request->getRequestURI()->getQueryParams());
$before_uri = $before_uri->alter('before', null);
$before_uri = $before_uri->alter('renamed', $renamed);
$before_uri = $before_uri->alter('follow', $follow);
return id(new AphrontRedirectResponse())->setURI($before_uri);
}
private function getBeforeLineNumber($target_commit) {
$drequest = $this->getDiffusionRequest();
$line = $drequest->getLine();
if (!$line) {
return null;
}
$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;
}
}
// We didn't find the target line.
return $line;
}
private function loadParentRevisionOf($commit) {
$drequest = $this->getDiffusionRequest();
$user = $this->getRequest()->getUser();
$before_req = DiffusionRequest::newFromDictionary(
array(
'user' => $user,
'repository' => $drequest->getRepository(),
'commit' => $commit,
));
$parents = DiffusionQuery::callConduitWithDiffusionRequest(
$user,
$before_req,
'diffusion.commitparentsquery',
array(
'commit' => $commit));
return head($parents);
}
+ private function buildHeaderView(DiffusionRequest $drequest) {
+ $viewer = $this->getRequest()->getUser();
+
+ $header = id(new PHUIHeaderView())
+ ->setUser($viewer)
+ ->setHeader($this->renderPathLinks($drequest))
+ ->setPolicyObject($drequest->getRepository());
+
+ return $header;
+ }
+
+ private function buildPropertyView(DiffusionRequest $drequest) {
+ $viewer = $this->getRequest()->getUser();
+
+ $view = id(new PhabricatorPropertyListView())
+ ->setUser($viewer);
+
+ $stable_commit = $drequest->getStableCommitName();
+ $callsign = $drequest->getRepository()->getCallsign();
+
+ $view->addProperty(
+ pht('Commit'),
+ phutil_tag(
+ 'a',
+ array(
+ 'href' => $drequest->generateURI(
+ array(
+ 'action' => 'commit',
+ 'commit' => $stable_commit,
+ )),
+ ),
+ $drequest->getRepository()->formatCommitName($stable_commit)));
+
+ return $view;
+ }
+
}
diff --git a/src/applications/diffusion/controller/DiffusionController.php b/src/applications/diffusion/controller/DiffusionController.php
index fbb7868969..30058ae55d 100644
--- a/src/applications/diffusion/controller/DiffusionController.php
+++ b/src/applications/diffusion/controller/DiffusionController.php
@@ -1,347 +1,441 @@
<?php
abstract class DiffusionController extends PhabricatorController {
protected $diffusionRequest;
public function willProcessRequest(array $data) {
if (isset($data['callsign'])) {
$drequest = DiffusionRequest::newFromAphrontRequestDictionary(
$data,
$this->getRequest());
$this->diffusionRequest = $drequest;
}
}
public function setDiffusionRequest(DiffusionRequest $request) {
$this->diffusionRequest = $request;
return $this;
}
protected function getDiffusionRequest() {
if (!$this->diffusionRequest) {
throw new Exception("No Diffusion request object!");
}
return $this->diffusionRequest;
}
public function buildStandardPageResponse($view, array $data) {
$page = $this->buildStandardPageView();
$page->setApplicationName(pht('Diffusion'));
$page->setBaseURI('/diffusion/');
$page->setTitle(idx($data, 'title'));
$page->setGlyph("\xE2\x89\x88");
$page->setSearchDefaultScope(PhabricatorSearchScope::SCOPE_COMMITS);
$page->appendChild($view);
$response = new AphrontWebpageResponse();
return $response->setContent($page->render());
}
final protected function buildSideNav($selected, $has_change_view) {
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI(''));
$navs = array(
'history' => pht('History View'),
'browse' => pht('Browse View'),
'change' => pht('Change View'),
);
if (!$has_change_view) {
unset($navs['change']);
}
$drequest = $this->getDiffusionRequest();
$branch = $drequest->loadBranch();
if ($branch && $branch->getLintCommit()) {
$navs['lint'] = pht('Lint View');
}
$selected_href = null;
foreach ($navs as $action => $name) {
$href = $drequest->generateURI(
array(
'action' => $action,
));
if ($action == $selected) {
$selected_href = $href;
}
$nav->addFilter($href, $name, $href);
}
$nav->selectFilter($selected_href, null);
// TODO: URI encoding might need to be sorted out for this link.
$nav->addFilter(
'',
pht("Search Owners \xE2\x86\x97"),
'/owners/view/search/'.
'?repository='.phutil_escape_uri($drequest->getCallsign()).
'&path='.phutil_escape_uri('/'.$drequest->getPath()));
return $nav;
}
public function buildCrumbs(array $spec = array()) {
$crumbs = $this->buildApplicationCrumbs();
$crumb_list = $this->buildCrumbList($spec);
foreach ($crumb_list as $crumb) {
$crumbs->addCrumb($crumb);
}
return $crumbs;
}
protected function buildOpenRevisions() {
$user = $this->getRequest()->getUser();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$path = $drequest->getPath();
$path_map = id(new DiffusionPathIDQuery(array($path)))->loadPathIDs();
$path_id = idx($path_map, $path);
if (!$path_id) {
return null;
}
$revisions = id(new DifferentialRevisionQuery())
->setViewer($user)
->withPath($repository->getID(), $path_id)
->withStatus(DifferentialRevisionQuery::STATUS_OPEN)
->setOrder(DifferentialRevisionQuery::ORDER_PATH_MODIFIED)
->setLimit(10)
->needRelationships(true)
->execute();
if (!$revisions) {
return null;
}
$view = id(new DifferentialRevisionListView())
->setRevisions($revisions)
->setFields(DifferentialRevisionListView::getDefaultFields($user))
->setUser($user)
->loadAssets();
$phids = $view->getRequiredHandlePHIDs();
$handles = $this->loadViewerHandles($phids);
$view->setHandles($handles);
$header = id(new PHUIHeaderView())
->setHeader(pht('Pending Differential Revisions'));
return array(
$header,
$view,
);
}
private function buildCrumbList(array $spec = array()) {
$spec = $spec + array(
'commit' => null,
'tags' => null,
'branches' => null,
'view' => null,
);
$crumb_list = array();
// On the home page, we don't have a DiffusionRequest.
if ($this->diffusionRequest) {
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
} else {
$drequest = null;
$repository = null;
}
if (!$repository) {
return $crumb_list;
}
$callsign = $repository->getCallsign();
$repository_name = 'r'.$callsign;
if (!$spec['commit'] && !$spec['tags'] && !$spec['branches']) {
$branch_name = $drequest->getBranch();
if ($branch_name) {
$repository_name .= ' ('.$branch_name.')';
}
}
$crumb = id(new PhabricatorCrumbView())
->setName($repository_name);
if (!$spec['view'] && !$spec['commit'] &&
!$spec['tags'] && !$spec['branches']) {
$crumb_list[] = $crumb;
return $crumb_list;
}
$crumb->setHref("/diffusion/{$callsign}/");
$crumb_list[] = $crumb;
$raw_commit = $drequest->getRawCommit();
if ($spec['tags']) {
$crumb = new PhabricatorCrumbView();
if ($spec['commit']) {
$crumb->setName(
pht("Tags for %s", 'r'.$callsign.$raw_commit));
$crumb->setHref($drequest->generateURI(
array(
'action' => 'commit',
'commit' => $raw_commit,
)));
} else {
$crumb->setName(pht('Tags'));
}
$crumb_list[] = $crumb;
return $crumb_list;
}
if ($spec['branches']) {
$crumb = id(new PhabricatorCrumbView())
->setName(pht('Branches'));
$crumb_list[] = $crumb;
return $crumb_list;
}
if ($spec['commit']) {
$crumb = id(new PhabricatorCrumbView())
->setName("r{$callsign}{$raw_commit}")
->setHref("r{$callsign}{$raw_commit}");
$crumb_list[] = $crumb;
return $crumb_list;
}
$crumb = new PhabricatorCrumbView();
$view = $spec['view'];
$path = null;
if (isset($spec['path'])) {
$path = $drequest->getPath();
}
if ($raw_commit) {
$commit_link = DiffusionView::linkCommit(
$repository,
$raw_commit);
} else {
$commit_link = '';
}
switch ($view) {
case 'history':
$view_name = pht('History');
break;
case 'browse':
$view_name = pht('Browse');
break;
case 'lint':
$view_name = pht('Lint');
break;
case 'change':
$view_name = pht('Change');
$crumb_list[] = $crumb->setName(
hsprintf('%s (%s)', $path, $commit_link));
return $crumb_list;
}
$uri_params = array(
'action' => $view,
);
$crumb = id(new PhabricatorCrumbView())
->setName($view_name);
if ($view == 'browse') {
$crumb_list[] = $crumb;
return $crumb_list;
}
$crumb->setHref($drequest->generateURI(
array(
'path' => '',
) + $uri_params));
$crumb_list[] = $crumb;
$path_parts = explode('/', $path);
do {
$last = array_pop($path_parts);
} while (count($path_parts) && $last == '');
$path_sections = array();
$thus_far = '';
foreach ($path_parts as $path_part) {
$thus_far .= $path_part.'/';
$path_sections[] = '/';
$path_sections[] = phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'path' => $thus_far,
) + $uri_params),
),
$path_part);
}
$path_sections[] = '/'.$last;
$crumb_list[] = id(new PhabricatorCrumbView())
->setName($path_sections);
$last_crumb = array_pop($crumb_list);
if ($raw_commit) {
$jump_link = phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'commit' => '',
) + $uri_params),
),
pht('Jump to HEAD'));
$name = $last_crumb->getName();
$name = hsprintf('%s @ %s (%s)', $name, $commit_link, $jump_link);
$last_crumb->setName($name);
} else if ($spec['view'] != 'lint') {
$name = $last_crumb->getName();
$name = hsprintf('%s @ HEAD', $name);
$last_crumb->setName($name);
}
$crumb_list[] = $last_crumb;
return $crumb_list;
}
protected function callConduitWithDiffusionRequest(
$method,
array $params = array()) {
$user = $this->getRequest()->getUser();
$drequest = $this->getDiffusionRequest();
return DiffusionQuery::callConduitWithDiffusionRequest(
$user,
$drequest,
$method,
$params);
}
protected function getRepositoryControllerURI(
PhabricatorRepository $repository,
$path) {
return $this->getApplicationURI($repository->getCallsign().'/'.$path);
}
+
+ protected function buildBrowseActionView(DiffusionRequest $drequest) {
+ $viewer = $this->getRequest()->getUser();
+
+ $view = id(new PhabricatorActionListView())
+ ->setUser($viewer);
+
+ $history_uri = $drequest->generateURI(
+ array(
+ 'action' => 'history',
+ ));
+
+ $view->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('View History'))
+ ->setHref($history_uri)
+ ->setIcon('perflab'));
+
+ $behind_head = $drequest->getRawCommit();
+ $head_uri = $drequest->generateURI(
+ array(
+ 'commit' => '',
+ 'action' => 'browse',
+ ));
+ $view->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('Jump to HEAD'))
+ ->setHref($head_uri)
+ ->setIcon('home')
+ ->setDisabled(!$behind_head));
+
+ // TODO: Ideally, this should live in Owners and be event-triggered, but
+ // there's no reasonable object for it to react to right now.
+
+ $owners_uri = id(new PhutilURI('/owners/view/search/'))
+ ->setQueryParams(
+ array(
+ 'repository' => $drequest->getCallsign(),
+ 'path' => '/'.$drequest->getPath(),
+ ));
+
+ $view->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('Find Owners'))
+ ->setHref((string)$owners_uri)
+ ->setIcon('preview'));
+
+ return $view;
+ }
+
+ protected function renderPathLinks(DiffusionRequest $drequest) {
+ $path = $drequest->getPath();
+ $path_parts = array_filter(explode('/', trim($path, '/')));
+
+ $links = array();
+ if ($path_parts) {
+ $links[] = phutil_tag(
+ 'a',
+ array(
+ 'href' => $drequest->generateURI(
+ array(
+ 'action' => 'browse',
+ 'path' => '',
+ )),
+ ),
+ 'r'.$drequest->getRepository()->getCallsign().'/');
+ $accum = '';
+ $last_key = last_key($path_parts);
+ foreach ($path_parts as $key => $part) {
+ $links[] = ' ';
+ $accum .= '/'.$part;
+ if ($key === $last_key) {
+ $links[] = $part;
+ } else {
+ $links[] = phutil_tag(
+ 'a',
+ array(
+ 'href' => $drequest->generateURI(
+ array(
+ 'action' => 'browse',
+ 'path' => $accum,
+ )),
+ ),
+ $part.'/');
+ }
+ }
+ } else {
+ $links[] = 'r'.$drequest->getRepository()->getCallsign().'/';
+ }
+
+ return $links;
+ }
+
}
+

File Metadata

Mime Type
text/x-diff
Expires
Jan 19 2025, 23:20 (6 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1129838
Default Alt Text
(54 KB)

Event Timeline