From 6ab8d9d0d031d0d3fae544efecdf23546380fe3d Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Tue, 28 Feb 2023 22:12:18 -0800 Subject: [PATCH] index: merge index_store.rs into index.rs These two files are closely related, and `Index` and `IndexStore` are expected to be customized together, so it seems better to keep them in a single file. --- lib/src/default_index_store.rs | 3 +-- lib/src/index.rs | 28 ++++++++++++++++++++++- lib/src/index_store.rs | 41 ---------------------------------- lib/src/lib.rs | 1 - lib/src/repo.rs | 3 +-- lib/src/workspace.rs | 2 +- 6 files changed, 30 insertions(+), 48 deletions(-) delete mode 100644 lib/src/index_store.rs diff --git a/lib/src/default_index_store.rs b/lib/src/default_index_store.rs index b44b5a0fa..b664f6814 100644 --- a/lib/src/default_index_store.rs +++ b/lib/src/default_index_store.rs @@ -33,8 +33,7 @@ use thiserror::Error; use crate::backend::{ChangeId, CommitId, ObjectId}; use crate::commit::Commit; use crate::file_util::persist_content_addressed_temp_file; -use crate::index::{HexPrefix, Index, PrefixResolution}; -use crate::index_store::{IndexStore, IndexWriteError}; +use crate::index::{HexPrefix, Index, IndexStore, IndexWriteError, PrefixResolution}; #[cfg(not(feature = "map_first_last"))] // This import is used on Rust 1.61, but not on recent version. // TODO: Remove it when our MSRV becomes recent enough. diff --git a/lib/src/index.rs b/lib/src/index.rs index 80fa80031..ab249c66c 100644 --- a/lib/src/index.rs +++ b/lib/src/index.rs @@ -13,9 +13,35 @@ // limitations under the License. use std::fmt::Debug; +use std::sync::Arc; + +use thiserror::Error; use crate::backend::{CommitId, ObjectId}; -use crate::default_index_store::{IndexEntry, IndexPosition, IndexStats, RevWalk}; +use crate::default_index_store::{ + IndexEntry, IndexPosition, IndexStats, MutableIndex, ReadonlyIndex, RevWalk, +}; +use crate::op_store::OperationId; +use crate::operation::Operation; +use crate::store::Store; + +#[derive(Debug, Error)] +pub enum IndexWriteError { + #[error("{0}")] + Other(String), +} + +pub trait IndexStore: Send + Sync + Debug { + fn name(&self) -> &str; + + fn get_index_at_op(&self, op: &Operation, store: &Arc) -> Arc; + + fn write_index( + &self, + index: MutableIndex, + op_id: &OperationId, + ) -> Result, IndexWriteError>; +} pub trait Index { fn num_commits(&self) -> u32; diff --git a/lib/src/index_store.rs b/lib/src/index_store.rs deleted file mode 100644 index 021ff66fb..000000000 --- a/lib/src/index_store.rs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2021 The Jujutsu Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use std::fmt::Debug; -use std::sync::Arc; - -use thiserror::Error; - -use crate::default_index_store::{MutableIndex, ReadonlyIndex}; -use crate::op_store::OperationId; -use crate::operation::Operation; -use crate::store::Store; - -#[derive(Debug, Error)] -pub enum IndexWriteError { - #[error("{0}")] - Other(String), -} - -pub trait IndexStore: Send + Sync + Debug { - fn name(&self) -> &str; - - fn get_index_at_op(&self, op: &Operation, store: &Arc) -> Arc; - - fn write_index( - &self, - index: MutableIndex, - op_id: &OperationId, - ) -> Result, IndexWriteError>; -} diff --git a/lib/src/lib.rs b/lib/src/lib.rs index f27b094bb..d0903ac82 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -31,7 +31,6 @@ pub mod git_backend; pub mod gitignore; pub mod hex_util; pub mod index; -pub mod index_store; #[cfg(feature = "legacy-thrift")] mod legacy_thrift_op_store; pub mod local_backend; diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 2cb53b8ff..20f802920 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -32,8 +32,7 @@ use crate::default_index_store::{ DefaultIndexStore, IndexEntry, IndexPosition, MutableIndex, ReadonlyIndex, }; use crate::git_backend::GitBackend; -use crate::index::{HexPrefix, Index, PrefixResolution}; -use crate::index_store::IndexStore; +use crate::index::{HexPrefix, Index, IndexStore, PrefixResolution}; use crate::local_backend::LocalBackend; use crate::op_heads_store::{self, OpHeadResolutionError, OpHeadsStore}; use crate::op_store::{BranchTarget, OpStore, OperationId, RefTarget, WorkspaceId}; diff --git a/lib/src/workspace.rs b/lib/src/workspace.rs index cc6154b47..fdcca87e7 100644 --- a/lib/src/workspace.rs +++ b/lib/src/workspace.rs @@ -21,7 +21,7 @@ use thiserror::Error; use crate::backend::Backend; use crate::git_backend::GitBackend; -use crate::index_store::IndexStore; +use crate::index::IndexStore; use crate::local_backend::LocalBackend; use crate::op_heads_store::OpHeadsStore; use crate::op_store::{OpStore, WorkspaceId};