1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00

Don't save highlithing errors to cache

Summary:
If I have Pygments enabled in config but `pygmentize` doesn't work then unhighlighted source is stored to cache.
If I later make `pygmentize` work then the unhighlighted source is still loaded from the cache.

Test Plan:
Break `pygmentize`.
View a diff with JS files.
Fix `pygmenize`.
View the diff again.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, gatos99, Koolvin

Differential Revision: https://secure.phabricator.com/D2227
This commit is contained in:
vrana 2012-04-12 23:52:50 -07:00
parent 1f1c7a34b7
commit 74cdad29d0
3 changed files with 26 additions and 7 deletions

View file

@ -55,8 +55,9 @@ final class DifferentialChangesetParser {
private $isTopLevel;
private $coverage;
private $markupEngine;
private $highlightErrors;
const CACHE_VERSION = 4;
const CACHE_VERSION = 5;
const ATTR_GENERATED = 'attr:generated';
const ATTR_DELETED = 'attr:deleted';
@ -503,7 +504,7 @@ final class DifferentialChangesetParser {
$new_corpus[] = $n['text'];
}
}
$new_corpus_block = implode("\n", $new_corpus);
$new_corpus_block = implode("\n", $old_corpus);
$old_future = $this->getHighlightFuture($old_corpus_block);
$new_future = $this->getHighlightFuture($new_corpus_block);
@ -511,18 +512,31 @@ final class DifferentialChangesetParser {
'old' => $old_future,
'new' => $new_future,
);
$corpus_blocks = array(
'old' => $old_corpus_block,
'new' => $new_corpus_block,
);
$this->highlightErrors = false;
foreach (Futures($futures) as $key => $future) {
try {
try {
$highlighted = $future->resolve();
} catch (PhutilSyntaxHighlighterException $ex) {
$this->highlightErrors = true;
$highlighted = id(new PhutilDefaultSyntaxHighlighter())
->getHighlightFuture($corpus_blocks[$key])
->resolve();
}
switch ($key) {
case 'old':
$this->oldRender = $this->processHighlightedSource(
$this->old,
$future->resolve());
$highlighted);
break;
case 'new':
$this->newRender = $this->processHighlightedSource(
$this->new,
$future->resolve());
$highlighted);
break;
}
} catch (Exception $ex) {
@ -630,6 +644,10 @@ final class DifferentialChangesetParser {
}
public function saveCache() {
if ($this->highlightErrors) {
return false;
}
$render_cache_key = $this->getRenderCacheKey();
if (!$render_cache_key) {
return false;

View file

@ -25,6 +25,7 @@ phutil_require_module('phutil', 'error');
phutil_require_module('phutil', 'events/engine');
phutil_require_module('phutil', 'future');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'markup/syntax/highlighter/default');
phutil_require_module('phutil', 'utils');

View file

@ -1,7 +1,7 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -39,12 +39,12 @@ final class PhabricatorSyntaxHighlighter {
public static function highlightWithFilename($filename, $source) {
$engine = self::newEngine();
$language = $engine->getLanguageFromFilename($filename);
return $engine->getHighlightFuture($language, $source)->resolve();
return $engine->highlightSource($language, $source);
}
public static function highlightWithLanguage($language, $source) {
$engine = self::newEngine();
return $engine->getHighlightFuture($language, $source)->resolve();
return $engine->highlightSource($language, $source);
}