ok/jj
1
0
Fork 0
forked from mirrors/jj

Replace NewRepoData with ReadonlyRepo in the UnpublishedOperation struct

`NewRepoData` is just a container that holds data used to construct a
`ReadonlyRepo`. The `ReaonlyRepo` is always constructed before the
`UnpublishedOperation` is dropped, so we can simply construct the
`ReadonlyRepo` upfront and delete the `NewRepoData` type.
This commit is contained in:
Evan Mesterhazy 2024-03-01 12:28:22 -05:00 committed by Evan Mesterhazy
parent c4cbf25545
commit 1439c902be

View file

@ -158,12 +158,6 @@ pub fn create_op_metadata(
}
}
struct NewRepoData {
operation: Operation,
view: View,
index: Box<dyn ReadonlyIndex>,
}
/// An Operation which has been written to the operation store but not
/// published. The repo can be loaded at an unpublished Operation, but the
/// Operation will not be visible in the op log if the repo is loaded at head.
@ -173,7 +167,7 @@ struct NewRepoData {
#[must_use = "Either publish() or leave_unpublished() must be called to finish the operation."]
pub struct UnpublishedOperation {
repo_loader: RepoLoader,
data: NewRepoData,
repo: Arc<ReadonlyRepo>,
}
impl UnpublishedOperation {
@ -183,34 +177,23 @@ impl UnpublishedOperation {
view: View,
index: Box<dyn ReadonlyIndex>,
) -> Self {
UnpublishedOperation {
repo_loader,
data: NewRepoData {
operation,
view,
index,
},
}
let repo = repo_loader.create_from(operation, view, index);
UnpublishedOperation { repo_loader, repo }
}
pub fn operation(&self) -> &Operation {
&self.data.operation
self.repo.operation()
}
pub fn publish(self) -> Arc<ReadonlyRepo> {
let data = self.data;
{
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 _lock = self.repo_loader.op_heads_store().lock();
self.repo_loader
.create_from(data.operation, data.view, data.index)
.op_heads_store()
.update_op_heads(self.operation().parent_ids(), self.operation().id());
self.repo
}
pub fn leave_unpublished(self) -> Arc<ReadonlyRepo> {
self.repo_loader
.create_from(self.data.operation, self.data.view, self.data.index)
self.repo
}
}