File tree Expand file tree Collapse file tree 6 files changed +36
-6
lines changed Expand file tree Collapse file tree 6 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -158,7 +158,10 @@ pub mod path;
158158/// The standard type for a store to handle git references.
159159pub 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
163166pub ( crate ) type Config = OwnShared < gix_config:: File < ' static > > ;
164167
Original file line number Diff line number Diff line change @@ -39,3 +39,14 @@ impl crate::Repository {
3939 ( ten_mb_for_every_10k_files as usize ) . max ( 4 * 1024 )
4040 }
4141}
42+
43+ /// Handling of InMemory object writing
44+ impl crate :: Repository {
45+ /// When writing objects, keep them in memory instead of writing them to disk.
46+ /// This makes any change to the object database non-persisting, while keeping the view
47+ /// to the object database consistent for this instance.
48+ pub fn with_object_memory ( mut self ) -> Self {
49+ self . objects . enable_object_memory ( ) ;
50+ self
51+ }
52+ }
Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments