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

Don't enable the "ScopeEngine" or try to identify scope context for diffs without context

Summary:
Depends on D20197. Ref T13161. We currently try to build a "ScopeEngine" even for diffs with no context (e.g., `git diff` instead of `git diff -U9999`).

Since we don't have any context, we won't really be able to figure out anything useful about scopes. Also, since ScopeEngine is pretty strict about what it accepts, we crash.

In these cases, just don't build a ScopeEngine.

Test Plan: Viewed a diff I copy/pasted with `git diff` instead of an `arc diff` / `git diff -U99999`, got a sensible diff with no context instead of a fatal.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13161

Differential Revision: https://secure.phabricator.com/D20198
This commit is contained in:
epriestley 2019-02-20 05:06:42 -08:00
parent f1a035d5c2
commit 1b83256421
2 changed files with 17 additions and 7 deletions

View file

@ -33,7 +33,7 @@ abstract class DifferentialChangesetRenderer extends Phobject {
private $canMarkDone; private $canMarkDone;
private $objectOwnerPHID; private $objectOwnerPHID;
private $highlightingDisabled; private $highlightingDisabled;
private $scopeEngine; private $scopeEngine = false;
private $depthOnlyLines; private $depthOnlyLines;
private $oldFile = false; private $oldFile = false;
@ -677,13 +677,23 @@ abstract class DifferentialChangesetRenderer extends Phobject {
return $views; return $views;
} }
final protected function getScopeEngine() { final protected function getScopeEngine() {
if (!$this->scopeEngine) { if ($this->scopeEngine === false) {
$line_map = $this->getNewLineTextMap(); $hunk_starts = $this->getHunkStartLines();
$scope_engine = id(new PhabricatorDiffScopeEngine()) // If this change is missing context, don't try to identify scopes, since
->setLineTextMap($line_map); // we won't really be able to get anywhere.
$has_multiple_hunks = (count($hunk_starts) > 1);
$has_offset_hunks = (head_key($hunk_starts) != 1);
$missing_context = ($has_multiple_hunks || $has_offset_hunks);
if ($missing_context) {
$scope_engine = null;
} else {
$line_map = $this->getNewLineTextMap();
$scope_engine = id(new PhabricatorDiffScopeEngine())
->setLineTextMap($line_map);
}
$this->scopeEngine = $scope_engine; $this->scopeEngine = $scope_engine;
} }

View file

@ -94,7 +94,7 @@ final class DifferentialChangesetTwoUpRenderer
$context_text = null; $context_text = null;
$context_line = null; $context_line = null;
if (!$is_last_block) { if (!$is_last_block && $scope_engine) {
$target_line = $new_lines[$ii + $len]['line']; $target_line = $new_lines[$ii + $len]['line'];
$context_line = $scope_engine->getScopeStart($target_line); $context_line = $scope_engine->getScopeStart($target_line);
if ($context_line !== null) { if ($context_line !== null) {