Struct git_repository::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§

General information and entries

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

Return the kind of hashes used in this instance.

Return our entries

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

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

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

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.

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.

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

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

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.

Mutation

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

Return mutable entries in a slice.

Return mutable entries along with their paths in an iterator.

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.

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.

Unconditionally sort entries as needed to perform lookups quickly.

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

Extensions

Access the tree extension.

Access the link extension.

Obtain the resolve-undo extension.

Obtain the untracked extension.

Obtain the fsmonitor extension.

Initialization

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

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

No extension data is currently produced.

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.

Assure our entries are consistent.

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

Serialize this instance to out with options.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.