Skip to content

Commit

Permalink
Merge pull request #29 from mbarbin/fsegment
Browse files Browse the repository at this point in the history
Upgrade to fpath-base 0.2.2 (rename Fpart to Fsegment)
  • Loading branch information
mbarbin authored Oct 15, 2024
2 parents a92c9a1 + 3895fee commit fd91ff2
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 53 deletions.
16 changes: 8 additions & 8 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
(fpath
(>= 0.7.3))
(fpath-base
(>= 0.2.0))
(>= 0.2.2))
(ppx_compare
(and
(>= v0.17)
Expand Down Expand Up @@ -89,7 +89,7 @@
(fpath
(>= 0.7.3))
(fpath-sexp0
(>= 0.2.0))
(>= 0.2.2))
(ppx_compare
(and
(>= v0.17)
Expand Down Expand Up @@ -138,7 +138,7 @@
(fpath
(>= 0.7.3))
(fpath-sexp0
(>= 0.2.0))
(>= 0.2.2))
(ppx_compare
(and
(>= v0.17)
Expand Down Expand Up @@ -188,7 +188,7 @@
(fpath
(>= 0.7.3))
(fpath-sexp0
(>= 0.2.0))
(>= 0.2.2))
(ppx_compare
(and
(>= v0.17)
Expand Down Expand Up @@ -240,7 +240,7 @@
(fpath
(>= 0.7.3))
(fpath-sexp0
(>= 0.2.0))
(>= 0.2.2))
(ppx_compare
(and
(>= v0.17)
Expand Down Expand Up @@ -325,9 +325,9 @@
(fpath
(>= 0.7.3))
(fpath-base
(>= 0.2.0))
(>= 0.2.2))
(fpath-sexp0
(>= 0.2.0))
(>= 0.2.2))
(mdx
(and
:with-doc
Expand Down Expand Up @@ -419,7 +419,7 @@
(fpath
(>= 0.7.3))
(fpath-sexp0
(>= 0.2.0))
(>= 0.2.2))
(ppx_compare
(and
(>= v0.17)
Expand Down
2 changes: 1 addition & 1 deletion lib/vcs/src/trait_file_system.mli
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ module type S = sig
according to [String.compare]. This must error out if [dir] is not a
directory, or if we don't have access to it. The unix entries "." and
".." shall not be included in the result. *)
val read_dir : t -> dir:Absolute_path.t -> Fpart.t list Or_error.t
val read_dir : t -> dir:Absolute_path.t -> Fsegment.t list Or_error.t
end
6 changes: 3 additions & 3 deletions lib/vcs/src/vcs.mli
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ val init : [> Trait.init ] t -> path:Absolute_path.t -> Repo_root.t
val find_enclosing_repo_root
: [> Trait.file_system ] t
-> from:Absolute_path.t
-> store:Fpart.t list
-> ([ `Store of Fpart.t ] * Repo_root.t) option
-> store:Fsegment.t list
-> ([ `Store of Fsegment.t ] * Repo_root.t) option

(** [find_enclosing_git_repo_root vcs ~from:dir] is a convenient wrapper around
{!val:find_enclosing_repo_root} for Git repositories. This is looking for
Expand Down Expand Up @@ -179,7 +179,7 @@ val save_file
(** Returns the entries of the supplied directory, ordered increasingly
according to [String.compare]. The result does not include the unix entries
".", "..". *)
val read_dir : [> Trait.file_system ] t -> dir:Absolute_path.t -> Fpart.t list
val read_dir : [> Trait.file_system ] t -> dir:Absolute_path.t -> Fsegment.t list

(** {1 Branches & Tags} *)

Expand Down
6 changes: 4 additions & 2 deletions lib/vcs/src/vcs0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ let init (Provider.T { t; handler }) ~path =
let find_enclosing_repo_root t ~from ~store =
let rec visit dir =
let entries = read_dir t ~dir in
match List.find entries ~f:(fun entry -> List.mem store entry ~equal:Fpart.equal) with
match
List.find entries ~f:(fun entry -> List.mem store entry ~equal:Fsegment.equal)
with
| Some entry ->
let dir =
Fpath.rem_empty_seg (dir :> Fpath.t)
Expand All @@ -80,7 +82,7 @@ let find_enclosing_repo_root t ~from ~store =
;;

let find_enclosing_git_repo_root t ~from =
match find_enclosing_repo_root t ~from ~store:[ Fpart.dot_git ] with
match find_enclosing_repo_root t ~from ~store:[ Fsegment.dot_git ] with
| None -> None
| Some (_, repo_root) -> Some repo_root
;;
Expand Down
6 changes: 3 additions & 3 deletions lib/vcs/src/vcs_interface.mli
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ module type S = sig
val find_enclosing_repo_root
: [> Trait.file_system ] t
-> from:Absolute_path.t
-> store:Fpart.t list
-> ([ `Store of Fpart.t ] * Repo_root.t) option result
-> store:Fsegment.t list
-> ([ `Store of Fsegment.t ] * Repo_root.t) option result

val add
: [> Trait.add ] t
Expand Down Expand Up @@ -111,7 +111,7 @@ module type S = sig
-> file_contents:File_contents.t
-> unit result

val read_dir : [> Trait.file_system ] t -> dir:Absolute_path.t -> Fpart.t list result
val read_dir : [> Trait.file_system ] t -> dir:Absolute_path.t -> Fsegment.t list result

val rename_current_branch
: [> Trait.branch ] t
Expand Down
10 changes: 5 additions & 5 deletions lib/vcs_command/src/vcs_command.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Initialized = struct
end

let find_enclosing_repo_root vcs ~from =
match Vcs.find_enclosing_repo_root vcs ~from ~store:[ Fpart.dot_git ] with
match Vcs.find_enclosing_repo_root vcs ~from ~store:[ Fsegment.dot_git ] with
| Some (`Store _, repo_root) -> repo_root
| None ->
Vcs.raise_s
Expand Down Expand Up @@ -130,9 +130,9 @@ let find_enclosing_repo_root_cmd =
and store =
Arg.named_opt
[ "store" ]
(Param.comma_separated (Param.validated_string (module Fpart)))
(Param.comma_separated (Param.validated_string (module Fsegment)))
~doc:"stop the search if one of these entries is found (e.g. '.hg')"
>>| Option.value ~default:[ Fpart.dot_git ]
>>| Option.value ~default:[ Fsegment.dot_git ]
in
Eio_main.run
@@ fun env ->
Expand All @@ -147,7 +147,7 @@ let find_enclosing_repo_root_cmd =
| Some (`Store store, repo_root) ->
Stdlib.Printf.printf
"%s: %s\n"
(Fpart.to_string store)
(Fsegment.to_string store)
(Vcs.Repo_root.to_string repo_root))
;;

Expand Down Expand Up @@ -307,7 +307,7 @@ let read_dir_cmd =
let { Initialized.vcs; repo_root = _; cwd } = initialize ~env in
let dir = Absolute_path.relativize ~root:cwd dir in
let entries = Vcs.read_dir vcs ~dir in
print_sexp [%sexp (entries : Fpart.t list)];
print_sexp [%sexp (entries : Fsegment.t list)];
())
;;

Expand Down
2 changes: 1 addition & 1 deletion lib/vcs_git_blocking/src/runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let read_dir () ~dir =
Or_error.try_with (fun () ->
let entries = Stdlib.Sys.readdir (Absolute_path.to_string dir) in
Array.sort entries ~compare:String.compare;
entries |> Array.map ~f:Fpart.v |> Array.to_list)
entries |> Array.map ~f:Fsegment.v |> Array.to_list)
;;

let with_cwd ~cwd ~f =
Expand Down
10 changes: 5 additions & 5 deletions lib/vcs_git_blocking/test/test__file_system.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

let%expect_test "read_dir" =
let vcs = Vcs_git_blocking.create () in
let read_dir dir = print_s [%sexp (Vcs.read_dir vcs ~dir : Fpart.t list)] in
let read_dir dir = print_s [%sexp (Vcs.read_dir vcs ~dir : Fsegment.t list)] in
let cwd = Unix.getcwd () in
let dir = Stdlib.Filename.temp_dir ~temp_dir:cwd "vcs_test" "" |> Absolute_path.v in
let save_file file file_contents =
Vcs.save_file
vcs
~path:(Absolute_path.extend dir (Fpart.v file))
~path:(Absolute_path.extend dir (Fsegment.v file))
~file_contents:(Vcs.File_contents.create file_contents)
in
read_dir dir;
Expand All @@ -45,7 +45,7 @@ let%expect_test "read_dir" =
let () =
(* [Vcs.read_dir] errors out on non-existing directories. *)
match Vcs.read_dir vcs ~dir:(Absolute_path.v "/non-existing") with
| (_ : Fpart.t list) -> assert false
| (_ : Fsegment.t list) -> assert false
| exception Vcs.E err ->
print_s (Vcs_test_helpers.redact_sexp (Vcs.Err.sexp_of_t err) ~fields:[ "dir" ])
in
Expand All @@ -57,13 +57,13 @@ let%expect_test "read_dir" =
let () =
(* [Vcs.read_dir] errors out when called on an existing file rather than a
directory. *)
let path = Absolute_path.extend dir (Fpart.v "foo") in
let path = Absolute_path.extend dir (Fsegment.v "foo") in
let file_exists = Stdlib.Sys.file_exists (Absolute_path.to_string path) in
assert file_exists;
print_s [%sexp { file_exists : bool }];
[%expect {| ((file_exists true)) |}];
match Vcs.read_dir vcs ~dir:path with
| (_ : Fpart.t list) -> assert false
| (_ : Fsegment.t list) -> assert false
| exception Vcs.E err ->
print_s
(Vcs_test_helpers.redact_sexp (Vcs.Err.sexp_of_t err) ~fields:[ "dir"; "error" ])
Expand Down
6 changes: 3 additions & 3 deletions lib/vcs_git_blocking/test/test__hello_commit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ let%expect_test "hello commit" =

let%expect_test "read_dir" =
let vcs = Vcs_git_blocking.create () in
let read_dir dir = print_s [%sexp (Vcs.read_dir vcs ~dir : Fpart.t list)] in
let read_dir dir = print_s [%sexp (Vcs.read_dir vcs ~dir : Fsegment.t list)] in
let cwd = Unix.getcwd () in
let dir = Stdlib.Filename.temp_dir ~temp_dir:cwd "vcs_test" "" |> Absolute_path.v in
let save_file file file_contents =
Vcs.save_file
vcs
~path:(Absolute_path.extend dir (Fpart.v file))
~path:(Absolute_path.extend dir (Fsegment.v file))
~file_contents:(Vcs.File_contents.create file_contents)
in
read_dir dir;
Expand All @@ -84,7 +84,7 @@ let%expect_test "read_dir" =
[%expect {| (foo hello.txt) |}];
let () =
match Vcs.read_dir vcs ~dir:(Absolute_path.v "/invalid") with
| (_ : Fpart.t list) -> assert false
| (_ : Fsegment.t list) -> assert false
| exception Vcs.E err -> print_s [%sexp (err : Vcs.Err.t)]
in
[%expect
Expand Down
2 changes: 1 addition & 1 deletion lib/vcs_git_eio/src/runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let save_file ?(perms = 0o666) t ~path ~(file_contents : Vcs.File_contents.t) =

let read_dir t ~dir =
let dir = Eio.Path.(t.fs / Absolute_path.to_string dir) in
Or_error.try_with (fun () -> Eio.Path.read_dir dir |> List.map ~f:Fpart.v)
Or_error.try_with (fun () -> Eio.Path.read_dir dir |> List.map ~f:Fsegment.v)
;;

(* The modules [Exit_status], [Lines] and the function [git] below are derived
Expand Down
10 changes: 5 additions & 5 deletions lib/vcs_git_eio/test/test__file_system.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ let%expect_test "read_dir" =
let vcs = Vcs_git_eio.create ~env in
let repo_root = Vcs_test_helpers.init_temp_repo ~env ~sw ~vcs in
let dir = Vcs.Repo_root.to_absolute_path repo_root in
let read_dir dir = print_s [%sexp (Vcs.read_dir vcs ~dir : Fpart.t list)] in
let read_dir dir = print_s [%sexp (Vcs.read_dir vcs ~dir : Fsegment.t list)] in
let save_file file file_contents =
Vcs.save_file
vcs
~path:(Absolute_path.extend dir (Fpart.v file))
~path:(Absolute_path.extend dir (Fsegment.v file))
~file_contents:(Vcs.File_contents.create file_contents)
in
read_dir dir;
Expand All @@ -50,7 +50,7 @@ let%expect_test "read_dir" =
let () =
(* [Vcs.read_dir] errors out on non-existing directories. *)
match Vcs.read_dir vcs ~dir:(Absolute_path.v "/non-existing") with
| (_ : Fpart.t list) -> assert false
| (_ : Fsegment.t list) -> assert false
| exception Vcs.E err ->
print_s
(Vcs_test_helpers.redact_sexp (Vcs.Err.sexp_of_t err) ~fields:[ "dir"; "error" ])
Expand All @@ -59,13 +59,13 @@ let%expect_test "read_dir" =
let () =
(* [Vcs.read_dir] errors out when called on an existing file rather than a
directory. *)
let path = Absolute_path.extend dir (Fpart.v "foo") in
let path = Absolute_path.extend dir (Fsegment.v "foo") in
let file_exists = Stdlib.Sys.file_exists (Absolute_path.to_string path) in
assert file_exists;
print_s [%sexp { file_exists : bool }];
[%expect {| ((file_exists true)) |}];
match Vcs.read_dir vcs ~dir:path with
| (_ : Fpart.t list) -> assert false
| (_ : Fsegment.t list) -> assert false
| exception Vcs.E err ->
print_s
(Vcs_test_helpers.redact_sexp (Vcs.Err.sexp_of_t err) ~fields:[ "dir"; "error" ])
Expand Down
16 changes: 8 additions & 8 deletions test/expect/find_enclosing_repo_root.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ let%expect_test "find_enclosing_repo_root" =
(* read_dir *)
let () =
let entries = Vcs.read_dir vcs ~dir:(Vcs.Repo_root.to_absolute_path repo_root) in
print_s [%sexp (entries : Fpart.t list)];
print_s [%sexp (entries : Fsegment.t list)];
[%expect {| (.git) |}];
(match Vcs.Result.read_dir vcs ~dir:(Vcs.Repo_root.to_absolute_path repo_root) with
| Error _ -> assert false
| Ok entries -> print_s [%sexp (entries : Fpart.t list)]);
| Ok entries -> print_s [%sexp (entries : Fsegment.t list)]);
[%expect {| (.git) |}]
in
(* Find the root from the root itself. *)
Expand Down Expand Up @@ -74,23 +74,23 @@ let%expect_test "find_enclosing_repo_root" =
Vcs.find_enclosing_repo_root
vcs
~from:subdir
~store:[ Fpart.dot_git; Fpart.dot_hg ]
~store:[ Fsegment.dot_git; Fsegment.dot_hg ]
with
| None -> assert false
| Some (`Store store, repo_root2) ->
require_equal [%here] (module Fpart) store Fpart.dot_git;
require_equal [%here] (module Fsegment) store Fsegment.dot_git;
require_equal [%here] (module Vcs.Repo_root) repo_root repo_root2;
[%expect {||}]);
(* 2. Non-raising [find_enclosing_repo_root]. *)
(match
Vcs.Result.find_enclosing_repo_root
vcs
~from:subdir
~store:[ Fpart.dot_git; Fpart.dot_hg ]
~store:[ Fsegment.dot_git; Fsegment.dot_hg ]
with
| Error _ | Ok None -> assert false
| Ok (Some (`Store store, repo_root2)) ->
require_equal [%here] (module Fpart) store Fpart.dot_git;
require_equal [%here] (module Fsegment) store Fsegment.dot_git;
require_equal [%here] (module Vcs.Repo_root) repo_root repo_root2;
[%expect {||}]);
(* 3. Raising [find_enclosing_git_repo_root]. *)
Expand All @@ -109,10 +109,10 @@ let%expect_test "find_enclosing_repo_root" =
~create:(`Or_truncate 0o666)
Eio.Path.(Eio.Stdenv.fs env / Absolute_path.to_string stop_at / ".hg")
"";
match Vcs.find_enclosing_repo_root vcs ~from:subdir ~store:[ Fpart.dot_hg ] with
match Vcs.find_enclosing_repo_root vcs ~from:subdir ~store:[ Fsegment.dot_hg ] with
| None -> assert false
| Some (`Store store, repo_root2) ->
require_equal [%here] (module Fpart) store Fpart.dot_hg;
require_equal [%here] (module Fsegment) store Fsegment.dot_hg;
require_equal
[%here]
(module Vcs.Repo_root)
Expand Down
2 changes: 1 addition & 1 deletion vcs-command.opam
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ depends: [
"eio_main" {>= "1.0"}
"err" {>= "0.0.5"}
"fpath" {>= "0.7.3"}
"fpath-sexp0" {>= "0.2.0"}
"fpath-sexp0" {>= "0.2.2"}
"ppx_compare" {>= "v0.17" & < "v0.18"}
"ppx_enumerate" {>= "v0.17" & < "v0.18"}
"ppx_hash" {>= "v0.17" & < "v0.18"}
Expand Down
2 changes: 1 addition & 1 deletion vcs-git-blocking.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ depends: [
"ocaml" {>= "5.2"}
"base" {>= "v0.17" & < "v0.18"}
"fpath" {>= "0.7.3"}
"fpath-sexp0" {>= "0.2.0"}
"fpath-sexp0" {>= "0.2.2"}
"ppx_compare" {>= "v0.17" & < "v0.18"}
"ppx_enumerate" {>= "v0.17" & < "v0.18"}
"ppx_hash" {>= "v0.17" & < "v0.18"}
Expand Down
2 changes: 1 addition & 1 deletion vcs-git-eio.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ depends: [
"base" {>= "v0.17" & < "v0.18"}
"eio" {>= "1.0"}
"fpath" {>= "0.7.3"}
"fpath-sexp0" {>= "0.2.0"}
"fpath-sexp0" {>= "0.2.2"}
"ppx_compare" {>= "v0.17" & < "v0.18"}
"ppx_enumerate" {>= "v0.17" & < "v0.18"}
"ppx_hash" {>= "v0.17" & < "v0.18"}
Expand Down
2 changes: 1 addition & 1 deletion vcs-git-provider.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ depends: [
"ocaml" {>= "5.2"}
"base" {>= "v0.17" & < "v0.18"}
"fpath" {>= "0.7.3"}
"fpath-sexp0" {>= "0.2.0"}
"fpath-sexp0" {>= "0.2.2"}
"ppx_compare" {>= "v0.17" & < "v0.18"}
"ppx_enumerate" {>= "v0.17" & < "v0.18"}
"ppx_hash" {>= "v0.17" & < "v0.18"}
Expand Down
2 changes: 1 addition & 1 deletion vcs-test-helpers.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ depends: [
"base" {>= "v0.17" & < "v0.18"}
"eio" {>= "1.0"}
"fpath" {>= "0.7.3"}
"fpath-sexp0" {>= "0.2.0"}
"fpath-sexp0" {>= "0.2.2"}
"ppx_compare" {>= "v0.17" & < "v0.18"}
"ppx_enumerate" {>= "v0.17" & < "v0.18"}
"ppx_hash" {>= "v0.17" & < "v0.18"}
Expand Down
Loading

0 comments on commit fd91ff2

Please sign in to comment.