@@ -23,7 +23,20 @@ impl GraphQLHelper {
2323 . join ( path) ;
2424 let path = normalize_path ( & path) ;
2525
26- let transaction = cache:: Transaction :: open ( & self . repo_path , Some ( & self . ref_prefix ) ) ?;
26+ let transaction = if let Ok ( to) =
27+ cache:: Transaction :: open ( & self . repo_path . join ( "mirror" ) , Some ( & self . ref_prefix ) )
28+ {
29+ to. repo ( ) . odb ( ) ?. add_disk_alternate (
30+ self . repo_path
31+ . join ( "overlay" )
32+ . join ( "objects" )
33+ . to_str ( )
34+ . unwrap ( ) ,
35+ ) ?;
36+ to
37+ } else {
38+ cache:: Transaction :: open ( & self . repo_path , Some ( & self . ref_prefix ) ) ?
39+ } ;
2740
2841 let tree = transaction. repo ( ) . find_commit ( self . commit_id ) ?. tree ( ) ?;
2942
@@ -41,8 +54,26 @@ impl GraphQLHelper {
4154 variables. insert ( k. to_string ( ) , juniper:: InputValue :: scalar ( v. render ( ) ) ) ;
4255 }
4356
44- let transaction = cache:: Transaction :: open ( & self . repo_path , None ) ?;
45- let transaction_overlay = cache:: Transaction :: open ( & self . repo_path , None ) ?;
57+ let ( transaction, transaction_overlay) =
58+ if let Ok ( to) = cache:: Transaction :: open ( & self . repo_path . join ( "overlay" ) , None ) {
59+ to. repo ( ) . odb ( ) ?. add_disk_alternate (
60+ self . repo_path
61+ . join ( "mirror" )
62+ . join ( "objects" )
63+ . to_str ( )
64+ . unwrap ( ) ,
65+ ) ?;
66+ (
67+ cache:: Transaction :: open ( & self . repo_path . join ( "mirror" ) , None ) ?,
68+ to,
69+ )
70+ } else {
71+ (
72+ cache:: Transaction :: open ( & self . repo_path , None ) ?,
73+ cache:: Transaction :: open ( & self . repo_path , None ) ?,
74+ )
75+ } ;
76+
4677 let ( res, _errors) = juniper:: execute_sync (
4778 & query,
4879 None ,
@@ -77,7 +108,7 @@ impl handlebars::HelperDef for GraphQLHelper {
77108 h. hash ( ) ,
78109 rc. get_current_template_name ( ) . unwrap_or ( & "/" . to_owned ( ) ) ,
79110 )
80- . map_err ( |_ | handlebars:: RenderError :: new ( "josh" ) ) ?,
111+ . map_err ( |e | handlebars:: RenderError :: new ( format ! ( "{}" , e ) ) ) ?,
81112 ) ) ;
82113 }
83114}
@@ -91,6 +122,7 @@ pub fn render(
91122 ref_prefix : & str ,
92123 commit_id : git2:: Oid ,
93124 query_and_params : & str ,
125+ split_odb : bool ,
94126) -> JoshResult < Option < String > > {
95127 let mut parameters = query_and_params. split ( '&' ) ;
96128 let query = parameters
@@ -162,13 +194,24 @@ pub fn render(
162194 drop ( obj) ;
163195 drop ( tree) ;
164196
197+ let repo_path = if split_odb {
198+ transaction
199+ . repo ( )
200+ . path ( )
201+ . parent ( )
202+ . ok_or ( josh_error ( "parent" ) ) ?
203+ . to_owned ( )
204+ } else {
205+ transaction. repo ( ) . path ( ) . to_owned ( )
206+ } ;
207+
165208 let mut handlebars = handlebars:: Handlebars :: new ( ) ;
166209 handlebars. register_template_string ( path, template) ?;
167210 handlebars. register_helper ( "concat" , Box :: new ( helpers:: concat_helper) ) ;
168211 handlebars. register_helper (
169212 "graphql" ,
170213 Box :: new ( GraphQLHelper {
171- repo_path : transaction . repo ( ) . path ( ) . to_owned ( ) ,
214+ repo_path : repo_path ,
172215 ref_prefix : ref_prefix. to_owned ( ) ,
173216 commit_id,
174217 } ) ,
0 commit comments