forked from mirrors/jj
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.
This commit is contained in:
parent
d1509ffdd4
commit
779db67f8f
2 changed files with 7 additions and 8 deletions
|
@ -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<ReadonlyIndex> {
|
||||
let op_id_hex = op_id.hex();
|
||||
pub fn get_index_at_op(&self, op: &Operation, store: &StoreWrapper) -> Arc<ReadonlyIndex> {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue