forked from mirrors/jj
operation: remove operation::View wrapper in favor of view::View
view::View doesn't track ViewId, but there are no callers of cheap Eq/Hash functions.
This commit is contained in:
parent
04c43a19c6
commit
ba42b37a67
2 changed files with 4 additions and 71 deletions
|
@ -15,14 +15,13 @@
|
||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
|
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::fmt::{Debug, Error, Formatter};
|
use std::fmt::{Debug, Error, Formatter};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::backend::CommitId;
|
|
||||||
use crate::op_store;
|
use crate::op_store;
|
||||||
use crate::op_store::{OpStore, OpStoreResult, OperationId, ViewId};
|
use crate::op_store::{OpStore, OpStoreResult, OperationId, ViewId};
|
||||||
|
use crate::view::View;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Operation {
|
pub struct Operation {
|
||||||
|
@ -94,76 +93,10 @@ impl Operation {
|
||||||
|
|
||||||
pub fn view(&self) -> OpStoreResult<View> {
|
pub fn view(&self) -> OpStoreResult<View> {
|
||||||
let data = self.op_store.read_view(&self.data.view_id)?;
|
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::new(data))
|
||||||
Ok(view)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn store_operation(&self) -> &op_store::Operation {
|
pub fn store_operation(&self) -> &op_store::Operation {
|
||||||
&self.data
|
&self.data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct View {
|
|
||||||
op_store: Arc<dyn OpStore>,
|
|
||||||
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<Ordering> {
|
|
||||||
Some(self.cmp(other))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Hash for View {
|
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
|
||||||
self.id.hash(state)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl View {
|
|
||||||
pub fn new(op_store: Arc<dyn OpStore>, id: ViewId, data: op_store::View) -> Self {
|
|
||||||
View { op_store, id, data }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn op_store(&self) -> Arc<dyn OpStore> {
|
|
||||||
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<CommitId> {
|
|
||||||
&self.data.head_ids
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -664,13 +664,13 @@ impl RepoLoader {
|
||||||
&self.op_store,
|
&self.op_store,
|
||||||
|op_heads| self._resolve_op_heads(op_heads, user_settings),
|
|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))
|
Ok(self._finish_load(op, view))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self))]
|
||||||
pub fn load_at(&self, op: &Operation) -> Result<Arc<ReadonlyRepo>, RepoLoaderError> {
|
pub fn load_at(&self, op: &Operation) -> Result<Arc<ReadonlyRepo>, RepoLoaderError> {
|
||||||
let view = View::new(op.view()?.take_store_view());
|
let view = op.view()?;
|
||||||
Ok(self._finish_load(op.clone(), view))
|
Ok(self._finish_load(op.clone(), view))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue