Struct gix::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>

Diffing

source

pub fn changes<'a>(&'a self) -> Result<Platform<'a, 'repo>, Error>

Available on crate feature 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>

Traversal

source

pub fn traverse(&self) -> Platform<'_, 'repo>

Obtain a platform for initiating a variety of traversals.

source§

impl<'repo> Tree<'repo>

source

pub fn iter(&self) -> impl Iterator<Item = Result<EntryRef<'repo, '_>, Error>>

Return an iterator over tree entries to obtain information about files and directories this tree contains.

source§

impl<'repo> Tree<'repo>

Initialization

source

pub fn from_data( id: impl Into<ObjectId>, data: Vec<u8>, repo: &'repo Repository ) -> Self

Obtain a tree instance by handing in all components that it is made up of.

source§

impl<'repo> Tree<'repo>

Access

source

pub fn id(&self) -> Id<'repo>

Return this tree’s identifier.

source

pub fn decode(&self) -> Result<TreeRef<'_>, Error>

Parse our tree data and return the parse tree for direct access to its entries.

source

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.

source

pub fn lookup_entry<I, P>( &self, path: I, buf: &mut Vec<u8> ) -> 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. 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.

source

pub fn peel_to_entry<I, P>( &mut 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, 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.

source

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.

source

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<'_>

Remove Lifetime

source

pub fn detached(&self) -> ObjectDetached

Create an owned instance of this object, copying our data in the process.

source

pub fn detach(self) -> ObjectDetached

Sever the connection to the Repository and turn this instance into a standalone object.

source

pub fn take_data(&mut self) -> Vec<u8>

Retrieve this instance’s encoded data, leaving its own data empty.

This method works around the immovability of members of this type.

Trait Implementations§

source§

impl<'repo> Clone for Tree<'repo>

source§

fn clone(&self) -> Tree<'repo>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'r> Debug for Tree<'r>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Drop for Tree<'a>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'repo> From<Tree<'repo>> for ObjectDetached

source§

fn from(v: Tree<'repo>) -> Self

Converts to this type from the input type.
source§

impl<'repo> TryFrom<Object<'repo>> for Tree<'repo>

§

type Error = Object<'repo>

The type returned in the event of a conversion error.
source§

fn try_from(value: Object<'repo>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Tree<'_>> for Tree

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(t: Tree<'_>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'repo> Freeze for Tree<'repo>

§

impl<'repo> !RefUnwindSafe for Tree<'repo>

§

impl<'repo> !Send for Tree<'repo>

§

impl<'repo> !Sync for Tree<'repo>

§

impl<'repo> Unpin for Tree<'repo>

§

impl<'repo> !UnwindSafe for Tree<'repo>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.