From: epriestley Date: Tue, 7 Jun 2016 15:22:03 +0000 (-0700) Subject: Use EditDistanceMatrix diff smoothing in Arcanist X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=41e8e30e8c136a7ff25a247aeec7ed74d54b349e;p=arcanist.git 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 --- diff --git a/src/difference/ArcanistDiffUtils.php b/src/difference/ArcanistDiffUtils.php index dab50e0c..f09573a1 100644 --- a/src/difference/ArcanistDiffUtils.php +++ b/src/difference/ArcanistDiffUtils.php @@ -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 diff --git a/src/difference/__tests__/ArcanistDiffUtilsTestCase.php b/src/difference/__tests__/ArcanistDiffUtilsTestCase.php index 26fa9e47..cce90c6f 100644 --- a/src/difference/__tests__/ArcanistDiffUtilsTestCase.php +++ b/src/difference/__tests__/ArcanistDiffUtilsTestCase.php @@ -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(