diff --git a/lib/src/operation.rs b/lib/src/operation.rs index 5d95a364a..896ab8ce2 100644 --- a/lib/src/operation.rs +++ b/lib/src/operation.rs @@ -15,14 +15,13 @@ #![allow(missing_docs)] use std::cmp::Ordering; -use std::collections::HashSet; use std::fmt::{Debug, Error, Formatter}; use std::hash::{Hash, Hasher}; use std::sync::Arc; -use crate::backend::CommitId; use crate::op_store; use crate::op_store::{OpStore, OpStoreResult, OperationId, ViewId}; +use crate::view::View; #[derive(Clone)] pub struct Operation { @@ -94,76 +93,10 @@ impl Operation { pub fn view(&self) -> OpStoreResult { let data = self.op_store.read_view(&self.data.view_id)?; - let view = View::new(self.op_store.clone(), self.data.view_id.clone(), data); - Ok(view) + Ok(View::new(data)) } pub fn store_operation(&self) -> &op_store::Operation { &self.data } } - -#[derive(Clone)] -pub struct View { - op_store: Arc, - id: ViewId, - data: op_store::View, -} - -impl Debug for View { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { - f.debug_struct("View").field("id", &self.id).finish() - } -} - -impl PartialEq for View { - fn eq(&self, other: &Self) -> bool { - self.id == other.id - } -} - -impl Eq for View {} - -impl Ord for View { - fn cmp(&self, other: &Self) -> Ordering { - self.id.cmp(&other.id) - } -} - -impl PartialOrd for View { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl Hash for View { - fn hash(&self, state: &mut H) { - self.id.hash(state) - } -} - -impl View { - pub fn new(op_store: Arc, id: ViewId, data: op_store::View) -> Self { - View { op_store, id, data } - } - - pub fn op_store(&self) -> Arc { - self.op_store.clone() - } - - pub fn id(&self) -> &ViewId { - &self.id - } - - pub fn store_view(&self) -> &op_store::View { - &self.data - } - - pub fn take_store_view(self) -> op_store::View { - self.data - } - - pub fn heads(&self) -> &HashSet { - &self.data.head_ids - } -} diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 81bb36fe9..7aad7b2d1 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -664,13 +664,13 @@ impl RepoLoader { &self.op_store, |op_heads| self._resolve_op_heads(op_heads, user_settings), )?; - let view = View::new(op.view()?.take_store_view()); + let view = op.view()?; Ok(self._finish_load(op, view)) } #[instrument(skip(self))] pub fn load_at(&self, op: &Operation) -> Result, RepoLoaderError> { - let view = View::new(op.view()?.take_store_view()); + let view = op.view()?; Ok(self._finish_load(op.clone(), view)) }