Skip to content

Commit 162d416

Browse files
committed
feat!: optionally store objects new objects in memory only.
The default object database changed to a version that allows to keep objects in memory. This needs a mutable `Repository` instance to setup.
1 parent ca5294a commit 162d416

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

gix/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ pub mod path;
158158
/// The standard type for a store to handle git references.
159159
pub type RefStore = gix_ref::file::Store;
160160
/// A handle for finding objects in an object database, abstracting away caches for thread-local use.
161-
pub type OdbHandle = gix_odb::Handle;
161+
pub type OdbHandle = gix_odb::memory::Proxy<gix_odb::Handle>;
162+
/// A handle for finding objects in an object database, abstracting away caches for moving across threads.
163+
pub type OdbHandleArc = gix_odb::memory::Proxy<gix_odb::HandleArc>;
164+
162165
/// A way to access git configuration
163166
pub(crate) type Config = OwnShared<gix_config::File<'static>>;
164167

gix/src/repository/impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl From<&crate::ThreadSafeRepository> for crate::Repository {
3838
fn from(repo: &crate::ThreadSafeRepository) -> Self {
3939
crate::Repository::from_refs_and_objects(
4040
repo.refs.clone(),
41-
repo.objects.to_handle().into(),
41+
gix_odb::memory::Proxy::from(gix_odb::Cache::from(repo.objects.to_handle())).with_write_passthrough(),
4242
repo.work_tree.clone(),
4343
repo.common_dir.clone(),
4444
repo.config.clone(),
@@ -56,7 +56,7 @@ impl From<crate::ThreadSafeRepository> for crate::Repository {
5656
fn from(repo: crate::ThreadSafeRepository) -> Self {
5757
crate::Repository::from_refs_and_objects(
5858
repo.refs,
59-
repo.objects.to_handle().into(),
59+
gix_odb::memory::Proxy::from(gix_odb::Cache::from(repo.objects.to_handle())).with_write_passthrough(),
6060
repo.work_tree,
6161
repo.common_dir,
6262
repo.config,

gix/src/repository/object.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl crate::Repository {
109109
#[doc(alias = "exists", alias = "git2")]
110110
pub fn has_object(&self, id: impl AsRef<gix_hash::oid>) -> bool {
111111
let id = id.as_ref();
112-
if id == ObjectId::empty_tree(self.object_hash()) {
112+
if id.to_owned().is_empty_tree() {
113113
true
114114
} else {
115115
self.objects.exists(id)

gix/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub struct PathspecDetached {
247247
/// The prepared search to use for checking matches.
248248
pub search: gix_pathspec::Search,
249249
/// A thread-safe version of an ODB.
250-
pub odb: gix_odb::HandleArc,
250+
pub odb: crate::OdbHandleArc,
251251
}
252252

253253
/// A stand-in for the submodule of a particular name.

gix/tests/repository/object.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,24 @@ mod write_blob {
229229
#[test]
230230
fn from_slice() -> crate::Result {
231231
let (_tmp, repo) = empty_bare_repo()?;
232+
let expected = hex_to_id("95d09f2b10159347eece71399a7e2e907ea3df4f");
233+
assert!(!repo.has_object(expected));
234+
232235
let oid = repo.write_blob(b"hello world")?;
233-
assert_eq!(oid, hex_to_id("95d09f2b10159347eece71399a7e2e907ea3df4f"));
236+
assert_eq!(oid, expected);
237+
238+
let mut other_repo = gix::open_opts(repo.path(), gix::open::Options::isolated())?;
239+
other_repo.objects.enable_object_memory();
240+
assert!(
241+
other_repo.has_object(oid),
242+
"we definitely don't accidentally write to memory only"
243+
);
244+
let in_memory_id = other_repo.write_blob("hello world - to memory")?;
245+
assert!(!repo.has_object(in_memory_id), "the object was never written to disk…");
246+
assert!(
247+
other_repo.has_object(in_memory_id),
248+
"…and exists only in the instance that wrote it"
249+
);
234250
Ok(())
235251
}
236252

0 commit comments

Comments
 (0)