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.
This commit is contained in:
Martin von Zweigbergk 2023-02-28 22:12:18 -08:00 committed by Martin von Zweigbergk
parent e5ba9d9e42
commit 6ab8d9d0d0
6 changed files with 30 additions and 48 deletions

View file

@ -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.

View file

@ -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<Store>) -> Arc<ReadonlyIndex>;
fn write_index(
&self,
index: MutableIndex,
op_id: &OperationId,
) -> Result<Arc<ReadonlyIndex>, IndexWriteError>;
}
pub trait Index {
fn num_commits(&self) -> u32;

View file

@ -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<Store>) -> Arc<ReadonlyIndex>;
fn write_index(
&self,
index: MutableIndex,
op_id: &OperationId,
) -> Result<Arc<ReadonlyIndex>, IndexWriteError>;
}

View file

@ -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;

View file

@ -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};

View file

@ -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};