gitdataai/libs/git/domain.rs
ZhenYi 14f6e1e500 feat(core): initialize project with access control and AI integration
- Add gitignore and prettier configuration files for project scaffolding
- Implement room access control service with project member verification
- Create user access key management with CRUD operations and activity logging
- Add accordion UI component for frontend expandable sections
- Implement room AI configuration with list, upsert, and delete operations
- Add AI event types for agent join/leave/status change tracking
- Create streaming AI processing services for mode and react patterns
- Build room AI service with model detection and idempotency handling
- Integrate chat service orchestration for AI message processing
- Add typing indicators and stream cancellation for AI interactions
- Implement mention parsing and context extraction for AI agents
2026-05-03 06:04:31 +08:00

59 lines
1.8 KiB
Rust

use std::path::Path;
use std::sync::Arc;
use crate::GitError;
use git2::Repository;
use models::repos::repo;
#[derive(Clone)]
pub struct GitDomain {
pub(crate) repo: Arc<Repository>,
}
// SAFETY: git2's Repository uses internal locking for thread-safe operations.
// We additionally enforce exclusive access via Arc::get_mut in repo_mut().
// All mutable access is gated through the synchronous methods of HookMetaDataSync,
// which are called from a single blocking thread per sync cycle.
#[allow(unsafe_code)]
unsafe impl Send for GitDomain {}
#[allow(unsafe_code)]
unsafe impl Sync for GitDomain {}
impl GitDomain {
pub fn from_model(model: repo::Model) -> crate::GitResult<Self> {
let repo =
Repository::open(model.storage_path).map_err(|e| GitError::Internal(e.to_string()))?;
Ok(Self {
repo: Arc::new(repo),
})
}
pub fn open<P: AsRef<Path>>(path: P) -> crate::GitResult<Self> {
let repo = Repository::open(path).map_err(|e| GitError::Internal(e.to_string()))?;
Ok(Self {
repo: Arc::new(repo),
})
}
pub fn open_bare<P: AsRef<Path>>(path: P) -> crate::GitResult<Self> {
let repo = Repository::open_bare(path).map_err(|e| GitError::Internal(e.to_string()))?;
Ok(Self {
repo: Arc::new(repo),
})
}
pub fn init_bare<P: AsRef<Path>>(path: P) -> crate::GitResult<Self> {
let repo = Repository::init_bare(path).map_err(|e| GitError::Internal(e.to_string()))?;
Ok(Self {
repo: Arc::new(repo),
})
}
pub fn repo(&self) -> &Repository {
&self.repo
}
pub fn repo_mut(&mut self) -> crate::GitResult<&mut Repository> {
Arc::get_mut(&mut self.repo)
.ok_or_else(|| GitError::Internal("GitDomain requires exclusive access".to_string()))
}
}