unidiff

Rust library for parsing unified diffs and extracting structured patch metadata.

Library
Cargo
v0.4.1
36stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
36/100Needs Attention
Development Activity44
Maintenance8
Community20
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
76/100Good
Architecture76
Code Quality78
Innovation68
Learning Curve82

unidiff is a small Rust library for parsing unified diff (patch) text into a structured, navigable object model. It reads the output produced by git, svn, hg, and other tools and gives you typed access to the patch set, its files, hunks, and individual added/removed/context lines.

Beyond raw parsing, it exposes metadata such as which files were added, modified, or removed and per-file line counts, making it easy to build code review tooling, diff statistics, and patch-analysis pipelines. Character encoding handling is available via an optional encoding feature.

What You Get

  • A PatchSet parser that consumes unified diff text from git, svn, hg, and similar tools
  • Typed access to patched files, hunks, and added/removed/context lines
  • File-level metadata: added/modified/removed classification and line counts
  • Optional character-encoding handling via the encoding feature (encoding_rs)
  • A dependency-light crate built on the regex engine

Common Use Cases

  • Parsing git/svn/hg diffs to compute added and removed line statistics
  • Building code review or patch-analysis tooling on top of structured diffs
  • Filtering or transforming hunks programmatically before applying or displaying them
  • Extracting the list of changed files and their change types from a patch

Under The Hood

Architecture The crate is implemented in a single src/lib.rs that uses compiled regex patterns to recognize the unified-diff grammar — file headers, hunk @@ ranges, and line prefixes — and assembles them into a nested PatchSet -> PatchedFile -> Hunk -> line model, with iterator-based access and derived metadata (added/removed/modified, line counts). Tech Stack Rust (2024 edition) depending only on regex, with an optional encoding feature backed by encoding_rs for non-UTF-8 diff decoding; documentation is published to docs.rs and a benches/ directory holds criterion-style benchmarks. Code Quality For its size the crate is well-structured, with an integration tests/ directory (3 test modules exercising real diff fixtures) and CI, though maintenance cadence and community footprint are modest. API Design The surface is minimal and idiomatic — construct a PatchSet, call parse on diff text, then iterate typed files and hunks — so there is little to learn and almost no boilerplate to get from a diff string to structured data.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search