LineDiffer
API reference › Diff › LineDiffer
Computes the line edit scripts of git diff with default settings, except on inputs that reach Git’s cost limit.
Ports the pipeline of Git’s xdiff library: lines are interned, the common head and tail are trimmed, lines without
a counterpart and runs of over-popular lines are discarded before the alignment, the remaining lines are aligned with
the linear-space middle-snake refinement of Myers’ algorithm, and every group of changes is slid to its canonical
position, scored by the indent heuristic. The cost-limiting heuristics Git applies to very expensive diffs are not
ported, so the alignment always runs to completion. Memory stays linear in the input size; because discarded lines
never anchor the alignment, the edit script is not always the shortest one.
See also: https://doi.org/10.1007/BF01840446 (Eugene W. Myers, “An O(ND) Difference Algorithm and Its Variations”.), https://github.com/git/git/tree/master/xdiff (Git’s xdiff library.).
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
diff() | Returns the edit script that transforms $old into $new, as git diff produces it below Git’s cost limit. | LineDiffer |
Method details
Section titled “Method details”diff()
Section titled “diff() ”public function diff(string $old, string $new): list<PHPForge\Diff\DiffLine>Returns the edit script that transforms $old into $new, as git diff produces it below Git’s cost limit.
Parameters
| Parameter | Type | Description |
|---|---|---|
$old | string | Original input, split into lines on "\. |
$new | string | Target input, split into lines on "\. |
Returns
list<DiffLine>: Edit script; its Context and Remove lines in order reproduce the lines of $old, and its Context and Add lines in order reproduce the lines of $new.