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: StringThe contents of the actual line
previous_commit: Option<String>§previous_filepath: Option<String>§boundary: boolSet to true when blame output contains boundary.
committer: String§committer_mail: String§committer_time: u64§committer_tz: StringImplementations§
Source§impl Blame
impl Blame
Sourcepub fn short_commit(&self) -> String
pub fn short_commit(&self) -> String
Returns the abbreviated (short-hand) version of the commit hash.
Examples found in repository?
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}