diff --git a/src/applications/diffusion/controller/DiffusionBrowseController.php b/src/applications/diffusion/controller/DiffusionBrowseController.php --- a/src/applications/diffusion/controller/DiffusionBrowseController.php +++ b/src/applications/diffusion/controller/DiffusionBrowseController.php @@ -585,6 +585,8 @@ } $file_corpus = $file_content->getCorpus(); + $highlight_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT; + $can_highlight = (strlen($file_corpus) <= $highlight_limit); if (!$show_color) { $lines = phutil_split_lines($file_corpus); @@ -625,12 +627,16 @@ implode('', $rows)); } } else { - require_celerity_resource('syntax-highlighting-css'); + if ($can_highlight) { + require_celerity_resource('syntax-highlighting-css'); - $highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename( - $path, - $file_corpus); - $lines = phutil_split_lines($highlighted); + $highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename( + $path, + $file_corpus); + $lines = phutil_split_lines($highlighted); + } else { + $lines = phutil_split_lines($file_corpus); + } $rows = $this->buildDisplayRows( $lines, @@ -706,6 +712,18 @@ ->appendChild($corpus) ->setCollapsed(true); + if (!$can_highlight) { + $message = pht( + 'This file is larger than %s, so syntax highlighting is disabled '. + 'by default.', + phutil_format_bytes($highlight_limit)); + + $corpus->setInfoView( + id(new PHUIInfoView()) + ->setSeverity(PHUIInfoView::SEVERITY_WARNING) + ->setErrors(array($message))); + } + return $corpus; } @@ -851,6 +869,7 @@ $show_blame) { $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); $handles = array(); if ($blame) { @@ -989,8 +1008,6 @@ } $handles = $this->loadViewerHandles($phids); - Javelin::initBehavior('phabricator-oncopy', array()); - $engine = null; $inlines = array(); if ($this->getRequest()->getStr('lint') !== null && $this->lintMessages) { @@ -1021,13 +1038,21 @@ (bool)$this->coverage, $engine); + // NOTE: We're doing this manually because rendering is otherwise + // dominated by URI generation for very large files. + $line_base = (string)$repository->generateURI( + array( + 'action' => 'browse', + 'stable' => true, + )); + + require_celerity_resource('aphront-tooltip-css'); + Javelin::initBehavior('phabricator-oncopy'); + Javelin::initBehavior('phabricator-tooltips'); + Javelin::initBehavior('phabricator-line-linker'); + foreach ($display as $line) { - $line_href = $drequest->generateURI( - array( - 'action' => 'browse', - 'line' => $line['line'], - 'stable' => true, - )); + $line_href = $line_base.'$'.$line['line']; $blame = array(); $style = null; @@ -1051,9 +1076,6 @@ $tooltip = null; } - Javelin::initBehavior('phabricator-tooltips', array()); - require_celerity_resource('aphront-tooltip-css'); - $commit_link = javelin_tag( 'a', array( @@ -1095,19 +1117,23 @@ } } - $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, + if ($commit) { + $identifier = $commit->getCommitIdentifier(); + $skip_href = $line_href.'?before='.$identifier.'&view=blame'; + + $before_link = javelin_tag( + 'a', + array( + 'href' => $skip_href, + 'sigil' => 'has-tooltip', + 'meta' => array( + 'tip' => pht('Skip Past This Commit'), + 'align' => 'E', + 'size' => 300, + ), ), - ), - "\xC2\xAB"); + "\xC2\xAB"); + } } $blame[] = phutil_tag( @@ -1149,8 +1175,6 @@ ), $line_link); - Javelin::initBehavior('phabricator-line-linker'); - if ($line['target']) { Javelin::initBehavior( 'diffusion-jump-to', diff --git a/src/view/form/PHUIInfoView.php b/src/view/form/PHUIInfoView.php --- a/src/view/form/PHUIInfoView.php +++ b/src/view/form/PHUIInfoView.php @@ -41,7 +41,6 @@ } public function addButton(PHUIButtonView $button) { - $this->buttons[] = $button; return $this; }