allow empty commit without revision

This commit is contained in:
Aiden McClelland
2021-09-01 16:14:18 -06:00
committed by Aiden McClelland
parent c3e28cb683
commit 932a5741e6

View File

@@ -27,7 +27,13 @@ pub struct Transaction<Parent: DbHandle> {
pub(crate) sub: Receiver<Arc<Revision>>, pub(crate) sub: Receiver<Arc<Revision>>,
} }
impl Transaction<&mut PatchDbHandle> { impl Transaction<&mut PatchDbHandle> {
pub async fn commit(mut self, expire_id: Option<String>) -> Result<Arc<Revision>, Error> { pub async fn commit(
mut self,
expire_id: Option<String>,
) -> Result<Option<Arc<Revision>>, Error> {
if (self.updates.0).0.is_empty() && expire_id.is_none() {
Ok(None)
} else {
let store_lock = self.parent.store(); let store_lock = self.parent.store();
let store = store_lock.write().await; let store = store_lock.write().await;
self.rebase()?; self.rebase()?;
@@ -36,7 +42,8 @@ impl Transaction<&mut PatchDbHandle> {
.db .db
.apply(self.updates, expire_id, Some(store)) .apply(self.updates, expire_id, Some(store))
.await?; .await?;
Ok(rev) Ok(Some(rev))
}
} }
pub async fn abort(mut self) -> Result<DiffPatch, Error> { pub async fn abort(mut self) -> Result<DiffPatch, Error> {
let store_lock = self.parent.store(); let store_lock = self.parent.store();