#patch #quilt #diff #editing #unified

patchkit

A library for parsing and manipulating patch files

12 releases

0.2.1 Nov 16, 2024
0.2.0 Nov 16, 2024
0.1.9 Nov 16, 2024
0.1.8 Jul 29, 2024
0.1.2 Nov 28, 2023

#1 in #patches

Download history 671/week @ 2024-11-29 713/week @ 2024-12-06 661/week @ 2024-12-13 737/week @ 2024-12-20 572/week @ 2024-12-27 639/week @ 2025-01-03 516/week @ 2025-01-10 444/week @ 2025-01-17 332/week @ 2025-01-24 805/week @ 2025-01-31 2930/week @ 2025-02-07 3503/week @ 2025-02-14 1141/week @ 2025-02-21 4857/week @ 2025-02-28 3671/week @ 2025-03-07 3879/week @ 2025-03-14

13,658 downloads per month
Used in 9 crates (3 directly)

Apache-2.0

285KB
2K 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::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");

Dependencies

~3.5–5MB
~88K SLoC