pub enum IndexPersistedOrInMemory {
Persisted(Index),
InMemory(File),
}index only.Expand description
A type to represent an index which either was loaded from disk as it was persisted there, or created on the fly in memory.
Variants§
Persisted(Index)
The index as loaded from disk, and shared across clones of the owning Repository.
InMemory(File)
A temporary index as created from the HEAD^{tree}, with the file path set to the place where it would be stored naturally.
Note that unless saved explicitly, it will not persist.
Implementations§
Source§impl IndexPersistedOrInMemory
impl IndexPersistedOrInMemory
Sourcepub fn into_owned(self) -> File
pub fn into_owned(self) -> File
Consume this instance and turn it into an owned index file.
Note that this will cause the persisted index to be cloned, which would happen whenever the repository has a worktree.
Methods from Deref<Target = File>§
Sourcepub fn path(&self) -> &Path
Available on crate feature excludes only.
pub fn path(&self) -> &Path
excludes only.The path from which the index was read or to which it is supposed to be written when used with File::from_state().
Sourcepub fn checksum(&self) -> Option<ObjectId>
Available on crate feature excludes only.
pub fn checksum(&self) -> Option<ObjectId>
excludes only.The checksum over the file that was read or written to disk, or None if the state in memory was never serialized.
Note that even if Some, it will only represent the state in memory right after reading or writing.
Sourcepub fn verify_integrity(&self) -> Result<(), Error>
Available on crate feature excludes only.
pub fn verify_integrity(&self) -> Result<(), Error>
excludes only.Verify the integrity of the index to assure its consistency.
Sourcepub fn write_to(
&self,
out: impl Write,
options: Options,
) -> Result<(Version, ObjectId), Error>
Available on crate feature excludes only.
pub fn write_to( &self, out: impl Write, options: Options, ) -> Result<(Version, ObjectId), Error>
excludes only.Write the index to out with options, to be readable by File::at(), returning the version that was actually written
to retain all information of this index.
Methods from Deref<Target = State>§
Sourcepub fn version(&self) -> Version
Available on crate feature excludes only.
pub fn version(&self) -> Version
excludes only.Return the version used to store this state’s information on disk.
Sourcepub fn timestamp(&self) -> FileTime
Available on crate feature excludes only.
pub fn timestamp(&self) -> FileTime
excludes only.Returns time at which the state was created, indicating its freshness compared to other files on disk.
Sourcepub fn set_timestamp(&mut self, timestamp: FileTime)
Available on crate feature excludes only.
pub fn set_timestamp(&mut self, timestamp: FileTime)
excludes only.Updates the timestamp of this state, indicating its freshness compared to other files on disk.
Be careful about using this as setting a timestamp without correctly updating the index will cause (file system) race conditions see racy-git.txt in the git documentation for more details.
Sourcepub fn object_hash(&self) -> Kind
Available on crate feature excludes only.
pub fn object_hash(&self) -> Kind
excludes only.Return the kind of hashes used in this instance.
Sourcepub fn path_backing(&self) -> &[u8] ⓘ
Available on crate feature excludes only.
pub fn path_backing(&self) -> &[u8] ⓘ
excludes only.Return our path backing, the place which keeps all paths one after another, with entries storing only the range to access them.
Sourcepub 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
Available on crate feature excludes only.
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
excludes only.Runs filter_map on all entries, returning an iterator over all paths along with the result of filter_map.
Sourcepub fn entries_mut_with_paths_in<'state, 'backing>(
&'state mut self,
backing: &'backing [u8],
) -> impl Iterator<Item = (&'state mut Entry, &'backing BStr)>
Available on crate feature excludes only.
pub fn entries_mut_with_paths_in<'state, 'backing>( &'state mut self, backing: &'backing [u8], ) -> impl Iterator<Item = (&'state mut Entry, &'backing BStr)>
excludes only.Return mutable entries along with their path, as obtained from backing.
Sourcepub fn entry_index_by_path_and_stage(
&self,
path: &BStr,
stage: Stage,
) -> Option<usize>
Available on crate feature excludes only.
pub fn entry_index_by_path_and_stage( &self, path: &BStr, stage: Stage, ) -> Option<usize>
excludes only.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.
Sourcepub fn prepare_icase_backing(&self) -> AccelerateLookup<'_>
Available on crate feature excludes only.
pub fn prepare_icase_backing(&self) -> AccelerateLookup<'_>
excludes only.Return a data structure to help with case-insensitive lookups.
It’s required perform any case-insensitive lookup. TODO: needs multi-threaded insertion, raw-table to have multiple locks depending on bucket.
Sourcepub fn entry_by_path_icase<'a>(
&'a self,
path: &BStr,
ignore_case: bool,
lookup: &AccelerateLookup<'a>,
) -> Option<&'a Entry>
Available on crate feature excludes only.
pub fn entry_by_path_icase<'a>( &'a self, path: &BStr, ignore_case: bool, lookup: &AccelerateLookup<'a>, ) -> Option<&'a Entry>
excludes only.Return the entry at path that is at the lowest available stage, using lookup for acceleration.
It must have been created from this instance, and was ideally kept up-to-date with it.
If ignore_case is true, a case-insensitive (ASCII-folding only) search will be performed.
Sourcepub fn entry_closest_to_directory_icase<'a>(
&'a self,
directory: &BStr,
ignore_case: bool,
lookup: &AccelerateLookup<'a>,
) -> Option<&'a Entry>
Available on crate feature excludes only.
pub fn entry_closest_to_directory_icase<'a>( &'a self, directory: &BStr, ignore_case: bool, lookup: &AccelerateLookup<'a>, ) -> Option<&'a Entry>
excludes only.Return the entry (at any stage) that is inside of directory, or None,
using lookup for acceleration.
Note that submodules are not detected as directories and the user should
make another call to entry_by_path_icase() to check for this
possibility. Doing so might also reveal a sparse directory.
If ignore_case is set
Sourcepub fn entry_closest_to_directory(&self, directory: &BStr) -> Option<&Entry>
Available on crate feature excludes only.
pub fn entry_closest_to_directory(&self, directory: &BStr) -> Option<&Entry>
excludes only.Return the entry (at any stage) that is inside of directory, or None.
Note that submodules are not detected as directories and the user should
make another call to entry_by_path_icase() to check for this
possibility. Doing so might also reveal a sparse directory.
Note that this is a case-sensitive search.
Sourcepub fn entry_index_by_path_and_stage_bounded(
&self,
path: &BStr,
stage: Stage,
upper_bound: usize,
) -> Option<usize>
Available on crate feature excludes only.
pub fn entry_index_by_path_and_stage_bounded( &self, path: &BStr, stage: Stage, upper_bound: usize, ) -> Option<usize>
excludes only.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.
Sourcepub fn entry_by_path_and_stage(
&self,
path: &BStr,
stage: Stage,
) -> Option<&Entry>
Available on crate feature excludes only.
pub fn entry_by_path_and_stage( &self, path: &BStr, stage: Stage, ) -> Option<&Entry>
excludes only.Like entry_index_by_path_and_stage(),
but returns the entry instead of the index.
Sourcepub fn entry_by_path(&self, path: &BStr) -> Option<&Entry>
Available on crate feature excludes only.
pub fn entry_by_path(&self, path: &BStr) -> Option<&Entry>
excludes only.Return the entry at path that is either at stage 0, or at stage 2 (ours) in case of a merge conflict.
Using this method is more efficient in comparison to doing two searches, one for stage 0 and one for stage 2.
Sourcepub fn entry_index_by_path(&self, path: &BStr) -> Result<usize, usize>
Available on crate feature excludes only.
pub fn entry_index_by_path(&self, path: &BStr) -> Result<usize, usize>
excludes only.Return the index at Ok(index) where the entry matching path (in any stage) can be found, or return
Err(index) to indicate the insertion position at which an entry with path would fit in.
Sourcepub fn prefixed_entries(&self, prefix: &BStr) -> Option<&[Entry]>
Available on crate feature excludes only.
pub fn prefixed_entries(&self, prefix: &BStr) -> Option<&[Entry]>
excludes only.Return the slice of entries which all share the same prefix, or None if there isn’t a single such entry.
If prefix is empty, all entries are returned.
Sourcepub fn prefixed_entries_range(&self, prefix: &BStr) -> Option<Range<usize>>
Available on crate feature excludes only.
pub fn prefixed_entries_range(&self, prefix: &BStr) -> Option<Range<usize>>
excludes only.Return the range of entries which all share the same prefix, or None if there isn’t a single such entry.
If prefix is empty, the range will include all entries.
Sourcepub fn entry(&self, idx: usize) -> &Entry
Available on crate feature excludes only.
pub fn entry(&self, idx: usize) -> &Entry
excludes only.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().
Sourcepub fn is_sparse(&self) -> bool
Available on crate feature excludes only.
pub fn is_sparse(&self) -> bool
excludes only.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.
Sourcepub fn entry_range(&self, path: &BStr) -> Option<Range<usize>>
Available on crate feature excludes only.
pub fn entry_range(&self, path: &BStr) -> Option<Range<usize>>
excludes only.Return the range of entries that exactly match the given path, in all available stages, or None if no entry with such
path exists.
The range can be used to access the respective entries via entries() or `entries_mut().
Sourcepub fn return_path_backing(&mut self, backing: Vec<u8>)
Available on crate feature excludes only.
pub fn return_path_backing(&mut self, backing: Vec<u8>)
excludes only.After usage of the storage obtained by take_path_backing(), return it here.
Note that it must not be empty.
Sourcepub fn entries_mut(&mut self) -> &mut [Entry]
Available on crate feature excludes only.
pub fn entries_mut(&mut self) -> &mut [Entry]
excludes only.Return mutable entries in a slice.
Sourcepub fn entries_mut_and_pathbacking(&mut self) -> (&mut [Entry], &[u8])
Available on crate feature excludes only.
pub fn entries_mut_and_pathbacking(&mut self) -> (&mut [Entry], &[u8])
excludes only.Return a writable slice to entries and read-access to their path storage at the same time.
Sourcepub fn entries_mut_with_paths(
&mut self,
) -> impl Iterator<Item = (&mut Entry, &BStr)>
Available on crate feature excludes only.
pub fn entries_mut_with_paths( &mut self, ) -> impl Iterator<Item = (&mut Entry, &BStr)>
excludes only.Return mutable entries along with their paths in an iterator.
Sourcepub fn take_path_backing(&mut self) -> Vec<u8> ⓘ
Available on crate feature excludes only.
pub fn take_path_backing(&mut self) -> Vec<u8> ⓘ
excludes only.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.
Sourcepub fn entry_mut_by_path_and_stage(
&mut self,
path: &BStr,
stage: Stage,
) -> Option<&mut Entry>
Available on crate feature excludes only.
pub fn entry_mut_by_path_and_stage( &mut self, path: &BStr, stage: Stage, ) -> Option<&mut Entry>
excludes only.Like entry_index_by_path_and_stage(),
but returns the mutable entry instead of the index.
Sourcepub fn dangerously_push_entry(
&mut self,
stat: Stat,
id: ObjectId,
flags: Flags,
mode: Mode,
path: &BStr,
)
Available on crate feature excludes only.
pub fn dangerously_push_entry( &mut self, stat: Stat, id: ObjectId, flags: Flags, mode: Mode, path: &BStr, )
excludes only.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.
Sourcepub fn sort_entries(&mut self)
Available on crate feature excludes only.
pub fn sort_entries(&mut self)
excludes only.Unconditionally sort entries as needed to perform lookups quickly.
Sourcepub fn sort_entries_by(
&mut self,
compare: impl FnMut(&Entry, &Entry) -> Ordering,
)
Available on crate feature excludes only.
pub fn sort_entries_by( &mut self, compare: impl FnMut(&Entry, &Entry) -> Ordering, )
excludes only.Similar to sort_entries(), but applies compare after comparing
by path and stage as a third criteria.
Sourcepub fn remove_entries(
&mut self,
should_remove: impl FnMut(usize, &BStr, &mut Entry) -> bool,
)
Available on crate feature excludes only.
pub fn remove_entries( &mut self, should_remove: impl FnMut(usize, &BStr, &mut Entry) -> bool, )
excludes only.Physically remove all entries for which should_remove(idx, path, entry) returns true, traversing them from first to last.
Note that the memory used for the removed entries paths is not freed, as it’s append-only, and that some extensions might refer to paths which are now deleted.
§Performance
To implement this operation typically, one would rather add entry::Flags::REMOVE to each entry to remove them when writing the index.
Sourcepub fn remove_entry_at_index(&mut self, index: usize) -> Entry
Available on crate feature excludes only.
pub fn remove_entry_at_index(&mut self, index: usize) -> Entry
excludes only.Physically remove the entry at index, or panic if the entry didn’t exist.
This call is typically made after looking up index, so it’s clear that it will not panic.
Note that the memory used for the removed entries paths is not freed, as it’s append-only, and that some extensions might refer to paths which are now deleted.
Sourcepub fn tree(&self) -> Option<&Tree>
Available on crate feature excludes only.
pub fn tree(&self) -> Option<&Tree>
excludes only.Access the tree extension.
Sourcepub fn remove_tree(&mut self) -> Option<Tree>
Available on crate feature excludes only.
pub fn remove_tree(&mut self) -> Option<Tree>
excludes only.Remove the tree extension.
Sourcepub fn link(&self) -> Option<&Link>
Available on crate feature excludes only.
pub fn link(&self) -> Option<&Link>
excludes only.Access the link extension.
Sourcepub fn resolve_undo(&self) -> Option<&Vec<ResolvePath>>
Available on crate feature excludes only.
pub fn resolve_undo(&self) -> Option<&Vec<ResolvePath>>
excludes only.Obtain the resolve-undo extension.
Sourcepub fn remove_resolve_undo(&mut self) -> Option<Vec<ResolvePath>>
Available on crate feature excludes only.
pub fn remove_resolve_undo(&mut self) -> Option<Vec<ResolvePath>>
excludes only.Remove the resolve-undo extension.
Sourcepub fn untracked(&self) -> Option<&UntrackedCache>
Available on crate feature excludes only.
pub fn untracked(&self) -> Option<&UntrackedCache>
excludes only.Obtain the untracked extension.
Sourcepub fn fs_monitor(&self) -> Option<&FsMonitor>
Available on crate feature excludes only.
pub fn fs_monitor(&self) -> Option<&FsMonitor>
excludes only.Obtain the fsmonitor extension.
Sourcepub fn had_end_of_index_marker(&self) -> bool
Available on crate feature excludes only.
pub fn had_end_of_index_marker(&self) -> bool
excludes only.Return true if the end-of-index extension was present when decoding this index.
Sourcepub fn had_offset_table(&self) -> bool
Available on crate feature excludes only.
pub fn had_offset_table(&self) -> bool
excludes only.Return true if the offset-table extension was present when decoding this index.
Sourcepub fn verify_entries(&self) -> Result<(), Error>
Available on crate feature excludes only.
pub fn verify_entries(&self) -> Result<(), Error>
excludes only.Assure our entries are consistent.
Trait Implementations§
Source§impl Clone for IndexPersistedOrInMemory
impl Clone for IndexPersistedOrInMemory
Source§fn clone(&self) -> IndexPersistedOrInMemory
fn clone(&self) -> IndexPersistedOrInMemory
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more