@@ -34,6 +34,15 @@ pub struct FileBlame {
34
34
pub lines : Vec < ( Option < BlameHunk > , String ) > ,
35
35
}
36
36
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
+
37
46
///
38
47
pub fn blame_file (
39
48
repo_path : & RepoPath ,
@@ -56,20 +65,18 @@ pub fn blame_file(
56
65
[ tip] ,
57
66
None :: < Vec < gix:: ObjectId > > ,
58
67
)
59
- . build ( )
60
- . expect ( "TODO" ) ;
68
+ . build ( ) ?;
61
69
62
70
let mut resource_cache =
63
- repo. diff_resource_cache_for_tree_diff ( ) . expect ( "TODO" ) ;
71
+ repo. diff_resource_cache_for_tree_diff ( ) ? ;
64
72
65
73
let outcome = gix_blame:: file (
66
74
& repo. objects ,
67
75
traverse,
68
76
& mut resource_cache,
69
77
file_path. into ( ) ,
70
78
None ,
71
- )
72
- . expect ( "TODO" ) ;
79
+ ) ?;
73
80
74
81
let commit_id = if let Some ( commit_id) = commit_id {
75
82
commit_id
@@ -82,12 +89,7 @@ pub fn blame_file(
82
89
let unique_commit_ids: HashSet < _ > = outcome
83
90
. entries
84
91
. 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 ) ) )
91
93
. collect ( ) ;
92
94
let mut commit_ids = Vec :: with_capacity ( unique_commit_ids. len ( ) ) ;
93
95
commit_ids. extend ( unique_commit_ids) ;
@@ -104,10 +106,8 @@ pub fn blame_file(
104
106
let lines: Vec < ( Option < BlameHunk > , String ) > = outcome
105
107
. entries_with_lines ( )
106
108
. 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 ) ) ;
111
111
let start_in_blamed_file =
112
112
entry. start_in_blamed_file as usize ;
113
113
@@ -128,7 +128,8 @@ pub fn blame_file(
128
128
author : commit_info. author . clone ( ) ,
129
129
time : commit_info. time ,
130
130
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 ,
132
133
} ) ,
133
134
trimmed_line,
134
135
) ;
0 commit comments