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>
Available on crate feature blob-diff
only.
pub fn changes<'a>(&'a self) -> Result<Platform<'a, 'repo>, Error>
blob-diff
only.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.
Note that if a clone with --filter=blob=none
was created, rename tracking may fail as it might
try to access blobs to compute a similarity metric. Thus, it’s more compatible to turn rewrite tracking off
using Platform::track_rewrites()
.
source§impl<'repo> Tree<'repo>
impl<'repo> Tree<'repo>
Access
sourcepub fn decode(&self) -> Result<TreeRef<'_>, Error>
pub fn decode(&self) -> Result<TreeRef<'_>, Error>
Parse our tree data and return the parse tree for direct access to its entries.
sourcepub fn find_entry(
&self,
name: impl PartialEq<BStr>
) -> Option<EntryRef<'repo, '_>>
pub fn find_entry( &self, name: impl PartialEq<BStr> ) -> Option<EntryRef<'repo, '_>>
Find the entry named name
by iteration, or return None
if it wasn’t found.
sourcepub fn lookup_entry<I, P>(
&self,
path: I,
buf: &mut Vec<u8>
) -> Result<Option<Entry<'repo>>, Error>
pub fn lookup_entry<I, P>( &self, path: I, buf: &mut Vec<u8> ) -> Result<Option<Entry<'repo>>, Error>
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.
Use buf
as temporary location for sub-trees to avoid allocating a temporary buffer for each lookup.
§Performance Notes
Searching tree entries is currently done in sequence, which allows to the search to be allocation free. It would be possible to reuse 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.
sourcepub fn peel_to_entry<I, P>(
&mut self,
path: I
) -> Result<Option<Entry<'repo>>, Error>
pub fn peel_to_entry<I, P>( &mut self, path: I ) -> Result<Option<Entry<'repo>>, Error>
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, while changing this instance to point to the last seen tree.
Note that if the lookup fails, it may be impossible to continue making lookups through this tree.
It’s useful to have this function to be able to reuse the internal buffer of the tree.
§Performance Notes
Searching tree entries is currently done in sequence, which allows to the search to be allocation free. It would be possible to reuse 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.
sourcepub fn lookup_entry_by_path(
&self,
relative_path: impl AsRef<Path>,
buf: &mut Vec<u8>
) -> Result<Option<Entry<'repo>>, Error>
pub fn lookup_entry_by_path( &self, relative_path: impl AsRef<Path>, buf: &mut Vec<u8> ) -> Result<Option<Entry<'repo>>, Error>
Like Self::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.
sourcepub fn peel_to_entry_by_path(
&mut self,
relative_path: impl AsRef<Path>
) -> Result<Option<Entry<'repo>>, Error>
pub fn peel_to_entry_by_path( &mut self, relative_path: impl AsRef<Path> ) -> Result<Option<Entry<'repo>>, Error>
Like Self::peel_to_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.
source§impl Tree<'_>
impl Tree<'_>
Remove Lifetime
sourcepub fn detached(&self) -> ObjectDetached
pub fn detached(&self) -> ObjectDetached
Create an owned instance of this object, copying our data in the process.
sourcepub fn detach(self) -> ObjectDetached
pub fn detach(self) -> ObjectDetached
Sever the connection to the Repository
and turn this instance into a standalone object.