@@ -39,6 +39,97 @@ impl Cache {
3939 . copied ( )
4040 }
4141
42+ #[ cfg( feature = "blob-diff" ) ]
43+ pub ( crate ) fn diff_drivers ( & self ) -> Result < Vec < gix_diff:: blob:: Driver > , config:: diff:: drivers:: Error > {
44+ use crate :: config:: cache:: util:: ApplyLeniencyDefault ;
45+ let mut out = Vec :: < gix_diff:: blob:: Driver > :: new ( ) ;
46+ for section in self
47+ . resolved
48+ . sections_by_name ( "diff" )
49+ . into_iter ( )
50+ . flatten ( )
51+ . filter ( |s| ( self . filter_config_section ) ( s. meta ( ) ) )
52+ {
53+ let Some ( name) = section. header ( ) . subsection_name ( ) . filter ( |n| !n. is_empty ( ) ) else {
54+ continue ;
55+ } ;
56+
57+ let driver = match out. iter_mut ( ) . find ( |d| d. name == name) {
58+ Some ( existing) => existing,
59+ None => {
60+ out. push ( gix_diff:: blob:: Driver {
61+ name : name. into ( ) ,
62+ ..Default :: default ( )
63+ } ) ;
64+ out. last_mut ( ) . expect ( "just pushed" )
65+ }
66+ } ;
67+
68+ if let Some ( binary) = section. value_implicit ( "binary" ) {
69+ driver. is_binary = config:: tree:: Diff :: DRIVER_BINARY
70+ . try_into_binary ( binary)
71+ . with_leniency ( self . lenient_config )
72+ . map_err ( |err| config:: diff:: drivers:: Error {
73+ name : driver. name . clone ( ) ,
74+ attribute : "binary" ,
75+ source : Box :: new ( err) ,
76+ } ) ?;
77+ }
78+ if let Some ( command) = section. value ( config:: tree:: Diff :: DRIVER_COMMAND . name ) {
79+ driver. command = command. into_owned ( ) . into ( ) ;
80+ }
81+ if let Some ( textconv) = section. value ( config:: tree:: Diff :: DRIVER_TEXTCONV . name ) {
82+ driver. binary_to_text_command = textconv. into_owned ( ) . into ( ) ;
83+ }
84+ if let Some ( algorithm) = section. value ( "algorithm" ) {
85+ driver. algorithm = config:: tree:: Diff :: DRIVER_ALGORITHM
86+ . try_into_algorithm ( algorithm)
87+ . or_else ( |err| match err {
88+ config:: diff:: algorithm:: Error :: Unimplemented { .. } if self . lenient_config => {
89+ Ok ( gix_diff:: blob:: Algorithm :: Histogram )
90+ }
91+ err => Err ( err) ,
92+ } )
93+ . with_lenient_default ( self . lenient_config )
94+ . map_err ( |err| config:: diff:: drivers:: Error {
95+ name : driver. name . clone ( ) ,
96+ attribute : "algorithm" ,
97+ source : Box :: new ( err) ,
98+ } ) ?
99+ . into ( ) ;
100+ }
101+ }
102+ Ok ( out)
103+ }
104+
105+ #[ cfg( feature = "blob-diff" ) ]
106+ pub ( crate ) fn diff_pipeline_options (
107+ & self ,
108+ ) -> Result < gix_diff:: blob:: pipeline:: Options , config:: diff:: pipeline_options:: Error > {
109+ Ok ( gix_diff:: blob:: pipeline:: Options {
110+ large_file_threshold_bytes : self . big_file_threshold ( ) ?,
111+ fs : self . fs_capabilities ( ) ?,
112+ } )
113+ }
114+
115+ #[ cfg( feature = "blob-diff" ) ]
116+ pub ( crate ) fn diff_renames ( & self ) -> Result < Option < crate :: diff:: Rewrites > , crate :: diff:: new_rewrites:: Error > {
117+ self . diff_renames
118+ . get_or_try_init ( || crate :: diff:: new_rewrites ( & self . resolved , self . lenient_config ) )
119+ . copied ( )
120+ }
121+
122+ #[ cfg( feature = "blob-diff" ) ]
123+ pub ( crate ) fn big_file_threshold ( & self ) -> Result < u64 , config:: unsigned_integer:: Error > {
124+ Ok ( self
125+ . resolved
126+ . integer_by_key ( "core.bigFileThreshold" )
127+ . map ( |number| Core :: BIG_FILE_THRESHOLD . try_into_u64 ( number) )
128+ . transpose ( )
129+ . with_leniency ( self . lenient_config ) ?
130+ . unwrap_or ( 512 * 1024 * 1024 ) )
131+ }
132+
42133 /// Returns a user agent for use with servers.
43134 #[ cfg( any( feature = "async-network-client" , feature = "blocking-network-client" ) ) ]
44135 pub ( crate ) fn user_agent_tuple ( & self ) -> ( & ' static str , Option < Cow < ' static , str > > ) {
@@ -92,13 +183,6 @@ impl Cache {
92183 } )
93184 }
94185
95- #[ cfg( feature = "blob-diff" ) ]
96- pub ( crate ) fn diff_renames ( & self ) -> Result < Option < crate :: diff:: Rewrites > , crate :: diff:: new_rewrites:: Error > {
97- self . diff_renames
98- . get_or_try_init ( || crate :: diff:: new_rewrites ( & self . resolved , self . lenient_config ) )
99- . copied ( )
100- }
101-
102186 /// Returns (file-timeout, pack-refs timeout)
103187 pub ( crate ) fn lock_timeout (
104188 & self ,
0 commit comments