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
6 changes: 3 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
(>= v0.16))
(ppx_sexp_conv
(>= v0.16))
(ppx_sexp_value
(>= v0.16))
(ppxlib
(>= 0.33))))
(>= 0.33))
(sexplib0
(>= v0.16))))

(package
(name volgo-base)
Expand Down
8 changes: 4 additions & 4 deletions example/hello_error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let%expect_test "hello error" =
[%expect
{|
((context
(Vcs.init ((path /invalid/path)))
(Vcs.init (path /invalid/path))
((prog git)
(args (init .))
(exit_status Unknown)
Expand All @@ -59,7 +59,7 @@ let%expect_test "hello error" =
[%expect
{|
((context
(Vcs.init ((path /invalid/path)))
(Vcs.init (path /invalid/path))
((prog git)
(args (init .))
(exit_status Unknown)
Expand All @@ -76,7 +76,7 @@ let%expect_test "hello error" =
[%expect
{|
((context
(Vcs.init ((path /invalid/path)))
(Vcs.init (path /invalid/path))
((prog git)
(args (init .))
(exit_status Unknown)
Expand All @@ -94,7 +94,7 @@ let%expect_test "hello error" =
{|
(Vcs (
(context
(Vcs.init ((path /invalid/path)))
(Vcs.init (path /invalid/path))
((prog git)
(args (init .))
(exit_status Unknown)
Expand Down
20 changes: 10 additions & 10 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" =
[%expect
{|
((context
(Vcs.git ((repo_root <REDACTED>) (args (rev-parse INVALID-REF))))
(Vcs.git (repo_root <REDACTED>) (args (rev-parse INVALID-REF)))
((prog git)
(args (rev-parse INVALID-REF))
(exit_status (Exited 128))
Expand Down Expand Up @@ -137,7 +137,7 @@ let%expect_test "hello cli" =
[%expect
{|
((context
(Vcs.git ((repo_root <REDACTED>) (args (rev-parse INVALID-REF))))
(Vcs.git (repo_root <REDACTED>) (args (rev-parse INVALID-REF)))
((prog git)
(args (rev-parse INVALID-REF))
(exit_status (Exited 128))
Expand All @@ -163,7 +163,7 @@ let%expect_test "hello cli" =
[%expect
{|
((context
(Vcs.git ((repo_root <REDACTED>) (args (rev-parse INVALID-REF))))
(Vcs.git (repo_root <REDACTED>) (args (rev-parse INVALID-REF)))
((prog git)
(args (rev-parse INVALID-REF))
(exit_status (Exited 128))
Expand Down Expand Up @@ -193,7 +193,7 @@ let%expect_test "hello cli" =
[%expect
{|
((context
(Vcs.git ((repo_root <REDACTED>) (args (rev-parse INVALID-REF))))
(Vcs.git (repo_root <REDACTED>) (args (rev-parse INVALID-REF)))
((prog git)
(args (rev-parse INVALID-REF))
(exit_status (Exited 128))
Expand Down Expand Up @@ -227,7 +227,7 @@ let%expect_test "hello cli" =
[%expect
{|
((context
(Vcs.git ((repo_root /bogus) (args (rev-parse --abbrev-ref HEAD))))
(Vcs.git (repo_root /bogus) (args (rev-parse --abbrev-ref HEAD)))
((prog git)
(args (rev-parse --abbrev-ref HEAD))
(exit_status Unknown)
Expand Down Expand Up @@ -263,7 +263,7 @@ let%expect_test "hello cli" =
{|
(Error (
(context
(Vcs.git ((repo_root /bogus) (args (rev-parse --abbrev-ref HEAD))))
(Vcs.git (repo_root /bogus) (args (rev-parse --abbrev-ref HEAD)))
((prog git)
(args (rev-parse --abbrev-ref HEAD))
(exit_status Unknown)
Expand All @@ -285,7 +285,7 @@ let%expect_test "hello cli" =
[%expect
{|
((context
(Vcs.git ((repo_root <REDACTED>) (args (rev-parse --abbrev-ref bogus))))
(Vcs.git (repo_root <REDACTED>) (args (rev-parse --abbrev-ref bogus)))
((prog git)
(args (rev-parse --abbrev-ref bogus))
(exit_status (Exited 128))
Expand Down Expand Up @@ -321,7 +321,7 @@ let%expect_test "hello cli" =
{|
(Error (
(context
(Vcs.git ((repo_root /bogus) (args (rev-parse --abbrev-ref HEAD))))
(Vcs.git (repo_root /bogus) (args (rev-parse --abbrev-ref HEAD)))
((prog git)
(args (rev-parse --abbrev-ref HEAD))
(exit_status Unknown)
Expand Down Expand Up @@ -362,7 +362,7 @@ let%expect_test "hello cli" =
[%expect
{|
((context
(Vcs.git ((repo_root <REDACTED>) (args (rev-parse --abbrev-ref HEAD))))
(Vcs.git (repo_root <REDACTED>) (args (rev-parse --abbrev-ref HEAD)))
((prog git)
(args (rev-parse --abbrev-ref HEAD))
(exit_status Unknown)
Expand All @@ -375,7 +375,7 @@ let%expect_test "hello cli" =
[%expect
{|
((context
(Vcs.git ((repo_root <REDACTED>) (args (rev-parse --abbrev-ref bogus))))
(Vcs.git (repo_root <REDACTED>) (args (rev-parse --abbrev-ref bogus)))
((prog git)
(args (rev-parse --abbrev-ref bogus))
(exit_status (Exited 128))
Expand Down
4 changes: 2 additions & 2 deletions example/hello_vcs_git_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ let%expect_test "hello commit" =
[%expect
{|
((context
(Vcs.git ((repo_root /invalid/path) (args ())))
(Vcs.git (repo_root /invalid/path) (args ()))
((prog <REDACTED>)
(args ())
(exit_status Unknown)
Expand All @@ -100,7 +100,7 @@ let%expect_test "hello commit" =
[%expect
{|
((context
(Vcs.git ((repo_root <REDACTED>) (args (rev-parse INVALID-REF))))
(Vcs.git (repo_root <REDACTED>) (args (rev-parse INVALID-REF)))
((prog <REDACTED>)
(args (rev-parse INVALID-REF))
(exit_status (Exited 128))
Expand Down
6 changes: 3 additions & 3 deletions lib/vcs_test_helpers/test/test__vcs_test_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let%expect_test "redact_sexp" =
[%expect
{|
((context
(Vcs.init ((path /invalid/path)))
(Vcs.init (path /invalid/path))
((prog git)
(args (init .))
(exit_status Unknown)
Expand All @@ -89,7 +89,7 @@ let%expect_test "redact_sexp" =
[%expect
{|
((context
(Vcs.init ((path /invalid/path)))
(Vcs.init (path /invalid/path))
((prog git)
(args (init .))
(exit_status Unknown)
Expand All @@ -103,7 +103,7 @@ let%expect_test "redact_sexp" =
[%expect
{|
((context
(Vcs.init ((path /invalid/path)))
(Vcs.init (path /invalid/path))
((prog git)
(args (init .))
(exit_status Unknown)
Expand Down
15 changes: 9 additions & 6 deletions lib/volgo/src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
Sexplib0
-open
Sexplib0.Sexp_conv)
(libraries astring fpath fpath-sexp0 pp pplumbing.err pplumbing.pp-tty)
(libraries
astring
fpath
fpath-sexp0
pp
pplumbing.err
pplumbing.pp-tty
sexplib0)
(modules
(:standard \ stdlib_compat4xx stdlib_compat5xx))
(instrumentation
Expand All @@ -27,11 +34,7 @@
validated_string_intf
vcs_intf)
(preprocess
(pps
-unused-code-warnings=force
ppx_enumerate
ppx_sexp_conv
ppx_sexp_value)))
(pps -unused-code-warnings=force ppx_enumerate ppx_sexp_conv)))

(rule
(enabled_if
Expand Down
33 changes: 23 additions & 10 deletions lib/volgo/src/graph.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ module T = struct
type t = Node_kind.t array

let sexp_of_t t =
Array.mapi t ~f:(fun i node -> i, node)
t
|> Array.mapi ~f:(fun node node_kind ->
Sexp.List [ node |> Node.sexp_of_t; node_kind |> Node_kind.sexp_of_t ])
|> Array.rev
|> [%sexp_of: (Node.t * Node_kind.t) array]
|> Array.sexp_of_t Fun.id
;;
end

Expand All @@ -107,8 +109,8 @@ module T = struct
let revs = Rev_table.to_seq t |> Array.of_seq in
Array.sort revs ~compare:(fun (_, n1) (_, n2) -> Int.compare n2 n1);
revs
|> Array.map ~f:(fun (rev, index) -> index, rev)
|> [%sexp_of: (Node.t * Rev.t) array]
|> Array.sexp_of_t (fun (rev, index) ->
Sexp.List [ index |> Node.sexp_of_t; rev |> Rev.sexp_of_t ])
;;
end

Expand All @@ -122,7 +124,10 @@ module T = struct
|> 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 |> [%sexp_of: (Node.t * Ref_kind.t list) array]
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 ])
;;
end

Expand All @@ -134,7 +139,11 @@ module T = struct
}

let sexp_of_t { nodes; revs; refs = _; reverse_refs } =
[%sexp { nodes : Nodes.t; revs : Revs.t; refs = (reverse_refs : Reverse_refs.t) }]
Sexp.List
[ sexp_field (module Nodes) "nodes" nodes
; sexp_field (module Revs) "revs" revs
; sexp_field (module Reverse_refs) "refs" reverse_refs
]
;;
end

Expand Down Expand Up @@ -234,7 +243,7 @@ let refs t =

let set_ref t ~rev ~ref_kind =
match Rev_table.find t.revs rev with
| None -> Err.raise [ Pp.text "Rev not found."; Err.sexp [%sexp (rev : Rev.t)] ]
| None -> Err.raise [ Pp.text "Rev not found."; Err.sexp (rev |> Rev.sexp_of_t) ]
| Some index ->
(match Ref_kind_table.find t.refs ref_kind with
| None -> ()
Expand Down Expand Up @@ -283,7 +292,7 @@ let add_nodes t ~log =
| Some node -> node
| None ->
Err.raise
[ Pp.text "Parent not found."; Err.sexp [%sexp (line : Log.Line.t)] ]
[ Pp.text "Parent not found."; Err.sexp (line |> Log.Line.sexp_of_t) ]
[@coverage off]
in
match (line : Log.Line.t) with
Expand Down Expand Up @@ -316,7 +325,7 @@ let add_nodes t ~log =
| None ->
Err.raise
[ Pp.text "Node not found during the building of new nodes (internal error)."
; Err.sexp [%sexp { rev : Rev.t }]
; Err.sexp (sexp_field (module Rev) "rev" rev)
] [@coverage off]
in
Queue.to_seq new_nodes
Expand Down Expand Up @@ -534,7 +543,11 @@ let check_index_exn t ~index =
then
Err.raise
[ Pp.text "Node index out of bounds."
; Err.sexp [%sexp { index : int; node_count : int }]
; Err.sexp
(List
[ sexp_field (module Int) "index" index
; sexp_field (module Int) "node_count" node_count
])
]
;;

Expand Down
28 changes: 27 additions & 1 deletion lib/volgo/src/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,24 @@

open! Stdlib_compat

module type To_sexpable = sig
type t

val sexp_of_t : t -> Sexp.t
end

let sexp_field' (type a) (sexp_of_a : a -> Sexp.t) field a =
Sexp.List [ Atom field; sexp_of_a a ]
;;

let sexp_field (type a) (module M : To_sexpable with type t = a) field a =
sexp_field' M.sexp_of_t field a
;;

module Array = struct
include ArrayLabels

let sexp_of_t = Sexplib0.Sexp_conv.sexp_of_array
let create ~len a = make len a

let filter_mapi t ~f =
Expand Down Expand Up @@ -101,7 +116,13 @@ module Hashtbl = struct

let add_exn t ~key ~data =
if mem t key
then raise (E [%sexp "Hashtbl.add_exn: key already present", { key : H.t }])
then
raise
(E
(List
[ Atom "Hashtbl.add_exn: key already present"
; sexp_field (module H) "key" key
]))
else add t ~key ~data
;;

Expand Down Expand Up @@ -158,11 +179,14 @@ module Int = struct
aux 0 initial_skip_count;
Buffer.contents buffer
;;

let sexp_of_t t = Sexp.Atom (to_string_hum t)
end

module List = struct
include ListLabels

let sexp_of_t = Sexplib0.Sexp_conv.sexp_of_list
let dedup_and_sort t ~compare = sort_uniq t ~cmp:compare

let hd = function
Expand All @@ -179,6 +203,7 @@ end
module Option = struct
include Option

let sexp_of_t = Sexplib0.Sexp_conv.sexp_of_option
let map t ~f = map f t
let some_if cond a = if cond then Some a else None
end
Expand Down Expand Up @@ -226,6 +251,7 @@ end
module String = struct
include StringLabels

let sexp_of_t = Sexplib0.Sexp_conv.sexp_of_string
let to_string t = t

let chop_prefix t ~prefix =
Expand Down
Loading
Loading