pub struct Git2DB { /* private fields */ }Expand description
Git-based model registry using submodules (unified implementation)
Implementations§
Source§impl Git2DB
impl Git2DB
Sourcepub async fn open<P: AsRef<Path>>(base_dir: P) -> Git2DBResult<Self>
pub async fn open<P: AsRef<Path>>(base_dir: P) -> Git2DBResult<Self>
Initialize or open the registry
Sourcepub async fn add_repository(
&mut self,
name: &str,
url: &str,
) -> Git2DBResult<RepoId>
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 repositoryurl- 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?;Sourcepub 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
pub async fn register_repository( &mut self, repo_id: &RepoId, name: Option<String>, url: String, ) -> Git2DBResult<()>
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?;Sourcepub async fn remove_repository(&mut self, id: &RepoId) -> Git2DBResult<()>
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?;Sourcepub async fn upsert_repository(
&mut self,
name: &str,
url: &str,
) -> Git2DBResult<RepoId>
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);Sourcepub async fn update_repository(
&mut self,
id: &RepoId,
new_url: Option<String>,
) -> Git2DBResult<()>
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?;Sourcepub fn register<'a>(&'a mut self, repo_id: RepoId) -> RegistrationBuilder<'a>
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?;Sourcepub fn list(&self) -> impl Iterator<Item = &TrackedRepository>
pub fn list(&self) -> impl Iterator<Item = &TrackedRepository>
List all repositories in the registry
Sourcepub fn get_by_name(&self, name: &str) -> Option<&TrackedRepository>
pub fn get_by_name(&self, name: &str) -> Option<&TrackedRepository>
Get repository by name
Sourcepub fn get_by_id(&self, id: &RepoId) -> Option<&TrackedRepository>
pub fn get_by_id(&self, id: &RepoId) -> Option<&TrackedRepository>
Get repository by ID
Sourcepub fn get_worktree_path(&self, id: &RepoId) -> Option<PathBuf>
pub fn get_worktree_path(&self, id: &RepoId) -> Option<PathBuf>
Get repository worktree path
Sourcepub fn repo(&self, id: &RepoId) -> Git2DBResult<RepositoryHandle<'_>>
pub fn repo(&self, id: &RepoId) -> Git2DBResult<RepositoryHandle<'_>>
Get a handle to a repository by ID
Sourcepub fn repo_by_name(&self, name: &str) -> Git2DBResult<RepositoryHandle<'_>>
pub fn repo_by_name(&self, name: &str) -> Git2DBResult<RepositoryHandle<'_>>
Get a handle to a repository by name
Sourcepub fn registry_path(&self) -> &Path
pub fn registry_path(&self) -> &Path
Get registry path
Source§impl Git2DB
impl Git2DB
Sourcepub async fn start_transaction(&self) -> Git2DBResult<TransactionHandle>
pub async fn start_transaction(&self) -> Git2DBResult<TransactionHandle>
Sourcepub async fn start_transaction_with_mode(
&self,
mode: IsolationMode,
) -> Git2DBResult<TransactionHandle>
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?;Sourcepub async fn transaction<F, Fut, R>(&mut self, f: F) -> Git2DBResult<R>
👎Deprecated since 2.1.0: Use start_transaction() instead
pub async fn transaction<F, Fut, R>(&mut self, f: F) -> Git2DBResult<R>
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§
impl Freeze for Git2DB
impl !RefUnwindSafe for Git2DB
impl Send for Git2DB
impl Sync for Git2DB
impl Unpin for Git2DB
impl UnsafeUnpin for Git2DB
impl !UnwindSafe for Git2DB
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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