forked from mirrors/jj
op heads: remove promote_new_op()
`OpHeadsStoreLock::promote_new_op()` doesn't add much over the new `update_op_heads()`, so let's switch to the latter.
This commit is contained in:
parent
b8e45d196f
commit
c304777a35
3 changed files with 11 additions and 21 deletions
|
@ -35,9 +35,7 @@ pub enum OpHeadResolutionError<E> {
|
|||
Err(#[source] E),
|
||||
}
|
||||
|
||||
pub trait OpHeadsStoreLock<'a> {
|
||||
fn promote_new_op(&self, new_op: &Operation);
|
||||
}
|
||||
pub trait OpHeadsStoreLock<'a> {}
|
||||
|
||||
/// Manages the set of current heads of the operation log.
|
||||
pub trait OpHeadsStore: Send + Sync + Debug {
|
||||
|
@ -109,7 +107,7 @@ pub fn resolve_op_heads<E>(
|
|||
// Note that the locking isn't necessary for correctness; we take the lock
|
||||
// only to prevent other concurrent processes from doing the same work (and
|
||||
// producing another set of divergent heads).
|
||||
let lock = op_heads_store.lock();
|
||||
let _lock = op_heads_store.lock();
|
||||
let op_head_ids = op_heads_store.get_op_heads();
|
||||
|
||||
if op_head_ids.is_empty() {
|
||||
|
@ -139,7 +137,7 @@ pub fn resolve_op_heads<E>(
|
|||
op_heads.sort_by_key(|op| op.store_operation().metadata.end_time.timestamp.clone());
|
||||
match resolver(op_heads) {
|
||||
Ok(new_op) => {
|
||||
lock.promote_new_op(&new_op);
|
||||
op_heads_store.update_op_heads(new_op.parent_ids(), new_op.id());
|
||||
Ok(new_op)
|
||||
}
|
||||
Err(e) => Err(OpHeadResolutionError::Err(e)),
|
||||
|
|
|
@ -22,7 +22,6 @@ use crate::backend::ObjectId;
|
|||
use crate::lock::FileLock;
|
||||
use crate::op_heads_store::{OpHeadsStore, OpHeadsStoreLock};
|
||||
use crate::op_store::OperationId;
|
||||
use crate::operation::Operation;
|
||||
|
||||
pub struct SimpleOpHeadsStore {
|
||||
dir: PathBuf,
|
||||
|
@ -53,19 +52,11 @@ impl SimpleOpHeadsStore {
|
|||
}
|
||||
}
|
||||
|
||||
struct SimpleOpHeadsStoreLock<'a> {
|
||||
store: &'a dyn OpHeadsStore,
|
||||
struct SimpleOpHeadsStoreLock {
|
||||
_lock: FileLock,
|
||||
}
|
||||
|
||||
impl OpHeadsStoreLock<'_> for SimpleOpHeadsStoreLock<'_> {
|
||||
fn promote_new_op(&self, new_op: &Operation) {
|
||||
self.store.add_op_head(new_op.id());
|
||||
for old_id in new_op.parent_ids() {
|
||||
self.store.remove_op_head(old_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
impl OpHeadsStoreLock<'_> for SimpleOpHeadsStoreLock {}
|
||||
|
||||
impl OpHeadsStore for SimpleOpHeadsStore {
|
||||
fn name(&self) -> &str {
|
||||
|
@ -105,7 +96,6 @@ impl OpHeadsStore for SimpleOpHeadsStore {
|
|||
|
||||
fn lock<'a>(&'a self) -> Box<dyn OpHeadsStoreLock<'a> + 'a> {
|
||||
Box::new(SimpleOpHeadsStoreLock {
|
||||
store: self,
|
||||
_lock: FileLock::lock(self.dir.join("lock")),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -175,10 +175,12 @@ impl UnpublishedOperation {
|
|||
|
||||
pub fn publish(mut self) -> Arc<ReadonlyRepo> {
|
||||
let data = self.data.take().unwrap();
|
||||
self.repo_loader
|
||||
.op_heads_store()
|
||||
.lock()
|
||||
.promote_new_op(&data.operation);
|
||||
{
|
||||
let _lock = self.repo_loader.op_heads_store().lock();
|
||||
self.repo_loader
|
||||
.op_heads_store()
|
||||
.update_op_heads(data.operation.parent_ids(), data.operation.id());
|
||||
}
|
||||
let repo = self
|
||||
.repo_loader
|
||||
.create_from(data.operation, data.view, data.index);
|
||||
|
|
Loading…
Reference in a new issue