Skip to main content

Module patch

Module patch 

Source
Expand description

Reconstructs a minimal unified-diff patch covering only a selected range of lines, so the commit screen can stage or unstage part of a file instead of the whole thing — the engine behind the Stage/Unstage button that floats over a highlighted region in the diff view.

The displayed diff (one file, with its diff --git / hunk headers and +/ -/context body) is filtered down to the rows the user highlighted, and the touched hunks are rebuilt with corrected line counts. The result is always oriented to apply forward to the index (git apply --cached), so the direction (stage vs. unstage) is baked into the patch rather than left to the caller — see RepoBackend::apply_to_index.

Enums§

PartialMode
Which way a partial patch runs. Both produce a patch applied forward to the index; the difference is which displayed diff it is built from and how the selected +/- lines are mapped.

Functions§

build_partial_patch
Build a patch staging/unstaging exactly the selected rows of diff (row indices into diff.lines). Returns None when the selection covers no changed line, so the caller can treat it as a no-op.
is_change_line
Whether a diff row is an actual change (+/-) — the only kind of row a partial stage/unstage can act on. Header and context rows may fall inside a selection but never make it stageable on their own.