ok/jj
1
0
Fork 0
forked from mirrors/jj

index: make IndexStore factory functions take &Path

This is just for consistency with the other backends.
This commit is contained in:
Martin von Zweigbergk 2023-02-26 22:35:41 -08:00 committed by Martin von Zweigbergk
parent da1c259211
commit 94bdbb7ff7
2 changed files with 13 additions and 9 deletions

View file

@ -16,7 +16,7 @@ use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::io;
use std::io::{Read, Write};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use itertools::Itertools;
@ -43,18 +43,22 @@ pub struct IndexStore {
}
impl IndexStore {
pub fn init(dir: PathBuf) -> Self {
pub fn init(dir: &Path) -> Self {
std::fs::create_dir(dir.join("operations")).unwrap();
IndexStore { dir }
IndexStore {
dir: dir.to_owned(),
}
}
pub fn reinit(&self) {
std::fs::remove_dir_all(self.dir.join("operations")).unwrap();
IndexStore::init(self.dir.clone());
IndexStore::init(&self.dir);
}
pub fn load(dir: PathBuf) -> IndexStore {
IndexStore { dir }
pub fn load(dir: &Path) -> IndexStore {
IndexStore {
dir: dir.to_owned(),
}
}
pub fn get_index_at_op(&self, op: &Operation, store: &Arc<Store>) -> Arc<ReadonlyIndex> {
@ -116,7 +120,7 @@ impl IndexStore {
let mut index_file = File::open(index_file_path).unwrap();
ReadonlyIndex::load_from(
&mut index_file,
self.dir.clone(),
self.dir.to_owned(),
index_file_id_hex,
commit_id_length,
change_id_length,

View file

@ -158,7 +158,7 @@ impl ReadonlyRepo {
let index_path = repo_path.join("index");
fs::create_dir(&index_path).context(&index_path)?;
let index_store = Arc::new(IndexStore::init(index_path));
let index_store = Arc::new(IndexStore::init(&index_path));
let view = View::new(root_view);
Ok(Arc::new(ReadonlyRepo {
@ -471,7 +471,7 @@ impl RepoLoader {
let op_store = Arc::from(store_factories.load_op_store(&repo_path.join("op_store"))?);
let op_heads_store =
Arc::from(store_factories.load_op_heads_store(&repo_path.join("op_heads"))?);
let index_store = Arc::new(IndexStore::load(repo_path.join("index")));
let index_store = Arc::new(IndexStore::load(&repo_path.join("index")));
Ok(Self {
repo_path: repo_path.to_path_buf(),
repo_settings,