From 779db67f8f8312c16a97ece029d95b80f39f5dfd Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 6 Mar 2021 10:37:57 -0800 Subject: [PATCH] index_store: avoid passing whole repo into get_index_at_op() I want to be able to load the index at an operation before the repo has been loaded. --- lib/src/index_store.rs | 11 ++++------- lib/src/repo.rs | 4 +++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/src/index_store.rs b/lib/src/index_store.rs index dcb013192..eed998e7d 100644 --- a/lib/src/index_store.rs +++ b/lib/src/index_store.rs @@ -17,7 +17,6 @@ use crate::dag_walk; use crate::index::{MutableIndex, ReadonlyIndex}; use crate::op_store::OperationId; use crate::operation::Operation; -use crate::repo::ReadonlyRepo; use crate::store::CommitId; use crate::store_wrapper::StoreWrapper; use std::collections::{HashMap, HashSet}; @@ -47,16 +46,14 @@ impl IndexStore { IndexStore { dir } } - pub fn get_index_at_op(&self, repo: &ReadonlyRepo, op_id: OperationId) -> Arc { - let op_id_hex = op_id.hex(); + pub fn get_index_at_op(&self, op: &Operation, store: &StoreWrapper) -> Arc { + let op_id_hex = op.id().hex(); let op_id_file = self.dir.join("operations").join(&op_id_hex); if op_id_file.exists() { - let op_id = OperationId(hex::decode(op_id_hex).unwrap()); - self.load_index_at_operation(repo.store().hash_length(), &op_id) + self.load_index_at_operation(store.hash_length(), op.id()) .unwrap() } else { - let op = repo.view().as_view_ref().get_operation(&op_id).unwrap(); - self.index_at_operation(repo.store(), &op).unwrap() + self.index_at_operation(store, op).unwrap() } } diff --git a/lib/src/repo.rs b/lib/src/repo.rs index d2789dfec..b386bbabd 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -272,7 +272,9 @@ 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(self.index_store.get_index_at_op(self, op_id)); + let op = self.view.op_store().read_operation(&op_id).unwrap(); + let op = Operation::new(self.view.op_store().clone(), op_id, op); + locked_index.replace(self.index_store.get_index_at_op(&op, self.store.as_ref())); } locked_index.as_ref().unwrap().clone() }