#patch #diff #parser #quilt #unified #editing

patchkit

A library for parsing and manipulating patch files

9 releases

0.1.8 Jul 29, 2024
0.1.7 Jul 7, 2024
0.1.2 Nov 28, 2023

#2 in #quilt

Download history 1036/week @ 2024-07-07 753/week @ 2024-07-14 651/week @ 2024-07-21 2330/week @ 2024-07-28 2249/week @ 2024-08-04 1681/week @ 2024-08-11 1932/week @ 2024-08-18 2617/week @ 2024-08-25 1883/week @ 2024-09-01 1850/week @ 2024-09-08 868/week @ 2024-09-15 1918/week @ 2024-09-22 1322/week @ 2024-09-29 855/week @ 2024-10-06 998/week @ 2024-10-13 714/week @ 2024-10-20

4,220 downloads per month
Used in 9 crates (3 directly)

Apache-2.0

75KB
1.5K SLoC

Parsing and manipulation of patch files

This crate provides support for parsing and editing of unified diff files, as well as related files (e.g. quilt).


lib.rs:

A crate for parsing and manipulating patches.

Examples

use patchkit::parse::parse_patch;
use patchkit::patch::{Patch as _, 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");

Dependencies

~3.5–5MB
~90K SLoC