Skip to content

Commit

Permalink
repo: add generic Repo::base_repo() to access current operation from …
Browse files Browse the repository at this point in the history
…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<_>.
  • Loading branch information
yuja committed Oct 9, 2024
1 parent 09d91ef commit bf93e59
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -312,6 +316,10 @@ impl ReadonlyRepo {
}

impl Repo for ReadonlyRepo {
fn base_repo(&self) -> &ReadonlyRepo {
self
}

fn store(&self) -> &Arc<Store> {
self.loader.store()
}
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit bf93e59

Please sign in to comment.