git-blame-parser 0.1.1

Parses the git blame porcelain format into a struct.
Documentation
  • Coverage
  • 37.5%
    9 out of 24 items documented0 out of 5 items with examples
  • Size
  • Source code size: 34.81 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.9 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • mitsu-ksgr/git-blame-parser
    1 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mitsu-ksgr

git-blame-parser

Badge Workflow

Parses the output of git blame command in the porcelain format into a struct. the output must be generated using the --line-porcelain option.

Usage

Run the following Cargo command in your project directory:

% cargo add git-blame-parser

Or add the following line to your Cargo.toml:

[dependencies]
git-blame-parser = "0.1.1"

Then:

let output = std::process::Command::new("git")
    .args(["blame", "--line-porcelain"])
    .arg(filepath)
    .output()
    .unwrap();

if output.status.success() {
    let raw_blame = String::from_utf8_lossy(&output.stdout);
    let blames = match git_blame_parser::parse(&raw_blame) {
        Ok(blames) => blames,
        Err(e) => {
            eprintln!("Error: {e}");
            std::process::exit(1);
        }
    };

    for blame in blames.iter() {
        println!(
            "* {}: {:0>4} by {} {}",
            blame.short_commit(),
            blame.original_line_no,
            blame.author,
            blame.author_mail
        );
        println!("summary: {}", blame.summary);
        println!("content: `{}`", blame.content);
        println!();
    }
}

See also examples.

License

MIT