@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Unify changeset line ID rendering and bring it to unified diffs

Summary:
Ref T2009. Currently, lines don't get their "C123NL456" IDs set in the unified view. This is the major way that inlines are glued to changesets.

Simplify this rendering and bring it into the HTML renderer, then use it in the OneUp renderer.

Test Plan:
- Interacted with side-by-side inlines (hovered, added, edited, deleted), saw unchanged behavior.
- Interacted with unified inlines. They still don't work, but the error that breaks them is deeper in the stack.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2009

Differential Revision: https://secure.phabricator.com/D11983

+73 -23
+43
src/applications/differential/render/DifferentialChangesetHTMLRenderer.php
··· 525 525 $text); 526 526 } 527 527 528 + /** 529 + * Build the prefixes for line IDs used to track inline comments. 530 + * 531 + * @return pair<wild, wild> Left and right prefixes. 532 + */ 533 + protected function getLineIDPrefixes() { 534 + // These look like "C123NL45", which means the line is line 45 on the 535 + // "new" side of the file in changeset 123. 536 + 537 + // The "C" stands for "changeset", and is followed by a changeset ID. 538 + 539 + // "N" stands for "new" and means the comment should attach to the new file 540 + // when stored. "O" stands for "old" and means the comment should attach to 541 + // the old file. These are important because either the old or new part 542 + // of a file may appear on the left or right side of the diff in the 543 + // diff-of-diffs view. 544 + 545 + // The "L" stands for "line" and is followed by the line number. 546 + 547 + if ($this->getOldChangesetID()) { 548 + $left_prefix = array(); 549 + $left_prefix[] = 'C'; 550 + $left_prefix[] = $this->getOldChangesetID(); 551 + $left_prefix[] = $this->getOldAttachesToNewFile() ? 'N' : 'O'; 552 + $left_prefix[] = 'L'; 553 + $left_prefix = implode('', $left_prefix); 554 + } else { 555 + $left_prefix = null; 556 + } 557 + 558 + if ($this->getNewChangesetID()) { 559 + $right_prefix = array(); 560 + $right_prefix[] = 'C'; 561 + $right_prefix[] = $this->getNewChangesetID(); 562 + $right_prefix[] = $this->getNewAttachesToNewFile() ? 'N' : 'O'; 563 + $right_prefix[] = 'L'; 564 + $right_prefix = implode('', $right_prefix); 565 + } else { 566 + $right_prefix = null; 567 + } 568 + 569 + return array($left_prefix, $right_prefix); 570 + } 528 571 529 572 }
+25 -4
src/applications/differential/render/DifferentialChangesetOneUpRenderer.php
··· 30 30 31 31 $primitives = $this->buildPrimitives($range_start, $range_len); 32 32 33 + list($left_prefix, $right_prefix) = $this->getLineIDPrefixes(); 34 + 33 35 $out = array(); 34 36 foreach ($primitives as $p) { 35 37 $type = $p['type']; ··· 43 45 } else { 44 46 $class = 'left'; 45 47 } 46 - $out[] = phutil_tag('th', array(), $p['line']); 48 + 49 + if ($left_prefix) { 50 + $left_id = $left_prefix.$p['line']; 51 + } else { 52 + $left_id = null; 53 + } 54 + $out[] = phutil_tag('th', array('id' => $left_id), $p['line']); 55 + 47 56 $out[] = phutil_tag('th', array()); 48 57 $out[] = phutil_tag('td', array('class' => $class), $p['render']); 49 - } else if ($type == 'new') { 58 + } else { 50 59 if ($p['htype']) { 51 60 $class = 'right new'; 52 61 $out[] = phutil_tag('th', array()); 53 62 } else { 54 63 $class = 'right'; 55 - $out[] = phutil_tag('th', array(), $p['oline']); 64 + if ($left_prefix) { 65 + $left_id = $left_prefix.$p['oline']; 66 + } else { 67 + $left_id = null; 68 + } 69 + $out[] = phutil_tag('th', array('id' => $left_id), $p['oline']); 56 70 } 57 - $out[] = phutil_tag('th', array(), $p['line']); 71 + 72 + if ($right_prefix) { 73 + $right_id = $right_prefix.$p['line']; 74 + } else { 75 + $right_id = null; 76 + } 77 + $out[] = phutil_tag('th', array('id' => $right_id), $p['line']); 78 + 58 79 $out[] = phutil_tag('td', array('class' => $class), $p['render']); 59 80 } 60 81 $out[] = hsprintf('</tr>');
+5 -19
src/applications/differential/render/DifferentialChangesetTwoUpRenderer.php
··· 55 55 $new_lines = $this->getNewLines(); 56 56 $gaps = $this->getGaps(); 57 57 $reference = $this->getRenderingReference(); 58 - $left_id = $this->getOldChangesetID(); 59 - $right_id = $this->getNewChangesetID(); 60 58 61 - // "N" stands for 'new' and means the comment should attach to the new file 62 - // when stored, i.e. DifferentialInlineComment->setIsNewFile(). 63 - // "O" stands for 'old' and means the comment should attach to the old file. 64 - 65 - $left_char = $this->getOldAttachesToNewFile() 66 - ? 'N' 67 - : 'O'; 68 - $right_char = $this->getNewAttachesToNewFile() 69 - ? 'N' 70 - : 'O'; 59 + list($left_prefix, $right_prefix) = $this->getLineIDPrefixes(); 71 60 72 61 $changeset = $this->getChangeset(); 73 62 $copy_lines = idx($changeset->getMetadata(), 'copy:lines', array()); ··· 234 223 $html[] = $context_not_available; 235 224 } 236 225 237 - if ($o_num && $left_id) { 238 - $o_id = 'C'.$left_id.$left_char.'L'.$o_num; 226 + if ($o_num && $left_prefix) { 227 + $o_id = $left_prefix.$o_num; 239 228 } else { 240 229 $o_id = null; 241 230 } 242 231 243 - if ($n_num && $right_id) { 244 - $n_id = 'C'.$right_id.$right_char.'L'.$n_num; 232 + if ($n_num && $right_prefix) { 233 + $n_id = $right_prefix.$n_num; 245 234 } else { 246 235 $n_id = null; 247 236 } ··· 250 239 // intercepting 'copy' events to make sure sensible text ends up on the 251 240 // clipboard. See the 'phabricator-oncopy' behavior. 252 241 $zero_space = "\xE2\x80\x8B"; 253 - 254 - // NOTE: The Javascript is sensitive to whitespace changes in this 255 - // block! 256 242 257 243 $html[] = phutil_tag('tr', array(), array( 258 244 phutil_tag('th', array('id' => $o_id), $o_num),