Skip to content

Commit

Permalink
upload-pack: Handle empty request
Browse files Browse the repository at this point in the history
The client uses empty requests when:
- It is already up to date
- `git ls-remote`

Signed-off-by: Paul-Elliot <[email protected]>
  • Loading branch information
panglesd authored and dinosaure committed Nov 22, 2023
1 parent da063d9 commit 12d4e15
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
10 changes: 6 additions & 4 deletions fuzz/smart.ml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ let () =
let wants = List.map Digestif.SHA1.to_hex wants in
let v = Smart.Want.v ~capabilities:[] wants in
let str = to_string v in
let res = of_string str in
Crowbar.check_eq ~pp:Smart.Want.pp
~eq:(Smart.Want.equal ~uid:String.equal ~reference:String.equal)
v res
match of_string str with
| Some res ->
Crowbar.check_eq ~pp:Smart.Want.pp
~eq:(Smart.Want.equal ~uid:String.equal ~reference:String.equal)
v res
| None -> Crowbar.failf "Invalid empty fetch request (%S)" str
7 changes: 5 additions & 2 deletions src/not-so-smart/protocol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,9 @@ module Decoder = struct
let v = peek_pkt decoder in
if Sub.is_empty v then (
junk_pkt decoder;
return (Want.v ~capabilities (first_want :: List.rev wants)) decoder
return
(Some (Want.v ~capabilities (first_want :: List.rev wants)))
decoder
(* TODO else if start with shallow or depth request or filter request then *))
else
match Sub.cut ~sep:v_space v with
Expand All @@ -639,7 +641,8 @@ module Decoder = struct

let decode_first_want decoder =
let v = peek_pkt decoder in
if Sub.is_prefix v ~affix:v_want then (
if Sub.is_empty v then return None decoder
else if Sub.is_prefix v ~affix:v_want then (
let v = v |> Sub.with_range ~first:(Sub.length v_want) in
(* NOTE(dinosaure): we accept more than Git. The BNF syntax of
[first-want] is:
Expand Down
5 changes: 4 additions & 1 deletion src/not-so-smart/protocol.mli
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ module Decoder : sig
?sideband:bool -> decoder -> (string Status.t, [> error ]) state

val decode_packet : trim:bool -> decoder -> (string, [> error ]) state
val decode_want : decoder -> ((string, string) Want.t, [> error ]) state

val decode_want :
decoder -> ((string, string) Want.t option, [> error ]) state

val decode_have : decoder -> (string Have.t, [> error ]) state

val decode_commands :
Expand Down
2 changes: 1 addition & 1 deletion src/not-so-smart/smart.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module Witness = struct
| Ack : string Negotiation.t recv
| Flush : unit recv
| Shallows : string Shallow.t list recv
| Want : (string, string) Want.t recv
| Want : (string, string) Want.t option recv
| Have : string Have.t recv
end

Expand Down
2 changes: 1 addition & 1 deletion src/not-so-smart/smart.mli
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ val shallows : string Shallow.t list recv
val status : bool -> string Status.t recv
val packet : trim:bool -> string recv
val send_advertised_refs : (string, string) Advertised_refs.t send
val recv_want : (string, string) Want.t recv
val recv_want : (string, string) Want.t option recv
val recv_have : string Have.t recv
val bind : ('a, 'err) t -> f:('a -> ('b, 'err) t) -> ('b, 'err) t
val ( let* ) : ('a, 'err) t -> ('a -> ('b, 'err) t) -> ('b, 'err) t
Expand Down

0 comments on commit 12d4e15

Please sign in to comment.