forked from mirrors/jj
index: move static functions from Index to IndexFile and delete it
The Index struct no longer has any state, so it's not needed.
This commit is contained in:
parent
00fb670c9c
commit
14e7df995a
2 changed files with 27 additions and 31 deletions
|
@ -908,6 +908,29 @@ impl IndexEntry<'_> {
|
|||
}
|
||||
|
||||
impl IndexFile {
|
||||
pub fn init(dir: PathBuf) {
|
||||
std::fs::create_dir(dir.join("operations")).unwrap();
|
||||
}
|
||||
|
||||
pub fn reinit(dir: PathBuf) {
|
||||
std::fs::remove_dir_all(dir.join("operations")).unwrap();
|
||||
IndexFile::init(dir);
|
||||
}
|
||||
|
||||
pub fn load(repo: &ReadonlyRepo, dir: PathBuf, op_id: OperationId) -> Arc<IndexFile> {
|
||||
let op_id_hex = op_id.hex();
|
||||
let op_id_file = dir.join("operations").join(&op_id_hex);
|
||||
let index_file = if op_id_file.exists() {
|
||||
let op_id = OperationId(hex::decode(op_id_hex).unwrap());
|
||||
IndexFile::load_at_operation(&dir, repo.store().hash_length(), &op_id).unwrap()
|
||||
} else {
|
||||
let op = repo.view().get_operation(&op_id).unwrap();
|
||||
IndexFile::index(repo.store(), &dir, &op).unwrap()
|
||||
};
|
||||
|
||||
Arc::new(index_file)
|
||||
}
|
||||
|
||||
fn load_from(
|
||||
file: &mut dyn Read,
|
||||
dir: &Path,
|
||||
|
@ -1103,33 +1126,6 @@ impl IndexFile {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Index;
|
||||
|
||||
impl Index {
|
||||
pub fn init(dir: PathBuf) {
|
||||
std::fs::create_dir(dir.join("operations")).unwrap();
|
||||
}
|
||||
|
||||
pub fn reinit(dir: PathBuf) {
|
||||
std::fs::remove_dir_all(dir.join("operations")).unwrap();
|
||||
Index::init(dir);
|
||||
}
|
||||
|
||||
pub fn load(repo: &ReadonlyRepo, dir: PathBuf, op_id: OperationId) -> Arc<IndexFile> {
|
||||
let op_id_hex = op_id.hex();
|
||||
let op_id_file = dir.join("operations").join(&op_id_hex);
|
||||
let index_file = if op_id_file.exists() {
|
||||
let op_id = OperationId(hex::decode(op_id_hex).unwrap());
|
||||
IndexFile::load_at_operation(&dir, repo.store().hash_length(), &op_id).unwrap()
|
||||
} else {
|
||||
let op = repo.view().get_operation(&op_id).unwrap();
|
||||
IndexFile::index(repo.store(), &dir, &op).unwrap()
|
||||
};
|
||||
|
||||
Arc::new(index_file)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -24,7 +24,7 @@ use thiserror::Error;
|
|||
use crate::commit_builder::{new_change_id, signature};
|
||||
use crate::evolution::{Evolution, ReadonlyEvolution};
|
||||
use crate::git_store::GitStore;
|
||||
use crate::index::{Index, IndexFile};
|
||||
use crate::index::IndexFile;
|
||||
use crate::local_store::LocalStore;
|
||||
use crate::operation::Operation;
|
||||
use crate::settings::{RepoSettings, UserSettings};
|
||||
|
@ -155,7 +155,7 @@ impl ReadonlyRepo {
|
|||
let static_lifetime_repo: &'static ReadonlyRepo = unsafe { std::mem::transmute(repo_ref) };
|
||||
|
||||
fs::create_dir(repo_path.join("index")).unwrap();
|
||||
Index::init(repo_path.join("index"));
|
||||
IndexFile::init(repo_path.join("index"));
|
||||
|
||||
let evolution = ReadonlyEvolution::new(static_lifetime_repo);
|
||||
|
||||
|
@ -221,13 +221,13 @@ impl ReadonlyRepo {
|
|||
let mut locked_index = self.index.lock().unwrap();
|
||||
if locked_index.is_none() {
|
||||
let op_id = self.view.base_op_head_id().clone();
|
||||
locked_index.replace(Index::load(self, self.repo_path.join("index"), op_id));
|
||||
locked_index.replace(IndexFile::load(self, self.repo_path.join("index"), op_id));
|
||||
}
|
||||
locked_index.as_ref().unwrap().clone()
|
||||
}
|
||||
|
||||
pub fn reindex(&mut self) -> Arc<IndexFile> {
|
||||
Index::reinit(self.repo_path.join("index"));
|
||||
IndexFile::reinit(self.repo_path.join("index"));
|
||||
{
|
||||
let mut locked_index = self.index.lock().unwrap();
|
||||
locked_index.take();
|
||||
|
|
Loading…
Reference in a new issue