Crate blame_rs

Crate blame_rs 

Source
Expand description

§blame-rs

A Rust library for line-by-line authorship tracking in revisioned text content.

This crate provides a blame/annotate algorithm that determines which revision introduced each line in a document by analyzing a sequence of revisions.

§Features

  • Generic metadata: Attach any metadata type to revisions (commit hashes, authors, timestamps, etc.)
  • Multiple diff algorithms: Support for Myers and Patience algorithms via the similar crate
  • Forward tracking: Efficiently traces line origins from oldest to newest revision
  • Zero-copy optimization: Uses string slices (&str) to avoid unnecessary allocations
  • Shared metadata: Reference-counted metadata sharing reduces memory usage
  • Pre-allocated vectors: Minimizes heap allocations during processing

§Example

use blame_rs::{blame, BlameRevision};
use std::rc::Rc;

#[derive(Debug)]
struct CommitInfo {
    hash: String,
    author: String,
}

let revisions = vec![
    BlameRevision {
        content: "line 1\nline 2",
        metadata: Rc::new(CommitInfo {
            hash: "abc123".to_string(),
            author: "Alice".to_string(),
        }),
    },
    BlameRevision {
        content: "line 1\nline 2\nline 3",
        metadata: Rc::new(CommitInfo {
            hash: "def456".to_string(),
            author: "Bob".to_string(),
        }),
    },
];

let result = blame(&revisions).unwrap();
for line in result.lines() {
    println!("{}: {}", line.revision_metadata.author, line.content);
}

Structs§

BlameLine
BlameOptions
Options
BlameResult
The result of a blame operation, containing all lines with their origin information
BlameRevision

Enums§

BlameError
Errors
DiffAlgorithm

Functions§

blame
Performs a blame operation on a sequence of revisions to determine the origin of each line.
blame_with_options
Performs a blame operation with custom options.