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>

Diffing

source

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>

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 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.

source

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.

Trait Implementations§

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> 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.

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.