Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/diff/prose/PhutilProseDifferenceEngine.php
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | private function buildDiff($u, $v, $level) { | ||||
$result = new PhutilProseDiff(); | $result = new PhutilProseDiff(); | ||||
foreach ($blocks as $block) { | foreach ($blocks as $block) { | ||||
$type = $block['type']; | $type = $block['type']; | ||||
if ($type == '=') { | if ($type == '=') { | ||||
$result->addPart('=', $block['text']); | $result->addPart('=', $block['text']); | ||||
} else { | } else { | ||||
$old = $block['old']; | $old = $block['old']; | ||||
$new = $block['new']; | $new = $block['new']; | ||||
if (!strlen($old) && !strlen($new)) { | |||||
$is_old_ok = phutil_nonempty_string($old); | |||||
$is_new_ok = phutil_nonempty_string($new); | |||||
if (!$is_old_ok && !$is_new_ok) { | |||||
// Nothing to do. | // Nothing to do. | ||||
} else if (!strlen($old)) { | } else if (!$is_old_ok) { | ||||
$result->addPart('+', $new); | $result->addPart('+', $new); | ||||
} else if (!strlen($new)) { | } else if (!$is_new_ok) { | ||||
$result->addPart('-', $old); | $result->addPart('-', $old); | ||||
} else { | } else { | ||||
if ($too_large) { | if ($too_large) { | ||||
// If this text was too big to diff, don't try to subdivide it. | // If this text was too big to diff, don't try to subdivide it. | ||||
$result->addPart('-', $old); | $result->addPart('-', $old); | ||||
$result->addPart('+', $new); | $result->addPart('+', $new); | ||||
} else { | } else { | ||||
$subdiff = $this->buildDiff( | $subdiff = $this->buildDiff( | ||||
▲ Show 20 Lines • Show All 200 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0