File tree 5 files changed +25
-6
lines changed
5 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -158,7 +158,10 @@ pub mod path;
158
158
/// The standard type for a store to handle git references.
159
159
pub type RefStore = gix_ref:: file:: Store ;
160
160
/// 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
+
162
165
/// A way to access git configuration
163
166
pub ( crate ) type Config = OwnShared < gix_config:: File < ' static > > ;
164
167
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ impl From<&crate::ThreadSafeRepository> for crate::Repository {
38
38
fn from ( repo : & crate :: ThreadSafeRepository ) -> Self {
39
39
crate :: Repository :: from_refs_and_objects (
40
40
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 ( ) ,
42
42
repo. work_tree . clone ( ) ,
43
43
repo. common_dir . clone ( ) ,
44
44
repo. config . clone ( ) ,
@@ -56,7 +56,7 @@ impl From<crate::ThreadSafeRepository> for crate::Repository {
56
56
fn from ( repo : crate :: ThreadSafeRepository ) -> Self {
57
57
crate :: Repository :: from_refs_and_objects (
58
58
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 ( ) ,
60
60
repo. work_tree ,
61
61
repo. common_dir ,
62
62
repo. config ,
Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ impl crate::Repository {
109
109
#[ doc( alias = "exists" , alias = "git2" ) ]
110
110
pub fn has_object ( & self , id : impl AsRef < gix_hash:: oid > ) -> bool {
111
111
let id = id. as_ref ( ) ;
112
- if id == ObjectId :: empty_tree ( self . object_hash ( ) ) {
112
+ if id. to_owned ( ) . is_empty_tree ( ) {
113
113
true
114
114
} else {
115
115
self . objects . exists ( id)
Original file line number Diff line number Diff line change @@ -247,7 +247,7 @@ pub struct PathspecDetached {
247
247
/// The prepared search to use for checking matches.
248
248
pub search : gix_pathspec:: Search ,
249
249
/// A thread-safe version of an ODB.
250
- pub odb : gix_odb :: HandleArc ,
250
+ pub odb : crate :: OdbHandleArc ,
251
251
}
252
252
253
253
/// 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 {
229
229
#[ test]
230
230
fn from_slice ( ) -> crate :: Result {
231
231
let ( _tmp, repo) = empty_bare_repo ( ) ?;
232
+ let expected = hex_to_id ( "95d09f2b10159347eece71399a7e2e907ea3df4f" ) ;
233
+ assert ! ( !repo. has_object( expected) ) ;
234
+
232
235
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
+ ) ;
234
250
Ok ( ( ) )
235
251
}
236
252
You can’t perform that action at this time.
0 commit comments