pub struct Odb { /* private fields */ }Expand description
A loose-object database rooted at a given objects/ directory.
Implementations§
Source§impl Odb
impl Odb
Sourcepub fn new(objects_dir: &Path) -> Self
pub fn new(objects_dir: &Path) -> Self
Create an Odb pointing at the given objects/ directory.
The directory does not need to exist yet; it will be created on the first write operation.
Sourcepub fn with_work_tree(objects_dir: &Path, work_tree: &Path) -> Self
pub fn with_work_tree(objects_dir: &Path, work_tree: &Path) -> Self
Create an Odb with a work tree for resolving relative alternate paths.
Sourcepub fn objects_dir(&self) -> &Path
pub fn objects_dir(&self) -> &Path
Return the path to the objects/ directory.
Sourcepub fn object_path(&self, oid: &ObjectId) -> PathBuf
pub fn object_path(&self, oid: &ObjectId) -> PathBuf
Return the filesystem path for a given object ID.
Sourcepub fn exists_local(&self, oid: &ObjectId) -> bool
pub fn exists_local(&self, oid: &ObjectId) -> bool
Whether the object exists under this database directory only (loose or local packs).
Unlike Self::exists, this ignores info/alternates and
GIT_ALTERNATE_OBJECT_DIRECTORIES. Used for partial-clone bookkeeping where
objects reachable via alternates are still treated as “missing” until copied locally.
The empty tree object is treated as present without a loose file (matches Git).
Sourcepub fn exists(&self, oid: &ObjectId) -> bool
pub fn exists(&self, oid: &ObjectId) -> bool
Check whether an object exists in the loose store or any pack file.
Sourcepub fn freshen_object(&self, oid: &ObjectId) -> bool
pub fn freshen_object(&self, oid: &ObjectId) -> bool
Touch the loose object file or pack file containing oid, matching Git’s
odb_freshen_object (updates mtime so age-based prune keeps recently re-referenced objects).
Returns true if an on-disk object was found and touched.
Sourcepub fn read_loose_verify_oid(
path: &Path,
expected_oid: &ObjectId,
) -> Result<Object>
pub fn read_loose_verify_oid( path: &Path, expected_oid: &ObjectId, ) -> Result<Object>
Read a loose object file at path, verifying the uncompressed payload hashes to expected_oid.
Git stores loose objects under paths derived from the OID; if the file contents hash to a
different id (for example after a mistaken mv), this returns Error::LooseHashMismatch.
§Errors
Error::Zlib— decompression failed.Error::CorruptObject— header is malformed.Error::LooseHashMismatch— payload OID does not matchexpected_oid.
Sourcepub fn read(&self, oid: &ObjectId) -> Result<Object>
pub fn read(&self, oid: &ObjectId) -> Result<Object>
Read and decompress an object from the loose store.
§Errors
Error::ObjectNotFound— no file at the expected path.Error::Zlib— decompression failed.Error::CorruptObject— header is malformed.
Sourcepub fn hash_object_data(kind: ObjectKind, data: &[u8]) -> ObjectId
pub fn hash_object_data(kind: ObjectKind, data: &[u8]) -> ObjectId
Hash raw content of a given kind and return the ObjectId.
This does not write anything to disk.
Sourcepub fn write(&self, kind: ObjectKind, data: &[u8]) -> Result<ObjectId>
pub fn write(&self, kind: ObjectKind, data: &[u8]) -> Result<ObjectId>
Write an object to the loose store and return its ObjectId.
If the object already exists it is not overwritten (Git behaviour).
§Errors
Error::Io— could not create the directory or write the file.Error::Zlib— compression failed.
Sourcepub fn write_raw(&self, store_bytes: &[u8]) -> Result<ObjectId>
pub fn write_raw(&self, store_bytes: &[u8]) -> Result<ObjectId>
Write an already-serialized object (header + data) to the loose store.
Useful when the caller has the full store bytes (e.g. from stdin with
--literally).
§Errors
Error::CorruptObject— the provided bytes don’t form a valid header.Error::Io/Error::Zlib— storage errors.