Skip to main content

Git2DB

Struct Git2DB 

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

Git-based model registry using submodules (unified implementation)

Implementations§

Source§

impl Git2DB

Source

pub fn storage_driver(&self) -> &Arc<dyn Driver> ⓘ

Get the pre-loaded storage driver for this registry

Source

pub fn version(&self) -> &str

Get the registry version

Returns the version string from the registry metadata.

Source§

impl Git2DB

Source

pub async fn open<P: AsRef<Path>>(base_dir: P) -> Git2DBResult<Self>

Initialize or open the registry

Source

pub async fn add_repository( &mut self, name: &str, url: &str, ) -> Git2DBResult<RepoId>

Add a repository to the registry

Clones the repository and registers it with the given name. Names must be unique - attempting to add a repository with a duplicate name will fail.

§Arguments
  • name - Unique name for the repository
  • url - Git URL to clone from
§Returns

The UUID (RepoId) of the newly added repository

§Examples
ⓘ
let id = registry.add_repository("myrepo", "https://github.com/user/repo.git").await?;
Source

pub async fn register_repository( &mut self, repo_id: &RepoId, name: Option<String>, url: String, ) -> Git2DBResult<()>

👎Deprecated since 2.1.0:

Use registry.register(repo_id) builder instead

Register a repository that was cloned to a UUID directory

DEPRECATED: Use registry.register(repo_id) builder instead.

This method assumes the repository is at base_dir/{uuid}/ which doesn’t work for worktrees at custom paths. Use the builder for flexibility:

ⓘ
registry.register(repo_id)
    .name("my-repo")
    .worktree_path(actual_path)
    .exec().await?;
Source

pub async fn remove_repository(&mut self, id: &RepoId) -> Git2DBResult<()>

Remove a repository from the registry with complete cleanup

This performs proper git submodule cleanup including:

  • Removes from .gitmodules
  • Removes from .git/config
  • Removes .git/modules/{id}/ directory
  • Removes working directory
  • Removes from registry metadata

Similar to git submodule deinit --force <name> && git rm --force <name>

§Examples
registry.remove_repository(id).await?;
Source

pub async fn upsert_repository( &mut self, name: &str, url: &str, ) -> Git2DBResult<RepoId>

Upsert a repository by name (add if missing, return existing if present)

This operation embodies git’s philosophy that “something is there but maybe you just don’t know it yet”. If a repository with the given name exists, returns its ID. Otherwise, clones and registers it.

§Examples
// First call clones the repository
let id1 = registry.upsert_repository("my-repo", "https://github.com/user/repo.git").await?;

// Second call returns the same ID without cloning
let id2 = registry.upsert_repository("my-repo", "https://github.com/user/repo.git").await?;
assert_eq!(id1, id2);
Source

pub async fn update_repository( &mut self, id: &RepoId, new_url: Option<String>, ) -> Git2DBResult<()>

Update a repository’s configuration

Allows updating URL, tracking ref, or remotes for an existing repository.

§Examples
ⓘ
// Update the primary URL
registry.update_repository(id, Some("https://new-host.com/repo.git".to_owned())).await?;

// Refresh without changing URL
registry.update_repository(id, None).await?;
Source

pub fn register<'a>(&'a mut self, repo_id: RepoId) -> RegistrationBuilder<'a>

Register an existing repository or worktree using fluent builder API

Returns a builder for configuring registration parameters. Use this to register repos/worktrees at custom paths.

§Examples
ⓘ
// Register a worktree (adapter)
registry.register(adapter_id)
    .name("my-adapter")
    .worktree_path(worktree_path)
    .tracking_ref(GitRef::Branch("adapter/uuid".to_owned()))
    .metadata("type", "adapter")
    .exec()
    .await?;
Source

pub fn base_dir(&self) -> &Path

Get the base directory where repositories are stored

Source

pub fn list(&self) -> impl Iterator<Item = &TrackedRepository>

List all repositories in the registry

Source

pub fn get_by_name(&self, name: &str) -> Option<&TrackedRepository>

Get repository by name

Source

pub fn get_by_id(&self, id: &RepoId) -> Option<&TrackedRepository>

Get repository by ID

Source

pub fn get_worktree_path(&self, id: &RepoId) -> Option<PathBuf>

Get repository worktree path

Source

pub fn repo(&self, id: &RepoId) -> Git2DBResult<RepositoryHandle<'_>>

Get a handle to a repository by ID

Source

pub fn repo_by_name(&self, name: &str) -> Git2DBResult<RepositoryHandle<'_>>

Get a handle to a repository by name

Source

pub fn registry_path(&self) -> &Path

Get registry path

Source§

impl Git2DB

Source

pub async fn start_transaction(&self) -> Git2DBResult<TransactionHandle>

Start a new transaction with default isolation (CopyOnWrite)

§Examples
ⓘ
let tx = registry.start_transaction().await?;
let id = tx.clone_repo("my-repo", "https://github.com/user/repo.git").await?;
tx.commit().await?;
Source

pub async fn start_transaction_with_mode( &self, mode: IsolationMode, ) -> Git2DBResult<TransactionHandle>

Start a transaction with specific isolation mode

§Examples
ⓘ
use git2db::IsolationMode;

// Full worktree isolation for maximum safety
let tx = registry.start_transaction_with_mode(IsolationMode::Worktree).await?;

// Optimistic mode for maximum performance
let tx = registry.start_transaction_with_mode(IsolationMode::Optimistic).await?;
Source

pub async fn transaction<F, Fut, R>(&mut self, f: F) -> Git2DBResult<R>
where F: FnOnce(&mut Transaction<'_>) -> Fut, Fut: Future<Output = Git2DBResult<R>>,

👎Deprecated since 2.1.0:

Use start_transaction() instead

Deprecated v2.0 API - provided for backward compatibility

Use start_transaction() instead for the new Arc-based API.

Auto Trait Implementations§

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
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

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.

§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

§

const WITNESS: W = W::MAKE

A constant of the type witness
§

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

§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSync for T
where T: Sync,

§

impl<T> MaybeSync for T
where T: Sync,