Skip to main content

HeadLookup

Struct HeadLookup 

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

One cheap question, asked on the check-in path: is this path already in HEAD in the clear?

The founding document gives the filter this job because the filter is the one mechanism that runs whatever client is driving git. A pre-commit hook is bypassed by --no-verify, switched off by a checkbox in an IDE, and does not survive a clone; the attribute mechanism git enforces itself.

The constraint that shapes it is that this runs while git add waits. A full history scan here would stall every commit, so the question is deliberately the narrow one — one path, one tree chain, one blob — and the answer is only ever a message. It must never make the filter exit non-zero. With required = true a non-zero exit aborts the whole operation, and this is a warning about the past, not a reason to refuse the present.

Everything is resolved lazily and cached, so a repository where nothing is declared never opens the object database at all, and one where a hundred secrets live in the same directory reads that directory’s tree once.

Implementations§

Source§

impl HeadLookup

Source

pub fn open(git_dir: &Path, common_dir: &Path, hash: Kind) -> Option<Self>

Prepares the lookup, or gives up quietly.

None when there is nothing to look in — an unborn branch, an unreadable object database. Quiet is right: this whole facility is an extra, and a repository that cannot answer the question is not a repository that should stop accepting commits over it.

Source

pub fn holds_in_the_clear(&mut self, path: &[u8]) -> bool

Whether HEAD holds path as content without our magic.

False for anything it cannot answer, deliberately: a false negative here costs a message, a false positive costs the user’s trust in every message this tool prints.

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> Same for T

Source§

type Output = T

Should always be Self
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.