2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2020 The Jujutsu Authors
|
2020-12-12 08:00:42 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2023-07-10 15:17:00 +00:00
|
|
|
#![allow(missing_docs)]
|
|
|
|
|
2023-03-11 19:25:13 +00:00
|
|
|
use std::any::Any;
|
2023-03-01 05:50:04 +00:00
|
|
|
use std::fmt::Debug;
|
2023-03-01 06:12:18 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use thiserror::Error;
|
2020-12-12 08:00:42 +00:00
|
|
|
|
2024-01-04 07:18:04 +00:00
|
|
|
use crate::backend::CommitId;
|
2023-03-11 20:52:55 +00:00
|
|
|
use crate::commit::Commit;
|
2024-01-04 07:42:52 +00:00
|
|
|
use crate::object_id::{HexPrefix, PrefixResolution};
|
2023-03-01 06:12:18 +00:00
|
|
|
use crate::op_store::OperationId;
|
|
|
|
use crate::operation::Operation;
|
2023-04-04 10:22:53 +00:00
|
|
|
use crate::revset::{ResolvedExpression, Revset, RevsetEvaluationError};
|
2023-03-01 06:12:18 +00:00
|
|
|
use crate::store::Store;
|
|
|
|
|
2023-12-17 05:47:14 +00:00
|
|
|
/// Error while reading index from the `IndexStore`.
|
|
|
|
#[derive(Debug, Error)]
|
|
|
|
#[error(transparent)]
|
|
|
|
pub struct IndexReadError(pub Box<dyn std::error::Error + Send + Sync>);
|
|
|
|
|
2023-12-17 05:43:56 +00:00
|
|
|
/// Error while writing index to the `IndexStore`.
|
2023-03-01 06:12:18 +00:00
|
|
|
#[derive(Debug, Error)]
|
2023-12-17 05:43:56 +00:00
|
|
|
#[error(transparent)]
|
|
|
|
pub struct IndexWriteError(pub Box<dyn std::error::Error + Send + Sync>);
|
2023-03-01 06:12:18 +00:00
|
|
|
|
|
|
|
pub trait IndexStore: Send + Sync + Debug {
|
2023-03-12 06:05:45 +00:00
|
|
|
fn as_any(&self) -> &dyn Any;
|
|
|
|
|
2023-03-01 06:12:18 +00:00
|
|
|
fn name(&self) -> &str;
|
|
|
|
|
2023-12-17 05:47:14 +00:00
|
|
|
fn get_index_at_op(
|
|
|
|
&self,
|
|
|
|
op: &Operation,
|
|
|
|
store: &Arc<Store>,
|
|
|
|
) -> Result<Box<dyn ReadonlyIndex>, IndexReadError>;
|
2023-03-01 06:12:18 +00:00
|
|
|
|
|
|
|
fn write_index(
|
|
|
|
&self,
|
2023-03-11 20:52:55 +00:00
|
|
|
index: Box<dyn MutableIndex>,
|
2023-03-01 06:12:18 +00:00
|
|
|
op_id: &OperationId,
|
2023-03-11 19:25:13 +00:00
|
|
|
) -> Result<Box<dyn ReadonlyIndex>, IndexWriteError>;
|
2023-03-01 06:12:18 +00:00
|
|
|
}
|
2020-12-12 08:00:42 +00:00
|
|
|
|
2023-03-21 05:04:21 +00:00
|
|
|
pub trait Index: Send + Sync {
|
2023-02-14 06:32:11 +00:00
|
|
|
fn shortest_unique_commit_id_prefix_len(&self, commit_id: &CommitId) -> usize;
|
|
|
|
|
2023-12-23 08:04:36 +00:00
|
|
|
fn resolve_commit_id_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId>;
|
2023-02-14 06:32:11 +00:00
|
|
|
|
|
|
|
fn has_id(&self, commit_id: &CommitId) -> bool;
|
|
|
|
|
|
|
|
fn is_ancestor(&self, ancestor_id: &CommitId, descendant_id: &CommitId) -> bool;
|
|
|
|
|
|
|
|
fn common_ancestors(&self, set1: &[CommitId], set2: &[CommitId]) -> Vec<CommitId>;
|
|
|
|
|
|
|
|
fn heads(&self, candidates: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId>;
|
|
|
|
|
2023-02-19 04:49:58 +00:00
|
|
|
/// Parents before children
|
2023-03-23 05:14:03 +00:00
|
|
|
fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId>;
|
2023-03-13 06:00:02 +00:00
|
|
|
|
|
|
|
fn evaluate_revset<'index>(
|
|
|
|
&'index self,
|
2023-04-04 10:22:53 +00:00
|
|
|
expression: &ResolvedExpression,
|
2023-03-30 17:04:15 +00:00
|
|
|
store: &Arc<Store>,
|
2023-04-02 01:59:22 +00:00
|
|
|
) -> Result<Box<dyn Revset<'index> + 'index>, RevsetEvaluationError>;
|
2023-02-14 06:32:11 +00:00
|
|
|
}
|
|
|
|
|
2023-03-11 19:25:13 +00:00
|
|
|
pub trait ReadonlyIndex: Send + Sync {
|
|
|
|
fn as_any(&self) -> &dyn Any;
|
|
|
|
|
|
|
|
fn as_index(&self) -> &dyn Index;
|
|
|
|
|
2023-12-07 15:22:48 +00:00
|
|
|
// TODO: might be better to split Index::evaluate_revset() to
|
|
|
|
// Readonly/MutableIndex::evaluate_static().
|
|
|
|
fn evaluate_revset_static(
|
|
|
|
&self,
|
|
|
|
expression: &ResolvedExpression,
|
|
|
|
store: &Arc<Store>,
|
|
|
|
) -> Result<Box<dyn Revset<'static>>, RevsetEvaluationError>;
|
|
|
|
|
2023-03-11 20:52:55 +00:00
|
|
|
fn start_modification(&self) -> Box<dyn MutableIndex>;
|
|
|
|
}
|
|
|
|
|
2023-12-08 03:56:15 +00:00
|
|
|
pub trait MutableIndex {
|
2023-05-26 07:01:59 +00:00
|
|
|
fn as_any(&self) -> &dyn Any;
|
|
|
|
|
2023-03-11 20:52:55 +00:00
|
|
|
fn into_any(self: Box<Self>) -> Box<dyn Any>;
|
|
|
|
|
|
|
|
fn as_index(&self) -> &dyn Index;
|
|
|
|
|
|
|
|
fn add_commit(&mut self, commit: &Commit);
|
|
|
|
|
|
|
|
fn merge_in(&mut self, other: &dyn ReadonlyIndex);
|
2023-03-11 19:25:13 +00:00
|
|
|
}
|