@@ -30,42 +30,52 @@ impl easy::Handle {
30
30
/// the cache efficiency is low. Use `GITOXIDE_PACK_CACHE_MEMORY=512MB` to use up to 512MB of RAM for the pack delta base
31
31
/// cache. If none of these are set, the default cache is fast enough to nearly never cause a (marginal) slow-down while providing
32
32
/// some gains most of the time. Note that the value given is _per-thread_.
33
- pub fn apply_environment ( mut self ) -> Self {
34
- self . objects . set_pack_cache ( || {
35
- #[ cfg( not( feature = "max-performance" ) ) ]
36
- {
37
- Box :: new ( git_pack:: cache:: Never )
38
- }
39
- #[ cfg( feature = "max-performance" ) ]
40
- {
41
- use std:: convert:: TryInto ;
42
- if std:: env:: var_os ( "GITOXIDE_DISABLE_PACK_CACHE" ) . is_some ( ) {
43
- Box :: new ( git_pack:: cache:: Never )
44
- } else if let Some ( bytes) = std:: env:: var ( "GITOXIDE_PACK_CACHE_MEMORY" )
45
- . ok ( )
46
- . and_then ( |v| {
47
- byte_unit:: Byte :: from_str ( & v)
48
- . map_err ( |err| log:: warn!( "Failed to parse {:?} into byte unit for pack cache: {}" , v, err) )
33
+ pub fn apply_environment ( self ) -> Self {
34
+ // We have no cache types available without this flag currently. Maybe this should change at some point.
35
+ #[ cfg( not( feature = "max-performance" ) ) ]
36
+ return self ;
37
+ #[ cfg( feature = "max-performance" ) ]
38
+ {
39
+ let new_pack_cache = {
40
+ let pack_cache_disabled = std:: env:: var_os ( "GITOXIDE_DISABLE_PACK_CACHE" ) . is_some ( ) ;
41
+ let bytes = ( !pack_cache_disabled)
42
+ . then ( || {
43
+ std:: env:: var ( "GITOXIDE_PACK_CACHE_MEMORY" )
49
44
. ok ( )
50
- } )
51
- . and_then ( |unit| {
52
- unit. get_bytes ( )
53
- . try_into ( )
54
- . map_err ( |err| {
55
- log:: warn!(
45
+ . and_then ( |v| {
46
+ byte_unit:: Byte :: from_str ( & v)
47
+ . map_err ( |err| {
48
+ log:: warn!( "Failed to parse {:?} into byte unit for pack cache: {}" , v, err)
49
+ } )
50
+ . ok ( )
51
+ } )
52
+ . and_then ( |unit| {
53
+ use std:: convert:: TryInto ;
54
+ unit. get_bytes ( )
55
+ . try_into ( )
56
+ . map_err ( |err| {
57
+ log:: warn!(
56
58
"Parsed bytes value is not representable as usize. Defaulting to standard pack cache: {}" ,
57
59
err
58
60
)
61
+ } )
62
+ . ok ( )
59
63
} )
60
- . ok ( )
61
64
} )
62
- {
63
- Box :: new ( git_pack:: cache:: lru:: MemoryCappedHashmap :: new ( bytes) )
64
- } else {
65
- Box :: new ( git_pack:: cache:: lru:: StaticLinkedList :: < 64 > :: default ( ) )
65
+ . flatten ( ) ;
66
+ move || -> Box < git_odb:: handle:: PackCache > {
67
+ if pack_cache_disabled {
68
+ Box :: new ( git_pack:: cache:: Never )
69
+ } else if let Some ( bytes) = bytes {
70
+ Box :: new ( git_pack:: cache:: lru:: MemoryCappedHashmap :: new ( bytes) )
71
+ } else {
72
+ Box :: new ( git_pack:: cache:: lru:: StaticLinkedList :: < 64 > :: default ( ) )
73
+ }
66
74
}
67
- }
68
- } ) ;
69
- self
75
+ } ;
76
+ let mut this = self ;
77
+ this. objects . set_pack_cache ( new_pack_cache) ;
78
+ this
79
+ }
70
80
}
71
81
}
0 commit comments