@@ -2,7 +2,7 @@ use gix_hash::ObjectId;
22pub use gix_object:: tree:: { EntryKind , EntryMode } ;
33use gix_object:: { bstr:: BStr , FindExt , TreeRefIter } ;
44
5- use crate :: { object:: find, Id , ObjectDetached , Tree } ;
5+ use crate :: { object:: find, Id , ObjectDetached , Repository , Tree } ;
66
77/// All state needed to conveniently edit a tree, using only [update-or-insert](Editor::upsert()) and [removals](Editor::remove()).
88#[ cfg( feature = "tree-editor" ) ]
@@ -185,15 +185,32 @@ pub mod diff;
185185pub mod traverse;
186186
187187///
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+ }
190199
191200impl std:: fmt:: Debug for Tree < ' _ > {
192201 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
193202 write ! ( f, "Tree({})" , self . id)
194203 }
195204}
196205
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+
197214/// An entry in a [`Tree`], similar to an entry in a directory.
198215#[ derive( PartialEq , Debug , Clone ) ]
199216pub struct Entry < ' repo > {
@@ -202,50 +219,7 @@ pub struct Entry<'repo> {
202219 pub repo : & ' repo crate :: Repository ,
203220}
204221
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;
249223
250224mod _impls {
251225 use crate :: Tree ;
0 commit comments