Skip to main content

Module preserve

Module preserve 

Source
Expand description

The publish-time invariant: a merge keeps each side’s changes.

The gate (crate::land) judges the files BOTH sides changed. A file only one side changed has nothing to resolve, so the gate never reads it — and a merge whose tree is not git’s merge (a half-applied merge, a merge git could not write to the index, a hand-made tree) can silently put such a file back to the merge base. This module checks the tree itself, however it was produced, over EVERY path in base→ours ∪ base→theirs:

  • a path only theirs changed must hold theirs’ version, or a version that still contains theirs’ change (every token theirs added is there, no token theirs deleted is back; the gate’s DROPPED / UNDELETED measure, the whole file read as one block). A deletion by theirs must stay deleted; a file theirs changed must not be deleted;
  • a path only ours changed may be edited further by the merge (the merge commit is ours’ own work), but must not go back to base: not restored to the base version, not deleted when ours changed it, not brought back when ours deleted it.

Paths both sides changed are the gate’s. Any violation refuses, the file named.

Structs§

Violation
A path whose change by one side the merge does not keep.

Functions§

check
Check the merge result (any tree-ish) of ours and theirs over base. Empty = every one-sided change is kept.
check_now
check, keeping only the violations that hold at now too (the branch as it is now: a later commit that put the change back counts).
contains_change
Whether merged still holds the change base → side, in tokens: every token the side added is there at least as often as the side has it, and no token the side deleted is there more often than the side has it. None = held; Some(why) = not.
index_tree
The tree the index would commit, read without touching the index or its lock (a scratch copy of the index).
merge_in_tree
The tree the merge in progress in dir would commit, once nothing is left unmerged; None when no merge is in progress or a path is still unmerged.
render
The violations as lines for a person: path (side's change lost: …).