repo: add generic Repo::base_repo() to access current operation from revset

This isn't fancy, but I couldn't find a better abstraction. Note that
MutableRepo::base_repo() isn't removed as it has to return &Arc<_>, whereas
<ReadonlyRepo as Repo>::base_repo() can't return &Arc<_>.
This commit is contained in:
Yuya Nishihara 2024-09-28 21:49:37 +09:00
parent c6568787f3
commit 303564ca2b

View file

@ -98,6 +98,10 @@ use crate::view::RenameWorkspaceError;
use crate::view::View;
pub trait Repo {
/// Base repository that contains all committed data. Returns `self` if this
/// is a `ReadonlyRepo`,
fn base_repo(&self) -> &ReadonlyRepo;
fn store(&self) -> &Arc<Store>;
fn op_store(&self) -> &Arc<dyn OpStore>;
@ -312,6 +316,10 @@ impl ReadonlyRepo {
}
impl Repo for ReadonlyRepo {
fn base_repo(&self) -> &ReadonlyRepo {
self
}
fn store(&self) -> &Arc<Store> {
self.loader.store()
}
@ -1821,6 +1829,10 @@ impl MutableRepo {
}
impl Repo for MutableRepo {
fn base_repo(&self) -> &ReadonlyRepo {
&self.base_repo
}
fn store(&self) -> &Arc<Store> {
self.base_repo.store()
}