mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 18:27:38 +00:00
index: move ReadonlyRepo::load_at_operation() to IndexStore
This commit is contained in:
parent
12bfbc489c
commit
c4fe7aab10
2 changed files with 29 additions and 22 deletions
|
@ -1283,7 +1283,7 @@ impl IndexEntry<'_> {
|
|||
}
|
||||
|
||||
impl ReadonlyIndex {
|
||||
fn load_from(
|
||||
pub(crate) fn load_from(
|
||||
file: &mut dyn Read,
|
||||
dir: PathBuf,
|
||||
name: String,
|
||||
|
@ -1344,23 +1344,6 @@ impl ReadonlyIndex {
|
|||
}))
|
||||
}
|
||||
|
||||
pub fn load_at_operation(
|
||||
dir: PathBuf,
|
||||
hash_length: usize,
|
||||
op_id: &OperationId,
|
||||
) -> io::Result<Arc<ReadonlyIndex>> {
|
||||
let op_id_file = dir.join("operations").join(op_id.hex());
|
||||
let mut buf = vec![];
|
||||
File::open(op_id_file)
|
||||
.unwrap()
|
||||
.read_to_end(&mut buf)
|
||||
.unwrap();
|
||||
let index_file_id_hex = String::from_utf8(buf).unwrap();
|
||||
let index_file_path = dir.join(&index_file_id_hex);
|
||||
let mut index_file = File::open(&index_file_path).unwrap();
|
||||
ReadonlyIndex::load_from(&mut index_file, dir, index_file_id_hex, hash_length)
|
||||
}
|
||||
|
||||
/// Records a link from the given operation to the this index version.
|
||||
pub fn associate_with_operation(&self, op_id: &OperationId) -> io::Result<()> {
|
||||
let mut temp_file = NamedTempFile::new_in(&self.dir)?;
|
||||
|
|
|
@ -21,7 +21,9 @@ use crate::repo::ReadonlyRepo;
|
|||
use crate::store::CommitId;
|
||||
use crate::store_wrapper::StoreWrapper;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -49,7 +51,7 @@ impl IndexStore {
|
|||
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());
|
||||
ReadonlyIndex::load_at_operation(self.dir.clone(), repo.store().hash_length(), &op_id)
|
||||
self.load_index_at_operation(repo.store().hash_length(), &op_id)
|
||||
.unwrap()
|
||||
} else {
|
||||
let op = repo.view().as_view_ref().get_operation(&op_id).unwrap();
|
||||
|
@ -57,6 +59,28 @@ impl IndexStore {
|
|||
}
|
||||
}
|
||||
|
||||
fn load_index_at_operation(
|
||||
&self,
|
||||
hash_length: usize,
|
||||
op_id: &OperationId,
|
||||
) -> io::Result<Arc<ReadonlyIndex>> {
|
||||
let op_id_file = self.dir.join("operations").join(op_id.hex());
|
||||
let mut buf = vec![];
|
||||
File::open(op_id_file)
|
||||
.unwrap()
|
||||
.read_to_end(&mut buf)
|
||||
.unwrap();
|
||||
let index_file_id_hex = String::from_utf8(buf).unwrap();
|
||||
let index_file_path = self.dir.join(&index_file_id_hex);
|
||||
let mut index_file = File::open(&index_file_path).unwrap();
|
||||
ReadonlyIndex::load_from(
|
||||
&mut index_file,
|
||||
self.dir.clone(),
|
||||
index_file_id_hex,
|
||||
hash_length,
|
||||
)
|
||||
}
|
||||
|
||||
fn index_at_operation(
|
||||
&self,
|
||||
store: &StoreWrapper,
|
||||
|
@ -90,8 +114,8 @@ impl IndexStore {
|
|||
data = MutableIndex::full(self.dir.clone(), hash_length);
|
||||
}
|
||||
Some(parent_op_id) => {
|
||||
let parent_file =
|
||||
ReadonlyIndex::load_at_operation(self.dir.clone(), hash_length, &parent_op_id)
|
||||
let parent_file = self
|
||||
.load_index_at_operation(hash_length, &parent_op_id)
|
||||
.unwrap();
|
||||
maybe_parent_file = Some(parent_file.clone());
|
||||
data = MutableIndex::incremental(parent_file)
|
||||
|
|
Loading…
Reference in a new issue