pub struct Store { /* private fields */ }Expand description
A local LFS object store rooted at <lfs_dir> (typically .git/lfs).
May reference any number of alternate stores — typically the LFS
objects of a git clone --shared source — and will materialize a
hit from one of them into the local store on demand. See
Store::with_references.
Implementations§
Source§impl Store
impl Store
Sourcepub fn new(lfs_dir: impl Into<PathBuf>) -> Self
pub fn new(lfs_dir: impl Into<PathBuf>) -> Self
Create a store rooted at the given LFS directory. The directory is not created eagerly; subdirectories are created on demand as objects land.
Sourcepub fn with_references(self, refs: impl IntoIterator<Item = PathBuf>) -> Self
pub fn with_references(self, refs: impl IntoIterator<Item = PathBuf>) -> Self
Attach alternate lfs/objects/ directories that the store may
hardlink-or-copy from when a local lookup misses. Used by
git clone --shared setups so the new repo can read the
source’s existing LFS objects without re-downloading.
Pass git_lfs_git::lfs_alternate_dirs
(<git-dir>/objects/info/alternates resolved to LFS-objects
dirs) at construction.
Sourcepub fn object_path(&self, oid: Oid) -> PathBuf
pub fn object_path(&self, oid: Oid) -> PathBuf
Where the object with this OID lives on disk.
For Oid::EMPTY this returns the platform null device, mirroring
upstream’s behavior so callers can open an empty object without
special-casing.
Sourcepub fn contains(&self, oid: Oid) -> bool
pub fn contains(&self, oid: Oid) -> bool
true if this object is present locally as a regular file. The empty
OID is always considered present. If the local copy is missing but
an alternate store has the object, materializes it locally first.
Sourcepub fn contains_with_size(&self, oid: Oid, size: u64) -> bool
pub fn contains_with_size(&self, oid: Oid, size: u64) -> bool
true if the object is present and its on-disk size matches size.
Used to detect partial/corrupted local copies. Like
contains, will fault in a matching alternate-store
object on demand.
Sourcepub fn each_object(&self) -> Result<Vec<(Oid, u64)>>
pub fn each_object(&self) -> Result<Vec<(Oid, u64)>>
Walk every object file in the store, yielding (oid, size_on_disk).
Traverses the sharded objects/<aa>/<bb>/<oid> layout. Filenames
that don’t parse as 64-char SHA-256 hex are silently skipped, as
are unexpected directories. The store directory not existing is
not an error — the result is just empty.
Used by git lfs prune and (eventually) fsck --orphaned.
Sourcepub fn open(&self, oid: Oid) -> Result<File>
pub fn open(&self, oid: Oid) -> Result<File>
Open an object for reading. Errors with io::ErrorKind::NotFound
if the object isn’t in the store. Faults in from a reference
store if needed.
Sourcepub fn insert(&self, src: &mut impl Read) -> Result<(Oid, u64), StoreError>
pub fn insert(&self, src: &mut impl Read) -> Result<(Oid, u64), StoreError>
Stream src into the store, computing SHA-256 as we go.
Returns the resulting OID and byte count.
This is the clean-filter path: we don’t know the OID until after the content is hashed.
Sourcepub fn insert_verified(
&self,
expected: Oid,
src: &mut impl Read,
) -> Result<u64, StoreError>
pub fn insert_verified( &self, expected: Oid, src: &mut impl Read, ) -> Result<u64, StoreError>
Stream src into the store, requiring the resulting hash to equal
expected. On mismatch, returns StoreError::HashMismatch and the
temp file is dropped without being committed.
This is the download path: we know the OID upfront and must verify what the server sent.