pub struct Odb<'repo> { /* private fields */ }
Expand description
A structure to represent a git object database
Implementations
sourceimpl<'repo> Odb<'repo>
impl<'repo> Odb<'repo>
sourcepub fn reader(
&self,
oid: Oid
) -> Result<(OdbReader<'_>, usize, ObjectType), Error>
pub fn reader(
&self,
oid: Oid
) -> Result<(OdbReader<'_>, usize, ObjectType), Error>
Create object database reading stream.
Note that most backends do not support streaming reads because they store their objects as compressed/delta’ed blobs.
If the backend does not support streaming reads, use the read
method instead.
sourcepub fn writer(
&self,
size: usize,
obj_type: ObjectType
) -> Result<OdbWriter<'_>, Error>
pub fn writer(
&self,
size: usize,
obj_type: ObjectType
) -> Result<OdbWriter<'_>, Error>
Create object database writing stream.
The type and final length of the object must be specified when opening the stream.
If the backend does not support streaming writes, use the write
method instead.
sourcepub fn foreach<C>(&self, callback: C) -> Result<(), Error> where
C: FnMut(&Oid) -> bool,
pub fn foreach<C>(&self, callback: C) -> Result<(), Error> where
C: FnMut(&Oid) -> bool,
Iterate over all objects in the object database.s
sourcepub fn read_header(&self, oid: Oid) -> Result<(usize, ObjectType), Error>
pub fn read_header(&self, oid: Oid) -> Result<(usize, ObjectType), Error>
Reads the header of an object from the database without reading the full content.
sourcepub fn write(&self, kind: ObjectType, data: &[u8]) -> Result<Oid, Error>
pub fn write(&self, kind: ObjectType, data: &[u8]) -> Result<Oid, Error>
Write an object to the database.
sourcepub fn packwriter(&self) -> Result<OdbPackwriter<'_>, Error>
pub fn packwriter(&self) -> Result<OdbPackwriter<'_>, Error>
Create stream for writing a pack file to the ODB
sourcepub fn exists_ext(&self, oid: Oid, flags: OdbLookupFlags) -> bool
pub fn exists_ext(&self, oid: Oid, flags: OdbLookupFlags) -> bool
Checks if the object database has an object, with extended flags.
sourcepub fn exists_prefix(&self, short_oid: Oid, len: usize) -> Result<Oid, Error>
pub fn exists_prefix(&self, short_oid: Oid, len: usize) -> Result<Oid, Error>
Potentially finds an object that starts with the given prefix.
sourcepub fn refresh(&self) -> Result<(), Error>
pub fn refresh(&self) -> Result<(), Error>
Refresh the object database. This should never be needed, and is provided purely for convenience. The object database will automatically refresh when an object is not found when requested.
sourcepub fn add_disk_alternate(&self, path: &str) -> Result<(), Error>
pub fn add_disk_alternate(&self, path: &str) -> Result<(), Error>
Adds an alternate disk backend to the object database.
sourcepub fn add_new_mempack_backend<'odb>(
&'odb self,
priority: i32
) -> Result<Mempack<'odb>, Error>
pub fn add_new_mempack_backend<'odb>(
&'odb self,
priority: i32
) -> Result<Mempack<'odb>, Error>
Create a new mempack backend, and add it to this odb with the given priority. Higher values give the backend higher precedence. The default loose and pack backends have priorities 1 and 2 respectively (hard-coded in libgit2). A reference to the new mempack backend is returned on success. The lifetime of the backend must be contained within the lifetime of this odb, since deletion of the odb will also result in deletion of the mempack backend.
Here is an example that fails to compile because it tries to hold the mempack reference beyond the odb’s lifetime:
use git2::Odb;
let mempack = {
let odb = Odb::new().unwrap();
odb.add_new_mempack_backend(1000).unwrap()
};
Trait Implementations
impl<'repo> Send for Odb<'repo>
impl<'repo> Sync for Odb<'repo>
Auto Trait Implementations
impl<'repo> RefUnwindSafe for Odb<'repo>
impl<'repo> Unpin for Odb<'repo>
impl<'repo> UnwindSafe for Odb<'repo>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more