pub struct CloneBuilder { /* private fields */ }Expand description
Builder for cloning repositories with fluent configuration.
Manages locks internally for minimal lock duration:
- Brief read lock for configuration (base_dir, existing repo check)
- No lock during network clone (the slow part)
- Brief write lock for final registration
§Examples
use git2db::Git2DB;
use std::sync::Arc;
use tokio::sync::RwLock;
let registry = Arc::new(RwLock::new(Git2DB::open("/models").await?));
// Basic clone
let id = git2db::CloneBuilder::new(Arc::clone(®istry), "https://github.com/user/repo.git")
.exec()
.await?;
// Clone with configuration
let id = git2db::CloneBuilder::new(Arc::clone(®istry), "https://github.com/user/repo.git")
.name("my-repo")
.branch("develop")
.depth(1)
.exec()
.await?;Implementations§
Source§impl CloneBuilder
impl CloneBuilder
Sourcepub fn new(registry: Arc<RwLock<Git2DB>>, url: impl Into<String>) -> Self
pub fn new(registry: Arc<RwLock<Git2DB>>, url: impl Into<String>) -> Self
Create a new clone builder.
Sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
Set a custom name for the repository
If not specified, a UUID will be used.
Sourcepub fn branch(self, branch: impl Into<String>) -> Self
pub fn branch(self, branch: impl Into<String>) -> Self
Checkout a specific branch
Similar to git clone --branch <name>
Sourcepub fn tag(self, tag: impl Into<String>) -> Self
pub fn tag(self, tag: impl Into<String>) -> Self
Checkout a specific tag
Similar to git clone --branch <tag>
Sourcepub fn revspec(self, spec: impl Into<String>) -> Self
pub fn revspec(self, spec: impl Into<String>) -> Self
Checkout a specific revspec
Can be branch, tag, commit hash, or complex expressions like HEAD~3
Sourcepub fn remote(self, name: impl Into<String>, url: impl Into<String>) -> Self
pub fn remote(self, name: impl Into<String>, url: impl Into<String>) -> Self
Add an additional remote
The primary URL becomes “origin”. Additional remotes are configured after cloning. Supports gittorrent:// URLs.
§Examples
CloneBuilder::new(Arc::clone(®istry), "https://github.com/user/repo.git")
.remote("backup", "https://backup.com/repo.git")
.remote("p2p", "gittorrent://peer/repo")
.exec()
.await?;Sourcepub fn depth(self, depth: u32) -> Self
pub fn depth(self, depth: u32) -> Self
Create a shallow clone with specific depth
Similar to git clone --depth <n>
Sourcepub fn callback_config(self, config: CallbackConfig) -> Self
pub fn callback_config(self, config: CallbackConfig) -> Self
Set callback configuration for progress reporting and authentication
This allows custom progress callbacks during clone operations.
§Example
use git2db::callback_config::{CallbackConfig, ProgressConfig, ProgressReporter};
use std::sync::Arc;
struct MyReporter;
impl ProgressReporter for MyReporter {
fn report(&self, stage: &str, current: usize, total: usize) {
println!("{}: {}/{}", stage, current, total);
}
}
let config = CallbackConfig::new()
.with_progress(ProgressConfig::Channel(Arc::new(MyReporter)));
CloneBuilder::new(Arc::clone(®istry), "https://github.com/user/repo.git")
.callback_config(config)
.exec()
.await?;Sourcepub async fn exec(self) -> Git2DBResult<RepoId>
pub async fn exec(self) -> Git2DBResult<RepoId>
Execute the clone operation with minimal lock duration.
Lock strategy:
- Read lock: Get config (base_dir, check existing, storage driver)
- No lock: Perform network clone (the slow part)
- Write lock: Register repository
Auto Trait Implementations§
impl Freeze for CloneBuilder
impl !RefUnwindSafe for CloneBuilder
impl Send for CloneBuilder
impl Sync for CloneBuilder
impl Unpin for CloneBuilder
impl UnsafeUnpin for CloneBuilder
impl !UnwindSafe for CloneBuilder
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