Expand description
Builds a connected, renderable graph describing changes between two states.
This module is the graph-construction half of gen-diff.
crate::operations uses Dolt’s table-diff functions to find affected block
groups, edges, and nodes and associate those rows with operations. This module
handles the boundary normalization, input construction, and graph unification.
The resulting graph is consumed by the CLI, patch preview, GenHub, and the
diff TUI to show unchanged context together with added, removed, and modified
graph elements.
§Source and target terminology
At a merge boundary, the source is the branch the changes are coming
from and the target is the branch they are being merged into. The
historical names in this crate use source and target differently:
source_ref is the graph’s comparison baseline and target_ref is the
changed state being displayed. Consequently, a caller showing “merge source
branch into target branch” passes the merge target as the first/internal
source endpoint and the merge source as the second/internal target endpoint.
This is the source/target swap visible in merge-oriented callers.
The same distinction applies to source_block_group and
target_block_group in BlockGroupDiff. They record whether the requested
block-group ID exists in the baseline and changed database states,
respectively; they do not identify the incoming and receiving branches of a
merge. Source/target on a GraphEdge is a third, unrelated use: it is only
the direction of that edge.
§Block-group membership and effective graph snapshots
Every block group, including one created for a child sample, owns a complete
set of block_group_edges. Copied memberships are stored as rows belonging
to the child block group, and its parent relationship is recorded separately
by parent_block_group_id. The child graph therefore does not need its
parent in order to load or reconstruct its stored state.
A parent is selected only to make an added or removed child graph
biologically meaningful. The changed rows would show a child’s entire graph
being removed or created. Thus, comparing to the parent shows the edits that
introduced in the child. build_block_group_comparison therefore
keeps two concepts separate:
source_block_groupandtarget_block_grouppreserve actual membership of the requested ID and determine whether the block group is added, removed, or modified.source_effective_block_group_idandtarget_effective_block_group_idselect the graph used for display. When the requested ID is absent, this may be the child’s parent ID.
The corresponding effective history ref comes from the endpoint where the
selected row is known to exist. Thus a target-only child uses its own graph
at target_ref and its parent graph at that same endpoint as the source
baseline; a source-only child uses the symmetric source-side pair. This
selection affects only the rendered graph. It never fills in the missing
source_block_group or target_block_group.
Dolt’s copied block_group_edges rows contain enough information to
reconstruct a new child’s graph from the table diff. The effective parent is
not a workaround for incomplete diff rows. It supplies the inherited
comparison baseline, and effective_edge_changes_for_source filters copied
memberships that Dolt reports as added but that already exist in that
selected parent graph.
§Graph-building approach
Graph construction has three steps:
- Load the selected endpoint edge sets and convert edge coordinates into
GraphNodesequence slices. Coordinates are slices of the backing sequence, not positions in graph space. - Split both sides at the union of their slice boundaries. For example,
N[0..10]on one side andN[0..4] + N[4..10]on the other become the same two comparison units. Real path edges are retained, persistence-only edit-site marker edges are omitted, and neutral continuation edges reconnect slices that belong to one covered span. - Union the normalized endpoint graphs into a
DiffGenGraph. Presence and Dolt operation metadata determine each node’s and edge’sDiffChange. Start/end nodes and unchanged context remain in the result because the renderer needs a connected graph for layout.
Loading both endpoint edge sets makes path membership and marker filtering
straightforward. An alternative is to load the baseline once and apply the
block_group_edges diff rows to reconstruct the changed graph; the copied
child rows are sufficient for that and it may be preferable if endpoint
loading becomes a measured bottleneck. Another alternative is a literal
database-membership diff with an empty missing side, but that intentionally
gives up the lineage-aware view. The current effective-ID/ref variables could
also be replaced by an explicit endpoint-snapshot struct resolved once
upstream; that would preserve the behavior while making the storage choice
less indirect.
Structs§
Enums§
- Block
Group Change Kind - Describes how a block group differs between the comparison endpoints.
- Diff
Change Kind