@@ -47,15 +47,23 @@ pub fn blame_file(
4747 options,
4848 ) ?;
4949 let statistics = outcome. statistics ;
50- write_blame_entries ( out, outcome) ?;
50+ write_blame_entries ( out, outcome, file ) ?;
5151
5252 if let Some ( err) = err {
5353 writeln ! ( err, "{statistics:#?}" ) ?;
5454 }
5555 Ok ( ( ) )
5656}
5757
58- fn write_blame_entries ( mut out : impl std:: io:: Write , outcome : gix:: blame:: Outcome ) -> Result < ( ) , std:: io:: Error > {
58+ fn write_blame_entries (
59+ mut out : impl std:: io:: Write ,
60+ outcome : gix:: blame:: Outcome ,
61+ source_file_name : gix:: bstr:: BString ,
62+ ) -> Result < ( ) , std:: io:: Error > {
63+ let show_file_names = outcome
64+ . entries_with_lines ( )
65+ . any ( |( entry, _) | entry. source_file_name . is_some ( ) ) ;
66+
5967 for ( entry, lines_in_hunk) in outcome. entries_with_lines ( ) {
6068 for ( ( actual_lno, source_lno) , line) in entry
6169 . range_in_blamed_file ( )
@@ -64,11 +72,20 @@ fn write_blame_entries(mut out: impl std::io::Write, outcome: gix::blame::Outcom
6472 {
6573 write ! (
6674 out,
67- "{short_id} {line_no} {src_line_no} {line}" ,
68- line_no = actual_lno + 1 ,
69- src_line_no = source_lno + 1 ,
75+ "{short_id} {line_no} " ,
7076 short_id = entry. commit_id. to_hex_with_len( 8 ) ,
77+ line_no = actual_lno + 1 ,
7178 ) ?;
79+
80+ if show_file_names {
81+ if let Some ( ref source_file_name) = entry. source_file_name {
82+ write ! ( out, "{source_file_name} " ) ?;
83+ } else {
84+ write ! ( out, "{source_file_name} " ) ?;
85+ }
86+ }
87+
88+ write ! ( out, "{src_line_no} {line}" , src_line_no = source_lno + 1 ) ?;
7289 }
7390 }
7491
0 commit comments