mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-26 00:32:41 +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:
parent
ca33240942
commit
41e8e30e8c
2 changed files with 3 additions and 21 deletions
|
@ -151,6 +151,7 @@ final class ArcanistDiffUtils extends Phobject {
|
||||||
->setReplaceCost(2)
|
->setReplaceCost(2)
|
||||||
->setMaximumLength($max)
|
->setMaximumLength($max)
|
||||||
->setSequences($ov, $nv)
|
->setSequences($ov, $nv)
|
||||||
|
->setApplySmoothing(true)
|
||||||
->getEditString();
|
->getEditString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,25 +168,6 @@ final class ArcanistDiffUtils extends Phobject {
|
||||||
|
|
||||||
$result = self::generateEditString($ov, $nv);
|
$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
|
// 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
|
// convert into a byte-based description. Walk through the edit string and
|
||||||
// adjust each operation to reflect the number of bytes in the underlying
|
// adjust each operation to reflect the number of bytes in the underlying
|
||||||
|
|
|
@ -60,12 +60,12 @@ final class ArcanistDiffUtilsTestCase extends PhutilTestCase {
|
||||||
array(
|
array(
|
||||||
'abcdefg',
|
'abcdefg',
|
||||||
'abxdxfg',
|
'abxdxfg',
|
||||||
'ssxsxss',
|
'ssxxxss',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'private function a($a, $b) {',
|
'private function a($a, $b) {',
|
||||||
'public function and($b, $c) {',
|
'public function and($b, $c) {',
|
||||||
'siixsdddxsssssssssssiissxsssxsss',
|
'siixxdddxsssssssssssiixxxxxxxsss',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue