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:
parent
da1c259211
commit
94bdbb7ff7
2 changed files with 13 additions and 9 deletions
|
@ -16,7 +16,7 @@ use std::collections::{HashMap, HashSet};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
@ -43,18 +43,22 @@ pub struct IndexStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IndexStore {
|
impl IndexStore {
|
||||||
pub fn init(dir: PathBuf) -> Self {
|
pub fn init(dir: &Path) -> Self {
|
||||||
std::fs::create_dir(dir.join("operations")).unwrap();
|
std::fs::create_dir(dir.join("operations")).unwrap();
|
||||||
IndexStore { dir }
|
IndexStore {
|
||||||
|
dir: dir.to_owned(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reinit(&self) {
|
pub fn reinit(&self) {
|
||||||
std::fs::remove_dir_all(self.dir.join("operations")).unwrap();
|
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 {
|
pub fn load(dir: &Path) -> IndexStore {
|
||||||
IndexStore { dir }
|
IndexStore {
|
||||||
|
dir: dir.to_owned(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_index_at_op(&self, op: &Operation, store: &Arc<Store>) -> Arc<ReadonlyIndex> {
|
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();
|
let mut index_file = File::open(index_file_path).unwrap();
|
||||||
ReadonlyIndex::load_from(
|
ReadonlyIndex::load_from(
|
||||||
&mut index_file,
|
&mut index_file,
|
||||||
self.dir.clone(),
|
self.dir.to_owned(),
|
||||||
index_file_id_hex,
|
index_file_id_hex,
|
||||||
commit_id_length,
|
commit_id_length,
|
||||||
change_id_length,
|
change_id_length,
|
||||||
|
|
|
@ -158,7 +158,7 @@ impl ReadonlyRepo {
|
||||||
|
|
||||||
let index_path = repo_path.join("index");
|
let index_path = repo_path.join("index");
|
||||||
fs::create_dir(&index_path).context(&index_path)?;
|
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);
|
let view = View::new(root_view);
|
||||||
Ok(Arc::new(ReadonlyRepo {
|
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_store = Arc::from(store_factories.load_op_store(&repo_path.join("op_store"))?);
|
||||||
let op_heads_store =
|
let op_heads_store =
|
||||||
Arc::from(store_factories.load_op_heads_store(&repo_path.join("op_heads"))?);
|
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 {
|
Ok(Self {
|
||||||
repo_path: repo_path.to_path_buf(),
|
repo_path: repo_path.to_path_buf(),
|
||||||
repo_settings,
|
repo_settings,
|
||||||
|
|
Loading…
Reference in a new issue