pub struct RepoManager { /* private fields */ }Expand description
Manages the set of active repositories and worktrees for the daemon.
The manager keeps at most max_active worktrees in the active set. When
this limit is exceeded, evict_idle removes the
least-recently-used entries.
Implementations§
Source§impl RepoManager
impl RepoManager
Sourcepub fn new(
layout: StorageLayout,
max_active: usize,
) -> Result<Self, ManagerError>
pub fn new( layout: StorageLayout, max_active: usize, ) -> Result<Self, ManagerError>
Create a new RepoManager.
max_active controls the upper bound on concurrently tracked worktrees.
The persistent ProjectRegistry is loaded from the storage layout; if
the registry file does not yet exist an empty registry is used.
Sourcepub async fn register(
&self,
root_path: &Path,
) -> Result<WorktreeId, ManagerError>
pub async fn register( &self, root_path: &Path, ) -> Result<WorktreeId, ManagerError>
Register a worktree by its root path.
Computes the WorktreeId from the path, adds the worktree to the
persistent registry, and inserts it into the active set with
WorktreeStatus::Idle.
Returns the computed WorktreeId on success.
§Errors
ManagerError::AlreadyRegisteredif the worktree is already active.ManagerError::Storageif theWorktreeIdcannot be computed or the registry cannot be persisted.
Sourcepub async fn get(&self, worktree_id: &WorktreeId) -> Option<WorktreeHandle>
pub async fn get(&self, worktree_id: &WorktreeId) -> Option<WorktreeHandle>
Retrieve a clone of the WorktreeHandle for the given identity.
Returns None if the worktree is not in the active set.
Sourcepub async fn touch(&self, worktree_id: &WorktreeId)
pub async fn touch(&self, worktree_id: &WorktreeId)
Update the last_accessed timestamp for an active worktree, keeping it
alive during LRU eviction.
Sourcepub async fn list_active(&self) -> Vec<WorktreeHandle>
pub async fn list_active(&self) -> Vec<WorktreeHandle>
List all active worktree handles.
The returned vector is in no particular order.
Sourcepub async fn evict_idle(&self) -> Vec<WorktreeId>
pub async fn evict_idle(&self) -> Vec<WorktreeId>
Evict the least-recently-used worktrees when the active set exceeds
max_active.
Only worktrees with WorktreeStatus::Idle or WorktreeStatus::Ready
are eligible for eviction; actively indexing worktrees are skipped.
Returns the list of evicted WorktreeIds.
Sourcepub async fn unregister(&self, worktree_id: &WorktreeId) -> bool
pub async fn unregister(&self, worktree_id: &WorktreeId) -> bool
Remove a worktree from the active set and the persistent registry.
Returns true if the worktree was present and removed, false
otherwise.
Sourcepub async fn set_status(
&self,
worktree_id: &WorktreeId,
status: WorktreeStatus,
) -> Result<(), ManagerError>
pub async fn set_status( &self, worktree_id: &WorktreeId, status: WorktreeStatus, ) -> Result<(), ManagerError>
Update the WorktreeStatus for an active worktree.
§Errors
Returns ManagerError::NotFound if the worktree is not in the active
set.
Sourcepub async fn active_count(&self) -> usize
pub async fn active_count(&self) -> usize
Return the number of currently active worktrees.
Sourcepub const fn max_active(&self) -> usize
pub const fn max_active(&self) -> usize
Return the configured maximum number of active worktrees.