Blame

Struct Blame 

Source
pub struct Blame {
Show 17 fields pub commit: String, pub original_line_no: usize, pub final_line_no: usize, pub filename: String, pub summary: String, pub content: String, pub previous_commit: Option<String>, pub previous_filepath: Option<String>, pub boundary: bool, pub author: String, pub author_mail: String, pub author_time: u64, pub author_tz: String, pub committer: String, pub committer_mail: String, pub committer_time: u64, pub committer_tz: String,
}
Expand description

The blame information

This struct stores the git blame output in PORCELAIN format.

§The Porcelain Format

The porcelain format is the output format produced by git blame when the --porcelain option is used.

Note that the --porcelain option generally suppresses commit information that has already been seen.

The --line-porcelain option can be used to outputs the full commit information for each line, use this when parsing. so use this for parsing.

More information about the porcelain format can be For more information, see git doc.

§time

author_time and committer_time are UNIX times (seconds).

§boundary

boundary is a metadata indicating the commit where the history tracking is stopped in git blame. This line means that the history will not be followed this point.

It is output only when necessary, and in that case, it is set to true.

Fields§

§commit: String§original_line_no: usize§final_line_no: usize§filename: String§summary: String§content: String

The contents of the actual line

§previous_commit: Option<String>§previous_filepath: Option<String>§boundary: bool

Set to true when blame output contains boundary.

§author: String§author_mail: String§author_time: u64§author_tz: String§committer: String§committer_mail: String§committer_time: u64§committer_tz: String

Implementations§

Source§

impl Blame

Source

pub fn short_commit(&self) -> String

Returns the abbreviated (short-hand) version of the commit hash.

Examples found in repository?
examples/demo.rs (line 42)
5fn main() {
6    let args: Vec<String> = std::env::args().collect();
7    if args.len() < 2 {
8        eprintln!("Error: missing args <FILE_PATH>");
9        std::process::exit(1);
10    }
11
12    let filepath = std::path::PathBuf::from(args[1].clone());
13    if !filepath.is_file() {
14        eprintln!("Error: invalid file path");
15        std::process::exit(1);
16    }
17
18    let output = std::process::Command::new("git")
19        .args(["blame", "--line-porcelain"])
20        .arg(filepath)
21        .output()
22        .unwrap();
23
24    if !output.status.success() {
25        let err = String::from_utf8_lossy(&output.stderr);
26        eprintln!("Error: {err}");
27        std::process::exit(1);
28    }
29
30    let raw_blame = String::from_utf8_lossy(&output.stdout);
31    let blames = match git_blame_parser::parse(&raw_blame) {
32        Ok(blames) => blames,
33        Err(e) => {
34            eprintln!("Error: {e}");
35            std::process::exit(1);
36        }
37    };
38
39    for blame in blames.iter() {
40        println!(
41            "* {}: {:0>4} by {} {}",
42            blame.short_commit(),
43            blame.original_line_no,
44            blame.author,
45            blame.author_mail
46        );
47        println!("summary: {}", blame.summary);
48        println!("content: `{}`", blame.content);
49        println!();
50    }
51}

Trait Implementations§

Source§

impl Debug for Blame

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Blame

Source§

fn default() -> Blame

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Blame

§

impl RefUnwindSafe for Blame

§

impl Send for Blame

§

impl Sync for Blame

§

impl Unpin for Blame

§

impl UnwindSafe for Blame

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.