Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/differential/render/DifferentialChangesetOneUpRenderer.php b/src/applications/differential/render/DifferentialChangesetOneUpRenderer.php
index 186924e359..bcdbf4dd46 100644
--- a/src/applications/differential/render/DifferentialChangesetOneUpRenderer.php
+++ b/src/applications/differential/render/DifferentialChangesetOneUpRenderer.php
@@ -1,526 +1,530 @@
<?php
final class DifferentialChangesetOneUpRenderer
extends DifferentialChangesetHTMLRenderer {
private $simpleMode;
public function setSimpleMode($simple_mode) {
$this->simpleMode = $simple_mode;
return $this;
}
public function getSimpleMode() {
return $this->simpleMode;
}
public function isOneUpRenderer() {
return true;
}
protected function getRendererTableClass() {
return 'diff-1up';
}
public function getRendererKey() {
return '1up';
}
protected function renderColgroup() {
return phutil_tag('colgroup', array(), array(
phutil_tag('col', array('class' => 'num')),
phutil_tag('col', array('class' => 'num')),
phutil_tag('col', array('class' => 'copy')),
phutil_tag('col', array('class' => 'unified')),
));
}
public function renderTextChange(
$range_start,
$range_len,
$rows) {
$primitives = $this->buildPrimitives($range_start, $range_len);
return $this->renderPrimitives($primitives, $rows);
}
protected function renderPrimitives(array $primitives, $rows) {
list($left_prefix, $right_prefix) = $this->getLineIDPrefixes();
$is_simple = $this->getSimpleMode();
$no_copy = phutil_tag('td', array('class' => 'copy'));
$no_coverage = null;
$column_width = 4;
$aural_minus = javelin_tag(
'span',
array(
'aural' => true,
'data-aural' => true,
),
'- ');
$aural_plus = javelin_tag(
'span',
array(
'aural' => true,
'data-aural' => true,
),
'+ ');
$out = array();
foreach ($primitives as $k => $p) {
$type = $p['type'];
switch ($type) {
case 'old':
case 'new':
case 'old-file':
case 'new-file':
$is_old = ($type == 'old' || $type == 'old-file');
$cells = array();
if ($is_old) {
if ($p['htype']) {
- if (empty($p['oline'])) {
+ if ($p['htype'] === '\\') {
+ $class = 'comment';
+ } else if (empty($p['oline'])) {
$class = 'left old old-full';
} else {
$class = 'left old';
}
$aural = $aural_minus;
} else {
$class = 'left';
$aural = null;
}
if ($type == 'old-file') {
$class = "{$class} differential-old-image";
}
if ($left_prefix) {
$left_id = $left_prefix.$p['line'];
} else {
$left_id = null;
}
$line = $p['line'];
$cells[] = phutil_tag(
'td',
array(
'id' => $left_id,
'class' => $class.' n',
'data-n' => $line,
));
$render = $p['render'];
if ($aural !== null) {
$render = array($aural, $render);
}
$cells[] = phutil_tag(
'td',
array(
'class' => $class.' n',
));
$cells[] = $no_copy;
$cells[] = phutil_tag('td', array('class' => $class), $render);
$cells[] = $no_coverage;
} else {
if ($p['htype']) {
- if (empty($p['oline'])) {
+ if ($p['htype'] === '\\') {
+ $class = 'comment';
+ } else if (empty($p['oline'])) {
$class = 'right new new-full';
} else {
$class = 'right new';
}
$cells[] = phutil_tag(
'td',
array(
'class' => $class.' n',
));
$aural = $aural_plus;
} else {
$class = 'right';
if ($left_prefix) {
$left_id = $left_prefix.$p['oline'];
} else {
$left_id = null;
}
$oline = $p['oline'];
$cells[] = phutil_tag(
'td',
array(
'id' => $left_id,
'class' => 'n',
'data-n' => $oline,
));
$aural = null;
}
if ($type == 'new-file') {
$class = "{$class} differential-new-image";
}
if ($right_prefix) {
$right_id = $right_prefix.$p['line'];
} else {
$right_id = null;
}
$line = $p['line'];
$cells[] = phutil_tag(
'td',
array(
'id' => $right_id,
'class' => $class.' n',
'data-n' => $line,
));
$render = $p['render'];
if ($aural !== null) {
$render = array($aural, $render);
}
$cells[] = $no_copy;
$cells[] = phutil_tag(
'td',
array(
'class' => $class,
'data-copy-mode' => 'copy-unified',
),
$render);
$cells[] = $no_coverage;
}
// In simple mode, only render the text. This is used to render
// "Edit Suggestions" in inline comments.
if ($is_simple) {
$cells = array($cells[3]);
}
$out[] = phutil_tag('tr', array(), $cells);
break;
case 'inline':
$inline = $this->buildInlineComment(
$p['comment'],
$p['right']);
$out[] = $this->getRowScaffoldForInline($inline);
break;
case 'no-context':
$out[] = phutil_tag(
'tr',
array(),
phutil_tag(
'td',
array(
'class' => 'show-more',
'colspan' => $column_width,
),
pht('Context not available.')));
break;
case 'context':
$top = $p['top'];
$len = $p['len'];
$links = $this->renderShowContextLinks($top, $len, $rows);
$out[] = javelin_tag(
'tr',
array(
'sigil' => 'context-target',
),
phutil_tag(
'td',
array(
'class' => 'show-more',
'colspan' => $column_width,
),
$links));
break;
default:
$out[] = hsprintf('<tr><th /><th /><td>%s</td></tr>', $type);
break;
}
}
$result = null;
if ($out) {
if ($is_simple) {
$result = $this->newSimpleTable($out);
} else {
$result = $this->wrapChangeInTable(phutil_implode_html('', $out));
}
}
return $result;
}
public function renderDocumentEngineBlocks(
PhabricatorDocumentEngineBlocks $block_list,
$old_changeset_key,
$new_changeset_key) {
$engine = $this->getDocumentEngine();
$layout = $block_list->newTwoUpLayout();
$old_comments = $this->getOldComments();
$new_comments = $this->getNewComments();
$unchanged = array();
foreach ($layout as $key => $row) {
list($old, $new) = $row;
if (!$old) {
continue;
}
if (!$new) {
continue;
}
if ($old->getDifferenceType() !== null) {
continue;
}
if ($new->getDifferenceType() !== null) {
continue;
}
$unchanged[$key] = true;
}
$rows = array();
$count = count($layout);
for ($ii = 0; $ii < $count;) {
$start = $ii;
for ($jj = $ii; $jj < $count; $jj++) {
list($old, $new) = $layout[$jj];
if (empty($unchanged[$jj])) {
break;
}
$rows[] = array(
'type' => 'unchanged',
'layoutKey' => $jj,
);
}
$ii = $jj;
for ($jj = $ii; $jj < $count; $jj++) {
list($old, $new) = $layout[$jj];
if (!empty($unchanged[$jj])) {
break;
}
$rows[] = array(
'type' => 'old',
'layoutKey' => $jj,
);
}
for ($jj = $ii; $jj < $count; $jj++) {
list($old, $new) = $layout[$jj];
if (!empty($unchanged[$jj])) {
break;
}
$rows[] = array(
'type' => 'new',
'layoutKey' => $jj,
);
}
$ii = $jj;
// We always expect to consume at least one row when iterating through
// the loop and make progress. If we don't, bail out to avoid spinning
// to death.
if ($ii === $start) {
throw new Exception(
pht(
'Failed to make progress during 1up diff layout.'));
}
}
$old_ref = null;
$new_ref = null;
$refs = $block_list->getDocumentRefs();
if ($refs) {
list($old_ref, $new_ref) = $refs;
}
$view = array();
foreach ($rows as $row) {
$row_type = $row['type'];
$layout_key = $row['layoutKey'];
$row_layout = $layout[$layout_key];
list($old, $new) = $row_layout;
if ($old) {
$old_key = $old->getBlockKey();
} else {
$old_key = null;
}
if ($new) {
$new_key = $new->getBlockKey();
} else {
$new_key = null;
}
$cells = array();
$cell_classes = array();
if ($row_type === 'unchanged') {
$cell_content = $engine->newBlockContentView(
$old_ref,
$old);
} else if ($old && $new) {
$block_diff = $engine->newBlockDiffViews(
$old_ref,
$old,
$new_ref,
$new);
// TODO: We're currently double-rendering this: once when building
// the old row, and once when building the new one. In both cases,
// we throw away the other half of the output. We could cache this
// to improve performance.
if ($row_type === 'old') {
$cell_content = $block_diff->getOldContent();
$cell_classes = $block_diff->getOldClasses();
} else {
$cell_content = $block_diff->getNewContent();
$cell_classes = $block_diff->getNewClasses();
}
} else if ($row_type === 'old') {
if (!$old_ref || !$old) {
continue;
}
$cell_content = $engine->newBlockContentView(
$old_ref,
$old);
$cell_classes[] = 'old';
$cell_classes[] = 'old-full';
$new_key = null;
} else if ($row_type === 'new') {
if (!$new_ref || !$new) {
continue;
}
$cell_content = $engine->newBlockContentView(
$new_ref,
$new);
$cell_classes[] = 'new';
$cell_classes[] = 'new-full';
$old_key = null;
}
if ($old_key === null) {
$old_id = null;
} else {
$old_id = "C{$old_changeset_key}OL{$old_key}";
}
if ($new_key === null) {
$new_id = null;
} else {
$new_id = "C{$new_changeset_key}NL{$new_key}";
}
$cells[] = phutil_tag(
'td',
array(
'id' => $old_id,
'data-n' => $old_key,
'class' => 'n',
));
$cells[] = phutil_tag(
'td',
array(
'id' => $new_id,
'data-n' => $new_key,
'class' => 'n',
));
$cells[] = phutil_tag(
'td',
array(
'class' => 'copy',
));
$cell_classes[] = 'diff-flush';
$cell_classes = implode(' ', $cell_classes);
$cells[] = phutil_tag(
'td',
array(
'class' => $cell_classes,
'data-copy-mode' => 'copy-unified',
),
$cell_content);
$view[] = phutil_tag(
'tr',
array(),
$cells);
if ($old_key !== null) {
$old_inlines = idx($old_comments, $old_key, array());
foreach ($old_inlines as $inline) {
$inline = $this->buildInlineComment(
$inline,
$on_right = false);
$view[] = $this->getRowScaffoldForInline($inline);
}
}
if ($new_key !== null) {
$new_inlines = idx($new_comments, $new_key, array());
foreach ($new_inlines as $inline) {
$inline = $this->buildInlineComment(
$inline,
$on_right = true);
$view[] = $this->getRowScaffoldForInline($inline);
}
}
}
$output = $this->wrapChangeInTable($view);
return $this->renderChangesetTable($output);
}
public function getRowScaffoldForInline(PHUIDiffInlineCommentView $view) {
return id(new PHUIDiffOneUpInlineCommentRowScaffold())
->addInlineView($view);
}
private function newSimpleTable($content) {
return phutil_tag(
'table',
array(
'class' => 'diff-1up-simple-table',
),
$content);
}
}
diff --git a/src/applications/differential/render/DifferentialChangesetRenderer.php b/src/applications/differential/render/DifferentialChangesetRenderer.php
index d493c0e886..dcae3b979b 100644
--- a/src/applications/differential/render/DifferentialChangesetRenderer.php
+++ b/src/applications/differential/render/DifferentialChangesetRenderer.php
@@ -1,767 +1,771 @@
<?php
abstract class DifferentialChangesetRenderer extends Phobject {
private $user;
private $changeset;
private $renderingReference;
private $renderPropertyChangeHeader;
private $isTopLevel;
private $isUndershield;
private $hunkStartLines;
private $oldLines;
private $newLines;
private $oldComments;
private $newComments;
private $oldChangesetID;
private $newChangesetID;
private $oldAttachesToNewFile;
private $newAttachesToNewFile;
private $highlightOld = array();
private $highlightNew = array();
private $codeCoverage;
private $handles;
private $markupEngine;
private $oldRender;
private $newRender;
private $originalOld;
private $originalNew;
private $gaps;
private $mask;
private $originalCharacterEncoding;
private $showEditAndReplyLinks;
private $canMarkDone;
private $objectOwnerPHID;
private $highlightingDisabled;
private $scopeEngine = false;
private $depthOnlyLines;
private $documentEngine;
private $documentEngineBlocks;
private $oldFile = false;
private $newFile = false;
abstract public function getRendererKey();
public function setShowEditAndReplyLinks($bool) {
$this->showEditAndReplyLinks = $bool;
return $this;
}
public function getShowEditAndReplyLinks() {
return $this->showEditAndReplyLinks;
}
public function setHighlightingDisabled($highlighting_disabled) {
$this->highlightingDisabled = $highlighting_disabled;
return $this;
}
public function getHighlightingDisabled() {
return $this->highlightingDisabled;
}
public function setOriginalCharacterEncoding($original_character_encoding) {
$this->originalCharacterEncoding = $original_character_encoding;
return $this;
}
public function getOriginalCharacterEncoding() {
return $this->originalCharacterEncoding;
}
public function setIsUndershield($is_undershield) {
$this->isUndershield = $is_undershield;
return $this;
}
public function getIsUndershield() {
return $this->isUndershield;
}
public function setMask($mask) {
$this->mask = $mask;
return $this;
}
protected function getMask() {
return $this->mask;
}
public function setGaps($gaps) {
$this->gaps = $gaps;
return $this;
}
protected function getGaps() {
return $this->gaps;
}
public function setDepthOnlyLines(array $lines) {
$this->depthOnlyLines = $lines;
return $this;
}
public function getDepthOnlyLines() {
return $this->depthOnlyLines;
}
public function attachOldFile(PhabricatorFile $old = null) {
$this->oldFile = $old;
return $this;
}
public function getOldFile() {
if ($this->oldFile === false) {
throw new PhabricatorDataNotAttachedException($this);
}
return $this->oldFile;
}
public function hasOldFile() {
return (bool)$this->oldFile;
}
public function attachNewFile(PhabricatorFile $new = null) {
$this->newFile = $new;
return $this;
}
public function getNewFile() {
if ($this->newFile === false) {
throw new PhabricatorDataNotAttachedException($this);
}
return $this->newFile;
}
public function hasNewFile() {
return (bool)$this->newFile;
}
public function setOriginalNew($original_new) {
$this->originalNew = $original_new;
return $this;
}
protected function getOriginalNew() {
return $this->originalNew;
}
public function setOriginalOld($original_old) {
$this->originalOld = $original_old;
return $this;
}
protected function getOriginalOld() {
return $this->originalOld;
}
public function setNewRender($new_render) {
$this->newRender = $new_render;
return $this;
}
protected function getNewRender() {
return $this->newRender;
}
public function setOldRender($old_render) {
$this->oldRender = $old_render;
return $this;
}
protected function getOldRender() {
return $this->oldRender;
}
public function setMarkupEngine(PhabricatorMarkupEngine $markup_engine) {
$this->markupEngine = $markup_engine;
return $this;
}
public function getMarkupEngine() {
return $this->markupEngine;
}
public function setHandles(array $handles) {
assert_instances_of($handles, 'PhabricatorObjectHandle');
$this->handles = $handles;
return $this;
}
protected function getHandles() {
return $this->handles;
}
public function setCodeCoverage($code_coverage) {
$this->codeCoverage = $code_coverage;
return $this;
}
protected function getCodeCoverage() {
return $this->codeCoverage;
}
public function setHighlightNew($highlight_new) {
$this->highlightNew = $highlight_new;
return $this;
}
protected function getHighlightNew() {
return $this->highlightNew;
}
public function setHighlightOld($highlight_old) {
$this->highlightOld = $highlight_old;
return $this;
}
protected function getHighlightOld() {
return $this->highlightOld;
}
public function setNewAttachesToNewFile($attaches) {
$this->newAttachesToNewFile = $attaches;
return $this;
}
protected function getNewAttachesToNewFile() {
return $this->newAttachesToNewFile;
}
public function setOldAttachesToNewFile($attaches) {
$this->oldAttachesToNewFile = $attaches;
return $this;
}
protected function getOldAttachesToNewFile() {
return $this->oldAttachesToNewFile;
}
public function setNewChangesetID($new_changeset_id) {
$this->newChangesetID = $new_changeset_id;
return $this;
}
protected function getNewChangesetID() {
return $this->newChangesetID;
}
public function setOldChangesetID($old_changeset_id) {
$this->oldChangesetID = $old_changeset_id;
return $this;
}
protected function getOldChangesetID() {
return $this->oldChangesetID;
}
public function setDocumentEngine(PhabricatorDocumentEngine $engine) {
$this->documentEngine = $engine;
return $this;
}
public function getDocumentEngine() {
return $this->documentEngine;
}
public function setDocumentEngineBlocks(
PhabricatorDocumentEngineBlocks $blocks) {
$this->documentEngineBlocks = $blocks;
return $this;
}
public function getDocumentEngineBlocks() {
return $this->documentEngineBlocks;
}
public function setNewComments(array $new_comments) {
foreach ($new_comments as $line_number => $comments) {
assert_instances_of($comments, 'PhabricatorInlineComment');
}
$this->newComments = $new_comments;
return $this;
}
protected function getNewComments() {
return $this->newComments;
}
public function setOldComments(array $old_comments) {
foreach ($old_comments as $line_number => $comments) {
assert_instances_of($comments, 'PhabricatorInlineComment');
}
$this->oldComments = $old_comments;
return $this;
}
protected function getOldComments() {
return $this->oldComments;
}
public function setNewLines(array $new_lines) {
$this->newLines = $new_lines;
return $this;
}
protected function getNewLines() {
return $this->newLines;
}
public function setOldLines(array $old_lines) {
$this->oldLines = $old_lines;
return $this;
}
protected function getOldLines() {
return $this->oldLines;
}
public function setHunkStartLines(array $hunk_start_lines) {
$this->hunkStartLines = $hunk_start_lines;
return $this;
}
protected function getHunkStartLines() {
return $this->hunkStartLines;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
protected function getUser() {
return $this->user;
}
public function setChangeset(DifferentialChangeset $changeset) {
$this->changeset = $changeset;
return $this;
}
protected function getChangeset() {
return $this->changeset;
}
public function setRenderingReference($rendering_reference) {
$this->renderingReference = $rendering_reference;
return $this;
}
protected function getRenderingReference() {
return $this->renderingReference;
}
public function setRenderPropertyChangeHeader($should_render) {
$this->renderPropertyChangeHeader = $should_render;
return $this;
}
private function shouldRenderPropertyChangeHeader() {
return $this->renderPropertyChangeHeader;
}
public function setIsTopLevel($is) {
$this->isTopLevel = $is;
return $this;
}
private function getIsTopLevel() {
return $this->isTopLevel;
}
public function setCanMarkDone($can_mark_done) {
$this->canMarkDone = $can_mark_done;
return $this;
}
public function getCanMarkDone() {
return $this->canMarkDone;
}
public function setObjectOwnerPHID($phid) {
$this->objectOwnerPHID = $phid;
return $this;
}
public function getObjectOwnerPHID() {
return $this->objectOwnerPHID;
}
final public function renderChangesetTable($content) {
$props = null;
if ($this->shouldRenderPropertyChangeHeader()) {
$props = $this->renderPropertyChangeHeader();
}
$notice = null;
if ($this->getIsTopLevel()) {
$force = (!$content && !$props);
// If we have DocumentEngine messages about the blocks, assume they
// explain why there's no content.
$blocks = $this->getDocumentEngineBlocks();
if ($blocks) {
if ($blocks->getMessages()) {
$force = false;
}
}
$notice = $this->renderChangeTypeHeader($force);
}
$undershield = null;
if ($this->getIsUndershield()) {
$undershield = $this->renderUndershieldHeader();
}
$result = array(
$notice,
$props,
$undershield,
$content,
);
return hsprintf('%s', $result);
}
abstract public function isOneUpRenderer();
abstract public function renderTextChange(
$range_start,
$range_len,
$rows);
public function renderDocumentEngineBlocks(
PhabricatorDocumentEngineBlocks $blocks,
$old_changeset_key,
$new_changeset_key) {
return null;
}
abstract protected function renderChangeTypeHeader($force);
abstract protected function renderUndershieldHeader();
protected function didRenderChangesetTableContents($contents) {
return $contents;
}
/**
* Render a "shield" over the diff, with a message like "This file is
* generated and does not need to be reviewed." or "This file was completely
* deleted." This UI element hides unimportant text so the reviewer doesn't
* need to scroll past it.
*
* The shield includes a link to view the underlying content. This link
* may force certain rendering modes when the link is clicked:
*
* - `"default"`: Render the diff normally, as though it was not
* shielded. This is the default and appropriate if the underlying
* diff is a normal change, but was hidden for reasons of not being
* important (e.g., generated code).
* - `"text"`: Force the text to be shown. This is probably only relevant
* when a file is not changed.
* - `"none"`: Don't show the link (e.g., text not available).
*
* @param string Message explaining why the diff is hidden.
* @param string|null Force mode, see above.
* @return string Shield markup.
*/
abstract public function renderShield($message, $force = 'default');
abstract protected function renderPropertyChangeHeader();
protected function buildPrimitives($range_start, $range_len) {
$primitives = array();
$hunk_starts = $this->getHunkStartLines();
$mask = $this->getMask();
$gaps = $this->getGaps();
$old = $this->getOldLines();
$new = $this->getNewLines();
$old_render = $this->getOldRender();
$new_render = $this->getNewRender();
$old_comments = $this->getOldComments();
$new_comments = $this->getNewComments();
$size = count($old);
for ($ii = $range_start; $ii < $range_start + $range_len; $ii++) {
if (empty($mask[$ii])) {
list($top, $len) = array_pop($gaps);
$primitives[] = array(
'type' => 'context',
'top' => $top,
'len' => $len,
);
$ii += ($len - 1);
continue;
}
$ospec = array(
'type' => 'old',
'htype' => null,
'cursor' => $ii,
'line' => null,
'oline' => null,
'render' => null,
);
$nspec = array(
'type' => 'new',
'htype' => null,
'cursor' => $ii,
'line' => null,
'oline' => null,
'render' => null,
'copy' => null,
'coverage' => null,
);
if (isset($old[$ii])) {
$ospec['line'] = (int)$old[$ii]['line'];
$nspec['oline'] = (int)$old[$ii]['line'];
$ospec['htype'] = $old[$ii]['type'];
if (isset($old_render[$ii])) {
$ospec['render'] = $old_render[$ii];
+ } else if ($ospec['htype'] === '\\') {
+ $ospec['render'] = $old[$ii]['text'];
}
}
if (isset($new[$ii])) {
$nspec['line'] = (int)$new[$ii]['line'];
$ospec['oline'] = (int)$new[$ii]['line'];
$nspec['htype'] = $new[$ii]['type'];
if (isset($new_render[$ii])) {
$nspec['render'] = $new_render[$ii];
+ } else if ($nspec['htype'] === '\\') {
+ $nspec['render'] = $new[$ii]['text'];
}
}
if (isset($hunk_starts[$ospec['line']])) {
$primitives[] = array(
'type' => 'no-context',
);
}
$primitives[] = $ospec;
$primitives[] = $nspec;
if ($ospec['line'] !== null && isset($old_comments[$ospec['line']])) {
foreach ($old_comments[$ospec['line']] as $comment) {
$primitives[] = array(
'type' => 'inline',
'comment' => $comment,
'right' => false,
);
}
}
if ($nspec['line'] !== null && isset($new_comments[$nspec['line']])) {
foreach ($new_comments[$nspec['line']] as $comment) {
$primitives[] = array(
'type' => 'inline',
'comment' => $comment,
'right' => true,
);
}
}
if ($hunk_starts && ($ii == $size - 1)) {
$primitives[] = array(
'type' => 'no-context',
);
}
}
if ($this->isOneUpRenderer()) {
$primitives = $this->processPrimitivesForOneUp($primitives);
}
return $primitives;
}
private function processPrimitivesForOneUp(array $primitives) {
// Primitives come out of buildPrimitives() in two-up format, because it
// is the most general, flexible format. To put them into one-up format,
// we need to filter and reorder them. In particular:
//
// - We discard unchanged lines in the old file; in one-up format, we
// render them only once.
// - We group contiguous blocks of old-modified and new-modified lines, so
// they render in "block of old, block of new" order instead of
// alternating old and new lines.
$out = array();
$old_buf = array();
$new_buf = array();
foreach ($primitives as $primitive) {
$type = $primitive['type'];
if ($type == 'old') {
if (!$primitive['htype']) {
// This is a line which appears in both the old file and the new
// file, or the spacer corresponding to a line added in the new file.
// Ignore it when rendering a one-up diff.
continue;
}
$old_buf[] = $primitive;
} else if ($type == 'new') {
if ($primitive['line'] === null) {
// This is an empty spacer corresponding to a line removed from the
// old file. Ignore it when rendering a one-up diff.
continue;
}
if (!$primitive['htype']) {
// If this line is the same in both versions of the file, put it in
// the old line buffer. This makes sure inlines on old, unchanged
// lines end up in the right place.
// First, we need to flush the line buffers if they're not empty.
if ($old_buf) {
$out[] = $old_buf;
$old_buf = array();
}
if ($new_buf) {
$out[] = $new_buf;
$new_buf = array();
}
$old_buf[] = $primitive;
} else {
$new_buf[] = $primitive;
}
} else if ($type == 'context' || $type == 'no-context') {
$out[] = $old_buf;
$out[] = $new_buf;
$old_buf = array();
$new_buf = array();
$out[] = array($primitive);
} else if ($type == 'inline') {
// If this inline is on the left side, put it after the old lines.
if (!$primitive['right']) {
$out[] = $old_buf;
$out[] = array($primitive);
$old_buf = array();
} else {
$out[] = $old_buf;
$out[] = $new_buf;
$out[] = array($primitive);
$old_buf = array();
$new_buf = array();
}
} else {
throw new Exception(pht("Unknown primitive type '%s'!", $primitive));
}
}
$out[] = $old_buf;
$out[] = $new_buf;
$out = array_mergev($out);
return $out;
}
protected function getChangesetProperties($changeset) {
$old = $changeset->getOldProperties();
$new = $changeset->getNewProperties();
// If a property has been changed, but is not present on one side of the
// change and has an uninteresting default value on the other, remove it.
// This most commonly happens when a change adds or removes a file: the
// side of the change with the file has a "100644" filemode in Git.
$defaults = array(
'unix:filemode' => '100644',
);
foreach ($defaults as $default_key => $default_value) {
$old_value = idx($old, $default_key, $default_value);
$new_value = idx($new, $default_key, $default_value);
$old_default = ($old_value === $default_value);
$new_default = ($new_value === $default_value);
if ($old_default && $new_default) {
unset($old[$default_key]);
unset($new[$default_key]);
}
}
$metadata = $changeset->getMetadata();
if ($this->hasOldFile()) {
$file = $this->getOldFile();
if ($file->getImageWidth()) {
$dimensions = $file->getImageWidth().'x'.$file->getImageHeight();
$old['file:dimensions'] = $dimensions;
}
$old['file:mimetype'] = $file->getMimeType();
$old['file:size'] = phutil_format_bytes($file->getByteSize());
} else {
$old['file:mimetype'] = idx($metadata, 'old:file:mime-type');
$size = idx($metadata, 'old:file:size');
if ($size !== null) {
$old['file:size'] = phutil_format_bytes($size);
}
}
if ($this->hasNewFile()) {
$file = $this->getNewFile();
if ($file->getImageWidth()) {
$dimensions = $file->getImageWidth().'x'.$file->getImageHeight();
$new['file:dimensions'] = $dimensions;
}
$new['file:mimetype'] = $file->getMimeType();
$new['file:size'] = phutil_format_bytes($file->getByteSize());
} else {
$new['file:mimetype'] = idx($metadata, 'new:file:mime-type');
$size = idx($metadata, 'new:file:size');
if ($size !== null) {
$new['file:size'] = phutil_format_bytes($size);
}
}
return array($old, $new);
}
public function renderUndoTemplates() {
$views = array(
'l' => id(new PHUIDiffInlineCommentUndoView())->setIsOnRight(false),
'r' => id(new PHUIDiffInlineCommentUndoView())->setIsOnRight(true),
);
foreach ($views as $key => $view) {
$scaffold = $this->getRowScaffoldForInline($view);
$views[$key] = id(new PHUIDiffInlineCommentTableScaffold())
->addRowScaffold($scaffold);
}
return $views;
}
final protected function getScopeEngine() {
if ($this->scopeEngine === false) {
$hunk_starts = $this->getHunkStartLines();
// If this change is missing context, don't try to identify scopes, since
// we won't really be able to get anywhere.
$has_multiple_hunks = (count($hunk_starts) > 1);
$has_offset_hunks = false;
if ($hunk_starts) {
$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;
}
return $this->scopeEngine;
}
private function getNewLineTextMap() {
$new = $this->getNewLines();
$text_map = array();
foreach ($new as $new_line) {
if (!isset($new_line['line'])) {
continue;
}
$text_map[$new_line['line']] = $new_line['text'];
}
return $text_map;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Nov 26, 8:49 PM (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1239
Default Alt Text
(35 KB)

Event Timeline