pub struct RepoScopes { /* private fields */ }Expand description
Buffer name → the repository that buffer acts on.
The DocumentId index is not redundant with the name map:
Event::DocumentClosed carries a DocumentId, and the two are not
interchangeable — the same reason ProjectDiffService keeps its own
by_document.
Implementations§
Source§impl RepoScopes
impl RepoScopes
Sourcepub fn set_resolver(&self, resolver: ProjectResolverHandle)
pub fn set_resolver(&self, resolver: ProjectResolverHandle)
PR.5: hand the resolver over at boot.
Separate from construction because RepoScopes is built in
magit’s install, and the resolver is a service looked up from
the same boot — a constructor argument would just move the
Option to the call site.
Sourcepub fn discovery_start(&self) -> Option<PathBuf>
pub fn discovery_start(&self) -> Option<PathBuf>
PR.5: where step 3 starts discovering from.
The bug this fixes: magit’s fallback was
Repository::discover(".") — the process’s working
directory. :cd sets editor.current_dir and never calls
set_current_dir, so after :cd /other/repo a fresh C-x g
still opened the repository the editor was launched in.
Returns a directory to discover from, not an answer: magit
needs a git worktree specifically, and the project root may not
be one. gix walking up from here preserves “None when not in a
repository” exactly as before.
Sourcepub fn record(&self, name: impl Into<String>, workdir: PathBuf)
pub fn record(&self, name: impl Into<String>, workdir: PathBuf)
Record (or re-point) the repository name acts on.
Overwrites rather than accumulating: re-triggering C-x g for a
repository must find the buffer you already have, not stack a
second record behind it.
Sourcepub fn workdir_for(&self, name: &str) -> Option<PathBuf>
pub fn workdir_for(&self, name: &str) -> Option<PathBuf>
The repository name acts on, if one was recorded.
None is a real answer, not a bug: a magit buffer reopened by
:b after a restart has a name but no record, and the view falls
back to resolving from scratch.
Sourcepub fn workdir_for_label(&self, label: &str) -> Option<PathBuf>
pub fn workdir_for_label(&self, label: &str) -> Option<PathBuf>
MR.3b: the repository behind a label, recovered from any magit buffer already recorded against it.
This is what lets a view opened from inside another magit
buffer — <CR> on a commit in the log, a file at a revision —
name itself correctly without reaching for services it does not
have. Those producers sit in helpers holding only their own
buffer’s state, so all they can carry across is the label their
own name already spells; this turns that label back into a path.
Sound because labels are unique among open magit buffers by
construction: two checkouts sharing a basename qualify at the
trigger (RepoScopes::collides) precisely so that one label
never names two repositories at once.
Sourcepub fn collides(&self, name: &str, workdir: &Path) -> bool
pub fn collides(&self, name: &str, workdir: &Path) -> bool
Is name already recorded against a different repository?
The collision question, asked by the trigger before it settles on a name. Merging two repositories into one buffer is the worst outcome available here — the staging chords would act on whichever was recorded last (design §3.1).
Sourcepub fn index_document(&self, document: DocumentId, name: impl Into<String>)
pub fn index_document(&self, document: DocumentId, name: impl Into<String>)
Index the document behind name, so closing the buffer drops the
record. Called by the view when it activates — the first moment
the document exists.
Sourcepub fn forget_by_document_id(&self, document: DocumentId) -> bool
pub fn forget_by_document_id(&self, document: DocumentId) -> bool
Cleanup entry point for the DocumentClosed subscriber.
Returns whether anything was dropped, which is what makes the wiring testable without reaching into the maps.
Trait Implementations§
Source§impl BufferScopeSource for RepoScopes
PR.6: RepoScopes already answers “which repository is the buffer called
this acting on” — which is exactly what the editor’s generic project
resolution needs from a buffer that has no path.
impl BufferScopeSource for RepoScopes
PR.6: RepoScopes already answers “which repository is the buffer called
this acting on” — which is exactly what the editor’s generic project
resolution needs from a buffer that has no path.
Implementing the trait rather than having the host read RepoScopesHandle
keeps a magit-specific service out of generic host code: the host learns a
directory and never learns whose, or that git was involved.
It works for every magit view at once — status, diff, log, stash, blame — because they all record through the same map.
Source§impl Debug for RepoScopes
impl Debug for RepoScopes
Source§impl Default for RepoScopes
impl Default for RepoScopes
Source§fn default() -> RepoScopes
fn default() -> RepoScopes
Auto Trait Implementations§
impl !Freeze for RepoScopes
impl RefUnwindSafe for RepoScopes
impl Send for RepoScopes
impl Sync for RepoScopes
impl Unpin for RepoScopes
impl UnsafeUnpin for RepoScopes
impl UnwindSafe for RepoScopes
Blanket Implementations§
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> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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