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
impl HeadLookup
Sourcepub fn open(git_dir: &Path, common_dir: &Path, hash: Kind) -> Option<Self>
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.
Sourcepub fn holds_in_the_clear(&mut self, path: &[u8]) -> bool
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.