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

cleanup: import futures::exectutor::block_on() instead of qualifying

It seems we'll end up using `block_on()` quite a bit, at least until
we're done transitioning to async, and the function name doesn't
conflict with anything else, so let's always import it when we need
it.
This commit is contained in:
Martin von Zweigbergk 2023-10-18 16:58:19 -07:00 committed by Martin von Zweigbergk
parent eee140eef3
commit f541f9f3a6
4 changed files with 28 additions and 27 deletions

View file

@ -931,6 +931,7 @@ fn bytes_vec_from_json(value: &serde_json::Value) -> Vec<u8> {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use futures::executor::block_on;
use test_case::test_case;
use super::*;
@ -1013,7 +1014,7 @@ mod tests {
.collect_vec();
assert_eq!(git_refs, vec![git_commit_id2]);
let commit = futures::executor::block_on(backend.read_commit(&commit_id)).unwrap();
let commit = block_on(backend.read_commit(&commit_id)).unwrap();
assert_eq!(&commit.change_id, &change_id);
assert_eq!(commit.parents, vec![CommitId::from_bytes(&[0; 20])]);
assert_eq!(commit.predecessors, vec![]);
@ -1042,7 +1043,7 @@ mod tests {
);
assert_eq!(commit.committer.timestamp.tz_offset, -480);
let root_tree = futures::executor::block_on(backend.read_tree(
let root_tree = block_on(backend.read_tree(
&RepoPath::root(),
&TreeId::from_bytes(root_tree_id.as_bytes()),
))
@ -1056,7 +1057,7 @@ mod tests {
&TreeValue::Tree(TreeId::from_bytes(dir_tree_id.as_bytes()))
);
let dir_tree = futures::executor::block_on(backend.read_tree(
let dir_tree = block_on(backend.read_tree(
&RepoPath::from_internal_string("dir"),
&TreeId::from_bytes(dir_tree_id.as_bytes()),
))
@ -1079,7 +1080,7 @@ mod tests {
&TreeValue::Symlink(SymlinkId::from_bytes(blob2.as_bytes()))
);
let commit2 = futures::executor::block_on(backend.read_commit(&commit_id2)).unwrap();
let commit2 = block_on(backend.read_commit(&commit_id2)).unwrap();
assert_eq!(commit2.parents, vec![commit_id.clone()]);
assert_eq!(commit.predecessors, vec![]);
assert_eq!(
@ -1118,10 +1119,9 @@ mod tests {
// read_commit() without import_head_commits() works as of now. This might be
// changed later.
assert!(futures::executor::block_on(
backend.read_commit(&CommitId::from_bytes(git_commit_id.as_bytes()))
)
.is_ok());
assert!(
block_on(backend.read_commit(&CommitId::from_bytes(git_commit_id.as_bytes()))).is_ok()
);
assert!(
backend
.cached_extra_metadata_table()
@ -1209,7 +1209,7 @@ mod tests {
// Only root commit as parent
commit.parents = vec![backend.root_commit_id().clone()];
let first_id = backend.write_commit(commit.clone()).unwrap().0;
let first_commit = futures::executor::block_on(backend.read_commit(&first_id)).unwrap();
let first_commit = block_on(backend.read_commit(&first_id)).unwrap();
assert_eq!(first_commit, commit);
let first_git_commit = git_repo.find_commit(git_id(&first_id)).unwrap();
assert_eq!(first_git_commit.parent_ids().collect_vec(), vec![]);
@ -1217,7 +1217,7 @@ mod tests {
// Only non-root commit as parent
commit.parents = vec![first_id.clone()];
let second_id = backend.write_commit(commit.clone()).unwrap().0;
let second_commit = futures::executor::block_on(backend.read_commit(&second_id)).unwrap();
let second_commit = block_on(backend.read_commit(&second_id)).unwrap();
assert_eq!(second_commit, commit);
let second_git_commit = git_repo.find_commit(git_id(&second_id)).unwrap();
assert_eq!(
@ -1228,7 +1228,7 @@ mod tests {
// Merge commit
commit.parents = vec![first_id.clone(), second_id.clone()];
let merge_id = backend.write_commit(commit.clone()).unwrap().0;
let merge_commit = futures::executor::block_on(backend.read_commit(&merge_id)).unwrap();
let merge_commit = block_on(backend.read_commit(&merge_id)).unwrap();
assert_eq!(merge_commit, commit);
let merge_git_commit = git_repo.find_commit(git_id(&merge_id)).unwrap();
assert_eq!(
@ -1278,8 +1278,7 @@ mod tests {
// When writing a tree-level conflict, the root tree on the git side has the
// individual trees as subtrees.
let read_commit_id = backend.write_commit(commit.clone()).unwrap().0;
let read_commit =
futures::executor::block_on(backend.read_commit(&read_commit_id)).unwrap();
let read_commit = block_on(backend.read_commit(&read_commit_id)).unwrap();
assert_eq!(read_commit, commit);
let git_commit = git_repo
.find_commit(Oid::from_bytes(read_commit_id.as_bytes()).unwrap())
@ -1308,8 +1307,7 @@ mod tests {
// regular git tree.
commit.root_tree = MergedTreeId::resolved(create_tree(5));
let read_commit_id = backend.write_commit(commit.clone()).unwrap().0;
let read_commit =
futures::executor::block_on(backend.read_commit(&read_commit_id)).unwrap();
let read_commit = block_on(backend.read_commit(&read_commit_id)).unwrap();
assert_eq!(read_commit, commit);
let git_commit = git_repo
.find_commit(Oid::from_bytes(read_commit_id.as_bytes()).unwrap())
@ -1375,7 +1373,7 @@ mod tests {
let (commit_id2, mut actual_commit2) = backend.write_commit(commit2.clone()).unwrap();
// The returned matches the ID
assert_eq!(
futures::executor::block_on(backend.read_commit(&commit_id2)).unwrap(),
block_on(backend.read_commit(&commit_id2)).unwrap(),
actual_commit2
);
assert_ne!(commit_id2, commit_id1);

View file

@ -461,6 +461,7 @@ fn conflict_term_to_proto(part: &ConflictTerm) -> crate::protos::local_store::co
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use futures::executor::block_on;
use super::*;
use crate::backend::MillisSinceEpoch;
@ -492,26 +493,25 @@ mod tests {
// Only root commit as parent
commit.parents = vec![backend.root_commit_id().clone()];
let first_id = backend.write_commit(commit.clone()).unwrap().0;
let first_commit = futures::executor::block_on(backend.read_commit(&first_id)).unwrap();
let first_commit = block_on(backend.read_commit(&first_id)).unwrap();
assert_eq!(first_commit, commit);
// Only non-root commit as parent
commit.parents = vec![first_id.clone()];
let second_id = backend.write_commit(commit.clone()).unwrap().0;
let second_commit = futures::executor::block_on(backend.read_commit(&second_id)).unwrap();
let second_commit = block_on(backend.read_commit(&second_id)).unwrap();
assert_eq!(second_commit, commit);
// Merge commit
commit.parents = vec![first_id.clone(), second_id.clone()];
let merge_id = backend.write_commit(commit.clone()).unwrap().0;
let merge_commit = futures::executor::block_on(backend.read_commit(&merge_id)).unwrap();
let merge_commit = block_on(backend.read_commit(&merge_id)).unwrap();
assert_eq!(merge_commit, commit);
// Merge commit with root as one parent
commit.parents = vec![first_id, backend.root_commit_id().clone()];
let root_merge_id = backend.write_commit(commit.clone()).unwrap().0;
let root_merge_commit =
futures::executor::block_on(backend.read_commit(&root_merge_id)).unwrap();
let root_merge_commit = block_on(backend.read_commit(&root_merge_id)).unwrap();
assert_eq!(root_merge_commit, commit);
}

View file

@ -20,6 +20,7 @@ use std::iter::zip;
use std::sync::Arc;
use std::{iter, vec};
use futures::executor::block_on;
use futures::stream::StreamExt;
use itertools::Itertools;
@ -891,7 +892,7 @@ impl Iterator for TreeDiffIterator<'_> {
let tree_after = after.is_tree();
let post_subdir =
if (tree_before || tree_after) && !self.matcher.visit(&path).is_nothing() {
let (before_tree, after_tree) = futures::executor::block_on(async {
let (before_tree, after_tree) = block_on(async {
let before_tree = Self::tree(dir.tree1.as_ref(), &path, &before);
let after_tree = Self::tree(dir.tree2.as_ref(), &path, &after);
futures::join!(before_tree, after_tree)

View file

@ -20,6 +20,8 @@ use std::fmt::{Debug, Formatter};
use std::io::Read;
use std::sync::{Arc, RwLock};
use futures::executor::block_on;
use crate::backend;
use crate::backend::{
Backend, BackendResult, ChangeId, CommitId, ConflictId, FileId, MergedTreeId, SymlinkId,
@ -97,7 +99,7 @@ impl Store {
}
pub fn get_commit(self: &Arc<Self>, id: &CommitId) -> BackendResult<Commit> {
futures::executor::block_on(self.get_commit_async(id))
block_on(self.get_commit_async(id))
}
pub async fn get_commit_async(self: &Arc<Self>, id: &CommitId) -> BackendResult<Commit> {
@ -132,7 +134,7 @@ impl Store {
}
pub fn get_tree(self: &Arc<Self>, dir: &RepoPath, id: &TreeId) -> BackendResult<Tree> {
futures::executor::block_on(self.get_tree_async(dir, id))
block_on(self.get_tree_async(dir, id))
}
pub async fn get_tree_async(
@ -192,7 +194,7 @@ impl Store {
}
pub fn read_file(&self, path: &RepoPath, id: &FileId) -> BackendResult<Box<dyn Read>> {
futures::executor::block_on(self.read_file_async(path, id))
block_on(self.read_file_async(path, id))
}
pub async fn read_file_async(
@ -208,7 +210,7 @@ impl Store {
}
pub fn read_symlink(&self, path: &RepoPath, id: &SymlinkId) -> BackendResult<String> {
futures::executor::block_on(self.read_symlink_async(path, id))
block_on(self.read_symlink_async(path, id))
}
pub async fn read_symlink_async(
@ -228,7 +230,7 @@ impl Store {
path: &RepoPath,
id: &ConflictId,
) -> BackendResult<Merge<Option<TreeValue>>> {
let backend_conflict = futures::executor::block_on(self.backend.read_conflict(path, id))?;
let backend_conflict = block_on(self.backend.read_conflict(path, id))?;
Ok(Merge::from_backend_conflict(backend_conflict))
}