1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-10 00:42:40 +01:00

Use EditDistanceMatrix diff smoothing in Arcanist

Summary:
Ref T7643. We've done the smoothing from D16068 for a long time, it just wasn't part of EditDistanceMatrix.

Since it now is, call it instead of keeping a copy of the logic around.

Previously, the unit tests were testing un-smoothed diffs. Just have them test smoothed diffs instead, since nothing actually uses unsmoothed diffs.

Test Plan: Pasted a raw diff into the web UI, got a sensible inline diff for it.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T7643

Differential Revision: https://secure.phabricator.com/D16069
This commit is contained in:
epriestley 2016-06-07 08:22:03 -07:00
parent ca33240942
commit 41e8e30e8c
2 changed files with 3 additions and 21 deletions

View file

@ -151,6 +151,7 @@ final class ArcanistDiffUtils extends Phobject {
->setReplaceCost(2)
->setMaximumLength($max)
->setSequences($ov, $nv)
->setApplySmoothing(true)
->getEditString();
}
@ -167,25 +168,6 @@ final class ArcanistDiffUtils extends Phobject {
$result = self::generateEditString($ov, $nv);
// Smooth the string out, by replacing short runs of similar characters
// with 'x' operations. This makes the result more readable to humans, since
// there are fewer choppy runs of short added and removed substrings.
do {
$original = $result;
$result = preg_replace(
'/([xdi])(s{3})([xdi])/',
'$1xxx$3',
$result);
$result = preg_replace(
'/([xdi])(s{2})([xdi])/',
'$1xx$3',
$result);
$result = preg_replace(
'/([xdi])(s{1})([xdi])/',
'$1x$3',
$result);
} while ($result != $original);
// Now we have a character-based description of the edit. We need to
// convert into a byte-based description. Walk through the edit string and
// adjust each operation to reflect the number of bytes in the underlying

View file

@ -60,12 +60,12 @@ final class ArcanistDiffUtilsTestCase extends PhutilTestCase {
array(
'abcdefg',
'abxdxfg',
'ssxsxss',
'ssxxxss',
),
array(
'private function a($a, $b) {',
'public function and($b, $c) {',
'siixsdddxsssssssssssiissxsssxsss',
'siixxdddxsssssssssssiixxxxxxxsss',
),
array(