Struct git2::Odb

source ·
pub struct Odb<'repo> { /* private fields */ }
Expand description

A structure to represent a git object database

Implementations§

source§

impl<'repo> Odb<'repo>

source

pub fn new<'a>() -> Result<Odb<'a>, Error>

Creates an object database without any backends.

source

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.

source

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.

source

pub fn foreach<C>(&self, callback: C) -> Result<(), Error>
where C: FnMut(&Oid) -> bool,

Iterate over all objects in the object database.s

source

pub fn read(&self, oid: Oid) -> Result<OdbObject<'_>, Error>

Read an object from the database.

source

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.

source

pub fn write(&self, kind: ObjectType, data: &[u8]) -> Result<Oid, Error>

Write an object to the database.

source

pub fn packwriter(&self) -> Result<OdbPackwriter<'_>, Error>

Create stream for writing a pack file to the ODB

source

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

Checks if the object database has an object.

source

pub fn exists_ext(&self, oid: Oid, flags: OdbLookupFlags) -> bool

Checks if the object database has an object, with extended flags.

source

pub fn exists_prefix(&self, short_oid: Oid, len: usize) -> Result<Oid, Error>

Potentially finds an object that starts with the given prefix.

source

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.

source

pub fn add_disk_alternate(&self, path: &str) -> Result<(), Error>

Adds an alternate disk backend to the object database.

source

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§

source§

impl<'repo> Drop for Odb<'repo>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'repo> Send for Odb<'repo>

source§

impl<'repo> Sync for Odb<'repo>

Auto Trait Implementations§

§

impl<'repo> Freeze for Odb<'repo>

§

impl<'repo> RefUnwindSafe for Odb<'repo>

§

impl<'repo> Unpin for Odb<'repo>

§

impl<'repo> UnwindSafe for Odb<'repo>

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

§

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>,

§

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.