Skip to main content

PerFunctionBlame

Struct PerFunctionBlame 

Source
pub struct PerFunctionBlame { /* private fields */ }
Available on crate feature vcs-git only.
Expand description

A blame engine bound to one repository, reusable across the per-file metrics walk.

Holds a gix::ThreadSafeRepository (so the field can be shared read-only across the CLI’s worker threads — a plain gix::Repository is not Sync). Construct once per invocation with open, then open one BlameSession per worker thread with session: the session carries the thread-local handle, its object cache, the mailmap, and the resolved-commit memo, none of which survive a per-file handle.

Implementations§

Source§

impl PerFunctionBlame

Source

pub fn open(root: &Path, options: Options) -> Result<Self, Error>

Open the repository enclosing root, resolve the target ref, and build a reusable blame engine.

§Errors

Returns Error::NotARepository when root is not inside a git working tree, Error::ResolveRef when the configured reference cannot be peeled to a commit, Error::InvalidBotPattern for a bad bot regex, or Error::OpenRepository for a bare repository (per-function blame needs a working tree to map files).

Source

pub fn workdir(&self) -> &Path

The working-tree root the engine resolved (canonicalised).

Source

pub fn session(self: &Arc<Self>) -> BlameSession

Open a reusable BlameSession on the calling thread.

Every cost that BlameSession::per_function would otherwise pay per file — the thread-local repository handle, its object cache, the parsed .mailmap, and the resolved-commit memo — lives on the session instead, so a caller that blames many files in one repository pays each once. Sessions are !Sync by construction (they hold a gix::Repository); a worker pool wants one per thread, not one shared.

Holding a handle for a whole thread rather than a single file does not widen the issue-#579 staleness window. The ThreadSafeRepository — and the gix_odb::Store behind it — is already fixed for the engine’s lifetime, so a handle’s age adds no config or pack staleness of its own; and a handle refreshes its own pack-index snapshot on a miss before reporting one, so the retry in per_function re-reads exactly what a fresh handle would. gix::Repository::reload (a full re-open from disk) is therefore the wrong tool inside that retry: the miss it guards is an internal gix index-load race, not an external write we need to observe.

Source

pub fn per_function( &self, absolute: &Path, spans: &[LineSpan], ) -> Result<Vec<Stats>, Error>

Blame the file at absolute once and return one Stats per entry in spans, in the same order.

A span with no surviving in-window lines yields a zero-valued Stats (the per-function analogue of a tracked file with no recent activity), so the caller can attach a block to every function space uniformly.

This is the one-shot form: it builds and discards a BlameSession per call. Callers blaming more than one file should hold a session (session) instead.

§Errors

Returns Error::Blame when the path lies outside the working tree, is not valid UTF-8, or the blame itself fails (e.g. the file does not exist at the target ref).

Trait Implementations§

Source§

impl Debug for PerFunctionBlame

Source§

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

Formats the value using the given formatter. Read more

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

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

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.