\Drupal\strata\Diff DiffBuilder

Names what changed between two commits, field by field.

Two commits are compared by replaying each subject at both and comparing the reconstructed field maps. That is the only comparison that means anything: a segment holds the operations that landed in one window, so reading the segments between two commits would say which subjects were touched and not what they were before or after.

Only subjects that exist at one of the two commits are examined. The union of the two subject sets is walked, so a subject created between them shows as added and one deleted shows as removed, while the thousands that did not change cost nothing.

The work is bounded. Each subject costs two replays, and a replay walks from an anchor forward, so a diff across a year of history over a hundred thousand subjects is not a page load. The subject count is capped and the report says when it was cut, rather than silently showing the first hundred as if they were all of them.

Line-level hunks come from core's own diff engine. Values are compared as text only when both sides look like text and at least one of them is more than a line, because running a line differ over two short strings produces a hunk that says less than showing the strings side by side.

Summary

Methods
Properties
Constants
__construct
between
subject
hunks
No public properties found
MAX_SUBJECTS
MAX_TEXT
MIN_LINES
No protected methods found
No protected properties found
No protected constants found
fields
isDiffable
render
status
subjectsAt
realmOf
label
replayer
entityTypeManager
No private constants found

Constant

MAX_SUBJECTS

MAX_SUBJECTS = 500

Subjects one diff examines.

MAX_TEXT

MAX_TEXT = 65536

Characters of a value beyond which it is not diffed by line.

A field holding a serialized blob is text by the letter of the check and unreadable as a diff, and the line differ is quadratic in the worst case.

MIN_LINES

MIN_LINES = 2

Lines a value must exceed before a line-level diff is worth drawing.

Properties

$replayer

$replayer : \Drupal\strata\Restore\Replayer

Type

Replayer

$entityTypeManager

$entityTypeManager : \Drupal\Core\Entity\EntityTypeManagerInterface

Type

EntityTypeManagerInterface

Methods

__construct()

__construct(\Drupal\strata\Restore\Replayer  $replayer, \Drupal\Core\Entity\EntityTypeManagerInterface  $entityTypeManager) : mixed

Constructs a builder.

Parameters

\Drupal\strata\Restore\Replayer $replayer

Reconstructs each subject at each commit.

\Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager

Resolves an entity subject to a human-readable label.

Returns

mixed —

between()

between(string  $fromCommit, string  $toCommit, int  $limit = \self::MAX_SUBJECTS, \Drupal\strata\Journal\Realm|null  $realm = null) : array{diffs: list<\Drupal\strata\Diff\SubjectDiff>, examined: int, truncated: bool}

Everything that changed between two commits.

Parameters

string $fromCommit

The earlier commit.

string $toCommit

The later commit.

int $limit

Subjects to examine.

\Drupal\strata\Journal\Realm|null $realm

Only subjects in this realm, or NULL for every realm.

Returns

array{diffs: list<\Drupal\strata\Diff\SubjectDiff>, examined: int, truncated: bool} —

The subjects that changed, how many were examined, and whether the walk was cut short.

subject()

subject(string  $subject, string  $fromCommit, string  $toCommit) : \Drupal\strata\Diff\SubjectDiff|null

What changed about one subject.

Parameters

string $subject

Subject path.

string $fromCommit

The earlier commit.

string $toCommit

The later commit.

Returns

\Drupal\strata\Diff\SubjectDiff|null —

The diff, or NULL when nothing changed.

hunks()

hunks(string  $before, string  $after) : list<\Drupal\strata\Diff\DiffHunk>

Hunks between two text values.

Parameters

string $before

The earlier value.

string $after

The later value.

Returns

list<\Drupal\strata\Diff\DiffHunk> —

The hunks, in order.

fields()

fields(\Drupal\strata\Restore\ReplayResult  $before, \Drupal\strata\Restore\ReplayResult  $after) : list<\Drupal\strata\Diff\FieldDiff>

What changed between two reconstructed field maps.

Parameters

\Drupal\strata\Restore\ReplayResult $before

The earlier version.

\Drupal\strata\Restore\ReplayResult $after

The later version.

Returns

list<\Drupal\strata\Diff\FieldDiff> —

One entry per field that differs.

isDiffable()

isDiffable(string  $before, string  $after) : bool

Whether two values are worth a line-level diff.

Parameters

string $before

The earlier value.

string $after

The later value.

Returns

bool —

TRUE when both are text of a reasonable size and one of them spans lines.

render()

render(mixed  $value) : string

Renders a stored value as the text a diff compares.

Parameters

mixed $value

The value out of a replay.

Returns

string —

The rendered value.

status()

status(\Drupal\strata\Restore\ReplayResult  $before, \Drupal\strata\Restore\ReplayResult  $after) : string|null

Whether and how a subject changed.

Parameters

\Drupal\strata\Restore\ReplayResult $before

The earlier version.

\Drupal\strata\Restore\ReplayResult $after

The later version.

Returns

string|null —

A SubjectDiff status, or NULL when nothing changed.

subjectsAt()

subjectsAt(string  $commit) : list<string>

The subjects that exist at a commit.

Parameters

string $commit

The commit.

Returns

list

Subject paths, empty when the commit cannot be read.

realmOf()

realmOf(string  $subject) : \Drupal\strata\Journal\Realm|null

The realm a subject path names.

Parameters

string $subject

Subject path.

Returns

\Drupal\strata\Journal\Realm|null —

The realm, or NULL when the path names one this release does not know.

label()

label(string  $subject) : string

A human-readable name for a subject.

The label comes from the LIVE entity, because a diff is read by someone who wants to know which article changed and the stored field map holds ids rather than titles. A subject that no longer exists has no label, which is correct: there is nothing to name it after.

Parameters

string $subject

Subject path.

Returns

string —

The label, or an empty string when none is available.