Struct git_repository::Tree
source · pub struct Tree<'repo> {
pub id: ObjectId,
pub data: Vec<u8>,
/* private fields */
}
Expand description
A decoded tree object with access to its owning repository.
Fields§
§id: ObjectId
The id of the tree
data: Vec<u8>
The fully decoded tree data
Implementations§
source§impl<'repo> Tree<'repo>
impl<'repo> Tree<'repo>
Diffing
sourcepub fn changes<'a>(&'a self) -> Result<Platform<'a, 'repo>, Error>
pub fn changes<'a>(&'a self) -> Result<Platform<'a, 'repo>, Error>
Return a platform to see the changes needed to create other trees, for instance.
Performance
It’s highly recommended to set an object cache to avoid extracting the same object multiple times.
By default, similar to git diff
, rename tracking will be enabled if it is not configured.
source§impl<'repo> Tree<'repo>
impl<'repo> Tree<'repo>
Access
sourcepub fn lookup_entry<I, P>(self, path: I) -> Result<Option<Entry<'repo>>, Error>where
I: IntoIterator<Item = P>,
P: PartialEq<BStr>,
pub fn lookup_entry<I, P>(self, path: I) -> Result<Option<Entry<'repo>>, Error>where I: IntoIterator<Item = P>, P: PartialEq<BStr>,
Follow a sequence of path
components starting from this instance, and look them up one by one until the last component
is looked up and its tree entry is returned.
Performance Notes
Searching tree entries is currently done in sequence, which allows to the search to be allocation free. It would be possible to re-use a vector and use a binary search instead, which might be able to improve performance over all. However, a benchmark should be created first to have some data and see which trade-off to choose here.
Why is this consuming?
The borrow checker shows pathological behaviour in loops that mutate a buffer, but also want to return from it. Workarounds include keeping an index and doing a separate access to the memory, which seems hard to do here without re-parsing the entries.
sourcepub fn lookup_entry_by_path(
self,
relative_path: impl AsRef<Path>
) -> Result<Option<Entry<'repo>>, Error>
pub fn lookup_entry_by_path( self, relative_path: impl AsRef<Path> ) -> Result<Option<Entry<'repo>>, Error>
Like lookup_entry()
, but takes a Path
directly via relative_path
, a path relative to this tree.
Note
If any path component contains illformed UTF-8 and thus can’t be converted to bytes on platforms which can’t do so natively, the returned component will be empty which makes the lookup fail.