File tree 2 files changed +25
-11
lines changed
revision/spec/parse/delegate
2 files changed +25
-11
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,24 @@ impl<'repo> Tree<'repo> {
60
60
}
61
61
Ok ( None )
62
62
}
63
+
64
+ /// Like [`lookup_path()`][Self::lookup_path()], but takes a `Path` directly via `relative_path`, a path relative to this tree.
65
+ ///
66
+ /// # Note
67
+ ///
68
+ /// If any path component contains illformed UTF-8 and thus can't be converted to bytes on platforms which can't do so natively,
69
+ /// the returned component will be empty which makes the lookup fail.
70
+ pub fn lookup_path_by_path (
71
+ self ,
72
+ relative_path : impl AsRef < std:: path:: Path > ,
73
+ ) -> Result < Option < git_object:: tree:: Entry > , find:: existing:: Error > {
74
+ self . lookup_path (
75
+ relative_path
76
+ . as_ref ( )
77
+ . components ( )
78
+ . map ( |c| git_path:: os_str_into_bstr ( c. as_os_str ( ) ) . unwrap_or ( "" . into ( ) ) . as_ref ( ) ) ,
79
+ )
80
+ }
63
81
}
64
82
65
83
///
Original file line number Diff line number Diff line change @@ -124,17 +124,13 @@ impl<'repo> delegate::Navigate for Delegate<'repo> {
124
124
return Ok ( tree_id) ;
125
125
}
126
126
let tree = repo. find_object ( tree_id) ?. into_tree ( ) ;
127
- let entry = tree
128
- . lookup_path ( git_path:: from_bstr ( path) . components ( ) . map ( |c| {
129
- git_path:: os_str_into_bstr ( c. as_os_str ( ) )
130
- . expect ( "no illformed UTF-8" )
131
- . as_ref ( )
132
- } ) ) ?
133
- . ok_or_else ( || Error :: PathNotFound {
134
- path : path. into ( ) ,
135
- object : obj. attach ( repo) . shorten_or_id ( ) ,
136
- tree : tree_id. attach ( repo) . shorten_or_id ( ) ,
137
- } ) ?;
127
+ let entry =
128
+ tree. lookup_path_by_path ( git_path:: from_bstr ( path) ) ?
129
+ . ok_or_else ( || Error :: PathNotFound {
130
+ path : path. into ( ) ,
131
+ object : obj. attach ( repo) . shorten_or_id ( ) ,
132
+ tree : tree_id. attach ( repo) . shorten_or_id ( ) ,
133
+ } ) ?;
138
134
Ok ( entry. oid )
139
135
} ;
140
136
for obj in objs. iter ( ) {
You can’t perform that action at this time.
0 commit comments