@@ -6,7 +6,7 @@ use std::{
66use anyhow:: Result ;
77use bytes:: { Buf , BufMut , Bytes , BytesMut } ;
88use callisto:: sea_orm_active_enums:: RefTypeEnum ;
9- use common:: errors:: { ProtocolError , mega_to_protocol_error} ;
9+ use common:: errors:: { ProtocolError , git_to_protocol_error , mega_to_protocol_error} ;
1010use tokio_stream:: wrappers:: ReceiverStream ;
1111
1212use crate :: {
@@ -153,48 +153,53 @@ impl SmartSession {
153153 let have: Vec < String > = have. into_iter ( ) . collect ( ) ;
154154
155155 if have. is_empty ( ) {
156- pack_data = repo_handler. full_pack ( want) . await . unwrap ( ) ;
156+ pack_data = repo_handler. full_pack ( want) . await . map_err ( |e| {
157+ tracing:: error!( error = %e, "git upload-pack full_pack failed" ) ;
158+ git_to_protocol_error ( e)
159+ } ) ?;
157160 add_pkt_line_string ( & mut protocol_buf, String :: from ( "NAK\n " ) ) ;
158- } else {
159- if self . capabilities . contains ( & Capability :: MultiAckDetailed ) {
160- // multi_ack_detailed mode, the server will differentiate the ACKs where it is signaling that
161- // it is ready to send data with ACK obj-id ready lines,
162- // and signals the identified common commits with ACK obj-id common lines
163-
164- for hash in & have {
165- if repo_handler. check_commit_exist ( hash) . await {
166- add_pkt_line_string ( & mut protocol_buf, format ! ( "ACK {hash} common\n " ) ) ;
167- if last_common_commit. is_empty ( ) {
168- last_common_commit = hash. to_string ( ) ;
169- }
161+ } else if self . capabilities . contains ( & Capability :: MultiAckDetailed ) {
162+ // multi_ack_detailed mode, the server will differentiate the ACKs where it is signaling that
163+ // it is ready to send data with ACK obj-id ready lines,
164+ // and signals the identified common commits with ACK obj-id common lines
165+
166+ for hash in & have {
167+ if repo_handler. check_commit_exist ( hash) . await {
168+ add_pkt_line_string ( & mut protocol_buf, format ! ( "ACK {hash} common\n " ) ) ;
169+ if last_common_commit. is_empty ( ) {
170+ last_common_commit = hash. to_string ( ) ;
170171 }
171172 }
172- pack_data = repo_handler
173- . incremental_pack ( want. clone ( ) , have)
174- . await
175- . unwrap ( ) ;
176-
177- if last_common_commit. is_empty ( ) {
178- //send NAK if missing common commit
179- add_pkt_line_string ( & mut protocol_buf, String :: from ( "NAK\n " ) ) ;
180- // need to handle rebase option, still need pack data when has no common commit
181- return Ok ( ( pack_data, protocol_buf) ) ;
182- }
173+ }
174+ pack_data = repo_handler
175+ . incremental_pack ( want. clone ( ) , have)
176+ . await
177+ . map_err ( |e| {
178+ tracing:: error!( error = %e, "git upload-pack incremental_pack failed" ) ;
179+ git_to_protocol_error ( e)
180+ } ) ?;
181+
182+ if last_common_commit. is_empty ( ) {
183+ //send NAK if missing common commit
184+ add_pkt_line_string ( & mut protocol_buf, String :: from ( "NAK\n " ) ) ;
185+ // need to handle rebase option, still need pack data when has no common commit
186+ return Ok ( ( pack_data, protocol_buf) ) ;
187+ }
183188
184- for hash in want {
185- if self . capabilities . contains ( & Capability :: NoDone ) {
186- // If multi_ack_detailed and no-done are both present, then the sender is free to immediately send a pack
187- // following its first "ACK obj-id ready" message.
188- add_pkt_line_string ( & mut protocol_buf, format ! ( "ACK {hash} ready\n " ) ) ;
189- }
189+ for hash in want {
190+ if self . capabilities . contains ( & Capability :: NoDone ) {
191+ // If multi_ack_detailed and no-done are both present, then the sender is free to immediately send a pack
192+ // following its first "ACK obj-id ready" message.
193+ add_pkt_line_string ( & mut protocol_buf, format ! ( "ACK {hash} ready\n " ) ) ;
190194 }
191- } else {
192- tracing:: error!( "capability unsupported" ) ;
193- // init a empty receiverstream
194- let ( _, rx) = tokio:: sync:: mpsc:: channel :: < Vec < u8 > > ( 1 ) ;
195- pack_data = ReceiverStream :: new ( rx) ;
196195 }
197196 add_pkt_line_string ( & mut protocol_buf, format ! ( "ACK {last_common_commit} \n " ) ) ;
197+ } else {
198+ tracing:: error!( "capability unsupported" ) ;
199+ // init a empty receiverstream
200+ let ( _, rx) = tokio:: sync:: mpsc:: channel :: < Vec < u8 > > ( 1 ) ;
201+ pack_data = ReceiverStream :: new ( rx) ;
202+ add_pkt_line_string ( & mut protocol_buf, format ! ( "ACK {last_common_commit} \n " ) ) ;
198203 }
199204 Ok ( ( pack_data, protocol_buf) )
200205 }
0 commit comments