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:
parent
c4cbf25545
commit
1439c902be
1 changed files with 9 additions and 26 deletions
|
@ -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
|
/// An Operation which has been written to the operation store but not
|
||||||
/// published. The repo can be loaded at an unpublished Operation, but the
|
/// 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.
|
/// 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."]
|
#[must_use = "Either publish() or leave_unpublished() must be called to finish the operation."]
|
||||||
pub struct UnpublishedOperation {
|
pub struct UnpublishedOperation {
|
||||||
repo_loader: RepoLoader,
|
repo_loader: RepoLoader,
|
||||||
data: NewRepoData,
|
repo: Arc<ReadonlyRepo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UnpublishedOperation {
|
impl UnpublishedOperation {
|
||||||
|
@ -183,34 +177,23 @@ impl UnpublishedOperation {
|
||||||
view: View,
|
view: View,
|
||||||
index: Box<dyn ReadonlyIndex>,
|
index: Box<dyn ReadonlyIndex>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
UnpublishedOperation {
|
let repo = repo_loader.create_from(operation, view, index);
|
||||||
repo_loader,
|
UnpublishedOperation { repo_loader, repo }
|
||||||
data: NewRepoData {
|
|
||||||
operation,
|
|
||||||
view,
|
|
||||||
index,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn operation(&self) -> &Operation {
|
pub fn operation(&self) -> &Operation {
|
||||||
&self.data.operation
|
self.repo.operation()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn publish(self) -> Arc<ReadonlyRepo> {
|
pub fn publish(self) -> Arc<ReadonlyRepo> {
|
||||||
let data = self.data;
|
let _lock = self.repo_loader.op_heads_store().lock();
|
||||||
{
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
self.repo_loader
|
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> {
|
pub fn leave_unpublished(self) -> Arc<ReadonlyRepo> {
|
||||||
self.repo_loader
|
self.repo
|
||||||
.create_from(self.data.operation, self.data.view, self.data.index)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue