diff --git a/src/graft.rs b/src/graft.rs index 678a3b5c7..a9acd68ac 100644 --- a/src/graft.rs +++ b/src/graft.rs @@ -8,7 +8,6 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Mutex; use bstr::ByteSlice; -use once_cell::sync::Lazy; use crate::cinnabar::GitChangesetId; use crate::git::{CommitId, TreeId}; @@ -28,11 +27,14 @@ pub fn grafted() -> bool { static DID_SOMETHING: AtomicBool = AtomicBool::new(false); -static GRAFT_TREES: Lazy>>> = - Lazy::new(|| Mutex::new(BTreeMap::new())); +static GRAFT_TREES: Mutex>> = Mutex::new(BTreeMap::new()); pub fn graft_finish() -> Option { - Lazy::get(&GRAFT_TREES).map(|_| grafted() || DID_SOMETHING.load(Ordering::Relaxed)) + if GRAFT_TREES.lock().unwrap().is_empty() { + None + } else { + Some(grafted() || DID_SOMETHING.load(Ordering::Relaxed)) + } } pub fn init_graft() { @@ -68,12 +70,12 @@ pub fn graft( tree: TreeId, parents: &[GitChangesetId], ) -> Result, GraftError> { - if Lazy::get(&GRAFT_TREES).is_none() { + let mut graft_trees = GRAFT_TREES.lock().unwrap(); + if graft_trees.is_empty() { return Ok(None); } let changeset = raw_changeset.parse().unwrap(); - let mut graft_trees = GRAFT_TREES.lock().unwrap(); let graft_trees_entry = graft_trees.get_mut(&tree).ok_or(GraftError::NoGraft)?; let candidates = graft_trees_entry .iter() diff --git a/src/libgit.rs b/src/libgit.rs index b63f75aac..a6c803d31 100644 --- a/src/libgit.rs +++ b/src/libgit.rs @@ -18,7 +18,6 @@ use getset::{CopyGetters, Getters}; use hex_literal::hex; use itertools::EitherOrBoth; use itertools::Itertools; -use once_cell::sync::Lazy; use crate::git::{BlobId, CommitId, GitObjectId, GitOid, RecursedTreeEntry, TreeId}; use crate::oid::{Abbrev, ObjectId}; @@ -921,7 +920,7 @@ mod refs { } } -static REFS_LOCK: Lazy> = Lazy::new(|| RwLock::new(())); +static REFS_LOCK: RwLock<()> = RwLock::new(()); pub fn for_each_ref_in, F: FnMut(&OsStr, CommitId) -> Result<(), E>>( prefix: S, diff --git a/src/store.rs b/src/store.rs index 98dc3c58c..6fe87a396 100644 --- a/src/store.rs +++ b/src/store.rs @@ -992,7 +992,7 @@ pub fn get_tags() -> TagSet { tags } -static BUNDLE_BLOB: Lazy>> = Lazy::new(|| Mutex::new(None)); +static BUNDLE_BLOB: Mutex> = Mutex::new(None); #[no_mangle] pub unsafe extern "C" fn store_changesets_metadata(result: *mut object_id) {