@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.

Force unified abstract block diffs into roughly usable shape

Summary: Depends on D20845. Ref T13425. In unified mode, render blocks diffs less-unreasonably.

Test Plan: {F6910436}

Maniphest Tasks: T13425

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

+219 -27
+217 -26
src/applications/differential/render/DifferentialChangesetOneUpRenderer.php
··· 233 233 $old_changeset_key, 234 234 $new_changeset_key) { 235 235 236 - // TODO: This should eventually merge into the normal primitives pathway, 237 - // but fake it for now and just share as much code as possible. 236 + $engine = $this->getDocumentEngine(); 237 + $layout = $block_list->newTwoUpLayout(); 238 + 239 + $old_comments = $this->getOldComments(); 240 + $new_comments = $this->getNewComments(); 241 + 242 + $unchanged = array(); 243 + foreach ($layout as $key => $row) { 244 + list($old, $new) = $row; 245 + 246 + if (!$old) { 247 + continue; 248 + } 249 + 250 + if (!$new) { 251 + continue; 252 + } 253 + 254 + if ($old->getDifferenceType() !== null) { 255 + continue; 256 + } 257 + 258 + if ($new->getDifferenceType() !== null) { 259 + continue; 260 + } 238 261 239 - $primitives = array(); 240 - foreach ($block_list->newOneUpLayout() as $block) { 241 - $primitives[] = array( 242 - 'type' => 'old-file', 243 - 'htype' => '', 244 - 'line' => $block->getBlockKey(), 245 - 'render' => $block->getContent(), 246 - ); 262 + $unchanged[$key] = true; 247 263 } 248 264 249 - // TODO: We'd like to share primitive code here, but buildPrimitives() 250 - // currently chokes on changesets with no textual data. 251 - foreach ($this->getOldComments() as $line => $group) { 252 - foreach ($group as $comment) { 253 - $primitives[] = array( 254 - 'type' => 'inline', 255 - 'comment' => $comment, 256 - 'right' => false, 265 + $rows = array(); 266 + $count = count($layout); 267 + for ($ii = 0; $ii < $count;) { 268 + $start = $ii; 269 + 270 + for ($jj = $ii; $jj < $count; $jj++) { 271 + list($old, $new) = $layout[$jj]; 272 + 273 + if (empty($unchanged[$jj])) { 274 + break; 275 + } 276 + 277 + $rows[] = array( 278 + 'type' => 'unchanged', 279 + 'layoutKey' => $jj, 257 280 ); 258 281 } 282 + $ii = $jj; 283 + 284 + for ($jj = $ii; $jj < $count; $jj++) { 285 + list($old, $new) = $layout[$jj]; 286 + 287 + if (!empty($unchanged[$jj])) { 288 + break; 289 + } 290 + 291 + $rows[] = array( 292 + 'type' => 'old', 293 + 'layoutKey' => $jj, 294 + ); 295 + } 296 + 297 + for ($jj = $ii; $jj < $count; $jj++) { 298 + list($old, $new) = $layout[$jj]; 299 + 300 + if (!empty($unchanged[$jj])) { 301 + break; 302 + } 303 + 304 + $rows[] = array( 305 + 'type' => 'new', 306 + 'layoutKey' => $jj, 307 + ); 308 + } 309 + $ii = $jj; 310 + 311 + // We always expect to consume at least one row when iterating through 312 + // the loop and make progress. If we don't, bail out to avoid spinning 313 + // to death. 314 + if ($ii === $start) { 315 + throw new Exception( 316 + pht( 317 + 'Failed to make progress during 1up diff layout.')); 318 + } 259 319 } 260 320 261 - foreach ($this->getNewComments() as $line => $group) { 262 - foreach ($group as $comment) { 263 - $primitives[] = array( 264 - 'type' => 'inline', 265 - 'comment' => $comment, 266 - 'right' => true, 267 - ); 321 + $old_ref = null; 322 + $new_ref = null; 323 + $refs = $block_list->getDocumentRefs(); 324 + if ($refs) { 325 + list($old_ref, $new_ref) = $refs; 326 + } 327 + 328 + $view = array(); 329 + foreach ($rows as $row) { 330 + $row_type = $row['type']; 331 + $layout_key = $row['layoutKey']; 332 + $row_layout = $layout[$layout_key]; 333 + list($old, $new) = $row_layout; 334 + 335 + if ($old) { 336 + $old_key = $old->getBlockKey(); 337 + } else { 338 + $old_key = null; 339 + } 340 + 341 + if ($new) { 342 + $new_key = $new->getBlockKey(); 343 + } else { 344 + $new_key = null; 345 + } 346 + 347 + $cells = array(); 348 + $cell_classes = array(); 349 + 350 + if ($row_type === 'unchanged') { 351 + $cell_content = $engine->newBlockContentView( 352 + $old_ref, 353 + $old); 354 + } else if ($old && $new) { 355 + $block_diff = $engine->newBlockDiffViews( 356 + $old_ref, 357 + $old, 358 + $new_ref, 359 + $new); 360 + 361 + // TODO: We're currently double-rendering this: once when building 362 + // the old row, and once when building the new one. In both cases, 363 + // we throw away the other half of the output. We could cache this 364 + // to improve performance. 365 + 366 + if ($row_type === 'old') { 367 + $cell_content = $block_diff->getOldContent(); 368 + $cell_classes = $block_diff->getOldClasses(); 369 + } else { 370 + $cell_content = $block_diff->getNewContent(); 371 + $cell_classes = $block_diff->getNewClasses(); 372 + } 373 + } else if ($row_type === 'old') { 374 + $cell_content = $engine->newBlockContentView( 375 + $old_ref, 376 + $old); 377 + $cell_classes[] = 'old'; 378 + $cell_classes[] = 'old-full'; 379 + 380 + $new_key = null; 381 + } else if ($row_type === 'new') { 382 + $cell_content = $engine->newBlockContentView( 383 + $new_ref, 384 + $new); 385 + $cell_classes[] = 'new'; 386 + $cell_classes[] = 'new-full'; 387 + 388 + $old_key = null; 389 + } 390 + 391 + if ($old_key === null) { 392 + $old_id = null; 393 + } else { 394 + $old_id = "C{$old_changeset_key}OL{$old_key}"; 395 + } 396 + 397 + if ($new_key === null) { 398 + $new_id = null; 399 + } else { 400 + $new_id = "C{$new_changeset_key}NL{$new_key}"; 401 + } 402 + 403 + $cells[] = phutil_tag( 404 + 'td', 405 + array( 406 + 'id' => $old_id, 407 + 'data-n' => $old_key, 408 + 'class' => 'n', 409 + )); 410 + 411 + $cells[] = phutil_tag( 412 + 'td', 413 + array( 414 + 'id' => $new_id, 415 + 'data-n' => $new_key, 416 + 'class' => 'n', 417 + )); 418 + 419 + $cells[] = phutil_tag( 420 + 'td', 421 + array( 422 + 'class' => 'copy', 423 + )); 424 + 425 + $cell_classes[] = 'diff-flush'; 426 + $cell_classes = implode(' ', $cell_classes); 427 + 428 + $cells[] = phutil_tag( 429 + 'td', 430 + array( 431 + 'class' => $cell_classes, 432 + 'data-copy-mode' => 'copy-unified', 433 + ), 434 + $cell_content); 435 + 436 + $view[] = phutil_tag( 437 + 'tr', 438 + array(), 439 + $cells); 440 + 441 + if ($old_key !== null) { 442 + $old_inlines = idx($old_comments, $old_key, array()); 443 + foreach ($old_inlines as $inline) { 444 + $inline = $this->buildInlineComment( 445 + $inline, 446 + $on_right = false); 447 + $view[] = $this->getRowScaffoldForInline($inline); 448 + } 449 + } 450 + 451 + if ($new_key !== null) { 452 + $new_inlines = idx($new_comments, $new_key, array()); 453 + foreach ($new_inlines as $inline) { 454 + $inline = $this->buildInlineComment( 455 + $inline, 456 + $on_right = true); 457 + $view[] = $this->getRowScaffoldForInline($inline); 458 + } 268 459 } 269 460 } 270 461 271 - $output = $this->renderPrimitives($primitives, 1); 462 + $output = $this->wrapChangeInTable($view); 272 463 return $this->renderChangesetTable($output); 273 464 } 274 465
+2 -1
src/infrastructure/diff/view/PHUIDiffOneUpInlineCommentRowScaffold.php
··· 17 17 $inline = head($inlines); 18 18 19 19 $attrs = array( 20 - 'colspan' => 3, 20 + 'colspan' => 2, 21 21 'id' => $inline->getScaffoldCellID(), 22 22 ); 23 23 ··· 32 32 $cells = array( 33 33 phutil_tag('td', array('class' => 'n'), $left_hidden), 34 34 phutil_tag('td', array('class' => 'n'), $right_hidden), 35 + phutil_tag('td', array('class' => 'copy')), 35 36 phutil_tag('td', $attrs, $inline), 36 37 ); 37 38