Skip to main content

Module patch

Module patch 

Source
Expand description

The *** Begin Patch envelope apply_patch takes: its parser and its matcher (spec 3.1 §7.26, §10 D8).

*** Begin Patch
*** Add File: docs/new.md
+first line
*** Delete File: old.txt
*** Update File: src/lib.rs
*** Move to: src/core.rs
@@ fn main()
 context line
-removed line
+added line
*** End Patch

A hunk is located by its context and removed lines, never by line numbers: an exact match first, then one that ignores trailing whitespace and line endings, and never an ambiguous or fuzzy one. A hunk with an @@ anchor matches at the first place at or after the anchor line — the line equal to the anchor, or starting with it — and the first anchor of a hunk must name one line; a hunk without one must match exactly once after the previous hunk. Each line keeps its own line ending, and added lines take the file’s prevailing one.

Structs§

Hunk
One located change of an Update File.
Patch
A parsed patch: its file operations in order.
PatchError
Why a patch does not parse or does not apply.

Enums§

HunkLine
A line of a Hunk.
PatchOp
One file operation of a Patch.

Functions§

apply_hunks
Applies hunks to text, returning the new text (spec 3.1 §7.26).
parse_patch
Parses the *** Begin Patch envelope (spec 3.1 §7.26).