Struct git_index::State

source ·
pub struct State { /* private fields */ }
Expand description

An in-memory cache of a fully parsed git index file.

As opposed to a snapshot, it’s meant to be altered and eventually be written back to disk or converted into a tree. We treat index and its state synonymous.

Implementations§

source§

impl State

General information and entries

source

pub fn version(&self) -> Version

Return the version used to store this state’s information on disk.

source

pub fn object_hash(&self) -> Kind

Return the kind of hashes used in this instance.

source

pub fn entries(&self) -> &[Entry]

Return our entries

source

pub fn path_backing(&self) -> &PathStorage

Return our path backing, the place which keeps all paths one after another, with entries storing only the range to access them.

source

pub fn entries_with_paths_by_filter_map<'a, T>( &'a self, filter_map: impl FnMut(&'a BStr, &Entry) -> Option<T> + 'a ) -> impl Iterator<Item = (&'a BStr, T)> + 'a

Runs filter_map on all entries, returning an iterator over all paths along with the result of filter_map.

source

pub fn entries_mut_with_paths_in<'state, 'backing>( &'state mut self, backing: &'backing PathStorage ) -> impl Iterator<Item = (&'state mut Entry, &'backing BStr)>

Return mutable entries along with their path, as obtained from backing.

source

pub fn entry_index_by_path_and_stage( &self, path: &BStr, stage: Stage ) -> Option<usize>

Find the entry index in entries() matching the given repository-relative path and stage, or None.

Use the index for accessing multiple stages if they exists, but at least the single matching entry.

source

pub fn entry_index_by_path_and_stage_bounded( &self, path: &BStr, stage: Stage, upper_bound: usize ) -> Option<usize>

Find the entry index in entries()[..upper_bound] matching the given repository-relative path and stage, or None.

Use the index for accessing multiple stages if they exists, but at least the single matching entry.

Panics

If upper_bound is out of bounds of our entries array.

source

pub fn entry_by_path_and_stage(&self, path: &BStr, stage: Stage) -> Option<&Entry>

Like entry_index_by_path_and_stage(), but returns the entry instead of the index.

source

pub fn entry(&self, idx: usize) -> &Entry

Return the entry at idx or panic if the index is out of bounds.

The idx is typically returned by entry_by_path_and_stage().

source

pub fn is_sparse(&self) -> bool

Returns a boolean value indicating whether the index is sparse or not.

An index is sparse if it contains at least one Mode::DIR entry.

source§

impl State

Mutation

source

pub fn return_path_backing(&mut self, backing: PathStorage)

After usage of the storage obtained by take_path_backing(), return it here. Note that it must not be empty.

source

pub fn entries_mut(&mut self) -> &mut [Entry]

Return mutable entries in a slice.

source

pub fn entries_mut_with_paths( &mut self ) -> impl Iterator<Item = (&mut Entry, &BStr)>

Return mutable entries along with their paths in an iterator.

source

pub fn take_path_backing(&mut self) -> PathStorage

Sometimes it’s needed to remove the path backing to allow certain mutation to happen in the state while supporting reading the entry’s path.

source

pub fn entry_mut_by_path_and_stage( &mut self, path: &BStr, stage: Stage ) -> Option<&mut Entry>

Like entry_index_by_path_and_stage(), but returns the mutable entry instead of the index.

source

pub fn dangerously_push_entry( &mut self, stat: Stat, id: ObjectId, flags: Flags, mode: Mode, path: &BStr )

Push a new entry containing stat, id, flags and mode and path to the end of our storage, without performing any sanity checks. This means it’s possible to push a new entry to the same path on the same stage and even after sorting the entries lookups may still return the wrong one of them unless the correct binary search criteria is chosen.

Note that this is likely to break invariants that will prevent further lookups by path unless entry_index_by_path_and_stage_bounded() is used with the upper_bound being the amount of entries before the first call to this method.

Alternatively, make sure to call sort_entries() before entry lookup by path to restore the invariant.

source

pub fn sort_entries(&mut self)

Unconditionally sort entries as needed to perform lookups quickly.

source

pub fn sort_entries_by( &mut self, compare: impl FnMut(&Entry, &Entry) -> Ordering )

Similar to [sort_entries()][State::sort_entries()], but applies compare` after comparing by path and stage as a third criteria.

source§

impl State

Extensions

source

pub fn tree(&self) -> Option<&Tree>

Access the tree extension.

Access the link extension.

source

pub fn resolve_undo(&self) -> Option<&Vec<ResolvePath>>

Obtain the resolve-undo extension.

source

pub fn untracked(&self) -> Option<&UntrackedCache>

Obtain the untracked extension.

source

pub fn fs_monitor(&self) -> Option<&FsMonitor>

Obtain the fsmonitor extension.

source§

impl State

Initialization

source

pub fn new(object_hash: Kind) -> Self

Return a new and empty in-memory index assuming the given object_hash.

source

pub fn from_tree<Find>(tree: &oid, find: Find) -> Result<Self, Error>where Find: for<'a> FnMut(&oid, &'a mut Vec<u8>) -> Option<TreeRefIter<'a>>,

Create an index State by traversing tree recursively, accessing sub-trees with find.

No extension data is currently produced.

source§

impl State

source

pub fn from_bytes( data: &[u8], timestamp: FileTime, object_hash: Kind, _: Options ) -> Result<(Self, ObjectId), Error>

Decode an index state from data and store timestamp in the resulting instance for pass-through, assuming object_hash to be used through the file.

source§

impl State

source

pub fn verify_entries(&self) -> Result<(), Error>

Assure our entries are consistent.

source

pub fn verify_extensions<F>(&self, use_find: bool, find: F) -> Result<(), Error>where F: for<'a> FnMut(&oid, &'a mut Vec<u8>) -> Option<TreeRefIter<'a>>,

Note: find cannot be Option<F> as we can’t call it with a closure then due to the indirection through Some.

source§

impl State

source

pub fn write_to(&self, out: impl Write, _: Options) -> Result<Version>

Serialize this instance to out with options.

Trait Implementations§

source§

impl Clone for State

source§

fn clone(&self) -> State

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for State

source§

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

Formats the value using the given formatter. Read more
source§

impl From<File> for State

source§

fn from(f: File) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl RefUnwindSafe for State

§

impl Send for State

§

impl Sync for State

§

impl Unpin for State

§

impl UnwindSafe for State

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.