mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-16 03:42:41 +01:00
21826ed7b3
Summary: Ref T5644. See some discussion in D8040. When a file is very large (more than 64KB of text), don't activate syntax highlighting by default. This should prevent us from wasting resources running `pygmentize` on enormous files. Users who want the file highlighted can still select "Highlight As...". The tricky part of this diff is separating the headers into "changeset" headers and "undershield" (rendering) headers. Specifically, a file might have these headers/shields: - "This file is newly added." - "This file is generated. Show Changes" - "Highlighting is disabled for this large file." In this case, I want the user to see "added" and "generated" when they load the page, and only see "highlighting disabled" after they click "Show Changes". So there are several categories: - "Changeset" headers, which discuss the changeset as a whole (binary file, image file, moved, added, deleted, etc.) - "Property" headers, which describe metadata changes (not relevant here). - "Shields", which hide files from view by default. - "Undershield" headers, which provide rendering information that is only relevant if there is no shield on the file. Test Plan: - Viewed a diff with the library map, clicked "show changes", got a "highlighting disabled" header back with highlighting disabled. - Enabled highlighting explicitly (this currently restores the shield, which it probably shouldn't, but that feels out of scope for this change). The deshielded file is highlighted per the user's request. - Loaded context on normal files. Reviewers: btrahan Reviewed By: btrahan Subscribers: joshuaspence, epriestley Maniphest Tasks: T5644 Differential Revision: https://secure.phabricator.com/D12132
136 lines
3 KiB
PHP
136 lines
3 KiB
PHP
<?php
|
|
|
|
abstract class DifferentialChangesetTestRenderer
|
|
extends DifferentialChangesetRenderer {
|
|
|
|
protected function renderChangeTypeHeader($force) {
|
|
$changeset = $this->getChangeset();
|
|
|
|
$old = nonempty($changeset->getOldFile(), '-');
|
|
$current = nonempty($changeset->getFilename(), '-');
|
|
$away = nonempty(implode(', ', $changeset->getAwayPaths()), '-');
|
|
|
|
$ctype = $changeset->getChangeType();
|
|
$ftype = $changeset->getFileType();
|
|
$force = ($force ? '(forced)' : '(unforced)');
|
|
|
|
return "CTYPE {$ctype} {$ftype} {$force}\n".
|
|
"{$old}\n".
|
|
"{$current}\n".
|
|
"{$away}\n";
|
|
}
|
|
|
|
protected function renderUndershieldHeader() {
|
|
return null;
|
|
}
|
|
|
|
public function renderShield($message, $force = 'default') {
|
|
return "SHIELD ({$force}) {$message}\n";
|
|
}
|
|
|
|
protected function renderPropertyChangeHeader() {
|
|
$changeset = $this->getChangeset();
|
|
list($old, $new) = $this->getChangesetProperties($changeset);
|
|
|
|
if (!$old && !$new) {
|
|
return null;
|
|
}
|
|
|
|
$props = '';
|
|
foreach ($old as $key => $value) {
|
|
$props .= "P - {$key} {$value}~\n";
|
|
}
|
|
foreach ($new as $key => $value) {
|
|
$props .= "P + {$key} {$value}~\n";
|
|
}
|
|
|
|
return "PROPERTIES\n".$props;
|
|
}
|
|
|
|
public function renderTextChange(
|
|
$range_start,
|
|
$range_len,
|
|
$rows) {
|
|
|
|
$out = array();
|
|
|
|
$any_old = false;
|
|
$any_new = false;
|
|
$primitives = $this->buildPrimitives($range_start, $range_len);
|
|
foreach ($primitives as $p) {
|
|
$type = $p['type'];
|
|
switch ($type) {
|
|
case 'old':
|
|
case 'new':
|
|
if ($type == 'old') {
|
|
$any_old = true;
|
|
}
|
|
if ($type == 'new') {
|
|
$any_new = true;
|
|
}
|
|
$num = nonempty($p['line'], '-');
|
|
$render = $p['render'];
|
|
$htype = nonempty($p['htype'], '.');
|
|
|
|
// TODO: This should probably happen earlier, whenever we deal with
|
|
// \r and \t normalization?
|
|
$render = str_replace(
|
|
array(
|
|
"\r",
|
|
"\n",
|
|
),
|
|
array(
|
|
'\\r',
|
|
'\\n',
|
|
),
|
|
$render);
|
|
|
|
$render = str_replace(
|
|
array(
|
|
'<span class="bright">',
|
|
'</span>',
|
|
),
|
|
array(
|
|
'{(',
|
|
')}',
|
|
),
|
|
$render);
|
|
|
|
$render = html_entity_decode($render, ENT_QUOTES);
|
|
|
|
$t = ($type == 'old') ? 'O' : 'N';
|
|
|
|
$out[] = "{$t} {$num} {$htype} {$render}~";
|
|
break;
|
|
case 'no-context':
|
|
$out[] = 'X <MISSING-CONTEXT>';
|
|
break;
|
|
default:
|
|
$out[] = $type;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!$any_old) {
|
|
$out[] = 'O X <EMPTY>';
|
|
}
|
|
|
|
if (!$any_new) {
|
|
$out[] = 'N X <EMPTY>';
|
|
}
|
|
|
|
$out = implode("\n", $out)."\n";
|
|
return $out;
|
|
}
|
|
|
|
|
|
public function renderFileChange(
|
|
$old_file = null,
|
|
$new_file = null,
|
|
$id = 0,
|
|
$vs = 0) {
|
|
|
|
throw new PhutilMethodNotImplementedException();
|
|
}
|
|
|
|
}
|