getChangeset(); $props = $this->renderPropertyChangeHeader($changeset); $table = null; if ($contents) { $table = javelin_render_tag( 'table', array( 'class' => 'differential-diff remarkup-code PhabricatorMonospaced', 'sigil' => 'differential-diff', ), $contents); } if (!$table && !$props) { $notice = $this->renderChangeTypeHeader($changeset, true); } else { $notice = $this->renderChangeTypeHeader($changeset, false); } $result = implode( "\n", array( $notice, $props, $table, )); // TODO: Let the user customize their tab width / display style. $result = str_replace("\t", ' ', $result); // TODO: We should possibly post-process "\r" as well. return $result; } public function renderTextChange( $range_start, $range_len, $mask_force, $feedback_mask) { $missing_old = $this->getMissingOldLines(); $missing_new = $this->getMissingNewLines(); $context_not_available = null; if ($missing_old || $missing_new) { $context_not_available = javelin_render_tag( 'tr', array( 'sigil' => 'context-target', ), phutil_render_tag( 'td', array( 'colspan' => 6, 'class' => 'show-more' ), pht('Context not available.') ) ); } $html = array(); $old_lines = $this->getOldLines(); $new_lines = $this->getNewLines(); $rows = max( count($old_lines), count($new_lines)); if ($range_start === null) { $range_start = 0; } if ($range_len === null) { $range_len = $rows; } $range_len = min($range_len, $rows - $range_start); // Gaps - compute gaps in the visible display diff, where we will render // "Show more context" spacers. This builds an aggregate $mask of all the // lines we must show (because they are near changed lines, near inline // comments, or the request has explicitly asked for them, i.e. resulting // from the user clicking "show more") and then finds all the gaps between // visible lines. If a gap is smaller than the context size, we just // display it. Otherwise, we record it into $gaps and will render a // "show more context" element instead of diff text below. $gaps = array(); $gap_start = 0; $in_gap = false; $lines_of_context = $this->getLinesOfContext(); $mask = $this->getVisibleLines() + $mask_force + $feedback_mask; $mask[$range_start + $range_len] = true; for ($ii = $range_start; $ii <= $range_start + $range_len; $ii++) { if (isset($mask[$ii])) { if ($in_gap) { $gap_length = $ii - $gap_start; if ($gap_length <= $lines_of_context) { for ($jj = $gap_start; $jj <= $gap_start + $gap_length; $jj++) { $mask[$jj] = true; } } else { $gaps[] = array($gap_start, $gap_length); } $in_gap = false; } } else { if (!$in_gap) { $gap_start = $ii; $in_gap = true; } } } $gaps = array_reverse($gaps); $reference = $this->getRenderingReference(); $left_id = $this->getOldChangesetID(); $right_id = $this->getNewChangesetID(); // "N" stands for 'new' and means the comment should attach to the new file // when stored, i.e. DifferentialInlineComment->setIsNewFile(). // "O" stands for 'old' and means the comment should attach to the old file. $left_char = $this->getOldAttachesToNewFile() ? 'N' : 'O'; $right_char = $this->getNewAttachesToNewFile() ? 'N' : 'O'; $changeset = $this->getChangeset(); $copy_lines = idx($changeset->getMetadata(), 'copy:lines', array()); $highlight_old = $this->getHighlightOld(); $highlight_new = $this->getHighlightNew(); $old_render = $this->getOldRender(); $new_render = $this->getNewRender(); $original_left = $this->getOriginalOld(); $original_right = $this->getOriginalNew(); // We need to go backwards to properly indent whitespace in this code: // // 0: class C { // 1: // 1: function f() { // 2: // 2: return; // 3: // 3: } // 4: // 4: } // $depths = array(); $last_depth = 0; $range_end = $range_start + $range_len; if (!isset($new_lines[$range_end])) { $range_end--; } for ($ii = $range_end; $ii >= $range_start; $ii--) { // We need to expand tabs to process mixed indenting and to round // correctly later. $line = str_replace("\t", " ", $new_lines[$ii]['text']); $trimmed = ltrim($line); if ($trimmed != '') { // We round down to flatten "/**" and " *". $last_depth = floor((strlen($line) - strlen($trimmed)) / 2); } $depths[$ii] = $last_depth; } for ($ii = $range_start; $ii < $range_start + $range_len; $ii++) { if (empty($mask[$ii])) { // If we aren't going to show this line, we've just entered a gap. // Pop information about the next gap off the $gaps stack and render // an appropriate "Show more context" element. This branch eventually // increments $ii by the entire size of the gap and then continues // the loop. $gap = array_pop($gaps); $top = $gap[0]; $len = $gap[1]; $end = $top + $len - 20; $contents = array(); if ($len > 40) { $is_first_block = false; if ($ii == 0) { $is_first_block = true; } $contents[] = javelin_render_tag( 'a', array( 'href' => '#', 'mustcapture' => true, 'sigil' => 'show-more', 'meta' => array( 'ref' => $reference, 'range' => "{$top}-{$len}/{$top}-20", ), ), $is_first_block ? "Show First 20 Lines" : "\xE2\x96\xB2 Show 20 Lines"); } $contents[] = javelin_render_tag( 'a', array( 'href' => '#', 'mustcapture' => true, 'sigil' => 'show-more', 'meta' => array( 'type' => 'all', 'ref' => $reference, 'range' => "{$top}-{$len}/{$top}-{$len}", ), ), 'Show All '.$len.' Lines'); $is_last_block = false; if ($ii + $len >= $rows) { $is_last_block = true; } if ($len > 40) { $contents[] = javelin_render_tag( 'a', array( 'href' => '#', 'mustcapture' => true, 'sigil' => 'show-more', 'meta' => array( 'ref' => $reference, 'range' => "{$top}-{$len}/{$end}-20", ), ), $is_last_block ? "Show Last 20 Lines" : "\xE2\x96\xBC Show 20 Lines"); } $context = null; $context_line = null; if (!$is_last_block && $depths[$ii + $len]) { for ($l = $ii + $len - 1; $l >= $ii; $l--) { $line = $new_lines[$l]['text']; if ($depths[$l] < $depths[$ii + $len] && trim($line) != '') { $context = $new_render[$l]; $context_line = $new_lines[$l]['line']; break; } } } $container = javelin_render_tag( 'tr', array( 'sigil' => 'context-target', ), '