Expand description
A crate for parsing and manipulating patches.
§Examples
use patchkit::ContentPatch;
use patchkit::unified::parse_patch;
use patchkit::unified::{UnifiedPatch, Hunk, HunkLine};
let patch = UnifiedPatch::parse_patch(vec![
"--- a/file1\n",
"+++ b/file1\n",
"@@ -1,1 +1,1 @@\n",
"-a\n",
"+b\n",
].into_iter().map(|s| s.as_bytes())).unwrap();
assert_eq!(patch, UnifiedPatch {
orig_name: b"a/file1".to_vec(),
mod_name: b"b/file1".to_vec(),
orig_ts: None,
mod_ts: None,
hunks: vec![
Hunk {
mod_pos: 1,
mod_range: 1,
orig_pos: 1,
orig_range: 1,
lines: vec![
HunkLine::RemoveLine(b"a\n".to_vec()),
HunkLine::InsertLine(b"b\n".to_vec()),
],
tail: None
},
],
});
let applied = patch.apply_exact(&b"a\n"[..]).unwrap();
assert_eq!(applied, b"b\n");
Modules§
- ed
- Parsing of ed-style patches
- quilt
- Quilt patch management
- timestamp
- Functions for parsing and formatting patch dates.
- unified
- Parsing of unified patches
Enums§
- Apply
Error - Error that occurs when applying a patch
Traits§
- Content
Patch - A patch that can be applied to file content
- Single
File Patch - A patch to a single file
Functions§
- strip_
prefix - Strip the specified number of path components from the beginning of the path.