vcs-diff 0.3.0

Parse and model Git-format unified diffs in pure Rust (no git binary required) — the diff types shared across the vcs-toolkit-rs wrappers.
Documentation

vcs-diff

crates.io docs.rs downloads

Shared git-format unified-diff model and parser for the vcs-toolkit-rs workspace.

git diff and jj diff --git emit byte-identical output for ASCII paths — they differ only in non-ASCII filename rendering (git octal-C-quotes by default, jj writes raw UTF-8), both of which this parser decodes — so vcs-git and vcs-jj share one parser here instead of each carrying a copy that could silently drift. Dependency-free (std only) — pure data types and pure functions, no process execution.

use vcs_diff::{parse_diff, ChangeKind};

let diff = "diff --git a/f b/f\n--- a/f\n+++ b/f\n@@ -1 +1 @@\n-a\n+b\n";
for file in parse_diff(diff) {              // Vec<FileDiff>
    let verb = match file.change {          // ChangeKind is #[non_exhaustive]
        ChangeKind::Added => "added",
        ChangeKind::Deleted => "deleted",
        ChangeKind::Renamed => "renamed",
        _ => "modified",
    };
    println!("{verb} {}", file.path);
    for hunk in &file.hunks {               // Vec<Hunk> of DiffLine
        //    }
}

It also exposes [DiffSpec] (the diff request — WorkingTree / Rev — the wrapper crates' diff/diff_text take), [DiffStat] (the file/line aggregate both --shortstat and --stat parse into), and [Version] + [parse_dotted_version] for reading a <tool> --version banner.

The wrapper crates re-export these types, so vcs_git::FileDiff, vcs_git::parse_diff, and vcs_git::GitVersion (an alias of vcs_diff::Version) all resolve — you rarely name this crate directly.

Part of vcs-toolkit-rs; used by vcs-git, vcs-jj, and vcs-core.

License

MIT