store: make write_commit() async

This just propagates the async a little bit futher where it's easy to
do so.
This commit is contained in:
Martin von Zweigbergk 2024-09-03 20:13:46 -07:00 committed by Martin von Zweigbergk
parent 8eb3d85b1c
commit 3136426dd6
4 changed files with 11 additions and 5 deletions

View file

@ -16,6 +16,8 @@
use std::sync::Arc;
use pollster::FutureExt;
use crate::backend;
use crate::backend::BackendResult;
use crate::backend::ChangeId;
@ -341,5 +343,7 @@ fn write_to_store(
// if we're rewriting a signed commit
commit.secure_sig = None;
store.write_commit(commit, should_sign.then_some(&mut &sign_fn))
store
.write_commit(commit, should_sign.then_some(&mut &sign_fn))
.block_on()
}

View file

@ -153,14 +153,14 @@ impl Store {
Ok(data)
}
pub fn write_commit(
pub async fn write_commit(
self: &Arc<Self>,
commit: backend::Commit,
sign_with: Option<&mut SigningFn>,
sign_with: Option<&mut SigningFn<'_>>,
) -> BackendResult<Commit> {
assert!(!commit.parents.is_empty());
let (commit_id, commit) = self.backend.write_commit(commit, sign_with).block_on()?;
let (commit_id, commit) = self.backend.write_commit(commit, sign_with).await?;
let data = Arc::new(commit);
{
let mut locked_cache = self.commit_cache.lock().unwrap();

View file

@ -22,5 +22,6 @@ git2 = { workspace = true }
hex = { workspace = true }
itertools = { workspace = true }
jj-lib = { workspace = true, features = ["testing"] }
pollster = { workspace = true }
rand = { workspace = true }
tempfile = { workspace = true }

View file

@ -58,6 +58,7 @@ use jj_lib::tree_builder::TreeBuilder;
use jj_lib::working_copy::SnapshotError;
use jj_lib::working_copy::SnapshotOptions;
use jj_lib::workspace::Workspace;
use pollster::FutureExt;
use tempfile::TempDir;
use crate::test_backend::TestBackend;
@ -387,7 +388,7 @@ pub fn commit_with_tree(store: &Arc<Store>, tree_id: MergedTreeId) -> Commit {
committer: signature,
secure_sig: None,
};
store.write_commit(commit, None).unwrap()
store.write_commit(commit, None).block_on().unwrap()
}
pub fn dump_tree(store: &Arc<Store>, tree_id: &MergedTreeId) -> String {