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)]
|
|
|
|
|
view: add wrapper that will exclude absent RefTarget entries from ContentHash
The next commit will change these maps to store Option<RefTarget> entries, but
None entries will still be omitted from the serialized data. Since ContentHash
should describe the serialized data, relying on the generic ContentHash would
cause future hash conflict where absent RefTarget entries will be preserved.
For example, ([remove], [None, add]) will be serialized as ([remove], [add]),
and deserialized to ([remove], [add, None]). If we add support for lossless
serialization, hash(([remove], [None, add])) should differ from the lossy one.
2023-07-13 10:05:01 +00:00
|
|
|
use std::collections::{btree_map, BTreeMap, HashMap, HashSet};
|
2020-12-12 08:00:42 +00:00
|
|
|
use std::fmt::{Debug, Error, Formatter};
|
view: add wrapper that will exclude absent RefTarget entries from ContentHash
The next commit will change these maps to store Option<RefTarget> entries, but
None entries will still be omitted from the serialized data. Since ContentHash
should describe the serialized data, relying on the generic ContentHash would
cause future hash conflict where absent RefTarget entries will be preserved.
For example, ([remove], [None, add]) will be serialized as ([remove], [add]),
and deserialized to ([remove], [add, None]). If we add support for lossless
serialization, hash(([remove], [None, add])) should differ from the lossy one.
2023-07-13 10:05:01 +00:00
|
|
|
use std::ops::{Deref, DerefMut};
|
2023-07-01 07:07:18 +00:00
|
|
|
use std::slice;
|
2020-12-12 08:00:42 +00:00
|
|
|
|
2022-05-25 15:56:01 +00:00
|
|
|
use thiserror::Error;
|
|
|
|
|
2021-09-12 06:52:38 +00:00
|
|
|
use crate::backend::{CommitId, Timestamp};
|
2022-11-11 17:33:22 +00:00
|
|
|
use crate::content_hash::ContentHash;
|
2021-03-14 17:37:28 +00:00
|
|
|
|
2022-11-11 17:33:22 +00:00
|
|
|
content_hash! {
|
|
|
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
|
|
|
|
pub struct WorkspaceId(String);
|
|
|
|
}
|
2021-11-17 21:06:02 +00:00
|
|
|
|
|
|
|
impl Debug for WorkspaceId {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
|
|
|
|
f.debug_tuple("WorkspaceId").field(&self.0).finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-09 18:56:30 +00:00
|
|
|
impl Default for WorkspaceId {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self("default".to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-17 21:06:02 +00:00
|
|
|
impl WorkspaceId {
|
|
|
|
pub fn new(value: String) -> Self {
|
|
|
|
Self(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_str(&self) -> &str {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-11 17:33:22 +00:00
|
|
|
content_hash! {
|
|
|
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
|
|
|
|
pub struct ViewId(Vec<u8>);
|
|
|
|
}
|
2020-12-12 08:00:42 +00:00
|
|
|
|
|
|
|
impl Debug for ViewId {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
|
|
|
|
f.debug_tuple("ViewId").field(&self.hex()).finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ViewId {
|
2021-11-17 22:13:41 +00:00
|
|
|
pub fn new(value: Vec<u8>) -> Self {
|
|
|
|
Self(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_hex(hex: &str) -> Self {
|
|
|
|
Self(hex::decode(hex).unwrap())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_bytes(&self) -> &[u8] {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn to_bytes(&self) -> Vec<u8> {
|
|
|
|
self.0.clone()
|
|
|
|
}
|
|
|
|
|
2020-12-12 08:00:42 +00:00
|
|
|
pub fn hex(&self) -> String {
|
|
|
|
hex::encode(&self.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-11 17:33:22 +00:00
|
|
|
content_hash! {
|
|
|
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
|
|
|
|
pub struct OperationId(Vec<u8>);
|
|
|
|
}
|
2020-12-12 08:00:42 +00:00
|
|
|
|
|
|
|
impl Debug for OperationId {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
|
|
|
|
f.debug_tuple("OperationId").field(&self.hex()).finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl OperationId {
|
2021-11-17 22:13:41 +00:00
|
|
|
pub fn new(value: Vec<u8>) -> Self {
|
|
|
|
Self(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_hex(hex: &str) -> Self {
|
|
|
|
Self(hex::decode(hex).unwrap())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_bytes(&self) -> &[u8] {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn to_bytes(&self) -> Vec<u8> {
|
|
|
|
self.0.clone()
|
|
|
|
}
|
|
|
|
|
2020-12-12 08:00:42 +00:00
|
|
|
pub fn hex(&self) -> String {
|
|
|
|
hex::encode(&self.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-14 13:34:55 +00:00
|
|
|
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
2021-07-11 17:58:01 +00:00
|
|
|
pub enum RefTarget {
|
|
|
|
Normal(CommitId),
|
|
|
|
Conflict {
|
|
|
|
removes: Vec<CommitId>,
|
|
|
|
adds: Vec<CommitId>,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-11-11 17:33:22 +00:00
|
|
|
impl ContentHash for RefTarget {
|
|
|
|
fn hash(&self, state: &mut impl digest::Update) {
|
|
|
|
use RefTarget::*;
|
2023-01-14 17:51:13 +00:00
|
|
|
match self {
|
|
|
|
Normal(id) => {
|
2022-11-11 17:33:22 +00:00
|
|
|
state.update(&0u32.to_le_bytes());
|
|
|
|
id.hash(state);
|
|
|
|
}
|
2023-01-14 17:51:13 +00:00
|
|
|
Conflict { removes, adds } => {
|
2022-11-11 17:33:22 +00:00
|
|
|
state.update(&1u32.to_le_bytes());
|
|
|
|
removes.hash(state);
|
|
|
|
adds.hash(state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-11 17:58:01 +00:00
|
|
|
impl RefTarget {
|
2023-07-12 16:56:02 +00:00
|
|
|
/// Creates non-conflicting target pointing to no commit.
|
|
|
|
pub fn absent() -> Option<Self> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns non-conflicting target pointing to no commit.
|
|
|
|
///
|
|
|
|
/// This will typically be used in place of `None` returned by map lookup.
|
|
|
|
pub fn absent_ref() -> Option<&'static Self> {
|
|
|
|
// TODO: This will be static ref to Conflict::resolved(None).
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2023-07-11 13:14:59 +00:00
|
|
|
/// Creates non-conflicting target pointing to a commit.
|
|
|
|
pub fn normal(id: CommitId) -> Option<Self> {
|
|
|
|
Some(RefTarget::Normal(id))
|
|
|
|
}
|
|
|
|
|
2023-07-11 15:22:21 +00:00
|
|
|
/// Creates conflicting target from removed/added ids.
|
|
|
|
pub fn from_legacy_form(
|
|
|
|
removed_ids: impl IntoIterator<Item = CommitId>,
|
|
|
|
added_ids: impl IntoIterator<Item = CommitId>,
|
|
|
|
) -> Option<Self> {
|
|
|
|
// TODO: This function will create non-conflicting target if there're only one
|
|
|
|
// add id and no removed ids.
|
|
|
|
let removes = removed_ids.into_iter().collect();
|
|
|
|
let adds = added_ids.into_iter().collect();
|
|
|
|
Some(RefTarget::Conflict { removes, adds })
|
|
|
|
}
|
|
|
|
|
2023-07-11 17:48:55 +00:00
|
|
|
/// Returns id if this target is non-conflicting and points to a commit.
|
|
|
|
pub fn as_normal(&self) -> Option<&CommitId> {
|
|
|
|
match self {
|
|
|
|
RefTarget::Normal(id) => Some(id),
|
|
|
|
RefTarget::Conflict { .. } => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-11 17:58:01 +00:00
|
|
|
pub fn is_conflict(&self) -> bool {
|
|
|
|
matches!(self, RefTarget::Conflict { .. })
|
|
|
|
}
|
|
|
|
|
2023-07-12 14:08:47 +00:00
|
|
|
pub fn removed_ids(&self) -> slice::Iter<'_, CommitId> {
|
|
|
|
let removes: &[_] = match self {
|
2023-07-01 07:07:18 +00:00
|
|
|
RefTarget::Normal(_) => &[],
|
|
|
|
RefTarget::Conflict { removes, adds: _ } => removes,
|
2023-07-12 14:08:47 +00:00
|
|
|
};
|
|
|
|
removes.iter()
|
2023-05-22 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
2023-07-12 14:08:47 +00:00
|
|
|
pub fn added_ids(&self) -> slice::Iter<'_, CommitId> {
|
|
|
|
let adds: &[_] = match self {
|
2023-07-01 07:07:18 +00:00
|
|
|
RefTarget::Normal(id) => slice::from_ref(id),
|
|
|
|
RefTarget::Conflict { removes: _, adds } => adds,
|
2023-07-12 14:08:47 +00:00
|
|
|
};
|
|
|
|
adds.iter()
|
2021-07-11 17:58:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-11 17:48:55 +00:00
|
|
|
// TODO: These methods will be migrate to new Conflict-based RefTarget type.
|
|
|
|
pub trait RefTargetExt {
|
|
|
|
fn as_normal(&self) -> Option<&CommitId>;
|
2023-07-11 19:36:25 +00:00
|
|
|
fn is_absent(&self) -> bool;
|
|
|
|
fn is_present(&self) -> bool;
|
2023-07-11 17:48:55 +00:00
|
|
|
fn is_conflict(&self) -> bool;
|
2023-07-12 14:08:47 +00:00
|
|
|
fn removed_ids(&self) -> slice::Iter<'_, CommitId>;
|
|
|
|
fn added_ids(&self) -> slice::Iter<'_, CommitId>;
|
2023-07-11 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2023-07-11 18:23:09 +00:00
|
|
|
impl RefTargetExt for Option<RefTarget> {
|
|
|
|
fn as_normal(&self) -> Option<&CommitId> {
|
|
|
|
self.as_ref().and_then(|target| target.as_normal())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_absent(&self) -> bool {
|
|
|
|
self.is_none()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_present(&self) -> bool {
|
|
|
|
self.is_some()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_conflict(&self) -> bool {
|
|
|
|
self.as_ref()
|
|
|
|
.map(|target| target.is_conflict())
|
|
|
|
.unwrap_or(false)
|
|
|
|
}
|
|
|
|
|
2023-07-12 14:08:47 +00:00
|
|
|
fn removed_ids(&self) -> slice::Iter<'_, CommitId> {
|
2023-07-11 18:23:09 +00:00
|
|
|
self.as_ref()
|
2023-07-12 14:08:47 +00:00
|
|
|
.map(|target| target.removed_ids())
|
|
|
|
.unwrap_or_else(|| [].iter())
|
2023-07-11 18:23:09 +00:00
|
|
|
}
|
|
|
|
|
2023-07-12 14:08:47 +00:00
|
|
|
fn added_ids(&self) -> slice::Iter<'_, CommitId> {
|
2023-07-11 18:23:09 +00:00
|
|
|
self.as_ref()
|
2023-07-12 14:08:47 +00:00
|
|
|
.map(|target| target.added_ids())
|
|
|
|
.unwrap_or_else(|| [].iter())
|
2023-07-11 18:23:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-11 17:48:55 +00:00
|
|
|
impl RefTargetExt for Option<&RefTarget> {
|
|
|
|
fn as_normal(&self) -> Option<&CommitId> {
|
|
|
|
self.and_then(|target| target.as_normal())
|
|
|
|
}
|
|
|
|
|
2023-07-11 19:36:25 +00:00
|
|
|
fn is_absent(&self) -> bool {
|
|
|
|
self.is_none()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_present(&self) -> bool {
|
|
|
|
self.is_some()
|
|
|
|
}
|
|
|
|
|
2023-07-11 17:48:55 +00:00
|
|
|
fn is_conflict(&self) -> bool {
|
|
|
|
self.map(|target| target.is_conflict()).unwrap_or(false)
|
|
|
|
}
|
2023-07-11 19:36:25 +00:00
|
|
|
|
2023-07-12 14:08:47 +00:00
|
|
|
fn removed_ids(&self) -> slice::Iter<'_, CommitId> {
|
|
|
|
self.map(|target| target.removed_ids())
|
|
|
|
.unwrap_or_else(|| [].iter())
|
2023-07-11 19:36:25 +00:00
|
|
|
}
|
|
|
|
|
2023-07-12 14:08:47 +00:00
|
|
|
fn added_ids(&self) -> slice::Iter<'_, CommitId> {
|
|
|
|
self.map(|target| target.added_ids())
|
|
|
|
.unwrap_or_else(|| [].iter())
|
2023-07-11 19:36:25 +00:00
|
|
|
}
|
2023-07-11 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
view: add wrapper that will exclude absent RefTarget entries from ContentHash
The next commit will change these maps to store Option<RefTarget> entries, but
None entries will still be omitted from the serialized data. Since ContentHash
should describe the serialized data, relying on the generic ContentHash would
cause future hash conflict where absent RefTarget entries will be preserved.
For example, ([remove], [None, add]) will be serialized as ([remove], [add]),
and deserialized to ([remove], [add, None]). If we add support for lossless
serialization, hash(([remove], [None, add])) should differ from the lossy one.
2023-07-13 10:05:01 +00:00
|
|
|
/// Wrapper to exclude absent `RefTarget` entries from `ContentHash`.
|
|
|
|
#[derive(Default, PartialEq, Eq, Clone, Debug)]
|
|
|
|
pub struct RefTargetMap(pub BTreeMap<String, RefTarget>);
|
|
|
|
|
|
|
|
impl RefTargetMap {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
RefTargetMap(BTreeMap::new())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Update serialization code to preserve absent RefTarget entries, and
|
|
|
|
// remove this wrapper.
|
|
|
|
impl ContentHash for RefTargetMap {
|
|
|
|
fn hash(&self, state: &mut impl digest::Update) {
|
|
|
|
// Derived from content_hash.rs. It's okay for this to produce a different hash
|
|
|
|
// value than the inner map, but the value must not be equal to the map which
|
|
|
|
// preserves absent RefTarget entries.
|
|
|
|
state.update(&(self.0.len() as u64).to_le_bytes());
|
|
|
|
for (k, v) in self.0.iter() {
|
|
|
|
k.hash(state);
|
|
|
|
v.hash(state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Abuse Deref as this is a temporary workaround. See the comment above.
|
|
|
|
impl Deref for RefTargetMap {
|
|
|
|
type Target = BTreeMap<String, RefTarget>;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DerefMut for RefTargetMap {
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
&mut self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoIterator for RefTargetMap {
|
|
|
|
type Item = (String, RefTarget);
|
|
|
|
type IntoIter = btree_map::IntoIter<String, RefTarget>;
|
|
|
|
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
self.0.into_iter()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> IntoIterator for &'a RefTargetMap {
|
|
|
|
type Item = (&'a String, &'a RefTarget);
|
|
|
|
type IntoIter = btree_map::Iter<'a, String, RefTarget>;
|
|
|
|
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
self.0.iter()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-11 17:33:22 +00:00
|
|
|
content_hash! {
|
|
|
|
#[derive(Default, PartialEq, Eq, Clone, Debug)]
|
|
|
|
pub struct BranchTarget {
|
|
|
|
/// The commit the branch points to locally. `None` if the branch has been
|
|
|
|
/// deleted locally.
|
|
|
|
pub local_target: Option<RefTarget>,
|
|
|
|
// TODO: Do we need to support tombstones for remote branches? For example, if the branch
|
|
|
|
// has been deleted locally and you pull from a remote, maybe it should make a difference
|
|
|
|
// whether the branch is known to have existed on the remote. We may not want to resurrect
|
|
|
|
// the branch if the branch's state on the remote was just not known.
|
view: add wrapper that will exclude absent RefTarget entries from ContentHash
The next commit will change these maps to store Option<RefTarget> entries, but
None entries will still be omitted from the serialized data. Since ContentHash
should describe the serialized data, relying on the generic ContentHash would
cause future hash conflict where absent RefTarget entries will be preserved.
For example, ([remove], [None, add]) will be serialized as ([remove], [add]),
and deserialized to ([remove], [add, None]). If we add support for lossless
serialization, hash(([remove], [None, add])) should differ from the lossy one.
2023-07-13 10:05:01 +00:00
|
|
|
pub remote_targets: RefTargetMap,
|
2022-11-11 17:33:22 +00:00
|
|
|
}
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 17:33:22 +00:00
|
|
|
content_hash! {
|
|
|
|
/// Represents the way the repo looks at a given time, just like how a Tree
|
|
|
|
/// object represents how the file system looks at a given time.
|
|
|
|
#[derive(PartialEq, Eq, Clone, Debug, Default)]
|
|
|
|
pub struct View {
|
|
|
|
/// All head commits
|
|
|
|
pub head_ids: HashSet<CommitId>,
|
|
|
|
/// Heads of the set of public commits.
|
|
|
|
pub public_head_ids: HashSet<CommitId>,
|
|
|
|
pub branches: BTreeMap<String, BranchTarget>,
|
view: add wrapper that will exclude absent RefTarget entries from ContentHash
The next commit will change these maps to store Option<RefTarget> entries, but
None entries will still be omitted from the serialized data. Since ContentHash
should describe the serialized data, relying on the generic ContentHash would
cause future hash conflict where absent RefTarget entries will be preserved.
For example, ([remove], [None, add]) will be serialized as ([remove], [add]),
and deserialized to ([remove], [add, None]). If we add support for lossless
serialization, hash(([remove], [None, add])) should differ from the lossy one.
2023-07-13 10:05:01 +00:00
|
|
|
pub tags: RefTargetMap,
|
|
|
|
pub git_refs: RefTargetMap,
|
2022-11-11 17:33:22 +00:00
|
|
|
/// The commit the Git HEAD points to.
|
|
|
|
// TODO: Support multiple Git worktrees?
|
|
|
|
// TODO: Do we want to store the current branch name too?
|
2022-12-17 17:34:09 +00:00
|
|
|
pub git_head: Option<RefTarget>,
|
2022-11-11 17:33:22 +00:00
|
|
|
// The commit that *should be* checked out in the workspace. Note that the working copy
|
|
|
|
// (.jj/working_copy/) has the source of truth about which commit *is* checked out (to be
|
|
|
|
// precise: the commit to which we most recently completed an update to).
|
|
|
|
pub wc_commit_ids: HashMap<WorkspaceId, CommitId>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
content_hash! {
|
|
|
|
/// Represents an operation (transaction) on the repo view, just like how a
|
|
|
|
/// Commit object represents an operation on the tree.
|
|
|
|
///
|
|
|
|
/// Operations and views are not meant to be exchanged between repos or users;
|
|
|
|
/// they represent local state and history.
|
|
|
|
///
|
|
|
|
/// The operation history will almost always be linear. It will only have
|
|
|
|
/// forks when parallel operations occurred. The parent is determined when
|
|
|
|
/// the transaction starts. When the transaction commits, a lock will be
|
|
|
|
/// taken and it will be checked that the current head of the operation
|
|
|
|
/// graph is unchanged. If the current head has changed, there has been
|
|
|
|
/// concurrent operation.
|
|
|
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
|
|
|
pub struct Operation {
|
|
|
|
pub view_id: ViewId,
|
|
|
|
pub parents: Vec<OperationId>,
|
|
|
|
pub metadata: OperationMetadata,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
content_hash! {
|
|
|
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
|
|
|
pub struct OperationMetadata {
|
|
|
|
pub start_time: Timestamp,
|
|
|
|
pub end_time: Timestamp,
|
|
|
|
// Whatever is useful to the user, such as exact command line call
|
|
|
|
pub description: String,
|
|
|
|
pub hostname: String,
|
|
|
|
pub username: String,
|
|
|
|
pub tags: HashMap<String, String>,
|
|
|
|
}
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
|
2022-05-25 15:56:01 +00:00
|
|
|
#[derive(Debug, Error)]
|
2020-12-12 08:00:42 +00:00
|
|
|
pub enum OpStoreError {
|
2022-05-25 15:56:01 +00:00
|
|
|
#[error("Operation not found")]
|
2020-12-12 08:00:42 +00:00
|
|
|
NotFound,
|
2022-05-25 15:56:01 +00:00
|
|
|
#[error("{0}")]
|
2020-12-12 08:00:42 +00:00
|
|
|
Other(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type OpStoreResult<T> = Result<T, OpStoreError>;
|
|
|
|
|
|
|
|
pub trait OpStore: Send + Sync + Debug {
|
2022-12-14 18:22:12 +00:00
|
|
|
fn name(&self) -> &str;
|
|
|
|
|
2020-12-12 08:00:42 +00:00
|
|
|
fn read_view(&self, id: &ViewId) -> OpStoreResult<View>;
|
|
|
|
|
|
|
|
fn write_view(&self, contents: &View) -> OpStoreResult<ViewId>;
|
|
|
|
|
|
|
|
fn read_operation(&self, id: &OperationId) -> OpStoreResult<Operation>;
|
|
|
|
|
|
|
|
fn write_operation(&self, contents: &Operation) -> OpStoreResult<OperationId>;
|
|
|
|
}
|