forked from mirrors/jj
Repo: repurpose ReadonlyRepo::loader() to return loader for existing repo
It's sometimes useful to create a `RepoLoader` given an existing `ReadonlyRepo`. We already do that in `ReadonlyRepo::reload()`. This patch repurposes `ReadonlyRepo::reload()` for that.
This commit is contained in:
parent
82c683bf63
commit
e9ddfdd8bc
3 changed files with 19 additions and 20 deletions
|
@ -256,14 +256,21 @@ impl ReadonlyRepo {
|
|||
user_settings: &UserSettings,
|
||||
wc_path: PathBuf,
|
||||
) -> Result<Arc<ReadonlyRepo>, RepoLoadError> {
|
||||
ReadonlyRepo::loader(user_settings, wc_path)?.load_at_head()
|
||||
RepoLoader::init(user_settings, wc_path)?.load_at_head()
|
||||
}
|
||||
|
||||
pub fn loader(
|
||||
user_settings: &UserSettings,
|
||||
wc_path: PathBuf,
|
||||
) -> Result<RepoLoader, RepoLoadError> {
|
||||
RepoLoader::init(user_settings, wc_path)
|
||||
&self
|
||||
) -> RepoLoader {
|
||||
RepoLoader {
|
||||
wc_path: self.wc_path.clone(),
|
||||
repo_path: self.repo_path.clone(),
|
||||
repo_settings: self.settings.clone(),
|
||||
store: self.store.clone(),
|
||||
op_store: self.op_store.clone(),
|
||||
op_heads_store: self.op_heads_store.clone(),
|
||||
index_store: self.index_store.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_repo_ref(&self) -> RepoRef {
|
||||
|
@ -356,15 +363,7 @@ impl ReadonlyRepo {
|
|||
}
|
||||
|
||||
pub fn reload(&mut self) {
|
||||
let repo_loader = RepoLoader {
|
||||
wc_path: self.working_copy_path().clone(),
|
||||
repo_path: self.repo_path.clone(),
|
||||
repo_settings: self.settings.clone(),
|
||||
store: self.store.clone(),
|
||||
op_store: self.op_store.clone(),
|
||||
op_heads_store: self.op_heads_store.clone(),
|
||||
index_store: self.index_store.clone(),
|
||||
};
|
||||
let repo_loader = self.loader();
|
||||
let operation = self
|
||||
.op_heads_store
|
||||
.get_single_op_head(&repo_loader)
|
||||
|
@ -404,7 +403,7 @@ pub struct RepoLoader {
|
|||
}
|
||||
|
||||
impl RepoLoader {
|
||||
fn init(user_settings: &UserSettings, wc_path: PathBuf) -> Result<RepoLoader, RepoLoadError> {
|
||||
pub fn init(user_settings: &UserSettings, wc_path: PathBuf) -> Result<RepoLoader, RepoLoadError> {
|
||||
let repo_path = wc_path.join(".jj");
|
||||
// TODO: Check if ancestor directory has a .jj/
|
||||
if !repo_path.is_dir() {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use jujube_lib::repo::{ReadonlyRepo, RepoLoadError};
|
||||
use jujube_lib::repo::{ReadonlyRepo, RepoLoadError, RepoLoader};
|
||||
use jujube_lib::testutils;
|
||||
use std::sync::Arc;
|
||||
use test_case::test_case;
|
||||
|
@ -44,13 +44,13 @@ fn test_load_at_operation(use_git: bool) {
|
|||
|
||||
// If we load the repo at head, we should not see the commit since it was
|
||||
// removed
|
||||
let loader = ReadonlyRepo::loader(&settings, repo.working_copy_path().clone()).unwrap();
|
||||
let loader = RepoLoader::init(&settings, repo.working_copy_path().clone()).unwrap();
|
||||
let head_repo = loader.load_at_head().unwrap();
|
||||
assert!(!head_repo.view().heads().contains(commit.id()));
|
||||
|
||||
// If we load the repo at the previous operation, we should see the commit since
|
||||
// it has not been removed yet
|
||||
let loader = ReadonlyRepo::loader(&settings, repo.working_copy_path().clone()).unwrap();
|
||||
let loader = RepoLoader::init(&settings, repo.working_copy_path().clone()).unwrap();
|
||||
let old_repo = loader.load_at(&op).unwrap();
|
||||
assert!(old_repo.view().heads().contains(commit.id()));
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ use jujube_lib::files;
|
|||
use jujube_lib::files::DiffLine;
|
||||
use jujube_lib::git;
|
||||
use jujube_lib::op_store::{OpStore, OpStoreError, OperationId};
|
||||
use jujube_lib::repo::{ReadonlyRepo, RepoLoadError};
|
||||
use jujube_lib::repo::{ReadonlyRepo, RepoLoadError, RepoLoader};
|
||||
use jujube_lib::repo_path::RepoPath;
|
||||
use jujube_lib::rewrite::{back_out_commit, merge_commit_trees, rebase_commit};
|
||||
use jujube_lib::settings::UserSettings;
|
||||
|
@ -94,7 +94,7 @@ impl From<RepoLoadError> for CommandError {
|
|||
fn get_repo(ui: &Ui, matches: &ArgMatches) -> Result<Arc<ReadonlyRepo>, CommandError> {
|
||||
let wc_path_str = matches.value_of("repository").unwrap();
|
||||
let wc_path = ui.cwd().join(wc_path_str);
|
||||
let loader = ReadonlyRepo::loader(ui.settings(), wc_path)?;
|
||||
let loader = RepoLoader::init(ui.settings(), wc_path)?;
|
||||
if let Some(op_str) = matches.value_of("at_op") {
|
||||
let op = resolve_single_op_from_store(loader.op_store(), op_str)?;
|
||||
Ok(loader.load_at(&op)?)
|
||||
|
|
Loading…
Reference in a new issue