Skip to main content

Odb

Struct Odb 

Source
pub struct Odb { /* private fields */ }
Expand description

A loose-object database rooted at a given objects/ directory.

Implementations§

Source§

impl Odb

Source

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.

Source

pub fn with_work_tree(objects_dir: &Path, work_tree: &Path) -> Self

Create an Odb with a work tree for resolving relative alternate paths.

Source

pub fn objects_dir(&self) -> &Path

Return the path to the objects/ directory.

Source

pub fn object_path(&self, oid: &ObjectId) -> PathBuf

Return the filesystem path for a given object ID.

Source

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

Source

pub fn exists(&self, oid: &ObjectId) -> bool

Check whether an object exists in the loose store or any pack file.

Source

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.

Source

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
Source

pub fn read(&self, oid: &ObjectId) -> Result<Object>

Read and decompress an object from the loose store.

§Errors
Source

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.

Source

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.
Source

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

Trait Implementations§

Source§

impl Clone for Odb

Source§

fn clone(&self) -> Odb

Returns a duplicate 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 Odb

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Odb

§

impl RefUnwindSafe for Odb

§

impl Send for Odb

§

impl Sync for Odb

§

impl Unpin for Odb

§

impl UnsafeUnpin for Odb

§

impl UnwindSafe for Odb

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.