Skip to main content

TreeAttributes

Struct TreeAttributes 

Source
pub struct TreeAttributes { /* private fields */ }
Expand description

A reusable handle that captures a tree’s .gitattributes chain once so repeated smudge-filter calls (e.g. git archive streaming every blob in a tree) resolve attributes from the tree being processed rather than the live worktree.

This is the attribute direction git archive uses: upstream unpacks the archived tree into a scratch index and sets GIT_ATTR_INDEX, so the .gitattributes that govern conversion come from the archived tree (plus the global/core.attributesFile chain and $GIT_DIR/info/attributes), not from whatever happens to be checked out. --worktree-attributes callers should use WorktreeAttributes instead.

Build it once with TreeAttributes::from_tree, then call TreeAttributes::apply_smudge_filter per blob. Behaviourally this mirrors apply_smudge_filter except the attribute source is the supplied tree and the expensive source scan is amortized across calls.

Implementations§

Source§

impl TreeAttributes

Source

pub fn from_tree( attr_root: impl AsRef<Path>, git_dir: impl AsRef<Path>, db: &FileObjectDatabase, format: ObjectFormat, tree_oid: &ObjectId, ) -> Result<Self>

Read the attribute sources for tree_oid once: the global / core.attributesFile chain, every .gitattributes blob found while walking tree_oid, and $GIT_DIR/info/attributes.

attr_root locates the global config (read_configured_attributes); pass the worktree root for a non-bare repo, or the git dir for a bare one. git_dir locates info/attributes directly (so this works for bare repos, where there is no nested .git). No worktree .gitattributes files are read — use WorktreeAttributes for the --worktree-attributes direction.

Source

pub fn apply_smudge_filter( &self, config: &GitConfig, path: &[u8], content: &[u8], ) -> Result<Vec<u8>>

Apply the smudge conversion (blob -> worktree: EOL LF->CRLF plus any configured filter.<name>.smudge driver) to content for path, reusing the cached attribute chain. Behaviourally identical to apply_smudge_filter except attributes come from the tree this handle was built from.

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.