@@ -4,6 +4,7 @@ pub use remote::GitRemoteRepo;
44
55use crate :: env:: DeltaEnv ;
66use regex:: Regex ;
7+ use std:: cell:: OnceCell ;
78use std:: collections:: HashMap ;
89use std:: path:: Path ;
910
@@ -14,6 +15,7 @@ pub struct GitConfig {
1415 config_from_env_var : HashMap < String , String > ,
1516 pub enabled : bool ,
1617 repo : Option < git2:: Repository > ,
18+ remote_url : OnceCell < Option < GitRemoteRepo > > ,
1719 // To make GitConfig cloneable when testing (in turn to make Config cloneable):
1820 #[ cfg( test) ]
1921 path : std:: path:: PathBuf ,
@@ -29,6 +31,7 @@ impl Clone for GitConfig {
2931 config_from_env_var : self . config_from_env_var . clone ( ) ,
3032 enabled : self . enabled ,
3133 repo : None ,
34+ remote_url : OnceCell :: new ( ) ,
3235 path : self . path . clone ( ) ,
3336 }
3437 }
@@ -57,6 +60,7 @@ impl GitConfig {
5760 config_from_env_var : parse_config_from_env_var ( env) ,
5861 repo,
5962 enabled : true ,
63+ remote_url : OnceCell :: new ( ) ,
6064 } )
6165 }
6266 None => None ,
@@ -76,6 +80,7 @@ impl GitConfig {
7680 config_from_env_var : HashMap :: new ( ) ,
7781 enabled : true ,
7882 repo : None ,
83+ remote_url : OnceCell :: new ( ) ,
7984 path : std:: path:: PathBuf :: from ( "/invalid_null.git" ) ,
8085 } )
8186 }
@@ -98,6 +103,7 @@ impl GitConfig {
98103 } ,
99104 repo : None ,
100105 enabled : true ,
106+ remote_url : OnceCell :: new ( ) ,
101107 #[ cfg( test) ]
102108 path : path. into ( ) ,
103109 }
@@ -119,8 +125,13 @@ impl GitConfig {
119125 }
120126 }
121127
128+ #[ cfg( test) ]
129+ fn get_remote_url_impl ( & self ) -> Option < GitRemoteRepo > {
130+ GitRemoteRepo :: for_testing ( )
131+ }
132+
122133 #[ cfg( not( test) ) ]
123- pub fn get_remote_url ( & self ) -> Option < GitRemoteRepo > {
134+ fn get_remote_url_impl ( & self ) -> Option < GitRemoteRepo > {
124135 use std:: str:: FromStr ;
125136 self . repo
126137 . as_ref ( ) ?
@@ -130,6 +141,10 @@ impl GitConfig {
130141 . and_then ( |url| GitRemoteRepo :: from_str ( url) . ok ( ) )
131142 }
132143
144+ pub fn get_remote_url ( & self ) -> & Option < GitRemoteRepo > {
145+ self . remote_url . get_or_init ( || self . get_remote_url_impl ( ) )
146+ }
147+
133148 pub fn for_each < F > ( & self , regex : & str , mut f : F )
134149 where
135150 F : FnMut ( & str , Option < & str > ) ,
0 commit comments