mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 18:27:38 +00:00
index: move load() to IndexStore
This commit is contained in:
parent
403e86c138
commit
2fdf9721c0
3 changed files with 20 additions and 20 deletions
|
@ -30,7 +30,6 @@ use crate::commit::Commit;
|
||||||
use crate::dag_walk;
|
use crate::dag_walk;
|
||||||
use crate::op_store::OperationId;
|
use crate::op_store::OperationId;
|
||||||
use crate::operation::Operation;
|
use crate::operation::Operation;
|
||||||
use crate::repo::ReadonlyRepo;
|
|
||||||
use crate::store::{ChangeId, CommitId};
|
use crate::store::{ChangeId, CommitId};
|
||||||
use crate::store_wrapper::StoreWrapper;
|
use crate::store_wrapper::StoreWrapper;
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
|
@ -1352,18 +1351,6 @@ impl IndexEntry<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReadonlyIndex {
|
impl ReadonlyIndex {
|
||||||
pub fn load(repo: &ReadonlyRepo, dir: PathBuf, op_id: OperationId) -> Arc<ReadonlyIndex> {
|
|
||||||
let op_id_hex = op_id.hex();
|
|
||||||
let op_id_file = 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(dir, repo.store().hash_length(), &op_id).unwrap()
|
|
||||||
} else {
|
|
||||||
let op = repo.view().as_view_ref().get_operation(&op_id).unwrap();
|
|
||||||
ReadonlyIndex::index(repo.store(), dir, &op).unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_from(
|
fn load_from(
|
||||||
file: &mut dyn Read,
|
file: &mut dyn Read,
|
||||||
dir: PathBuf,
|
dir: PathBuf,
|
||||||
|
@ -1425,7 +1412,7 @@ impl ReadonlyIndex {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_at_operation(
|
pub fn load_at_operation(
|
||||||
dir: PathBuf,
|
dir: PathBuf,
|
||||||
hash_length: usize,
|
hash_length: usize,
|
||||||
op_id: &OperationId,
|
op_id: &OperationId,
|
||||||
|
@ -1442,7 +1429,7 @@ impl ReadonlyIndex {
|
||||||
ReadonlyIndex::load_from(&mut index_file, dir, index_file_id_hex, hash_length)
|
ReadonlyIndex::load_from(&mut index_file, dir, index_file_id_hex, hash_length)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index(
|
pub fn index(
|
||||||
store: &StoreWrapper,
|
store: &StoreWrapper,
|
||||||
dir: PathBuf,
|
dir: PathBuf,
|
||||||
operation: &Operation,
|
operation: &Operation,
|
||||||
|
|
|
@ -12,7 +12,11 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
use crate::index::ReadonlyIndex;
|
||||||
|
use crate::op_store::OperationId;
|
||||||
|
use crate::repo::ReadonlyRepo;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct IndexStore {
|
pub struct IndexStore {
|
||||||
dir: PathBuf,
|
dir: PathBuf,
|
||||||
|
@ -32,4 +36,17 @@ impl IndexStore {
|
||||||
pub fn load(dir: PathBuf) -> IndexStore {
|
pub fn load(dir: PathBuf) -> IndexStore {
|
||||||
IndexStore { dir }
|
IndexStore { dir }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_index_at_op(&self, repo: &ReadonlyRepo, op_id: OperationId) -> 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());
|
||||||
|
ReadonlyIndex::load_at_operation(self.dir.clone(), repo.store().hash_length(), &op_id)
|
||||||
|
.unwrap()
|
||||||
|
} else {
|
||||||
|
let op = repo.view().as_view_ref().get_operation(&op_id).unwrap();
|
||||||
|
ReadonlyIndex::index(repo.store(), self.dir.clone(), &op).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,11 +272,7 @@ impl ReadonlyRepo {
|
||||||
let mut locked_index = self.index.lock().unwrap();
|
let mut locked_index = self.index.lock().unwrap();
|
||||||
if locked_index.is_none() {
|
if locked_index.is_none() {
|
||||||
let op_id = self.view.base_op_head_id().clone();
|
let op_id = self.view.base_op_head_id().clone();
|
||||||
locked_index.replace(ReadonlyIndex::load(
|
locked_index.replace(self.index_store.get_index_at_op(self, op_id));
|
||||||
self,
|
|
||||||
self.repo_path.join("index"),
|
|
||||||
op_id,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
locked_index.as_ref().unwrap().clone()
|
locked_index.as_ref().unwrap().clone()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue