Skip to content
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
2 changes: 0 additions & 2 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,6 @@
(>= v0.17))
(ppx_hash
(>= v0.17))
(ppx_sexp_value
(>= v0.17))
(ppxlib
(>= 0.33))
(re
Expand Down
2 changes: 1 addition & 1 deletion example/dune
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
(lint
(pps ppx_js_style -allow-let-operators -check-doc-comments))
(preprocess
(pps ppx_expect ppx_sexp_value)))
(pps ppx_expect)))
8 changes: 4 additions & 4 deletions example/hello_error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let%expect_test "hello error" =
let () =
match Vcs.init vcs ~path:invalid_path with
| _ -> assert false
| exception Err.E err -> print_s (redact_sexp [%sexp (err : Err.t)])
| exception Err.E err -> print_s (redact_sexp (err |> Err.sexp_of_t))
in
[%expect
{|
Expand All @@ -49,7 +49,7 @@ let%expect_test "hello error" =
let () =
match Vcs.Or_error.init vcs ~path:invalid_path with
| Ok _ -> assert false
| Error err -> print_s (redact_sexp [%sexp (err : Error.t)])
| Error err -> print_s (redact_sexp (err |> Error.sexp_of_t))
in
[%expect
{|
Expand All @@ -61,7 +61,7 @@ let%expect_test "hello error" =
let () =
match Vcs.Result.init vcs ~path:invalid_path with
| Ok _ -> assert false
| Error err -> print_s (redact_sexp [%sexp (err : Err.t)])
| Error err -> print_s (redact_sexp (err |> Err.sexp_of_t))
in
[%expect
{|
Expand All @@ -73,7 +73,7 @@ let%expect_test "hello error" =
let () =
match Vcs.Rresult.init vcs ~path:invalid_path with
| Ok _ -> assert false
| Error err -> print_s (redact_sexp [%sexp (err : Vcs.Rresult.err)])
| Error err -> print_s (redact_sexp (err |> Vcs.Rresult.sexp_of_err))
in
[%expect
{|
Expand Down
30 changes: 15 additions & 15 deletions example/hello_git_cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ let%expect_test "hello cli" =
| exception Err.E err ->
print_s
(Vcs_test_helpers.redact_sexp
[%sexp (err : Err.t)]
(err |> Err.sexp_of_t)
~fields:[ "cwd"; "repo_root"; "stderr" ])
in
[%expect
Expand All @@ -134,7 +134,7 @@ let%expect_test "hello cli" =
| Error error ->
print_s
(Vcs_test_helpers.redact_sexp
[%sexp (error : Error.t)]
(error |> Error.sexp_of_t)
~fields:[ "cwd"; "repo_root"; "stderr" ])
in
[%expect
Expand All @@ -155,7 +155,7 @@ let%expect_test "hello cli" =
| Error err ->
print_s
(Vcs_test_helpers.redact_sexp
[%sexp (err : Err.t)]
(err |> Err.sexp_of_t)
~fields:[ "cwd"; "repo_root"; "stderr" ])
in
[%expect
Expand All @@ -180,7 +180,7 @@ let%expect_test "hello cli" =
| Error (`Vcs err) ->
print_s
(Vcs_test_helpers.redact_sexp
[%sexp (err : Err.t)]
(err |> Err.sexp_of_t)
~fields:[ "cwd"; "repo_root"; "stderr" ])
in
[%expect
Expand All @@ -203,14 +203,14 @@ let%expect_test "hello cli" =
in
(* You may be tempted to think the setup is ok, based on the happy path
behavior. *)
print_s [%sexp (abbrev_ref "HEAD" : string Or_error.t)];
print_s (abbrev_ref "HEAD" |> Or_error.sexp_of_t String.sexp_of_t);
[%expect {| (Ok main) |}];
(* However, note that the call can still raise, despite its [Result] return type. *)
let () =
match abbrev_ref ~repo_root:(Vcs.Repo_root.v "/bogus") "HEAD" with
| Ok (_ : string) | Error (_ : Error.t) -> assert false [@coverage off]
| exception Err.E err ->
print_s (Vcs_test_helpers.redact_sexp [%sexp (err : Err.t)] ~fields:[ "error" ])
print_s (Vcs_test_helpers.redact_sexp (err |> Err.sexp_of_t) ~fields:[ "error" ])
in
[%expect
{|
Expand All @@ -221,7 +221,7 @@ let%expect_test "hello cli" =
|}];
(* Another difference is that you do not get the context when the [f] helper
returns an error. *)
print_s [%sexp (abbrev_ref "/bogus" : string Or_error.t)];
print_s (abbrev_ref "/bogus" |> Or_error.sexp_of_t String.sexp_of_t);
[%expect {| (Error "Expected exit code 0.") |}];
(* If you are using a non-raising handler [f], you probably meant to use
[Vcs.Or_error.git]. The type of [abbrev_ref] is the same. *)
Expand All @@ -234,13 +234,13 @@ let%expect_test "hello cli" =
|> Or_error.map ~f:String.strip
in
(* The behavior is the same in the happy path. *)
print_s [%sexp (abbrev_ref "HEAD" : string Or_error.t)];
print_s (abbrev_ref "HEAD" |> Or_error.sexp_of_t String.sexp_of_t);
[%expect {| (Ok main) |}];
(* However, now the function will not raise. *)
print_s
(Vcs_test_helpers.redact_sexp
[%sexp
(abbrev_ref ~repo_root:(Vcs.Repo_root.v "/bogus") "HEAD" : string Or_error.t)]
(abbrev_ref ~repo_root:(Vcs.Repo_root.v "/bogus") "HEAD"
|> Or_error.sexp_of_t String.sexp_of_t)
~fields:[ "error" ]);
[%expect
{|
Expand Down Expand Up @@ -283,14 +283,14 @@ let%expect_test "hello cli" =
in
(* You may be tempted to think the setup is ok, based on the happy path
behavior. *)
print_s [%sexp (abbrev_ref "HEAD" : string Or_error.t)];
print_s (abbrev_ref "HEAD" |> Or_error.sexp_of_t String.sexp_of_t);
[%expect {| (Ok main) |}];
(* Some error condition will even correctly be turned into Errors, which may
further prevent you from hitting a raising case. *)
print_s
(Vcs_test_helpers.redact_sexp
[%sexp
(abbrev_ref ~repo_root:(Vcs.Repo_root.v "/bogus") "HEAD" : string Or_error.t)]
(abbrev_ref ~repo_root:(Vcs.Repo_root.v "/bogus") "HEAD"
|> Or_error.sexp_of_t String.sexp_of_t)
~fields:[ "error" ]);
[%expect
{|
Expand All @@ -316,8 +316,8 @@ let%expect_test "hello cli" =
| _ -> failwith "Unexpected error code" [@coverage off])
in
(* You get a function that does not raise in the happy path. *)
print_s [%sexp (abbrev_ref "HEAD" : string)];
[%expect {| main |}];
print_dyn (abbrev_ref "HEAD" |> Dyn.string);
[%expect {| "main" |}];
(* And always raises [Err.E], with context, whether the error comes from your handler or not. *)
let abbrev_ref_does_raise ?repo_root ref_ ~redact_fields =
match abbrev_ref ?repo_root ref_ with
Expand Down
15 changes: 10 additions & 5 deletions example/hello_vcs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ let%expect_test "hello commit" =
let rev =
Vcs.commit vcs ~repo_root ~commit_message:(Vcs.Commit_message.v "hello commit")
in
print_s
[%sexp
(Vcs.Or_error.show_file_at_rev vcs ~repo_root ~rev ~path:hello_file
: [ `Present of Vcs.File_contents.t | `Absent ] Or_error.t)];
[%expect {| (Ok (Present "Hello World!\n")) |}];
let () =
match Vcs.Or_error.show_file_at_rev vcs ~repo_root ~rev ~path:hello_file with
| Error _ | Ok `Absent -> assert false
| Ok (`Present file_contents) -> print_dyn (file_contents |> Vcs.File_contents.to_dyn)
in
[%expect
{|
"Hello World!\n\
"
|}];
()
;;
15 changes: 10 additions & 5 deletions example/hello_vcs_git_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ let%expect_test "hello commit" =
let rev =
Vcs.commit vcs ~repo_root ~commit_message:(Vcs.Commit_message.v "hello commit")
in
print_s
[%sexp
(Vcs.Or_error.show_file_at_rev vcs ~repo_root ~rev ~path:hello_file
: [ `Present of Vcs.File_contents.t | `Absent ] Or_error.t)];
[%expect {| (Ok (Present "Hello World!\n")) |}];
let () =
match Vcs.Or_error.show_file_at_rev vcs ~repo_root ~rev ~path:hello_file with
| Error _ | Ok `Absent -> assert false
| Ok (`Present file_contents) -> print_dyn (file_contents |> Vcs.File_contents.to_dyn)
in
[%expect
{|
"Hello World!\n\
"
|}];
(* Let's cover a case where the command fails. *)
let () =
match
Expand Down
6 changes: 6 additions & 0 deletions src/stdlib/volgo_stdlib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ module Char = struct
;;
end

module Fsegment = struct
include Fsegment

let to_dyn t = Dyn.string (Fsegment.to_string t)
end

module Hashtbl = struct
include (
MoreLabels.Hashtbl :
Expand Down
8 changes: 8 additions & 0 deletions src/stdlib/volgo_stdlib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ module Char : sig
val is_whitespace : char -> bool
end

module Fsegment : sig
include module type of struct
include Fsegment
end

val to_dyn : t -> Dyn.t
end

module Hashtbl : sig
include module type of MoreLabels.Hashtbl with module Make := MoreLabels.Hashtbl.Make

Expand Down
1 change: 1 addition & 0 deletions src/volgo-git-backend/munged_path.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module T = struct
}

let equal = Vcs.Num_status.Key.equal
let to_dyn = Vcs.Num_status.Key.to_dyn
let sexp_of_t = Vcs.Num_status.Key.sexp_of_t
end

Expand Down
1 change: 1 addition & 0 deletions src/volgo-git-backend/munged_path.mli
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type t = Vcs.Num_status.Key.t =
; dst : Vcs.Path_in_repo.t
}

val to_dyn : t -> Dyn.t
val sexp_of_t : t -> Sexp.t
val equal : t -> t -> bool
val parse_exn : string -> t
1 change: 1 addition & 0 deletions src/volgo-git-backend/name_status.mli
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module Diff_status : sig
| `Not_supported
]

val to_dyn : t -> Dyn.t
val sexp_of_t : t -> Sexp.t
val parse_exn : string -> t
end
Expand Down
1 change: 1 addition & 0 deletions src/volgo-git-backend/refs.mli
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module Dereferenced : sig
; dereferenced : bool
}

val to_dyn : t -> Dyn.t
val sexp_of_t : t -> Sexp.t
val equal : t -> t -> bool
val parse_exn : line:string -> t
Expand Down
36 changes: 21 additions & 15 deletions src/volgo/graph.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,41 +99,45 @@ module T = struct
module Nodes = struct
type t = Node_kind.t array

let sexp_of_t t =
let to_dyn t =
t
|> Array.mapi ~f:(fun node node_kind ->
Sexp.List [ node |> Node.sexp_of_t; node_kind |> Node_kind.sexp_of_t ])
Dyn.Tuple [ Node.to_dyn node; Node_kind.to_dyn node_kind ])
|> Array.rev
|> Array.sexp_of_t Fun.id
|> Array.to_list
|> Dyn.list Fun.id
;;
end

module Revs = struct
type t = int Rev_table.t

let sexp_of_t (t : t) =
let to_dyn (t : t) =
let revs = Rev_table.to_seq t |> Array.of_seq in
Array.sort revs ~compare:(fun (_, n1) (_, n2) -> Int.compare n2 n1);
revs
|> Array.sexp_of_t (fun (rev, index) ->
Sexp.List [ index |> Node.sexp_of_t; rev |> Rev.sexp_of_t ])
|> Array.map ~f:(fun (rev, index) ->
Dyn.Tuple [ Node.to_dyn index; Rev.to_dyn rev ])
|> Array.to_list
|> Dyn.list Fun.id
;;
end

module Reverse_refs = struct
type t = Ref_kind.t list Int_table.t

let sexp_of_t (t : t) =
let to_dyn (t : t) =
let revs =
Int_table.to_seq t
|> Array.of_seq
|> Array.map ~f:(fun (n, refs) -> n, List.sort refs ~compare:Ref_kind.compare)
in
Array.sort revs ~compare:(fun (n1, _) (n2, _) -> Int.compare n2 n1);
revs
|> Array.sexp_of_t (fun (node, ref_kinds) ->
Sexp.List
[ node |> Node.sexp_of_t; ref_kinds |> List.sexp_of_t Ref_kind.sexp_of_t ])
|> Array.map ~f:(fun (node, ref_kinds) ->
Dyn.Tuple [ Node.to_dyn node; Dyn.list Ref_kind.to_dyn ref_kinds ])
|> Array.to_list
|> Dyn.list Fun.id
;;
end

Expand All @@ -144,13 +148,15 @@ module T = struct
; reverse_refs : Ref_kind.t list Int_table.t
}

let sexp_of_t { nodes; revs; refs = _; reverse_refs } =
Sexp.List
[ sexp_field (module Nodes) "nodes" nodes
; sexp_field (module Revs) "revs" revs
; sexp_field (module Reverse_refs) "refs" reverse_refs
let to_dyn { nodes; revs; refs = _; reverse_refs } =
Dyn.record
[ "nodes", Nodes.to_dyn nodes
; "revs", Revs.to_dyn revs
; "refs", Reverse_refs.to_dyn reverse_refs
]
;;

let sexp_of_t t = Dyn.to_sexp (to_dyn t)
end

include T
Expand Down
4 changes: 4 additions & 0 deletions src/volgo/graph.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
type t

val sexp_of_t : t -> Sexp.t
val to_dyn : t -> Dyn.t

(** Create an empty graph that has no nodes. *)
val create : unit -> t
Expand Down Expand Up @@ -98,6 +99,7 @@ module Node_kind : sig
}

val sexp_of_t : t -> Sexp.t
val to_dyn : t -> Dyn.t
val equal : t -> t -> bool

(** A helper to access the revision of the node itself. This simply returns
Expand Down Expand Up @@ -257,6 +259,7 @@ module Subgraph : sig
}

val sexp_of_t : t -> Sexp.t
val to_dyn : t -> Dyn.t
val is_empty : t -> bool
end

Expand All @@ -275,6 +278,7 @@ module Summary : sig
type t

val sexp_of_t : t -> Sexplib0.Sexp.t
val to_dyn : t -> Dyn.t
end

(** Print a summary for use in expect test and quick exploratory tests *)
Expand Down
1 change: 1 addition & 0 deletions src/volgo/name_status.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ end
module T = struct
type t = Change.t list

let to_dyn t = Dyn.list Change.to_dyn t
let sexp_of_t t = sexp_of_list Change.sexp_of_t t
end

Expand Down
Loading