1616//! connect git-upload-pack → GET /info/refs | POST /git-upload-pack
1717//! connect git-receive-pack → GET /info/refs | POST /git-receive-pack (+ auth header)
1818
19- use std:: io:: { self , BufRead , Read , Write } ;
2019use anyhow:: { bail, Context , Result } ;
21- use gitlawb_core:: identity:: Keypair ;
2220use gitlawb_core:: http_sig:: sign_request;
21+ use gitlawb_core:: identity:: Keypair ;
22+ use std:: io:: { self , BufRead , Read , Write } ;
2323
2424fn main ( ) -> Result < ( ) > {
2525 // All logging goes to stderr so it doesn't corrupt the git protocol on stdout
2626 tracing_subscriber:: fmt ( )
2727 . with_writer ( std:: io:: stderr)
28- . with_env_filter (
29- std:: env:: var ( "GITLAWB_LOG" ) . unwrap_or_else ( |_| "warn" . to_string ( ) ) ,
30- )
28+ . with_env_filter ( std:: env:: var ( "GITLAWB_LOG" ) . unwrap_or_else ( |_| "warn" . to_string ( ) ) )
3129 . init ( ) ;
3230
3331 let args: Vec < String > = std:: env:: args ( ) . collect ( ) ;
@@ -42,8 +40,8 @@ fn main() -> Result<()> {
4240 let ( _, short_owner, repo_name) = parse_gitlawb_url ( url) ?;
4341
4442 // v0.1: default to localhost. Override with GITLAWB_NODE env var.
45- let node_base = std :: env :: var ( "GITLAWB_NODE" )
46- . unwrap_or_else ( |_| "http://127.0.0.1:7545" . to_string ( ) ) ;
43+ let node_base =
44+ std :: env :: var ( "GITLAWB_NODE" ) . unwrap_or_else ( |_| "http://127.0.0.1:7545" . to_string ( ) ) ;
4745 let repo_base = format ! ( "{}/{}/{}" , node_base, short_owner, repo_name) ;
4846 tracing:: debug!( "repo_base: {repo_base}" ) ;
4947
@@ -62,7 +60,9 @@ fn run_helper(repo_base: &str, keypair: Option<&Keypair>) -> Result<()> {
6260
6361 loop {
6462 let mut line = String :: new ( ) ;
65- let n = stdin_buf. read_line ( & mut line) . context ( "reading command from git" ) ?;
63+ let n = stdin_buf
64+ . read_line ( & mut line)
65+ . context ( "reading command from git" ) ?;
6666 if n == 0 {
6767 break ; // EOF
6868 }
@@ -149,7 +149,10 @@ fn handle_connect(
149149 // But git's `connect` protocol expects raw git-upload-pack output (no HTTP wrapper).
150150 // Strip the service-line pkt-line + flush before forwarding.
151151 let advertisement = strip_service_announcement ( & refs_bytes) ;
152- tracing:: debug!( "ref advertisement: {} bytes (stripped)" , advertisement. len( ) ) ;
152+ tracing:: debug!(
153+ "ref advertisement: {} bytes (stripped)" ,
154+ advertisement. len( )
155+ ) ;
153156
154157 let mut stdout = io:: stdout ( ) ;
155158 stdout. write_all ( advertisement) ?;
@@ -172,7 +175,9 @@ fn handle_connect(
172175 read_upload_pack_request ( stdin) . context ( "reading upload-pack request" ) ?
173176 } else {
174177 let mut buf = Vec :: new ( ) ;
175- stdin. read_to_end ( & mut buf) . context ( "reading receive-pack request" ) ?;
178+ stdin
179+ . read_to_end ( & mut buf)
180+ . context ( "reading receive-pack request" ) ?;
176181 buf
177182 } ;
178183
@@ -192,10 +197,7 @@ fn handle_connect(
192197
193198 let mut req = client
194199 . post ( & post_url)
195- . header (
196- "Content-Type" ,
197- format ! ( "application/x-{}-request" , service) ,
198- )
200+ . header ( "Content-Type" , format ! ( "application/x-{}-request" , service) )
199201 . header ( "User-Agent" , "git/2.0 git-remote-gitlawb/0.1.0" )
200202 . body ( request_body. clone ( ) ) ;
201203
@@ -215,9 +217,7 @@ fn handle_connect(
215217 }
216218 }
217219
218- let pack_resp = req
219- . send ( )
220- . with_context ( || format ! ( "POST {post_url}" ) ) ?;
220+ let pack_resp = req. send ( ) . with_context ( || format ! ( "POST {post_url}" ) ) ?;
221221
222222 if !pack_resp. status ( ) . is_success ( ) {
223223 bail ! ( "POST /{} returned {}" , service, pack_resp. status( ) ) ;
@@ -296,7 +296,9 @@ fn read_upload_pack_request(stdin: &mut io::BufReader<io::Stdin>) -> Result<Vec<
296296
297297 let data_len = pkt_len - 4 ;
298298 let mut data = vec ! [ 0u8 ; data_len] ;
299- stdin. read_exact ( & mut data) . context ( "reading pkt-line data" ) ?;
299+ stdin
300+ . read_exact ( & mut data)
301+ . context ( "reading pkt-line data" ) ?;
300302 buf. extend_from_slice ( & data) ;
301303
302304 // "done\n" signals the end of the want/have negotiation
@@ -380,8 +382,8 @@ fn load_keypair() -> Option<Keypair> {
380382}
381383
382384fn resolve_key_path ( ) -> std:: path:: PathBuf {
383- let path_str = std :: env :: var ( "GITLAWB_KEY" )
384- . unwrap_or_else ( |_| "~/.gitlawb/identity.pem" . to_string ( ) ) ;
385+ let path_str =
386+ std :: env :: var ( "GITLAWB_KEY" ) . unwrap_or_else ( |_| "~/.gitlawb/identity.pem" . to_string ( ) ) ;
385387
386388 if let Some ( stripped) = path_str. strip_prefix ( "~/" ) {
387389 let home = std:: env:: var ( "HOME" ) . unwrap_or_else ( |_| "." . to_string ( ) ) ;
@@ -399,17 +401,15 @@ mod tests {
399401
400402 #[ test]
401403 fn parse_standard_url ( ) {
402- let ( did, owner, repo) =
403- parse_gitlawb_url ( "gitlawb://did:key:z6MkFoo123/my-repo" ) . unwrap ( ) ;
404+ let ( did, owner, repo) = parse_gitlawb_url ( "gitlawb://did:key:z6MkFoo123/my-repo" ) . unwrap ( ) ;
404405 assert_eq ! ( did, "did:key:z6MkFoo123" ) ;
405406 assert_eq ! ( owner, "z6MkFoo123" ) ;
406407 assert_eq ! ( repo, "my-repo" ) ;
407408 }
408409
409410 #[ test]
410411 fn parse_url_strips_dot_git ( ) {
411- let ( _, _, repo) =
412- parse_gitlawb_url ( "gitlawb://did:key:z6MkFoo123/my-repo.git" ) . unwrap ( ) ;
412+ let ( _, _, repo) = parse_gitlawb_url ( "gitlawb://did:key:z6MkFoo123/my-repo.git" ) . unwrap ( ) ;
413413 assert_eq ! ( repo, "my-repo" ) ;
414414 }
415415
0 commit comments