Skip to main content

GitContext

Struct GitContext 

Source
#[non_exhaustive]
pub struct GitContext { pub repo_kind: RepoKind, pub repo_path: PathBuf, pub head: Head, /* private fields */ }
Expand description

Git state shared across all git_* segments for the duration of one render invocation. Populated once by resolve_repo and held behind an Arc in DataContext.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§repo_kind: RepoKind

Which repo flavor was discovered.

§repo_path: PathBuf

Absolute path to the repository directory (the .git dir for main, the .git/worktrees/<name>/ dir for linked worktrees, the repo path itself for bare).

§head: Head

Resolved HEAD.

Implementations§

Source§

impl GitContext

Source

pub fn new(repo_kind: RepoKind, repo_path: PathBuf, head: Head) -> Self

Construct a GitContext from pre-resolved fields without opening a repo. Lazy dirty / upstream accessors then return their defaults (empty dirty state, no upstream) because no gix::Repository is held. Pair with DataContext::preseed_git.

Source

pub fn dirty(&self) -> Arc<DirtyState>

Dirty state, scanned lazily on first access. Returns DirtyState::Clean when no repo handle is held.

The scan covers untracked files and tracked modifications. HEAD↔index (staged-only) changes are not detected because gix 0.67 doesn’t expose that comparison.

Source

pub fn preseed_upstream( &self, value: Option<UpstreamState>, ) -> Result<(), Arc<Option<UpstreamState>>>

Pre-populate the upstream OnceCell with an explicit value, bypassing the real walker. Returns Err via OnceCell::set’s semantics when the cell was already populated.

Source

pub fn preseed_dirty_state( &self, value: DirtyState, ) -> Result<(), Arc<DirtyState>>

Pre-populate the dirty OnceCell with an explicit value, bypassing the real scan. Same OnceCell::set semantics as Self::preseed_upstream.

Source

pub fn upstream(&self) -> Arc<Option<UpstreamState>>

Upstream-tracking state, scanned lazily on first access.

Returns Arc<None> in five distinct cases:

  1. HEAD is detached / unborn / an OtherRef.
  2. The branch has no tracking upstream configured.
  3. The configured tracking ref has no local object (never fetched, or remote pruned).
  4. The repo is shallow — ancestor walks truncate at the shallow frontier and would silently undercount.
  5. HEAD and upstream share no merge base (unrelated histories) OR gix failed partway through (corrupt index, cache open failure, …). In the failure case the cause is written to stderr with the linesmith: prefix on the first read.

Cases 1-4 render identically to ahead/behind segments (no upstream). Case 5 deliberately fuses “walker failed” into “no upstream” — distinguishing them in the plugin mirror requires a structured variant (follow-up).

Trait Implementations§

Source§

impl Debug for GitContext

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