Verified Commit ce28a427 authored by Dave Long's avatar Dave Long
Browse files

Issue #3299678 by mondrake, catch, longwave: Deprecate DiffEngine and replace with sebastian/diff

parent b6b60144
Loading
Loading
Loading
Loading
+68 −67
Original line number Diff line number Diff line
@@ -446,7 +446,7 @@
            "dist": {
                "type": "path",
                "url": "core",
                "reference": "9e2d1532ca02ec3d0fb258d23a5c404533bcac43"
                "reference": "4a6aa3700723fe42a3a8add8c27af45f8710ddb2"
            },
            "require": {
                "asm89/stack-cors": "^2.1",
@@ -474,6 +474,7 @@
                "pear/archive_tar": "^1.4.14",
                "php": ">=8.1.0",
                "psr/log": "^3.0",
                "sebastian/diff": "^4",
                "symfony/console": "^6.2",
                "symfony/dependency-injection": "^6.2",
                "symfony/event-dispatcher": "^6.2",
@@ -1824,6 +1825,72 @@
            },
            "time": "2019-03-08T08:55:37+00:00"
        },
        {
            "name": "sebastian/diff",
            "version": "4.0.4",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/diff.git",
                "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3461e3fccc7cfdfc2720be910d3bd73c69be590d",
                "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d",
                "shasum": ""
            },
            "require": {
                "php": ">=7.3"
            },
            "require-dev": {
                "phpunit/phpunit": "^9.3",
                "symfony/process": "^4.2 || ^5"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "4.0-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Sebastian Bergmann",
                    "email": "sebastian@phpunit.de"
                },
                {
                    "name": "Kore Nordmann",
                    "email": "mail@kore-nordmann.de"
                }
            ],
            "description": "Diff implementation",
            "homepage": "https://github.com/sebastianbergmann/diff",
            "keywords": [
                "diff",
                "udiff",
                "unidiff",
                "unified diff"
            ],
            "support": {
                "issues": "https://github.com/sebastianbergmann/diff/issues",
                "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4"
            },
            "funding": [
                {
                    "url": "https://github.com/sebastianbergmann",
                    "type": "github"
                }
            ],
            "time": "2020-10-26T13:10:38+00:00"
        },
        {
            "name": "symfony/console",
            "version": "v6.2.5",
@@ -6765,72 +6832,6 @@
            ],
            "time": "2020-10-26T15:52:27+00:00"
        },
        {
            "name": "sebastian/diff",
            "version": "4.0.4",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/diff.git",
                "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3461e3fccc7cfdfc2720be910d3bd73c69be590d",
                "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d",
                "shasum": ""
            },
            "require": {
                "php": ">=7.3"
            },
            "require-dev": {
                "phpunit/phpunit": "^9.3",
                "symfony/process": "^4.2 || ^5"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "4.0-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Sebastian Bergmann",
                    "email": "sebastian@phpunit.de"
                },
                {
                    "name": "Kore Nordmann",
                    "email": "mail@kore-nordmann.de"
                }
            ],
            "description": "Diff implementation",
            "homepage": "https://github.com/sebastianbergmann/diff",
            "keywords": [
                "diff",
                "udiff",
                "unidiff",
                "unified diff"
            ],
            "support": {
                "issues": "https://github.com/sebastianbergmann/diff/issues",
                "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4"
            },
            "funding": [
                {
                    "url": "https://github.com/sebastianbergmann",
                    "type": "github"
                }
            ],
            "time": "2020-10-26T13:10:38+00:00"
        },
        {
            "name": "sebastian/environment",
            "version": "5.1.4",
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
        "psr/http-message": "~1.0.1",
        "psr/log": "~3.0.0",
        "ralouphie/getallheaders": "~3.0.3",
        "sebastian/diff": "~4.0.4",
        "symfony/console": "~v6.2.5",
        "symfony/dependency-injection": "~v6.2.6",
        "symfony/deprecation-contracts": "~v3.2.0",
+0 −1
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@
        "sebastian/code-unit-reverse-lookup": "2.0.3",
        "sebastian/comparator": "4.0.8",
        "sebastian/complexity": "2.0.2",
        "sebastian/diff": "4.0.4",
        "sebastian/environment": "5.1.4",
        "sebastian/exporter": "4.0.5",
        "sebastian/global-state": "5.0.5",
+2 −1
Original line number Diff line number Diff line
@@ -42,7 +42,8 @@
        "asm89/stack-cors": "^2.1",
        "pear/archive_tar": "^1.4.14",
        "psr/log": "^3.0",
        "mck89/peast": "^1.14"
        "mck89/peast": "^1.14",
        "sebastian/diff": "^4"
    },
    "conflict": {
        "drush/drush": "<8.1.10"
+44 −10
Original line number Diff line number Diff line
@@ -2,17 +2,15 @@

namespace Drupal\Component\Diff;

use Drupal\Component\Diff\Engine\DiffEngine;
use SebastianBergmann\Diff\Differ;

/**
 * Class representing a 'diff' between two sequences of strings.
 * @todo document
 * @subpackage DifferenceEngine
 *
 * Copied from https://www.drupal.org/project/diff which was based PHP diff
 * engine for phpwiki. (Taken from phpwiki-1.3.3) The original code in phpwiki
 * was copyright (C) 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org> and
 * licensed under GPL.
 * Component code originally taken from https://www.drupal.org/project/diff
 * which was itself based on the PHP diff engine for phpwiki. The original code
 * in phpwiki was copyright (C) 2000, 2001 Geoffrey T. Dairiki
 * <dairiki@dairiki.org> and licensed under GPL.
 */
class Diff {

@@ -34,9 +32,9 @@ class Diff {
   *   An array of strings.
   */
  public function __construct($from_lines, $to_lines) {
    $eng = new DiffEngine();
    $this->edits = $eng->diff($from_lines, $to_lines);
    //$this->_check($from_lines, $to_lines);
    $diffOpBuilder = new DiffOpOutputBuilder();
    $differ = new Differ($diffOpBuilder);
    $this->edits = $diffOpBuilder->toOpsArray($differ->diffToArray($from_lines, $to_lines));
  }

  /**
@@ -48,8 +46,14 @@ public function __construct($from_lines, $to_lines) {
   *  $rev = $diff->reverse();
   * @return object
   *   A Diff object representing the inverse of the original diff.
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no
   *   replacement.
   *
   * @see https://www.drupal.org/node/3337942
   */
  public function reverse() {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3337942', E_USER_DEPRECATED);
    $rev = $this;
    $rev->edits = [];
    foreach ($this->edits as $edit) {
@@ -62,8 +66,14 @@ public function reverse() {
   * Check for empty diff.
   *
   * @return bool True iff two sequences were identical.
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no
   *   replacement.
   *
   * @see https://www.drupal.org/node/3337942
   */
  public function isEmpty() {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3337942', E_USER_DEPRECATED);
    foreach ($this->edits as $edit) {
      if ($edit->type != 'copy') {
        return FALSE;
@@ -78,8 +88,14 @@ public function isEmpty() {
   * This is mostly for diagnostic purposed.
   *
   * @return int The length of the LCS.
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no
   *   replacement.
   *
   * @see https://www.drupal.org/node/3337942
   */
  public function lcs() {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3337942', E_USER_DEPRECATED);
    $lcs = 0;
    foreach ($this->edits as $edit) {
      if ($edit->type == 'copy') {
@@ -96,8 +112,14 @@ public function lcs() {
   * constructor.
   *
   * @return array The original sequence of strings.
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no
   *   replacement.
   *
   * @see https://www.drupal.org/node/3337942
   */
  public function orig() {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3337942', E_USER_DEPRECATED);
    $lines = [];

    foreach ($this->edits as $edit) {
@@ -115,8 +137,14 @@ public function orig() {
   * constructor.
   *
   * @return array The sequence of strings.
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no
   *   replacement.
   *
   * @see https://www.drupal.org/node/3337942
   */
  public function closing() {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3337942', E_USER_DEPRECATED);
    $lines = [];

    foreach ($this->edits as $edit) {
@@ -131,8 +159,14 @@ public function closing() {
   * Check a Diff for validity.
   *
   * This is here only for debugging purposes.
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no
   *   replacement.
   *
   * @see https://www.drupal.org/node/3337942
   */
  public function check($from_lines, $to_lines) {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3337942', E_USER_DEPRECATED);
    if (serialize($from_lines) != serialize($this->orig())) {
      trigger_error("Reconstructed original doesn't match", E_USER_ERROR);
    }
Loading