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§
- Partial
Mode - 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
selectedrows ofdiff(row indices intodiff.lines). ReturnsNonewhen 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.