@@ -34,6 +34,15 @@ pub struct FileBlame {
3434 pub lines : Vec < ( Option < BlameHunk > , String ) > ,
3535}
3636
37+ fn object_id_to_oid ( object_id : gix:: ObjectId ) -> git2:: Oid {
38+ // TODO
39+ // This should not fail. It will also become obsolete once `gix::ObjectId` is used throughout
40+ // `gitui`.
41+ #[ allow( clippy:: expect_used) ]
42+ git2:: Oid :: from_bytes ( object_id. as_bytes ( ) )
43+ . expect ( "ObjectId could not be converted to Oid" )
44+ }
45+
3746///
3847pub fn blame_file (
3948 repo_path : & RepoPath ,
@@ -56,20 +65,18 @@ pub fn blame_file(
5665 [ tip] ,
5766 None :: < Vec < gix:: ObjectId > > ,
5867 )
59- . build ( )
60- . expect ( "TODO" ) ;
68+ . build ( ) ?;
6169
6270 let mut resource_cache =
63- repo. diff_resource_cache_for_tree_diff ( ) . expect ( "TODO" ) ;
71+ repo. diff_resource_cache_for_tree_diff ( ) ? ;
6472
6573 let outcome = gix_blame:: file (
6674 & repo. objects ,
6775 traverse,
6876 & mut resource_cache,
6977 file_path. into ( ) ,
7078 None ,
71- )
72- . expect ( "TODO" ) ;
79+ ) ?;
7380
7481 let commit_id = if let Some ( commit_id) = commit_id {
7582 commit_id
@@ -82,12 +89,7 @@ pub fn blame_file(
8289 let unique_commit_ids: HashSet < _ > = outcome
8390 . entries
8491 . iter ( )
85- . map ( |entry| {
86- CommitId :: new (
87- git2:: Oid :: from_bytes ( entry. commit_id . as_bytes ( ) )
88- . expect ( "TODO" ) ,
89- )
90- } )
92+ . map ( |entry| CommitId :: new ( object_id_to_oid ( entry. commit_id ) ) )
9193 . collect ( ) ;
9294 let mut commit_ids = Vec :: with_capacity ( unique_commit_ids. len ( ) ) ;
9395 commit_ids. extend ( unique_commit_ids) ;
@@ -104,10 +106,8 @@ pub fn blame_file(
104106 let lines: Vec < ( Option < BlameHunk > , String ) > = outcome
105107 . entries_with_lines ( )
106108 . flat_map ( |( entry, lines) | {
107- let commit_id = CommitId :: new (
108- git2:: Oid :: from_bytes ( entry. commit_id . as_bytes ( ) )
109- . expect ( "TODO" ) ,
110- ) ;
109+ let commit_id =
110+ CommitId :: new ( object_id_to_oid ( entry. commit_id ) ) ;
111111 let start_in_blamed_file =
112112 entry. start_in_blamed_file as usize ;
113113
@@ -128,7 +128,8 @@ pub fn blame_file(
128128 author : commit_info. author . clone ( ) ,
129129 time : commit_info. time ,
130130 start_line : start_in_blamed_file + i,
131- end_line : start_in_blamed_file + i,
131+ end_line : start_in_blamed_file
132+ + i + 1 ,
132133 } ) ,
133134 trimmed_line,
134135 ) ;
0 commit comments