Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Context.server/client_caps -> their/my_caps #627

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions fuzz/smart.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ let ( >>= ) = Crowbar.dynamic_bind

let () =
let of_string str =
let ctx = Smart.Context.make ~client_caps:[] in
let ctx = Smart.Context.make ~my_caps:[] in
let state =
Smart.decode ctx (Smart.packet ~trim:false) (fun _ctx res -> Return res)
in
Expand Down Expand Up @@ -99,7 +99,7 @@ let () =

let () =
let of_string str =
let ctx = Smart.Context.make ~client_caps:[] in
let ctx = Smart.Context.make ~my_caps:[] in
let state =
Smart.decode ctx Smart.advertised_refs (fun _ctx res -> Return res)
in
Expand All @@ -119,7 +119,7 @@ let () =
go state
in
let to_string v =
let ctx = Smart.Context.make ~client_caps:[] in
let ctx = Smart.Context.make ~my_caps:[] in
let buf = Buffer.create 0x1000 in
let state =
Smart.encode ctx Smart.send_advertised_refs v (fun _ctx ->
Expand Down Expand Up @@ -155,7 +155,7 @@ let () =

let () =
let of_string str =
let ctx = Smart.Context.make ~client_caps:[] in
let ctx = Smart.Context.make ~my_caps:[] in
let state = Smart.decode ctx Smart.recv_want (fun _ctx res -> Return res) in
let pos = ref 0 in
let rec go = function
Expand All @@ -173,7 +173,7 @@ let () =
go state
in
let to_string v =
let ctx = Smart.Context.make ~client_caps:[] in
let ctx = Smart.Context.make ~my_caps:[] in
let buf = Buffer.create 0x1000 in
let state =
Smart.encode ctx Smart.send_want v (fun _ctx ->
Expand Down
6 changes: 3 additions & 3 deletions src/not-so-smart/fetch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct
let fetch_v1 ?(uses_git_transport = false) ?(push_stdout = ignore)
?(push_stderr = ignore) ~capabilities ?deepen ?want:(refs = `None) ~host
path flow store access fetch_cfg pack =
let client_caps =
let my_caps =
(* XXX(dinosaure): HTTP ([stateless]) enforces no-done capabilities. Otherwise, you never
will receive the PACK file. *)
if fetch_cfg.Neg.no_done && not (no_done capabilities) then
Expand All @@ -97,11 +97,11 @@ struct
let* v = recv ctx advertised_refs in
let v = Smart.Advertised_refs.map ~fuid:Uid.of_hex ~fref:Ref.v v in
let uids, refs = references refs (Smart.Advertised_refs.refs v) in
Smart.Context.replace_server_caps ctx
Smart.Context.replace_their_caps ctx
(Smart.Advertised_refs.capabilities v);
return (uids, refs)
in
let ctx = Smart.Context.make ~client_caps in
let ctx = Smart.Context.make ~my_caps in
let negotiator = Neg.make ~compare:Uid.compare in
Neg.tips sched access store negotiator |> prj >>= fun () ->
Smart_flow.run sched fail io flow (prelude ctx) |> prj
Expand Down
6 changes: 2 additions & 4 deletions src/not-so-smart/find_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,13 @@ let find_common (type t) scheduler io flow cfg
Smart.(
let uid = to_hex uid in
let others = List.map (fun (uid, _) -> to_hex uid) others in
let { Smart.Context.client_caps; _ } =
Smart.Context.capabilities ctx
in
let { Smart.Context.my_caps; _ } = Smart.Context.capabilities ctx in
let deepen =
(deepen
:> [ `Depth of int | `Not of string | `Timestamp of int64 ] option)
in
send ctx send_want
(Want.v ~capabilities:client_caps ~shallows:shallowed ?deepen
(Want.v ~capabilities:my_caps ~shallows:shallowed ?deepen
(uid :: others)))
>>= fun () ->
(match deepen with
Expand Down
10 changes: 5 additions & 5 deletions src/not-so-smart/push.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ struct
pp_error = Flow.pp_error;
}

let push ?(uses_git_transport = false) ~capabilities:client_caps cmds ~host
path flow store access { stateless } pack =
let push ?(uses_git_transport = false) ~capabilities:my_caps cmds ~host path
flow store access { stateless } pack =
let fiber ctx =
let open Smart in
let* () =
Expand All @@ -50,13 +50,13 @@ struct
else return ()
in
let* v = recv ctx advertised_refs in
Context.replace_server_caps ctx (Smart.Advertised_refs.capabilities v);
Context.replace_their_caps ctx (Smart.Advertised_refs.capabilities v);
return (Smart.Advertised_refs.map ~fuid:Uid.of_hex ~fref:Ref.v v)
in
let ctx = Smart.Context.make ~client_caps in
let ctx = Smart.Context.make ~my_caps in
Smart_flow.run sched fail io flow (fiber ctx) |> prj
>>= fun advertised_refs ->
Pck.commands sched ~capabilities:client_caps ~equal:Ref.equal
Pck.commands sched ~capabilities:my_caps ~equal:Ref.equal
~deref:access.Sigs.deref store cmds
(Smart.Advertised_refs.refs advertised_refs)
|> prj
Expand Down
6 changes: 3 additions & 3 deletions src/not-so-smart/smart.ml
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ module Context = struct
type t = State.Context.t

type capabilities = State.Context.capabilities = {
client_caps : Capability.t list;
server_caps : Capability.t list;
my_caps : Capability.t list;
their_caps : Capability.t list;
}

let make = State.Context.make
let with_decoder = State.Context.with_decoder
let replace_server_caps = State.Context.replace_server_caps
let replace_their_caps = State.Context.replace_their_caps
let is_cap_shared = State.Context.is_cap_shared
let capabilities = State.Context.capabilities
end
Expand Down
13 changes: 5 additions & 8 deletions src/not-so-smart/smart.mli
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,13 @@ module Context : sig
type t

type capabilities = State.Context.capabilities = {
client_caps : Capability.t list;
server_caps : Capability.t list;
my_caps : Capability.t list;
their_caps : Capability.t list;
}

val make : client_caps:Capability.t list -> t

val with_decoder :
client_caps:Capability.t list -> Pkt_line.Decoder.decoder -> t

val replace_server_caps : t -> Capability.t list -> unit
val make : my_caps:Capability.t list -> t
val with_decoder : my_caps:Capability.t list -> Pkt_line.Decoder.decoder -> t
val replace_their_caps : t -> Capability.t list -> unit
val is_cap_shared : t -> Capability.t -> bool
val capabilities : t -> capabilities
end
Expand Down
20 changes: 10 additions & 10 deletions src/not-so-smart/state.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ end

module Context = struct
type capabilities = {
client_caps : Capability.t list;
server_caps : Capability.t list;
my_caps : Capability.t list;
their_caps : Capability.t list;
}

type t = {
Expand All @@ -50,31 +50,31 @@ module Context = struct

let pp _pp_ctx _ppf _t = ()

let make ~client_caps =
let capabilities = { client_caps; server_caps = [] } in
let make ~my_caps =
let capabilities = { my_caps; their_caps = [] } in
{
encoder = Pkt_line.Encoder.create ();
decoder = Pkt_line.Decoder.create ();
capabilities;
}

let with_decoder ~client_caps decoder =
let with_decoder ~my_caps decoder =
{
encoder = Pkt_line.Encoder.create ();
decoder;
capabilities = { client_caps; server_caps = [] };
capabilities = { my_caps; their_caps = [] };
}

let encoder { encoder; _ } = encoder
let decoder { decoder; _ } = decoder
let capabilities { capabilities; _ } = capabilities

let replace_server_caps ctx server_caps =
ctx.capabilities <- { ctx.capabilities with server_caps }
let replace_their_caps ctx their_caps =
ctx.capabilities <- { ctx.capabilities with their_caps }

let is_cap_shared { capabilities = { client_caps; server_caps }; _ } cap =
let is_cap_shared { capabilities = { my_caps; their_caps }; _ } cap =
let is_cap_in caps = List.exists (fun c -> Capability.equal c cap) caps in
is_cap_in client_caps && is_cap_in server_caps
is_cap_in my_caps && is_cap_in their_caps
end

module Scheduler
Expand Down
13 changes: 5 additions & 8 deletions src/not-so-smart/state.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,19 @@ end

module Context : sig
type capabilities = {
client_caps : Capability.t list;
server_caps : Capability.t list;
my_caps : Capability.t list;
their_caps : Capability.t list;
}

include
CONTEXT
with type encoder = Pkt_line.Encoder.encoder
and type decoder = Pkt_line.Decoder.decoder

val make : client_caps:Capability.t list -> t

val with_decoder :
client_caps:Capability.t list -> Pkt_line.Decoder.decoder -> t

val make : my_caps:Capability.t list -> t
val with_decoder : my_caps:Capability.t list -> Pkt_line.Decoder.decoder -> t
val capabilities : t -> capabilities
val replace_server_caps : t -> Capability.t list -> unit
val replace_their_caps : t -> Capability.t list -> unit
val is_cap_shared : t -> Capability.t -> bool
end

Expand Down
2 changes: 1 addition & 1 deletion test/smart/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1784,7 +1784,7 @@ let test_push_capabilities () =
| Ok () -> (
let[@warning "-8"] (Some v) = !output in
let decoder = Pkt_line.Decoder.of_string (Cstruct.to_string v) in
let ctx = Smart.Context.with_decoder ~client_caps:capabilities decoder in
let ctx = Smart.Context.with_decoder ~my_caps:capabilities decoder in
match Smart.recv ctx Smart.recv_commands with
| Smart.Return (Some v) ->
let c = Smart.Commands.capabilities v in
Expand Down