From 303564ca2b724b62ea55db8c4eaf8b2cd43c0e97 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 28 Sep 2024 21:49:37 +0900 Subject: [PATCH] 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 ::base_repo() can't return &Arc<_>. --- lib/src/repo.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index d4293756c..6a0398248 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -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; fn op_store(&self) -> &Arc; @@ -312,6 +316,10 @@ impl ReadonlyRepo { } impl Repo for ReadonlyRepo { + fn base_repo(&self) -> &ReadonlyRepo { + self + } + fn store(&self) -> &Arc { 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 { self.base_repo.store() }