Skip to content
Closed
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
4 changes: 2 additions & 2 deletions git.opam
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ depends: [
"checkseum" {>= "0.0.9"}
"stdlib-shims"
"ke"
"encore" {>= "0.5"}
"duff"
"encore" {>= "0.5" & < "0.6"}
"duff" {< "0.3"}
"hex"
"ocplib-endian"
"rresult"
Expand Down
25 changes: 22 additions & 3 deletions src/git-mirage/git_mirage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ module Sync (G : Git.S) = struct

module Tcp = Git.Tcp.Make (Net) (Endpoint) (G)

module Ssh = Git.Ssh.Make (Net) (Endpoint) (G)

module Client = struct
(* XXX(samoht): too much copy/paste from git-unix ... *)

Expand Down Expand Up @@ -93,15 +95,17 @@ module Sync (G : Git.S) = struct

module Http = Git_http.Sync.CohttpMake (Client) (Endpoint) (G)

type error = Tcp of Tcp.error | Http of Http.error
type error = Tcp of Tcp.error | Http of Http.error | Ssh of Ssh.error

let pp_error ppf = function
| Tcp x -> Tcp.pp_error ppf x
| Http x -> Http.pp_error ppf x
| Ssh x -> Ssh.pp_error ppf x

let dispatch e f =
match Uri.scheme e.uri with
| Some "git" -> f `Tcp
| Some "ssh" -> f `Ssh
| Some ("http" | "https") -> f `Http
| Some s -> Fmt.invalid_arg "%a: invalid scheme (%s)" Uri.pp_hum e.uri s
| None -> Fmt.invalid_arg "%a: missing scheme" Uri.pp_hum e.uri
Expand All @@ -118,17 +122,22 @@ module Sync (G : Git.S) = struct
let tcp_error x =
Lwt.map (function Ok _ as x -> x | Error e -> Error (Tcp e)) x

let ssh_error x =
Lwt.map (function Ok _ as x -> x | Error e -> Error (Ssh e)) x

let http_error x =
Lwt.map (function Ok _ as x -> x | Error e -> Error (Http e)) x

let push t ~push ?capabilities e =
dispatch e (function
| `Tcp -> Tcp.push t ~push ?capabilities e |> tcp_error
| `Http -> Http.push t ~push ?capabilities e |> http_error )
| `Tcp -> Tcp.push t ~push ?capabilities e |> tcp_error
| `Ssh -> Ssh.push t ~push ?capabilities e |> ssh_error
| `Http -> Http.push t ~push ?capabilities e |> http_error )

let ls t ?capabilities e =
dispatch e (function
| `Tcp -> Tcp.ls t ?capabilities e |> tcp_error
| `Ssh -> Ssh.ls t ?capabilities e |> ssh_error
| `Http -> Http.ls t ?capabilities e |> http_error )

let fetch t ?shallow ?capabilities ~notify ~negociate ~have ~want ?deepen e =
Expand All @@ -137,6 +146,10 @@ module Sync (G : Git.S) = struct
Tcp.fetch t ?shallow ?capabilities ~notify ~negociate ~have ~want
?deepen e
|> tcp_error
| `Ssh ->
Ssh.fetch t ?shallow ?capabilities ~notify ~negociate ~have ~want
?deepen e
|> ssh_error
| `Http ->
Http.fetch t ?shallow ?capabilities ~notify ~negociate ~have ~want
?deepen e
Expand All @@ -145,27 +158,33 @@ module Sync (G : Git.S) = struct
let clone t ?capabilities ~reference e =
dispatch e (function
| `Tcp -> Tcp.clone t ?capabilities ~reference e |> tcp_error
| `Ssh -> Ssh.clone t ?capabilities ~reference e |> ssh_error
| `Http -> Http.clone t ?capabilities ~reference e |> http_error )

let fetch_some t ?capabilities ~references e =
dispatch e (function
| `Tcp -> Tcp.fetch_some t ?capabilities ~references e |> tcp_error
| `Ssh -> Ssh.fetch_some t ?capabilities ~references e |> ssh_error
| `Http -> Http.fetch_some t ?capabilities ~references e |> http_error )

let fetch_all t ?capabilities ~references e =
dispatch e (function
| `Tcp -> Tcp.fetch_all t ?capabilities ~references e |> tcp_error
| `Ssh -> Ssh.fetch_all t ?capabilities ~references e |> ssh_error
| `Http -> Http.fetch_all t ?capabilities ~references e |> http_error )

let fetch_one t ?capabilities ~reference e =
dispatch e (function
| `Tcp -> Tcp.fetch_one t ?capabilities ~reference e |> tcp_error
| `Ssh -> Ssh.fetch_one t ?capabilities ~reference e |> ssh_error
| `Http -> Http.fetch_one t ?capabilities ~reference e |> http_error )

let update_and_create t ?capabilities ~references e =
dispatch e (function
| `Tcp ->
Tcp.update_and_create t ?capabilities ~references e |> tcp_error
| `Ssh ->
Ssh.update_and_create t ?capabilities ~references e |> ssh_error
| `Http ->
Http.update_and_create t ?capabilities ~references e |> http_error )
end
2 changes: 2 additions & 0 deletions src/git-mirage/git_mirage.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ val endpoint :
module Sync (G : Git.S) : sig
module Tcp : Git.Sync.S with module Store := G and type Endpoint.t = endpoint

module Ssh : Git.Sync.S with module Store := G and type Endpoint.t = endpoint

module Http :
Git_http.Sync.S with module Store := G and type Client.endpoint = endpoint

Expand Down
10 changes: 8 additions & 2 deletions src/git-mirage/net.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ let read {ic; _} raw off len =
(* XXX(dinosaure): Channel.error is not a variant. *)
Lwt.return_ok 0

let socket (t : endpoint) =
let socket ?cmd (t : endpoint) =
let open Lwt.Infix in
let uri = (t.uri :> Uri.t) in
Resolver_lwt.resolve_uri ~uri t.resolver
>>= fun endp ->
Conduit_mirage.client endp
let config =
match Cohttp.Header.get t.headers "config", cmd with
| None, None -> None
| Some cfg, Some e -> Some (e ^ ":" ^ cfg)
| _ -> None
in
Conduit_mirage.client ?config endp
>>= fun client ->
Conduit_mirage.connect t.conduit client
>>= fun flow ->
Expand Down
2 changes: 1 addition & 1 deletion src/git-unix/net.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let host uri =
| None ->
Fmt.kstrf failwith "Expected a git url with host: %a." Uri.pp_hum uri

let socket (e : endpoint) =
let socket ?cmd:_ (e : endpoint) =
let open Lwt.Infix in
let uri = e.uri in
Log.debug (fun l ->
Expand Down
1 change: 1 addition & 0 deletions src/git/git.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ module Buffer = Cstruct_buffer
module Hash = Hash
module Gri = Gri
module Tcp = Tcp
module Ssh = Ssh
module Path = Path
1 change: 1 addition & 0 deletions src/git/git.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module Buffer = Cstruct_buffer
module Hash = Hash
module Gri = Gri
module Tcp = Tcp
module Ssh = Ssh
module Path = Path

module type FILE = S.FILE
Expand Down
17 changes: 10 additions & 7 deletions src/git/smart.ml
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ module type CLIENT = sig

val pp_result : result Fmt.t
val run : context -> action -> process
val context : Common.git_proto_request -> context * process
val context : Common.git_proto_request option -> context * process
end

module Decoder
Expand Down Expand Up @@ -2542,10 +2542,13 @@ struct
; encoder= Encoder.encoder ()
; capabilities= [] }
in
( context
, encode (`GitProtoRequest c)
(decode Decoder.ReferenceDiscovery (fun refs ctx -> match refs with
| Ok refs -> ctx.capabilities <- refs.Common.capabilities ; `Refs refs
| Error (`Msg err) -> `SmartError err))
context )
let decoder =
decode Decoder.ReferenceDiscovery (fun refs ctx -> match refs with
| Ok refs -> ctx.capabilities <- refs.Common.capabilities ; `Refs refs
| Error (`Msg err) -> `SmartError err)
in
( context ,
match c with
| None -> decoder context
| Some c -> encode (`GitProtoRequest c) decoder context)
end
2 changes: 1 addition & 1 deletion src/git/smart.mli
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ module type CLIENT = sig
(** [run ctx action] sends an action to the server and schedule a specific
{!Decoder.transaction} then. *)

val context : Common.git_proto_request -> context * process
val context : Common.git_proto_request option -> context * process
(** [context request] makes a new context and the continuation of the
transport. *)
end
Expand Down
Loading