1- use crate :: client:: git;
1+ use crate :: {
2+ client:: { self , git, MessageKind , RequestWriter , SetServiceResponse , WriteMode } ,
3+ Service ,
4+ } ;
25use quick_error:: quick_error;
3- use std:: { path:: Path , process} ;
6+ use std:: process:: Stdio ;
7+ use std:: {
8+ path:: { Path , PathBuf } ,
9+ process,
10+ } ;
411
512quick_error ! {
613 #[ derive( Debug ) ]
@@ -11,9 +18,57 @@ quick_error! {
1118 }
1219}
1320
14- pub fn connect (
15- _path : & Path ,
16- _version : crate :: Protocol ,
17- ) -> Result < git:: Connection < process:: ChildStdout , process:: ChildStdin > , Error > {
18- unimplemented ! ( "file connection" )
21+ // from https://github.com/git/git/blob/20de7e7e4f4e9ae52e6cc7cfaa6469f186ddb0fa/environment.c#L115:L115
22+ const ENV_VARS_TO_REMOVE : & ' static [ & ' static str ] = & [
23+ "GIT_ALTERNATE_OBJECT_DIRECTORIES" ,
24+ "GIT_CONFIG" ,
25+ "GIT_CONFIG_PARAMETERS" ,
26+ "GIT_OBJECT_DIRECTORY" ,
27+ "GIT_DIR" ,
28+ "GIT_WORK_TREE" ,
29+ "GIT_IMPLICIT_WORK_TREE" ,
30+ "GIT_GRAFT_FILE" ,
31+ "GIT_INDEX_FILE" ,
32+ "GIT_NO_REPLACE_OBJECTS" ,
33+ "GIT_REPLACE_REF_BASE" ,
34+ "GIT_PREFIX" ,
35+ "GIT_INTERNAL_SUPER_PREFIX" ,
36+ "GIT_SHALLOW_FILE" ,
37+ "GIT_COMMON_DIR" ,
38+ ] ;
39+
40+ pub struct SpawnProcessOnDemand {
41+ path : PathBuf ,
42+ version : crate :: Protocol ,
43+ connection : Option < git:: Connection < process:: ChildStdout , process:: ChildStdin > > ,
44+ }
45+
46+ impl client:: Transport for SpawnProcessOnDemand {
47+ fn handshake ( & mut self , service : Service ) -> Result < SetServiceResponse , client:: Error > {
48+ assert ! (
49+ self . connection. is_none( ) ,
50+ "cannot handshake twice with the same connection"
51+ ) ;
52+ let mut cmd = std:: process:: Command :: new ( service. as_str ( ) ) ;
53+ for env_to_remove in ENV_VARS_TO_REMOVE {
54+ cmd. env_remove ( env_to_remove) ;
55+ }
56+ cmd. stderr ( Stdio :: null ( ) ) . stdout ( Stdio :: piped ( ) ) . stdin ( Stdio :: piped ( ) ) ;
57+ cmd. arg ( "--strict" ) . arg ( "--timeout=0" ) ;
58+ let child = cmd. spawn ( ) ?;
59+ // self.connection = Some(git::Connection {})
60+ unimplemented ! ( "invoke command" )
61+ }
62+
63+ fn request ( & mut self , write_mode : WriteMode , on_drop : Vec < MessageKind > ) -> Result < RequestWriter , client:: Error > {
64+ unimplemented ! ( )
65+ }
66+ }
67+
68+ pub fn connect ( path : & Path , version : crate :: Protocol ) -> Result < SpawnProcessOnDemand , std:: convert:: Infallible > {
69+ Ok ( SpawnProcessOnDemand {
70+ path : path. to_owned ( ) ,
71+ version,
72+ connection : None ,
73+ } )
1974}
0 commit comments