forked from mirrors/jj
op heads: add a new trait method combining add and remove of op heads
Consider how one would implment the current `OpHeadsStore` interface for a cloud-based backend. After `OpHeadsStore::add_op_head()` is called, the set of op heads temporarily contains two heads (typically) until `OpHeadsStore::remove_op_head()` is called. That's not invalid, but it's annoying to have to deal with that state more than necessary. Also, it's unnecessarily inefficient to send the addition and removal of op heads as separate RPCs. This patch therefore adds a `update_op_heads()` method that takes a list of old heads to remove and a single new head to add. Coming patches will start migrating to that method.
This commit is contained in:
parent
8137975785
commit
b8e45d196f
3 changed files with 15 additions and 1 deletions
|
@ -43,8 +43,15 @@ pub trait OpHeadsStoreLock<'a> {
|
|||
pub trait OpHeadsStore: Send + Sync + Debug {
|
||||
fn name(&self) -> &str;
|
||||
|
||||
/// Remove the old op heads and add the new one.
|
||||
///
|
||||
/// The old op heads must not contain the new one.
|
||||
fn update_op_heads(&self, old_ids: &[OperationId], new_id: &OperationId);
|
||||
|
||||
// TODO: migrate callers update_op_heads()
|
||||
fn add_op_head(&self, id: &OperationId);
|
||||
|
||||
// TODO: migrate callers update_op_heads()
|
||||
fn remove_op_head(&self, id: &OperationId);
|
||||
|
||||
fn get_op_heads(&self) -> Vec<OperationId>;
|
||||
|
|
|
@ -186,7 +186,7 @@ impl ReadonlyRepo {
|
|||
let init_operation_id = op_store.write_operation(&init_operation).unwrap();
|
||||
let init_operation = Operation::new(op_store.clone(), init_operation_id, init_operation);
|
||||
let op_heads_store = op_heads_store_initializer(user_settings, &op_heads_path);
|
||||
op_heads_store.add_op_head(init_operation.id());
|
||||
op_heads_store.update_op_heads(&[], init_operation.id());
|
||||
let op_heads_type_path = op_heads_path.join("type");
|
||||
fs::write(&op_heads_type_path, op_heads_store.name()).context(&op_heads_type_path)?;
|
||||
let op_heads_store = Arc::from(op_heads_store);
|
||||
|
|
|
@ -72,6 +72,13 @@ impl OpHeadsStore for SimpleOpHeadsStore {
|
|||
Self::name()
|
||||
}
|
||||
|
||||
fn update_op_heads(&self, old_ids: &[OperationId], new_id: &OperationId) {
|
||||
self.add_op_head(new_id);
|
||||
for old_id in old_ids {
|
||||
self.remove_op_head(old_id)
|
||||
}
|
||||
}
|
||||
|
||||
fn add_op_head(&self, id: &OperationId) {
|
||||
std::fs::write(self.dir.join(id.hex()), "").unwrap();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue