pub struct GitManager { /* private fields */ }Expand description
Centralized Git manager with thread-safe operations
Implementations§
Source§impl GitManager
impl GitManager
Sourcepub fn new(config: Git2DBConfig) -> Self
pub fn new(config: Git2DBConfig) -> Self
Create a new GitManager with the given configuration
Sourcepub fn init_with_config(config: Git2DBConfig) -> Result<(), Git2DBError>
pub fn init_with_config(config: Git2DBConfig) -> Result<(), Git2DBError>
Initialize the global GitManager with a custom configuration
This must be called before the first call to global().
Subsequent calls will return an error to avoid silent configuration changes.
Returns Ok(()) if initialization succeeded, Err if it failed or already initialized.
§Example
use git2db::config::Git2DBConfig;
use git2db::GitManager;
let config = Git2DBConfig::default();
GitManager::init_with_config(config)?;Sourcepub fn global() -> &'static GitManager
pub fn global() -> &'static GitManager
Get the global GitManager instance
If not already initialized via init_with_config(), this will initialize
it with default configuration.
Sourcepub fn config(&self) -> &Git2DBConfig
pub fn config(&self) -> &Git2DBConfig
Get the configuration for this GitManager
Sourcepub fn default_clone_options(&self) -> CloneOptions
pub fn default_clone_options(&self) -> CloneOptions
Create default clone options based on configuration
Sourcepub fn is_initialized() -> bool
pub fn is_initialized() -> bool
Check if the global GitManager has been initialized
Sourcepub fn validate_path(&self, base_dir: &Path, path: &Path) -> Result<PathBuf>
pub fn validate_path(&self, base_dir: &Path, path: &Path) -> Result<PathBuf>
Validate path for security (prevents directory traversal)
Sourcepub fn get_repository<P: AsRef<Path>>(
&self,
path: P,
) -> Git2DBResult<RepositoryCache>
pub fn get_repository<P: AsRef<Path>>( &self, path: P, ) -> Git2DBResult<RepositoryCache>
Get a repository cache handle with intelligent caching
Returns a RepositoryCache that tracks metadata and provides fresh Repository instances on each .open() call (for thread safety with git2).
Sourcepub fn cache_stats(&self) -> CacheStats
pub fn cache_stats(&self) -> CacheStats
Get repository cache statistics
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Clear the entire repository cache
Sourcepub fn cleanup_cache(&self)
pub fn cleanup_cache(&self)
Manually trigger cache cleanup (remove expired entries)
Sourcepub async fn clone_repository(
&self,
url: &str,
target_path: &Path,
options: Option<CloneOptions>,
) -> Git2DBResult<Repository>
pub async fn clone_repository( &self, url: &str, target_path: &Path, options: Option<CloneOptions>, ) -> Git2DBResult<Repository>
Clone a repository with Send-safe async support
Uses spawn_blocking internally to handle git2 operations safely.
§Example
use git2db::clone_options::CloneOptions;
use git2db::callback_config::{CallbackConfigBuilder, ProgressConfig};
use git2db::auth::AuthStrategy;
let options = CloneOptions::builder()
.callback_config(
CallbackConfigBuilder::new()
.auth(AuthStrategy::SshAgent { username: Some("git".to_owned()) })
.progress(ProgressConfig::Stdout)
.build()
)
.shallow(true)
.depth(1)
.build();
let repo = manager.clone_repository(url, path, Some(options)).await?;Sourcepub fn create_signature(
&self,
name: Option<&str>,
email: Option<&str>,
) -> Git2DBResult<Signature<'static>>
pub fn create_signature( &self, name: Option<&str>, email: Option<&str>, ) -> Git2DBResult<Signature<'static>>
Create a signature for commits
Sourcepub fn remove_worktree(
&self,
base_repo_path: &Path,
worktree_name: &str,
base_dir: Option<&Path>,
) -> Git2DBResult<()>
pub fn remove_worktree( &self, base_repo_path: &Path, worktree_name: &str, base_dir: Option<&Path>, ) -> Git2DBResult<()>
Remove a worktree with cleanup
Sourcepub fn list_worktrees(&self, repo_path: &Path) -> Git2DBResult<Vec<String>>
pub fn list_worktrees(&self, repo_path: &Path) -> Git2DBResult<Vec<String>>
List all worktrees for a repository
Sourcepub fn active_operations(&self) -> Vec<(String, Duration)>
pub fn active_operations(&self) -> Vec<(String, Duration)>
Get statistics about cached paths Get active operations
Sourcepub fn register_transport(
&self,
scheme: &str,
factory: Arc<dyn TransportFactory>,
) -> Result<(), Git2DBError>
pub fn register_transport( &self, scheme: &str, factory: Arc<dyn TransportFactory>, ) -> Result<(), Git2DBError>
Register a custom transport for a URL scheme
This allows integration with custom git transports like gittorrent://, ipfs://, s3://, or any other custom protocol using a thread-safe registry.
§Example
use git2db::GitManager;
let manager = GitManager::new(Default::default());
let factory = Arc::new(MyTransportFactory);
manager.register_transport("custom", factory).unwrap();Sourcepub fn unregister_transport(
&self,
scheme: &str,
) -> Option<Arc<dyn TransportFactory>>
pub fn unregister_transport( &self, scheme: &str, ) -> Option<Arc<dyn TransportFactory>>
Unregister a custom transport
Returns the factory if it was registered, None otherwise. Uses reference counting for thread-safe cleanup.
Sourcepub fn has_transport(&self, scheme: &str) -> bool
pub fn has_transport(&self, scheme: &str) -> bool
Check if a custom transport is registered for a given scheme
Sourcepub fn registered_transports(&self) -> Vec<String>
pub fn registered_transports(&self) -> Vec<String>
Get a list of all registered transport schemes
Sourcepub fn transport_stats(&self) -> RegistryStats
pub fn transport_stats(&self) -> RegistryStats
Get transport registry statistics
Sourcepub fn driver_registry(&self) -> &Arc<DriverRegistry> ⓘ
pub fn driver_registry(&self) -> &Arc<DriverRegistry> ⓘ
Get the driver registry
Auto Trait Implementations§
impl Freeze for GitManager
impl !RefUnwindSafe for GitManager
impl Send for GitManager
impl Sync for GitManager
impl Unpin for GitManager
impl UnsafeUnpin for GitManager
impl !UnwindSafe for GitManager
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