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 {
|
impl ReadonlyIndex {
|
||||||
fn load_from(
|
pub(crate) fn load_from(
|
||||||
file: &mut dyn Read,
|
file: &mut dyn Read,
|
||||||
dir: PathBuf,
|
dir: PathBuf,
|
||||||
name: String,
|
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.
|
/// Records a link from the given operation to the this index version.
|
||||||
pub fn associate_with_operation(&self, op_id: &OperationId) -> io::Result<()> {
|
pub fn associate_with_operation(&self, op_id: &OperationId) -> io::Result<()> {
|
||||||
let mut temp_file = NamedTempFile::new_in(&self.dir)?;
|
let mut temp_file = NamedTempFile::new_in(&self.dir)?;
|
||||||
|
|
|
@ -21,7 +21,9 @@ use crate::repo::ReadonlyRepo;
|
||||||
use crate::store::CommitId;
|
use crate::store::CommitId;
|
||||||
use crate::store_wrapper::StoreWrapper;
|
use crate::store_wrapper::StoreWrapper;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::io::Read;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -49,7 +51,7 @@ impl IndexStore {
|
||||||
let op_id_file = self.dir.join("operations").join(&op_id_hex);
|
let op_id_file = self.dir.join("operations").join(&op_id_hex);
|
||||||
if op_id_file.exists() {
|
if op_id_file.exists() {
|
||||||
let op_id = OperationId(hex::decode(op_id_hex).unwrap());
|
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()
|
.unwrap()
|
||||||
} else {
|
} else {
|
||||||
let op = repo.view().as_view_ref().get_operation(&op_id).unwrap();
|
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(
|
fn index_at_operation(
|
||||||
&self,
|
&self,
|
||||||
store: &StoreWrapper,
|
store: &StoreWrapper,
|
||||||
|
@ -90,9 +114,9 @@ impl IndexStore {
|
||||||
data = MutableIndex::full(self.dir.clone(), hash_length);
|
data = MutableIndex::full(self.dir.clone(), hash_length);
|
||||||
}
|
}
|
||||||
Some(parent_op_id) => {
|
Some(parent_op_id) => {
|
||||||
let parent_file =
|
let parent_file = self
|
||||||
ReadonlyIndex::load_at_operation(self.dir.clone(), hash_length, &parent_op_id)
|
.load_index_at_operation(hash_length, &parent_op_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
maybe_parent_file = Some(parent_file.clone());
|
maybe_parent_file = Some(parent_file.clone());
|
||||||
data = MutableIndex::incremental(parent_file)
|
data = MutableIndex::incremental(parent_file)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue