]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Use EditDistanceMatrix diff smoothing in Arcanist
authorepriestley <git@epriestley.com>
Tue, 7 Jun 2016 15:22:03 +0000 (08:22 -0700)
committerepriestley <git@epriestley.com>
Tue, 7 Jun 2016 16:13:34 +0000 (09:13 -0700)
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

src/difference/ArcanistDiffUtils.php
src/difference/__tests__/ArcanistDiffUtilsTestCase.php

index dab50e0c7c3a4df2acda698d0b4e58d800339fc6..f09573a1ca8944eaaf9682b9ddfbfb962a7feee3 100644 (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
index 26fa9e47842ba95371712b2f4a639cbf15a3df42..cce90c6f2eefd685fbb903f766cece39a253001e 100644 (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(