patch
Parses, creates, encodes, and applies unified and git-style patches.
Types
| Type | Description |
|---|---|
ApplyError |
Raised when a patch does not apply cleanly. |
ParseError |
Raised for malformed patch data. |
Patch |
One file-level patch operation. |
PatchIter |
Iterator over a patch stream. |
Functions
decode input -> PatchIter
Parses a patch stream.
Parameters
| Name | Type | Description |
|---|---|---|
input |
(Str | Bin) |
Unified or git-style patch. |
Errors
ParseError when iteration reaches malformed patch data.
Example
diff before after … -> Patch
Builds a text patch from two versions of the same content.
Parameters
| Name | Type | Description |
|---|---|---|
before |
(Str | Bin) |
Original content. Must be
the same kind of value as after. |
after |
(Str | Bin) |
Modified content. |
:source? |
(fs.Path | Str) |
Source filename for the patch headers. |
:target? |
(fs.Path | Str) |
Target filename for the patch headers. |
Errors
| Exception | Condition |
|---|---|
TypeError |
before and after are not both text or both binary |
TypeError |
source or target is not a Path or Str |
Example
encode value -> (Str | Bin)
Encodes a Patch or iterable of patches back to patch text.
Parameters
| Name | Type | Description |
|---|---|---|
value |
(Patch | Iterable[Patch]) |
One patch or an iterable of patches. |
Returns
Str when every encoded byte is valid UTF-8, and
Bin otherwise.
Errors
TypeError if an iterable contains a non-Patch value.