@@ -2,7 +2,7 @@ use gix_hash::ObjectId;
2
2
pub use gix_object:: tree:: { EntryKind , EntryMode } ;
3
3
use gix_object:: { bstr:: BStr , FindExt , TreeRefIter } ;
4
4
5
- use crate :: { object:: find, Id , ObjectDetached , Tree } ;
5
+ use crate :: { object:: find, Id , ObjectDetached , Repository , Tree } ;
6
6
7
7
/// All state needed to conveniently edit a tree, using only [update-or-insert](Editor::upsert()) and [removals](Editor::remove()).
8
8
#[ cfg( feature = "tree-editor" ) ]
@@ -185,15 +185,32 @@ pub mod diff;
185
185
pub mod traverse;
186
186
187
187
///
188
- mod iter;
189
- pub use iter:: EntryRef ;
188
+ mod iter {
189
+ use super :: { EntryRef , Tree } ;
190
+
191
+ impl < ' repo > Tree < ' repo > {
192
+ /// Return an iterator over tree entries to obtain information about files and directories this tree contains.
193
+ pub fn iter ( & self ) -> impl Iterator < Item = Result < EntryRef < ' repo , ' _ > , gix_object:: decode:: Error > > {
194
+ let repo = self . repo ;
195
+ gix_object:: TreeRefIter :: from_bytes ( & self . data ) . map ( move |e| e. map ( |entry| EntryRef { inner : entry, repo } ) )
196
+ }
197
+ }
198
+ }
190
199
191
200
impl std:: fmt:: Debug for Tree < ' _ > {
192
201
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
193
202
write ! ( f, "Tree({})" , self . id)
194
203
}
195
204
}
196
205
206
+ /// An entry within a tree
207
+ pub struct EntryRef < ' repo , ' a > {
208
+ /// The actual entry ref we are wrapping.
209
+ pub inner : gix_object:: tree:: EntryRef < ' a > ,
210
+ /// The owning repository.
211
+ pub repo : & ' repo Repository ,
212
+ }
213
+
197
214
/// An entry in a [`Tree`], similar to an entry in a directory.
198
215
#[ derive( PartialEq , Debug , Clone ) ]
199
216
pub struct Entry < ' repo > {
@@ -202,50 +219,7 @@ pub struct Entry<'repo> {
202
219
pub repo : & ' repo crate :: Repository ,
203
220
}
204
221
205
- mod entry {
206
- use crate :: { bstr:: BStr , ext:: ObjectIdExt , object:: tree:: Entry } ;
207
-
208
- /// Access
209
- impl < ' repo > Entry < ' repo > {
210
- /// The kind of object to which `oid` is pointing to.
211
- pub fn mode ( & self ) -> gix_object:: tree:: EntryMode {
212
- self . inner . mode
213
- }
214
-
215
- /// The name of the file in the parent tree.
216
- pub fn filename ( & self ) -> & BStr {
217
- self . inner . filename . as_ref ( )
218
- }
219
-
220
- /// Return the object id of the entry.
221
- pub fn id ( & self ) -> crate :: Id < ' repo > {
222
- self . inner . oid . attach ( self . repo )
223
- }
224
-
225
- /// Return the object this entry points to.
226
- pub fn object ( & self ) -> Result < crate :: Object < ' repo > , crate :: object:: find:: existing:: Error > {
227
- self . id ( ) . object ( )
228
- }
229
-
230
- /// Return the plain object id of this entry, without access to the repository.
231
- pub fn oid ( & self ) -> & gix_hash:: oid {
232
- & self . inner . oid
233
- }
234
-
235
- /// Return the plain object id of this entry, without access to the repository.
236
- pub fn object_id ( & self ) -> gix_hash:: ObjectId {
237
- self . inner . oid
238
- }
239
- }
240
-
241
- /// Consuming
242
- impl Entry < ' _ > {
243
- /// Return the contained object.
244
- pub fn detach ( self ) -> gix_object:: tree:: Entry {
245
- self . inner
246
- }
247
- }
248
- }
222
+ mod entry;
249
223
250
224
mod _impls {
251
225
use crate :: Tree ;
0 commit comments