From 79e0ccb130e20825de843709bd235890e3efc802 Mon Sep 17 00:00:00 2001 From: Mathieu Barbin Date: Thu, 17 Oct 2024 16:09:09 +0200 Subject: [PATCH 1/4] Prepare scope via import --- lib/vcs/src/author.ml | 2 ++ lib/vcs/src/bit_vector.ml | 2 ++ lib/vcs/src/branch_name.ml | 2 ++ lib/vcs/src/commit_message.ml | 2 ++ lib/vcs/src/err.ml | 2 ++ lib/vcs/src/file_contents.ml | 2 ++ lib/vcs/src/git.ml | 2 ++ lib/vcs/src/graph.ml | 2 ++ lib/vcs/src/import.ml | 20 ++++++++++++++++++++ lib/vcs/src/import.mli | 20 ++++++++++++++++++++ lib/vcs/src/log.ml | 2 ++ lib/vcs/src/mock_rev_gen.ml | 2 ++ lib/vcs/src/name_status.ml | 2 ++ lib/vcs/src/non_raising.ml | 2 ++ lib/vcs/src/num_lines_in_diff.ml | 2 ++ lib/vcs/src/num_status.ml | 2 ++ lib/vcs/src/path_in_repo.ml | 2 ++ lib/vcs/src/platform.ml | 2 ++ lib/vcs/src/ref_kind.ml | 2 ++ lib/vcs/src/refs.ml | 2 ++ lib/vcs/src/remote_branch_name.ml | 2 ++ lib/vcs/src/remote_name.ml | 2 ++ lib/vcs/src/repo_name.ml | 2 ++ lib/vcs/src/repo_root.ml | 2 ++ lib/vcs/src/rev.ml | 2 ++ lib/vcs/src/tag_name.ml | 2 ++ lib/vcs/src/url.ml | 2 ++ lib/vcs/src/user_email.ml | 2 ++ lib/vcs/src/user_handle.ml | 2 ++ lib/vcs/src/user_name.ml | 2 ++ lib/vcs/src/validated_string.ml | 2 ++ lib/vcs/src/vcs.ml | 1 + lib/vcs/src/vcs.mli | 1 + lib/vcs/src/vcs0.ml | 2 ++ lib/vcs_command/src/import.ml | 22 ++++++++++++++++++++++ lib/vcs_command/src/import.mli | 22 ++++++++++++++++++++++ lib/vcs_command/src/vcs_command.ml | 2 ++ lib/vcs_git_blocking/src/import.ml | 22 ++++++++++++++++++++++ lib/vcs_git_blocking/src/import.mli | 22 ++++++++++++++++++++++ lib/vcs_git_blocking/src/runtime.ml | 2 ++ lib/vcs_git_eio/src/import.ml | 22 ++++++++++++++++++++++ lib/vcs_git_eio/src/import.mli | 22 ++++++++++++++++++++++ lib/vcs_git_eio/src/runtime.ml | 2 ++ lib/vcs_git_provider/src/add.ml | 2 ++ lib/vcs_git_provider/src/branch.ml | 2 ++ lib/vcs_git_provider/src/commit.ml | 2 ++ lib/vcs_git_provider/src/config.ml | 2 ++ lib/vcs_git_provider/src/import.ml | 22 ++++++++++++++++++++++ lib/vcs_git_provider/src/import.mli | 22 ++++++++++++++++++++++ lib/vcs_git_provider/src/init.ml | 2 ++ lib/vcs_git_provider/src/log.ml | 2 ++ lib/vcs_git_provider/src/ls_files.ml | 2 ++ lib/vcs_git_provider/src/munged_path.ml | 2 ++ lib/vcs_git_provider/src/name_status.ml | 2 ++ lib/vcs_git_provider/src/num_status.ml | 2 ++ lib/vcs_git_provider/src/refs.ml | 2 ++ lib/vcs_git_provider/src/rev_parse.ml | 2 ++ lib/vcs_git_provider/src/show.ml | 2 ++ 58 files changed, 310 insertions(+) create mode 100644 lib/vcs/src/import.ml create mode 100644 lib/vcs/src/import.mli create mode 100644 lib/vcs_command/src/import.ml create mode 100644 lib/vcs_command/src/import.mli create mode 100644 lib/vcs_git_blocking/src/import.ml create mode 100644 lib/vcs_git_blocking/src/import.mli create mode 100644 lib/vcs_git_eio/src/import.ml create mode 100644 lib/vcs_git_eio/src/import.mli create mode 100644 lib/vcs_git_provider/src/import.ml create mode 100644 lib/vcs_git_provider/src/import.mli diff --git a/lib/vcs/src/author.ml b/lib/vcs/src/author.ml index cafde77..f5c4dd8 100644 --- a/lib/vcs/src/author.ml +++ b/lib/vcs/src/author.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/bit_vector.ml b/lib/vcs/src/bit_vector.ml index 4e6afe1..c9a84bd 100644 --- a/lib/vcs/src/bit_vector.ml +++ b/lib/vcs/src/bit_vector.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + type t = bool array let sexp_of_t t = diff --git a/lib/vcs/src/branch_name.ml b/lib/vcs/src/branch_name.ml index 4e6f502..6399c33 100644 --- a/lib/vcs/src/branch_name.ml +++ b/lib/vcs/src/branch_name.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/commit_message.ml b/lib/vcs/src/commit_message.ml index 117b05c..2dd1426 100644 --- a/lib/vcs/src/commit_message.ml +++ b/lib/vcs/src/commit_message.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/err.ml b/lib/vcs/src/err.ml index ec216db..e903f75 100644 --- a/lib/vcs/src/err.ml +++ b/lib/vcs/src/err.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + type t = { steps : Info.t list ; error : Error.t diff --git a/lib/vcs/src/file_contents.ml b/lib/vcs/src/file_contents.ml index fd2db23..5174673 100644 --- a/lib/vcs/src/file_contents.ml +++ b/lib/vcs/src/file_contents.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/git.ml b/lib/vcs/src/git.ml index 6ba657f..3d5f3e0 100644 --- a/lib/vcs/src/git.ml +++ b/lib/vcs/src/git.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Output = struct [@@@coverage off] diff --git a/lib/vcs/src/graph.ml b/lib/vcs/src/graph.ml index 1d52e24..ddf8470 100644 --- a/lib/vcs/src/graph.ml +++ b/lib/vcs/src/graph.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Node = struct module T0 = struct [@@@coverage off] diff --git a/lib/vcs/src/import.ml b/lib/vcs/src/import.ml new file mode 100644 index 0000000..0c36076 --- /dev/null +++ b/lib/vcs/src/import.ml @@ -0,0 +1,20 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) diff --git a/lib/vcs/src/import.mli b/lib/vcs/src/import.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs/src/import.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs/src/log.ml b/lib/vcs/src/log.ml index 335938c..04bccb0 100644 --- a/lib/vcs/src/log.ml +++ b/lib/vcs/src/log.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Line = struct [@@@coverage off] diff --git a/lib/vcs/src/mock_rev_gen.ml b/lib/vcs/src/mock_rev_gen.ml index f95147a..a768069 100644 --- a/lib/vcs/src/mock_rev_gen.ml +++ b/lib/vcs/src/mock_rev_gen.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/name_status.ml b/lib/vcs/src/name_status.ml index e8f07a4..4ac043f 100644 --- a/lib/vcs/src/name_status.ml +++ b/lib/vcs/src/name_status.ml @@ -43,6 +43,8 @@ * which are available in Git. The file utils return sets rather than lists. *) +open! Import + module Change = struct [@@@coverage off] diff --git a/lib/vcs/src/non_raising.ml b/lib/vcs/src/non_raising.ml index 1718e7b..84cf2d5 100644 --- a/lib/vcs/src/non_raising.ml +++ b/lib/vcs/src/non_raising.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module type M = Vcs_interface.Error_S module type S = Vcs_interface.S diff --git a/lib/vcs/src/num_lines_in_diff.ml b/lib/vcs/src/num_lines_in_diff.ml index 7c8cba2..d5a2311 100644 --- a/lib/vcs/src/num_lines_in_diff.ml +++ b/lib/vcs/src/num_lines_in_diff.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct type t = { insertions : int diff --git a/lib/vcs/src/num_status.ml b/lib/vcs/src/num_status.ml index 53c3d0b..1910a53 100644 --- a/lib/vcs/src/num_status.ml +++ b/lib/vcs/src/num_status.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Key = struct [@@@coverage off] diff --git a/lib/vcs/src/path_in_repo.ml b/lib/vcs/src/path_in_repo.ml index 86ecb0c..d0a3bc4 100644 --- a/lib/vcs/src/path_in_repo.ml +++ b/lib/vcs/src/path_in_repo.ml @@ -43,6 +43,8 @@ * related to [.fe] files. *) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/platform.ml b/lib/vcs/src/platform.ml index 834a074..ea3faf0 100644 --- a/lib/vcs/src/platform.ml +++ b/lib/vcs/src/platform.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/ref_kind.ml b/lib/vcs/src/ref_kind.ml index b5e4dac..497961f 100644 --- a/lib/vcs/src/ref_kind.ml +++ b/lib/vcs/src/ref_kind.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/refs.ml b/lib/vcs/src/refs.ml index 49ba816..cbdbeac 100644 --- a/lib/vcs/src/refs.ml +++ b/lib/vcs/src/refs.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Line = struct [@@@coverage off] diff --git a/lib/vcs/src/remote_branch_name.ml b/lib/vcs/src/remote_branch_name.ml index 44a56a2..ad56ef1 100644 --- a/lib/vcs/src/remote_branch_name.ml +++ b/lib/vcs/src/remote_branch_name.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/remote_name.ml b/lib/vcs/src/remote_name.ml index 1a9946d..43364ff 100644 --- a/lib/vcs/src/remote_name.ml +++ b/lib/vcs/src/remote_name.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/repo_name.ml b/lib/vcs/src/repo_name.ml index a42a345..771c443 100644 --- a/lib/vcs/src/repo_name.ml +++ b/lib/vcs/src/repo_name.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/repo_root.ml b/lib/vcs/src/repo_root.ml index 7963db9..9a5d0d0 100644 --- a/lib/vcs/src/repo_root.ml +++ b/lib/vcs/src/repo_root.ml @@ -42,6 +42,8 @@ * removed the logic pertaining to the repo root in which the program started. *) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/rev.ml b/lib/vcs/src/rev.ml index 4af4b3e..c8bcbfb 100644 --- a/lib/vcs/src/rev.ml +++ b/lib/vcs/src/rev.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct type t = string [@@deriving compare, hash, sexp_of] end diff --git a/lib/vcs/src/tag_name.ml b/lib/vcs/src/tag_name.ml index 8d02f94..ae1380e 100644 --- a/lib/vcs/src/tag_name.ml +++ b/lib/vcs/src/tag_name.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/url.ml b/lib/vcs/src/url.ml index 82ea4e9..2bb78ae 100644 --- a/lib/vcs/src/url.ml +++ b/lib/vcs/src/url.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Protocol = struct module T = struct [@@@coverage off] diff --git a/lib/vcs/src/user_email.ml b/lib/vcs/src/user_email.ml index 6656f58..d3d372f 100644 --- a/lib/vcs/src/user_email.ml +++ b/lib/vcs/src/user_email.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/user_handle.ml b/lib/vcs/src/user_handle.ml index 238d904..5e78365 100644 --- a/lib/vcs/src/user_handle.ml +++ b/lib/vcs/src/user_handle.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/user_name.ml b/lib/vcs/src/user_name.ml index 5a55087..dba29c6 100644 --- a/lib/vcs/src/user_name.ml +++ b/lib/vcs/src/user_name.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs/src/validated_string.ml b/lib/vcs/src/validated_string.ml index a80b7a9..ff04acf 100644 --- a/lib/vcs/src/validated_string.ml +++ b/lib/vcs/src/validated_string.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module type S = Validated_string_intf.S module type X = Validated_string_intf.X diff --git a/lib/vcs/src/vcs.ml b/lib/vcs/src/vcs.ml index 1f11f8e..332711b 100644 --- a/lib/vcs/src/vcs.ml +++ b/lib/vcs/src/vcs.ml @@ -57,5 +57,6 @@ include Vcs0 module Private = struct module Bit_vector = Bit_vector + module Import = Import module Validated_string = Validated_string end diff --git a/lib/vcs/src/vcs.mli b/lib/vcs/src/vcs.mli index d42ecda..67e95b2 100644 --- a/lib/vcs/src/vcs.mli +++ b/lib/vcs/src/vcs.mli @@ -334,5 +334,6 @@ module Private : sig Use at your own risk/convenience! *) module Bit_vector = Bit_vector + module Import = Import module Validated_string = Validated_string end diff --git a/lib/vcs/src/vcs0.ml b/lib/vcs/src/vcs0.ml index d1dbfdf..8d07c74 100644 --- a/lib/vcs/src/vcs0.ml +++ b/lib/vcs/src/vcs0.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + type 'a t = 'a Provider.t let create provider = provider diff --git a/lib/vcs_command/src/import.ml b/lib/vcs_command/src/import.ml new file mode 100644 index 0000000..0c4e2b4 --- /dev/null +++ b/lib/vcs_command/src/import.ml @@ -0,0 +1,22 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +include Vcs.Private.Import diff --git a/lib/vcs_command/src/import.mli b/lib/vcs_command/src/import.mli new file mode 100644 index 0000000..cdc4488 --- /dev/null +++ b/lib/vcs_command/src/import.mli @@ -0,0 +1,22 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +include module type of Vcs.Private.Import diff --git a/lib/vcs_command/src/vcs_command.ml b/lib/vcs_command/src/vcs_command.ml index a38493a..4771c59 100644 --- a/lib/vcs_command/src/vcs_command.ml +++ b/lib/vcs_command/src/vcs_command.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + (* The commands below are sorted alphabetically. Their name must be derived from the name the associated function has in the [V.S] interface, prepending the suffix "_cmd". *) diff --git a/lib/vcs_git_blocking/src/import.ml b/lib/vcs_git_blocking/src/import.ml new file mode 100644 index 0000000..0c4e2b4 --- /dev/null +++ b/lib/vcs_git_blocking/src/import.ml @@ -0,0 +1,22 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +include Vcs.Private.Import diff --git a/lib/vcs_git_blocking/src/import.mli b/lib/vcs_git_blocking/src/import.mli new file mode 100644 index 0000000..cdc4488 --- /dev/null +++ b/lib/vcs_git_blocking/src/import.mli @@ -0,0 +1,22 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +include module type of Vcs.Private.Import diff --git a/lib/vcs_git_blocking/src/runtime.ml b/lib/vcs_git_blocking/src/runtime.ml index bf5e0cc..7f75786 100644 --- a/lib/vcs_git_blocking/src/runtime.ml +++ b/lib/vcs_git_blocking/src/runtime.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + type t = unit let create () = () diff --git a/lib/vcs_git_eio/src/import.ml b/lib/vcs_git_eio/src/import.ml new file mode 100644 index 0000000..0c4e2b4 --- /dev/null +++ b/lib/vcs_git_eio/src/import.ml @@ -0,0 +1,22 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +include Vcs.Private.Import diff --git a/lib/vcs_git_eio/src/import.mli b/lib/vcs_git_eio/src/import.mli new file mode 100644 index 0000000..cdc4488 --- /dev/null +++ b/lib/vcs_git_eio/src/import.mli @@ -0,0 +1,22 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +include module type of Vcs.Private.Import diff --git a/lib/vcs_git_eio/src/runtime.ml b/lib/vcs_git_eio/src/runtime.ml index 958a05f..9cec393 100644 --- a/lib/vcs_git_eio/src/runtime.ml +++ b/lib/vcs_git_eio/src/runtime.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + type t = { fs : Eio.Fs.dir_ty Eio.Path.t ; process_mgr : [ `Generic ] Eio.Process.mgr_ty Eio.Process.mgr diff --git a/lib/vcs_git_provider/src/add.ml b/lib/vcs_git_provider/src/add.ml index 84093db..b0fc062 100644 --- a/lib/vcs_git_provider/src/add.ml +++ b/lib/vcs_git_provider/src/add.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Make (Runtime : Runtime.S) = struct type t = Runtime.t diff --git a/lib/vcs_git_provider/src/branch.ml b/lib/vcs_git_provider/src/branch.ml index a5aa226..8f1cdec 100644 --- a/lib/vcs_git_provider/src/branch.ml +++ b/lib/vcs_git_provider/src/branch.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Make (Runtime : Runtime.S) = struct type t = Runtime.t diff --git a/lib/vcs_git_provider/src/commit.ml b/lib/vcs_git_provider/src/commit.ml index b1aca18..baa6c92 100644 --- a/lib/vcs_git_provider/src/commit.ml +++ b/lib/vcs_git_provider/src/commit.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Make (Runtime : Runtime.S) = struct type t = Runtime.t diff --git a/lib/vcs_git_provider/src/config.ml b/lib/vcs_git_provider/src/config.ml index 69311e3..129d382 100644 --- a/lib/vcs_git_provider/src/config.ml +++ b/lib/vcs_git_provider/src/config.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Make (Runtime : Runtime.S) = struct type t = Runtime.t diff --git a/lib/vcs_git_provider/src/import.ml b/lib/vcs_git_provider/src/import.ml new file mode 100644 index 0000000..0c4e2b4 --- /dev/null +++ b/lib/vcs_git_provider/src/import.ml @@ -0,0 +1,22 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +include Vcs.Private.Import diff --git a/lib/vcs_git_provider/src/import.mli b/lib/vcs_git_provider/src/import.mli new file mode 100644 index 0000000..cdc4488 --- /dev/null +++ b/lib/vcs_git_provider/src/import.mli @@ -0,0 +1,22 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +include module type of Vcs.Private.Import diff --git a/lib/vcs_git_provider/src/init.ml b/lib/vcs_git_provider/src/init.ml index 981981f..1811fa1 100644 --- a/lib/vcs_git_provider/src/init.ml +++ b/lib/vcs_git_provider/src/init.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Make (Runtime : Runtime.S) = struct type t = Runtime.t diff --git a/lib/vcs_git_provider/src/log.ml b/lib/vcs_git_provider/src/log.ml index 44cb38e..9acb5bc 100644 --- a/lib/vcs_git_provider/src/log.ml +++ b/lib/vcs_git_provider/src/log.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + let parse_log_line_exn ~line:str : Vcs.Log.Line.t = match String.split (String.strip str) ~on:' ' with | [ rev ] -> Root { rev = Vcs.Rev.v rev } diff --git a/lib/vcs_git_provider/src/ls_files.ml b/lib/vcs_git_provider/src/ls_files.ml index 1955076..2ed0a09 100644 --- a/lib/vcs_git_provider/src/ls_files.ml +++ b/lib/vcs_git_provider/src/ls_files.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Make (Runtime : Runtime.S) = struct type t = Runtime.t diff --git a/lib/vcs_git_provider/src/munged_path.ml b/lib/vcs_git_provider/src/munged_path.ml index 50d8dd5..53cd6b5 100644 --- a/lib/vcs_git_provider/src/munged_path.ml +++ b/lib/vcs_git_provider/src/munged_path.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module T = struct [@@@coverage off] diff --git a/lib/vcs_git_provider/src/name_status.ml b/lib/vcs_git_provider/src/name_status.ml index 6ebf7c6..ec92d12 100644 --- a/lib/vcs_git_provider/src/name_status.ml +++ b/lib/vcs_git_provider/src/name_status.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Diff_status = struct module T = struct [@@@coverage off] diff --git a/lib/vcs_git_provider/src/num_status.ml b/lib/vcs_git_provider/src/num_status.ml index 3db322e..5d04a2a 100644 --- a/lib/vcs_git_provider/src/num_status.ml +++ b/lib/vcs_git_provider/src/num_status.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Status_code = struct module T = struct [@@@coverage off] diff --git a/lib/vcs_git_provider/src/refs.ml b/lib/vcs_git_provider/src/refs.ml index 26e51df..44457f3 100644 --- a/lib/vcs_git_provider/src/refs.ml +++ b/lib/vcs_git_provider/src/refs.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Dereferenced = struct module T = struct [@@@coverage off] diff --git a/lib/vcs_git_provider/src/rev_parse.ml b/lib/vcs_git_provider/src/rev_parse.ml index f0b1428..f7b508b 100644 --- a/lib/vcs_git_provider/src/rev_parse.ml +++ b/lib/vcs_git_provider/src/rev_parse.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + module Make (Runtime : Runtime.S) = struct type t = Runtime.t diff --git a/lib/vcs_git_provider/src/show.ml b/lib/vcs_git_provider/src/show.ml index 1f4c535..1f1379b 100644 --- a/lib/vcs_git_provider/src/show.ml +++ b/lib/vcs_git_provider/src/show.ml @@ -19,6 +19,8 @@ (* and , respectively. *) (*******************************************************************************) +open! Import + let interpret_output output = match%map Vcs.Git.Or_error.exit_code output ~accept:[ 0, `Present; 128, `Absent ] with | `Present -> `Present (Vcs.File_contents.create output.stdout) From 06f5dd528837a867beb85971b8fbaae33705e5fd Mon Sep 17 00:00:00 2001 From: Mathieu Barbin Date: Thu, 17 Oct 2024 16:20:06 +0200 Subject: [PATCH 2/4] Initialize vcs_base library (empty for now) --- dune-project | 49 +++++++++++++++++++++++++++++++++++++++++++ lib/vcs_base/src/dune | 28 +++++++++++++++++++++++++ vcs-base.opam | 42 +++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 lib/vcs_base/src/dune create mode 100644 vcs-base.opam diff --git a/dune-project b/dune-project index 60acefa..64b5622 100644 --- a/dune-project +++ b/dune-project @@ -64,6 +64,55 @@ (provider (>= 0.0.8)))) +(package + (name vcs-base) + (synopsis "An Extension of Vcs to use with Base") + (depends + (ocaml + (>= 5.2)) + (base + (and + (>= v0.17) + (< v0.18))) + (fpath + (>= 0.7.3)) + (fpath-base + (>= 0.2.2)) + (ppx_compare + (and + (>= v0.17) + (< v0.18))) + (ppx_enumerate + (and + (>= v0.17) + (< v0.18))) + (ppx_hash + (and + (>= v0.17) + (< v0.18))) + (ppx_here + (and + (>= v0.17) + (< v0.18))) + (ppx_let + (and + (>= v0.17) + (< v0.18))) + (ppx_sexp_conv + (and + (>= v0.17) + (< v0.18))) + (ppx_sexp_value + (and + (>= v0.17) + (< v0.18))) + (ppxlib + (>= 0.33)) + (provider + (>= 0.0.8)) + (vcs + (= :version)))) + (package (name vcs-command) (synopsis "A command line tool for the Vcs library") diff --git a/lib/vcs_base/src/dune b/lib/vcs_base/src/dune new file mode 100644 index 0000000..b2378e8 --- /dev/null +++ b/lib/vcs_base/src/dune @@ -0,0 +1,28 @@ +(library + (name vcs_base) + (public_name vcs-base) + (flags + :standard + -w + +a-4-40-41-42-44-45-48-66 + -warn-error + +a + -open + Base + -open + Fpath_base) + (libraries base fpath fpath-base provider vcs) + (instrumentation + (backend bisect_ppx)) + (lint + (pps ppx_js_style -check-doc-comments)) + (preprocess + (pps + -unused-code-warnings=force + ppx_compare + ppx_enumerate + ppx_hash + ppx_here + ppx_let + ppx_sexp_conv + ppx_sexp_value))) diff --git a/vcs-base.opam b/vcs-base.opam new file mode 100644 index 0000000..8c96e1a --- /dev/null +++ b/vcs-base.opam @@ -0,0 +1,42 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "An Extension of Vcs to use with Base" +maintainer: ["Mathieu Barbin "] +authors: ["Mathieu Barbin"] +license: "LGPL-3.0-or-later WITH LGPL-3.0-linking-exception" +homepage: "https://github.com/mbarbin/vcs" +doc: "https://mbarbin.github.io/vcs/" +bug-reports: "https://github.com/mbarbin/vcs/issues" +depends: [ + "dune" {>= "3.16"} + "ocaml" {>= "5.2"} + "base" {>= "v0.17" & < "v0.18"} + "fpath" {>= "0.7.3"} + "fpath-base" {>= "0.2.2"} + "ppx_compare" {>= "v0.17" & < "v0.18"} + "ppx_enumerate" {>= "v0.17" & < "v0.18"} + "ppx_hash" {>= "v0.17" & < "v0.18"} + "ppx_here" {>= "v0.17" & < "v0.18"} + "ppx_let" {>= "v0.17" & < "v0.18"} + "ppx_sexp_conv" {>= "v0.17" & < "v0.18"} + "ppx_sexp_value" {>= "v0.17" & < "v0.18"} + "ppxlib" {>= "0.33"} + "provider" {>= "0.0.8"} + "vcs" {= version} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/mbarbin/vcs.git" From e624da9dce2915017d54e03d81efc34e6c9037af Mon Sep 17 00:00:00 2001 From: Mathieu Barbin Date: Fri, 18 Oct 2024 09:30:03 +0200 Subject: [PATCH 3/4] Start populating Vcs_base --- CHANGES.md | 1 + TODO.md | 57 +++++++++++ example/hello_blocking.ml | 2 +- headache.sh | 2 + lib/vcs/src/author.ml | 9 +- lib/vcs/src/author.mli | 3 +- lib/vcs/src/branch_name.ml | 10 +- lib/vcs/src/branch_name.mli | 4 +- lib/vcs/src/commit_message.ml | 9 +- lib/vcs/src/commit_message.mli | 3 +- lib/vcs/src/container_key.ml | 42 ++++++++ lib/vcs/src/container_key.mli | 32 ++++++ lib/vcs/src/dune | 6 +- lib/vcs/src/file_contents.ml | 9 +- lib/vcs/src/file_contents.mli | 4 +- lib/vcs/src/for_test.ml | 16 +-- lib/vcs/src/for_test.mli | 5 +- lib/vcs/src/graph.ml | 52 +++++++--- lib/vcs/src/graph.mli | 15 ++- lib/vcs/src/log.ml | 30 +++++- lib/vcs/src/log.mli | 7 +- lib/vcs/src/name_status.ml | 99 +++++++++++++------ lib/vcs/src/name_status.mli | 12 ++- lib/vcs/src/num_lines_in_diff.ml | 24 ++++- lib/vcs/src/num_lines_in_diff.mli | 4 +- lib/vcs/src/num_status.ml | 77 ++++++++++++++- lib/vcs/src/num_status.mli | 11 ++- lib/vcs/src/path_in_repo.ml | 10 +- lib/vcs/src/path_in_repo.mli | 4 +- lib/vcs/src/platform.ml | 12 +-- lib/vcs/src/platform.mli | 6 +- lib/vcs/src/ref_kind.ml | 65 +++++++++--- lib/vcs/src/ref_kind.mli | 3 +- lib/vcs/src/refs.ml | 28 ++++-- lib/vcs/src/refs.mli | 18 ++-- lib/vcs/src/remote_branch_name.ml | 49 ++++++--- lib/vcs/src/remote_branch_name.mli | 3 +- lib/vcs/src/remote_name.ml | 10 +- lib/vcs/src/remote_name.mli | 4 +- lib/vcs/src/repo_name.ml | 10 +- lib/vcs/src/repo_name.mli | 4 +- lib/vcs/src/repo_root.ml | 10 +- lib/vcs/src/repo_root.mli | 3 +- lib/vcs/src/rev.ml | 8 +- lib/vcs/src/rev.mli | 4 +- lib/vcs/src/tag_name.ml | 10 +- lib/vcs/src/tag_name.mli | 4 +- lib/vcs/src/url.ml | 99 +++++++++++++------ lib/vcs/src/url.mli | 8 +- lib/vcs/src/user_email.ml | 9 +- lib/vcs/src/user_email.mli | 3 +- lib/vcs/src/user_handle.ml | 10 +- lib/vcs/src/user_handle.mli | 4 +- lib/vcs/src/user_name.ml | 9 +- lib/vcs/src/user_name.mli | 3 +- lib/vcs/src/vcs0.ml | 10 +- lib/vcs/test/dune | 1 + lib/vcs/test/test__graph.ml | 4 +- lib/vcs/test/test__name_status.ml | 22 ++++- lib/vcs/test/test__platform.ml | 14 +++ lib/vcs_base/src/author.ml | 27 +++++ lib/vcs_base/src/author.mli | 25 +++++ lib/vcs_base/src/branch_name.ml | 27 +++++ lib/vcs_base/src/branch_name.mli | 25 +++++ lib/vcs_base/src/commit_message.ml | 26 +++++ lib/vcs_base/src/commit_message.mli | 24 +++++ lib/vcs_base/src/file_contents.ml | 26 +++++ lib/vcs_base/src/file_contents.mli | 24 +++++ lib/vcs_base/src/graph.ml | 51 ++++++++++ lib/vcs_base/src/graph.mli | 43 ++++++++ lib/vcs_base/src/name_status.ml | 64 ++++++++++++ lib/vcs_base/src/name_status.mli | 61 ++++++++++++ lib/vcs_base/src/num_lines_in_diff.ml | 36 +++++++ lib/vcs_base/src/num_lines_in_diff.mli | 31 ++++++ lib/vcs_base/src/path_in_repo.ml | 27 +++++ lib/vcs_base/src/path_in_repo.mli | 25 +++++ lib/vcs_base/src/platform.ml | 32 ++++++ lib/vcs_base/src/platform.mli | 25 +++++ lib/vcs_base/src/ref_kind.ml | 37 +++++++ lib/vcs_base/src/ref_kind.mli | 30 ++++++ lib/vcs_base/src/refs.ml | 48 +++++++++ lib/vcs_base/src/refs.mli | 45 +++++++++ lib/vcs_base/src/remote_branch_name.ml | 38 +++++++ lib/vcs_base/src/remote_branch_name.mli | 29 ++++++ lib/vcs_base/src/remote_name.ml | 27 +++++ lib/vcs_base/src/remote_name.mli | 25 +++++ lib/vcs_base/src/repo_name.ml | 27 +++++ lib/vcs_base/src/repo_name.mli | 25 +++++ lib/vcs_base/src/repo_root.ml | 27 +++++ lib/vcs_base/src/repo_root.mli | 25 +++++ lib/vcs_base/src/rev.ml | 27 +++++ lib/vcs_base/src/rev.mli | 25 +++++ lib/vcs_base/src/tag_name.ml | 27 +++++ lib/vcs_base/src/tag_name.mli | 25 +++++ lib/vcs_base/src/url.ml | 47 +++++++++ lib/vcs_base/src/url.mli | 39 ++++++++ lib/vcs_base/src/user_email.ml | 27 +++++ lib/vcs_base/src/user_email.mli | 25 +++++ lib/vcs_base/src/user_handle.ml | 27 +++++ lib/vcs_base/src/user_handle.mli | 25 +++++ lib/vcs_base/src/user_name.ml | 27 +++++ lib/vcs_base/src/user_name.mli | 25 +++++ lib/vcs_base/src/vcs_base.ml | 69 +++++++++++++ lib/vcs_base/src/vcs_base.mli | 70 +++++++++++++ lib/vcs_base/test/dune | 42 ++++++++ lib/vcs_base/test/test__platform.ml | 38 +++++++ lib/vcs_base/test/test__platform.mli | 20 ++++ lib/vcs_command/src/vcs_command.ml | 9 +- .../test/test__hello_commit.ml | 2 +- lib/vcs_git_eio/test/test__init.ml | 2 +- .../test/test__name_status.ml | 2 +- lib/vcs_git_provider/test/test__refs.ml | 2 +- lib/vcs_test_helpers/src/vcs_test_helpers.ml | 2 +- test/expect/dune | 5 +- 114 files changed, 2269 insertions(+), 328 deletions(-) create mode 100644 TODO.md create mode 100644 lib/vcs/src/container_key.ml create mode 100644 lib/vcs/src/container_key.mli create mode 100644 lib/vcs_base/src/author.ml create mode 100644 lib/vcs_base/src/author.mli create mode 100644 lib/vcs_base/src/branch_name.ml create mode 100644 lib/vcs_base/src/branch_name.mli create mode 100644 lib/vcs_base/src/commit_message.ml create mode 100644 lib/vcs_base/src/commit_message.mli create mode 100644 lib/vcs_base/src/file_contents.ml create mode 100644 lib/vcs_base/src/file_contents.mli create mode 100644 lib/vcs_base/src/graph.ml create mode 100644 lib/vcs_base/src/graph.mli create mode 100644 lib/vcs_base/src/name_status.ml create mode 100644 lib/vcs_base/src/name_status.mli create mode 100644 lib/vcs_base/src/num_lines_in_diff.ml create mode 100644 lib/vcs_base/src/num_lines_in_diff.mli create mode 100644 lib/vcs_base/src/path_in_repo.ml create mode 100644 lib/vcs_base/src/path_in_repo.mli create mode 100644 lib/vcs_base/src/platform.ml create mode 100644 lib/vcs_base/src/platform.mli create mode 100644 lib/vcs_base/src/ref_kind.ml create mode 100644 lib/vcs_base/src/ref_kind.mli create mode 100644 lib/vcs_base/src/refs.ml create mode 100644 lib/vcs_base/src/refs.mli create mode 100644 lib/vcs_base/src/remote_branch_name.ml create mode 100644 lib/vcs_base/src/remote_branch_name.mli create mode 100644 lib/vcs_base/src/remote_name.ml create mode 100644 lib/vcs_base/src/remote_name.mli create mode 100644 lib/vcs_base/src/repo_name.ml create mode 100644 lib/vcs_base/src/repo_name.mli create mode 100644 lib/vcs_base/src/repo_root.ml create mode 100644 lib/vcs_base/src/repo_root.mli create mode 100644 lib/vcs_base/src/rev.ml create mode 100644 lib/vcs_base/src/rev.mli create mode 100644 lib/vcs_base/src/tag_name.ml create mode 100644 lib/vcs_base/src/tag_name.mli create mode 100644 lib/vcs_base/src/url.ml create mode 100644 lib/vcs_base/src/url.mli create mode 100644 lib/vcs_base/src/user_email.ml create mode 100644 lib/vcs_base/src/user_email.mli create mode 100644 lib/vcs_base/src/user_handle.ml create mode 100644 lib/vcs_base/src/user_handle.mli create mode 100644 lib/vcs_base/src/user_name.ml create mode 100644 lib/vcs_base/src/user_name.mli create mode 100644 lib/vcs_base/src/vcs_base.ml create mode 100644 lib/vcs_base/src/vcs_base.mli create mode 100644 lib/vcs_base/test/dune create mode 100644 lib/vcs_base/test/test__platform.ml create mode 100644 lib/vcs_base/test/test__platform.mli diff --git a/CHANGES.md b/CHANGES.md index 14687b4..5ce55b4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ### Added +- Add new `vcs-base` package meant to extend `vcs` with base-style functionality. - Add `Vcs.find_enclosing_repo_root` helper (#28, @mbarbin). - Add `Vcs.read_dir` helper (#28, @mbarbin). diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..a34ede3 --- /dev/null +++ b/TODO.md @@ -0,0 +1,57 @@ +# Vcs_base + +In this file we document a multi-stages refactoring that is currently in progress in the repository. + +## Targeted end result + +The aim of this refactoring is to remove the base dependency of the `Vcs` library. To achieve this, we will offer two distinct libraries: + +- `Vcs` - a kernel library that can be used with very little dependencies; +- `Vcs_base` - an extension of `Vcs` which will add some functionality related to working with `Base`. + +## Stages + +### Stage 1 - Introducing `Vcs_base` + +- [x] Completed: Oct. 2024 + +In this stage, we create the library `Vcs_base` and setup the way in which this library extends `Vcs`. It exposes the same modules, plus extra functionality, such as: + +- Base style `hash` signatures +- `Comparable.S` signatures for use with Base style containers +- Make some functions return sets instead of lists. + +### Stage 2 - Reducing ppx dependencies in `Vcs` + +- [x] Completed: Oct. 2024 + +Only keep sexp related ppx that have no runtime dependency on `base`, such as `sexplib0` only. + +- Remove `ppx_compare`, `ppx_here`, `ppx_let` dependencies. + +### Stage 3 - Refactor non-raising APIs + +- [ ] Pending + +- Rename `Result` => `Rresult`, introduce a new `Result` one. + +### Stage 4 - Trait implementation use `Result` + +- [ ] Pending + +### Stage 5 - Move `Or_error` module into `Vcs_base`. + +- [ ] Pending + +### Stage 6 - Remove base dependency from `Vcs` + +- [ ] Pending + +Use `vcs/src/import` to make a local mini-stdlib with utils required to remove `base` dependency. + +Do this for the other libraries: + +- [ ] vcs +- [ ] vcs_git_eio +- [ ] vcs_git_provider +- [ ] vcs_git_blocking diff --git a/example/hello_blocking.ml b/example/hello_blocking.ml index 13fa597..da086eb 100644 --- a/example/hello_blocking.ml +++ b/example/hello_blocking.ml @@ -34,7 +34,7 @@ let%expect_test "hello commit" = GitHub Actions environment, where no default user config exists. *) let repo_root = let path = Stdlib.Filename.temp_dir ~temp_dir:(Unix.getcwd ()) "vcs" "test" in - Vcs.For_test.init vcs ~path:(Absolute_path.v path) |> Or_error.ok_exn + Vcs.For_test.init vcs ~path:(Absolute_path.v path) in (* Ok, we are all set, we are now inside a Git repo and we can start using [Vcs]. What we do in this example is simply create a new file and commit it diff --git a/headache.sh b/headache.sh index fa144ae..02e4fdf 100755 --- a/headache.sh +++ b/headache.sh @@ -5,6 +5,8 @@ dirs=( "example" "lib/vcs/src" "lib/vcs/test" + "lib/vcs_base/src" + "lib/vcs_base/test" "lib/vcs_command/src" "lib/vcs_command/test" "lib/vcs_git_blocking/src" diff --git a/lib/vcs/src/author.ml b/lib/vcs/src/author.ml index f5c4dd8..01ff021 100644 --- a/lib/vcs/src/author.ml +++ b/lib/vcs/src/author.ml @@ -20,14 +20,7 @@ (*******************************************************************************) open! Import - -module T = struct - [@@@coverage off] - - type t = string [@@deriving compare, equal, hash, sexp_of] -end - -include T +include Container_key.String_impl let invariant t = (not (String.is_empty t)) diff --git a/lib/vcs/src/author.mli b/lib/vcs/src/author.mli index ca7fcfd..3c92e91 100644 --- a/lib/vcs/src/author.mli +++ b/lib/vcs/src/author.mli @@ -26,8 +26,9 @@ For example: [Author.v "John Doe "]. *) -type t [@@deriving compare, equal, hash, sexp_of] +type t +include Container_key.S with type t := t include Validated_string.S with type t := t val of_user_config : user_name:User_name.t -> user_email:User_email.t -> t diff --git a/lib/vcs/src/branch_name.ml b/lib/vcs/src/branch_name.ml index 6399c33..b3bb763 100644 --- a/lib/vcs/src/branch_name.ml +++ b/lib/vcs/src/branch_name.ml @@ -20,15 +20,7 @@ (*******************************************************************************) open! Import - -module T = struct - [@@@coverage off] - - type t = string [@@deriving compare, hash, sexp_of] -end - -include T -include Comparable.Make (T) +include Container_key.String_impl let invariant t = (not (String.is_empty t)) diff --git a/lib/vcs/src/branch_name.mli b/lib/vcs/src/branch_name.mli index fbc95dd..9d8e161 100644 --- a/lib/vcs/src/branch_name.mli +++ b/lib/vcs/src/branch_name.mli @@ -19,9 +19,9 @@ (*_ and , respectively. *) (*_******************************************************************************) -type t [@@deriving compare, equal, hash, sexp_of] +type t -include Comparable.S with type t := t +include Container_key.S with type t := t include Validated_string.S with type t := t (** {1 Some standard names} *) diff --git a/lib/vcs/src/commit_message.ml b/lib/vcs/src/commit_message.ml index 2dd1426..9e58ffa 100644 --- a/lib/vcs/src/commit_message.ml +++ b/lib/vcs/src/commit_message.ml @@ -20,14 +20,7 @@ (*******************************************************************************) open! Import - -module T = struct - [@@@coverage off] - - type t = string [@@deriving compare, equal, hash, sexp_of] -end - -include T +include Container_key.String_impl let invariant t = (not (String.is_empty t)) && String.length t <= 512 diff --git a/lib/vcs/src/commit_message.mli b/lib/vcs/src/commit_message.mli index 46e6566..db096a7 100644 --- a/lib/vcs/src/commit_message.mli +++ b/lib/vcs/src/commit_message.mli @@ -25,6 +25,7 @@ sets some arbitrary limits on the length of the message, and mustn't be empty. *) -type t [@@deriving compare, equal, hash, sexp_of] +type t +include Container_key.S with type t := t include Validated_string.S with type t := t diff --git a/lib/vcs/src/container_key.ml b/lib/vcs/src/container_key.ml new file mode 100644 index 0000000..c80284c --- /dev/null +++ b/lib/vcs/src/container_key.ml @@ -0,0 +1,42 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +open! Import + +module type S = sig + type t + + val compare : t -> t -> int + val equal : t -> t -> bool + val hash : t -> int + val seeded_hash : int -> t -> int + val sexp_of_t : t -> Sexp.t +end + +module String_impl = struct + type t = string + + let compare = compare_string + let equal = equal_string + let hash = hash_string + let seeded_hash = Stdlib.String.seeded_hash + let sexp_of_t = sexp_of_string +end diff --git a/lib/vcs/src/container_key.mli b/lib/vcs/src/container_key.mli new file mode 100644 index 0000000..c98c361 --- /dev/null +++ b/lib/vcs/src/container_key.mli @@ -0,0 +1,32 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +module type S = sig + type t + + val compare : t -> t -> int + val equal : t -> t -> bool + val hash : t -> int + val seeded_hash : int -> t -> int + val sexp_of_t : t -> Sexp.t +end + +module String_impl : S with type t = string diff --git a/lib/vcs/src/dune b/lib/vcs/src/dune index da028f6..3ce729f 100644 --- a/lib/vcs/src/dune +++ b/lib/vcs/src/dune @@ -15,7 +15,7 @@ (instrumentation (backend bisect_ppx)) (lint - (pps ppx_js_style -check-doc-comments)) + (pps ppx_js_style -allow-let-operators -check-doc-comments)) (modules_without_implementation trait_add trait_branch @@ -36,10 +36,6 @@ (preprocess (pps -unused-code-warnings=force - ppx_compare ppx_enumerate - ppx_hash - ppx_here - ppx_let ppx_sexp_conv ppx_sexp_value))) diff --git a/lib/vcs/src/file_contents.ml b/lib/vcs/src/file_contents.ml index 5174673..17a662e 100644 --- a/lib/vcs/src/file_contents.ml +++ b/lib/vcs/src/file_contents.ml @@ -20,14 +20,7 @@ (*******************************************************************************) open! Import - -module T = struct - [@@@coverage off] - - type t = string [@@deriving compare, equal, hash, sexp_of] -end - -include T +include Container_key.String_impl let create t = t let to_string t = t diff --git a/lib/vcs/src/file_contents.mli b/lib/vcs/src/file_contents.mli index ba3afd2..cb696cb 100644 --- a/lib/vcs/src/file_contents.mli +++ b/lib/vcs/src/file_contents.mli @@ -22,7 +22,9 @@ (** Representing the raw contents of files on disk. *) (** This is a simple wrapper for the type string, used to increase type safety. *) -type t = private string [@@deriving compare, equal, hash, sexp_of] +type t = private string + +include Container_key.S with type t := t (** [create file_contents] returns a [t] representing the given file contents. *) val create : string -> t diff --git a/lib/vcs/src/for_test.ml b/lib/vcs/src/for_test.ml index e6d2262..1227ecc 100644 --- a/lib/vcs/src/for_test.ml +++ b/lib/vcs/src/for_test.ml @@ -20,16 +20,8 @@ (*******************************************************************************) let init vcs ~path = - let open Or_error.Let_syntax in - let%bind repo_root = Vcs_or_error.init vcs ~path in - let%bind () = - Vcs_or_error.set_user_name vcs ~repo_root ~user_name:(User_name.v "Test User") - in - let%bind () = - Vcs_or_error.set_user_email - vcs - ~repo_root - ~user_email:(User_email.v "test@example.com") - in - return repo_root + let repo_root = Vcs0.init vcs ~path in + Vcs0.set_user_name vcs ~repo_root ~user_name:(User_name.v "Test User"); + Vcs0.set_user_email vcs ~repo_root ~user_email:(User_email.v "test@example.com"); + repo_root ;; diff --git a/lib/vcs/src/for_test.mli b/lib/vcs/src/for_test.mli index 9a9f2a5..71eab67 100644 --- a/lib/vcs/src/for_test.mli +++ b/lib/vcs/src/for_test.mli @@ -26,7 +26,4 @@ your machine. This isolates the test from your local settings, and also makes things work when running in the GitHub Actions environment, where no default user config exists. *) -val init - : [> Trait.config | Trait.init ] Vcs0.t - -> path:Absolute_path.t - -> Repo_root.t Or_error.t +val init : [> Trait.config | Trait.init ] Vcs0.t -> path:Absolute_path.t -> Repo_root.t diff --git a/lib/vcs/src/graph.ml b/lib/vcs/src/graph.ml index ddf8470..648674a 100644 --- a/lib/vcs/src/graph.ml +++ b/lib/vcs/src/graph.ml @@ -22,18 +22,13 @@ open! Import module Node = struct - module T0 = struct - [@@@coverage off] - - type t = int [@@deriving compare, hash] - - [@@@coverage on] - - let sexp_of_t i = Sexp.Atom ("#" ^ Int.to_string_hum i) - end + type t = int - include T0 - include Comparable.Make (T0) + let compare = Int.compare + let equal = Int.equal + let hash = Int.hash + let seeded_hash = Stdlib.Int.seeded_hash + let sexp_of_t i = Sexp.Atom ("#" ^ Int.to_string_hum i) end module Node_kind = struct @@ -51,7 +46,31 @@ module Node_kind = struct ; parent1 : Node.t ; parent2 : Node.t } - [@@deriving equal, sexp_of] + [@@deriving sexp_of] + + let equal = + (fun a__001_ b__002_ -> + if Stdlib.( == ) a__001_ b__002_ + then true + else ( + match a__001_, b__002_ with + | Root _a__003_, Root _b__004_ -> Rev.equal _a__003_.rev _b__004_.rev + | Root _, _ -> false + | _, Root _ -> false + | Commit _a__005_, Commit _b__006_ -> + Stdlib.( && ) + (Rev.equal _a__005_.rev _b__006_.rev) + (Node.equal _a__005_.parent _b__006_.parent) + | Commit _, _ -> false + | _, Commit _ -> false + | Merge _a__007_, Merge _b__008_ -> + Stdlib.( && ) + (Rev.equal _a__007_.rev _b__008_.rev) + (Stdlib.( && ) + (Node.equal _a__007_.parent1 _b__008_.parent1) + (Node.equal _a__007_.parent2 _b__008_.parent2))) + : t -> t -> bool) + ;; end include T @@ -337,7 +356,12 @@ module Descendance = struct | Strict_ancestor | Strict_descendant | Other - [@@deriving equal, enumerate, hash, sexp_of] + [@@deriving enumerate, sexp_of] + + let compare = (Stdlib.compare : t -> t -> int) + let equal = (Stdlib.( = ) : t -> t -> bool) + let seeded_hash = (Stdlib.Hashtbl.seeded_hash : int -> t -> int) + let hash = (Stdlib.Hashtbl.hash : t -> int) end let descendance t a b : Descendance.t = @@ -481,4 +505,4 @@ let get_node_exn t ~index = (index :> Node.t) ;; -let node_index _ (node : Node.t) = (node :> int) +let node_index (node : Node.t) = (node :> int) diff --git a/lib/vcs/src/graph.mli b/lib/vcs/src/graph.mli index 79827a9..0a91f5d 100644 --- a/lib/vcs/src/graph.mli +++ b/lib/vcs/src/graph.mli @@ -77,9 +77,9 @@ val set_ref : t -> rev:Rev.t -> ref_kind:Ref_kind.t -> unit function) then you can be certain that [n1] is not a parent of [n2]. *) module Node : sig - type t [@@deriving compare, equal, hash, sexp_of] + type t - include Comparable.S with type t := t + include Container_key.S with type t := t end module Node_kind : sig @@ -94,7 +94,9 @@ module Node_kind : sig ; parent1 : Node.t ; parent2 : Node.t } - [@@deriving equal, sexp_of] + [@@deriving sexp_of] + + val equal : t -> t -> bool (** A helper to access the revision of the node itself. This simply returns the first argument of each constructor. *) @@ -190,7 +192,10 @@ module Descendance : sig | Strict_ancestor | Strict_descendant | Other - [@@deriving equal, enumerate, hash, sexp_of] + + val all : t list + + include Container_key.S with type t := t end (** [descendance graph a b] characterizes the descendance relationship between @@ -285,4 +290,4 @@ val summary : t -> Summary.t exposed API isn't enough for your use case. *) val get_node_exn : t -> index:int -> Node.t -val node_index : t -> Node.t -> int +val node_index : Node.t -> int diff --git a/lib/vcs/src/log.ml b/lib/vcs/src/log.ml index 04bccb0..b8d0c1c 100644 --- a/lib/vcs/src/log.ml +++ b/lib/vcs/src/log.ml @@ -35,7 +35,31 @@ module Line = struct ; parent1 : Rev.t ; parent2 : Rev.t } - [@@deriving equal, sexp_of] + [@@deriving sexp_of] + + let equal = + (fun a__001_ b__002_ -> + if Stdlib.( == ) a__001_ b__002_ + then true + else ( + match a__001_, b__002_ with + | Root _a__003_, Root _b__004_ -> Rev.equal _a__003_.rev _b__004_.rev + | Root _, _ -> false + | _, Root _ -> false + | Commit _a__005_, Commit _b__006_ -> + Stdlib.( && ) + (Rev.equal _a__005_.rev _b__006_.rev) + (Rev.equal _a__005_.parent _b__006_.parent) + | Commit _, _ -> false + | _, Commit _ -> false + | Merge _a__007_, Merge _b__008_ -> + Stdlib.( && ) + (Rev.equal _a__007_.rev _b__008_.rev) + (Stdlib.( && ) + (Rev.equal _a__007_.parent1 _b__008_.parent1) + (Rev.equal _a__007_.parent2 _b__008_.parent2))) + : t -> t -> bool) + ;; let rev = function | Commit { rev; _ } | Merge { rev; _ } | Root { rev } -> rev @@ -45,7 +69,9 @@ end module T = struct [@@@coverage off] - type t = Line.t list [@@deriving equal, sexp_of] + type t = Line.t list [@@deriving sexp_of] + + let equal a b = equal_list Line.equal a b end include T diff --git a/lib/vcs/src/log.mli b/lib/vcs/src/log.mli index c229c7e..7f0a6a7 100644 --- a/lib/vcs/src/log.mli +++ b/lib/vcs/src/log.mli @@ -35,12 +35,15 @@ module Line : sig ; parent1 : Rev.t ; parent2 : Rev.t } - [@@deriving equal, sexp_of] + [@@deriving sexp_of] + val equal : t -> t -> bool val rev : t -> Rev.t end -type t = Line.t list [@@deriving equal, sexp_of] +type t = Line.t list [@@deriving sexp_of] + +val equal : t -> t -> bool (** {1 Accessors} *) diff --git a/lib/vcs/src/name_status.ml b/lib/vcs/src/name_status.ml index 4ac043f..14d9450 100644 --- a/lib/vcs/src/name_status.ml +++ b/lib/vcs/src/name_status.ml @@ -40,7 +40,7 @@ * * Changes: This has similarities with the module [Hg.Status]. We added support * for renames, removed support for [Changed_by Rev.t], added [similarity] values - * which are available in Git. The file utils return sets rather than lists. + * which are available in Git. *) open! Import @@ -63,6 +63,38 @@ module Change = struct ; similarity : int } [@@deriving sexp_of] + + let equal = + (fun a__001_ b__002_ -> + if Stdlib.( == ) a__001_ b__002_ + then true + else ( + match a__001_, b__002_ with + | Added _a__003_, Added _b__004_ -> Path_in_repo.equal _a__003_ _b__004_ + | Added _, _ -> false + | _, Added _ -> false + | Removed _a__005_, Removed _b__006_ -> Path_in_repo.equal _a__005_ _b__006_ + | Removed _, _ -> false + | _, Removed _ -> false + | Modified _a__007_, Modified _b__008_ -> Path_in_repo.equal _a__007_ _b__008_ + | Modified _, _ -> false + | _, Modified _ -> false + | Copied _a__009_, Copied _b__010_ -> + Stdlib.( && ) + (Path_in_repo.equal _a__009_.src _b__010_.src) + (Stdlib.( && ) + (Path_in_repo.equal _a__009_.dst _b__010_.dst) + (equal_int _a__009_.similarity _b__010_.similarity)) + | Copied _, _ -> false + | _, Copied _ -> false + | Renamed _a__011_, Renamed _b__012_ -> + Stdlib.( && ) + (Path_in_repo.equal _a__011_.src _b__012_.src) + (Stdlib.( && ) + (Path_in_repo.equal _a__011_.dst _b__012_.dst) + (equal_int _a__011_.similarity _b__012_.similarity))) + : t -> t -> bool) + ;; end module T = struct @@ -72,40 +104,34 @@ end include T let files_at_src (t : t) = - List.fold - t - ~init:(Set.empty (module Path_in_repo)) - ~f:(fun set change -> - match change with - | Added _ -> set - | Removed path - | Modified path - | Copied { src = path; dst = _; similarity = _ } - | Renamed { src = path; dst = _; similarity = _ } -> Set.add set path) + List.fold t ~init:[] ~f:(fun acc change -> + match change with + | Added _ -> acc + | Removed path + | Modified path + | Copied { src = path; dst = _; similarity = _ } + | Renamed { src = path; dst = _; similarity = _ } -> path :: acc) + |> List.dedup_and_sort ~compare:Path_in_repo.compare ;; let files_at_dst (t : t) = - List.fold - t - ~init:(Set.empty (module Path_in_repo)) - ~f:(fun set change -> - match change with - | Removed _ -> set - | Added path - | Modified path - | Copied { src = _; dst = path; similarity = _ } - | Renamed { src = _; dst = path; similarity = _ } -> Set.add set path) + List.fold t ~init:[] ~f:(fun acc change -> + match change with + | Removed _ -> acc + | Added path + | Modified path + | Copied { src = _; dst = path; similarity = _ } + | Renamed { src = _; dst = path; similarity = _ } -> path :: acc) + |> List.dedup_and_sort ~compare:Path_in_repo.compare ;; let files (t : t) = - List.fold - t - ~init:(Set.empty (module Path_in_repo)) - ~f:(fun set change -> - match change with - | Removed path | Added path | Modified path -> Set.add set path - | Copied { src; dst; similarity = _ } | Renamed { src; dst; similarity = _ } -> - Set.add (Set.add set src) dst) + List.fold t ~init:[] ~f:(fun acc change -> + match change with + | Removed path | Added path | Modified path -> path :: acc + | Copied { src; dst; similarity = _ } | Renamed { src; dst; similarity = _ } -> + src :: dst :: acc) + |> List.dedup_and_sort ~compare:Path_in_repo.compare ;; module Changed = struct @@ -116,5 +142,18 @@ module Changed = struct { src : Rev.t ; dst : Rev.t } - [@@deriving equal, sexp_of] + [@@deriving sexp_of] + + let equal = + (fun a__034_ b__035_ -> + if Stdlib.( == ) a__034_ b__035_ + then true + else ( + match a__034_, b__035_ with + | Between _a__036_, Between _b__037_ -> + Stdlib.( && ) + (Rev.equal _a__036_.src _b__037_.src) + (Rev.equal _a__036_.dst _b__037_.dst)) + : t -> t -> bool) + ;; end diff --git a/lib/vcs/src/name_status.mli b/lib/vcs/src/name_status.mli index 30a712c..d51778d 100644 --- a/lib/vcs/src/name_status.mli +++ b/lib/vcs/src/name_status.mli @@ -58,19 +58,21 @@ module Change : sig ; similarity : int } [@@deriving sexp_of] + + val equal : t -> t -> bool end type t = Change.t list [@@deriving sexp_of] (** Returns the set of files that are involved by the changes, either at [src] or [dst]. *) -val files : t -> Set.M(Path_in_repo).t +val files : t -> Path_in_repo.t list (** Returns the set of files that are involved by the changes, that are also present at [src] or [dst] respectively. *) -val files_at_src : t -> Set.M(Path_in_repo).t -val files_at_dst : t -> Set.M(Path_in_repo).t +val files_at_src : t -> Path_in_repo.t list +val files_at_dst : t -> Path_in_repo.t list module Changed : sig (** Specifies which {!type:Name_status.t} we want to compute. *) @@ -79,5 +81,7 @@ module Changed : sig { src : Rev.t ; dst : Rev.t } - [@@deriving equal, sexp_of] + [@@deriving sexp_of] + + val equal : t -> t -> bool end diff --git a/lib/vcs/src/num_lines_in_diff.ml b/lib/vcs/src/num_lines_in_diff.ml index d5a2311..75ae21c 100644 --- a/lib/vcs/src/num_lines_in_diff.ml +++ b/lib/vcs/src/num_lines_in_diff.ml @@ -26,7 +26,29 @@ module T = struct { insertions : int ; deletions : int } - [@@deriving compare, equal, sexp_of] + [@@deriving sexp_of] + + let compare = + (fun a__001_ b__002_ -> + if Stdlib.( == ) a__001_ b__002_ + then 0 + else ( + match compare_int a__001_.insertions b__002_.insertions with + | 0 -> compare_int a__001_.deletions b__002_.deletions + | n -> n) + : t -> t -> int) + ;; + + let equal = + (fun a__003_ b__004_ -> + if Stdlib.( == ) a__003_ b__004_ + then true + else + Stdlib.( && ) + (equal_int a__003_.insertions b__004_.insertions) + (equal_int a__003_.deletions b__004_.deletions) + : t -> t -> bool) + ;; let zero = { insertions = 0; deletions = 0 } diff --git a/lib/vcs/src/num_lines_in_diff.mli b/lib/vcs/src/num_lines_in_diff.mli index 27b3327..0f017d7 100644 --- a/lib/vcs/src/num_lines_in_diff.mli +++ b/lib/vcs/src/num_lines_in_diff.mli @@ -29,8 +29,10 @@ type t = { insertions : int ; deletions : int } -[@@deriving compare, equal, sexp_of] +[@@deriving sexp_of] +val compare : t -> t -> int +val equal : t -> t -> bool val zero : t val ( + ) : t -> t -> t val sum : t list -> t diff --git a/lib/vcs/src/num_status.ml b/lib/vcs/src/num_status.ml index 1910a53..910681b 100644 --- a/lib/vcs/src/num_status.ml +++ b/lib/vcs/src/num_status.ml @@ -30,7 +30,42 @@ module Key = struct { src : Path_in_repo.t ; dst : Path_in_repo.t } - [@@deriving compare, equal, hash, sexp_of] + [@@deriving sexp_of] + + let compare = + (fun a__001_ b__002_ -> + if Stdlib.( == ) a__001_ b__002_ + then 0 + else ( + match a__001_, b__002_ with + | One_file _a__003_, One_file _b__004_ -> Path_in_repo.compare _a__003_ _b__004_ + | One_file _, _ -> -1 + | _, One_file _ -> 1 + | Two_files _a__005_, Two_files _b__006_ -> + (match Path_in_repo.compare _a__005_.src _b__006_.src with + | 0 -> Path_in_repo.compare _a__005_.dst _b__006_.dst + | n -> n)) + : t -> t -> int) + ;; + + let equal = + (fun a__007_ b__008_ -> + if Stdlib.( == ) a__007_ b__008_ + then true + else ( + match a__007_, b__008_ with + | One_file _a__009_, One_file _b__010_ -> Path_in_repo.equal _a__009_ _b__010_ + | One_file _, _ -> false + | _, One_file _ -> false + | Two_files _a__011_, Two_files _b__012_ -> + Stdlib.( && ) + (Path_in_repo.equal _a__011_.src _b__012_.src) + (Path_in_repo.equal _a__011_.dst _b__012_.dst)) + : t -> t -> bool) + ;; + + let seeded_hash = (Stdlib.Hashtbl.seeded_hash : int -> t -> int) + let hash = (Stdlib.Hashtbl.hash : t -> int) end module Change = struct @@ -41,6 +76,20 @@ module Change = struct | Num_lines_in_diff of Num_lines_in_diff.t | Binary_file [@@deriving sexp_of] + + let equal = + (fun a__008_ b__009_ -> + if Stdlib.( == ) a__008_ b__009_ + then true + else ( + match a__008_, b__009_ with + | Num_lines_in_diff _a__010_, Num_lines_in_diff _b__011_ -> + Num_lines_in_diff.equal _a__010_ _b__011_ + | Num_lines_in_diff _, _ -> false + | _, Num_lines_in_diff _ -> false + | Binary_file, Binary_file -> true) + : t -> t -> bool) + ;; end type t = @@ -48,6 +97,17 @@ module Change = struct ; num_stat : Num_stat.t } [@@deriving sexp_of] + + let equal = + (fun a__014_ b__015_ -> + if Stdlib.( == ) a__014_ b__015_ + then true + else + Stdlib.( && ) + (Key.equal a__014_.key b__015_.key) + (Num_stat.equal a__014_.num_stat b__015_.num_stat) + : t -> t -> bool) + ;; end module T = struct @@ -64,5 +124,18 @@ module Changed = struct { src : Rev.t ; dst : Rev.t } - [@@deriving equal, sexp_of] + [@@deriving sexp_of] + + let equal = + (fun a__022_ b__023_ -> + if Stdlib.( == ) a__022_ b__023_ + then true + else ( + match a__022_, b__023_ with + | Between _a__024_, Between _b__025_ -> + Stdlib.( && ) + (Rev.equal _a__024_.src _b__025_.src) + (Rev.equal _a__024_.dst _b__025_.dst)) + : t -> t -> bool) + ;; end diff --git a/lib/vcs/src/num_status.mli b/lib/vcs/src/num_status.mli index 52d5cde..6b6f861 100644 --- a/lib/vcs/src/num_status.mli +++ b/lib/vcs/src/num_status.mli @@ -26,7 +26,8 @@ module Key : sig { src : Path_in_repo.t ; dst : Path_in_repo.t } - [@@deriving compare, equal, hash, sexp_of] + + include Container_key.S with type t := t end module Change : sig @@ -39,6 +40,8 @@ module Change : sig | Num_lines_in_diff of Num_lines_in_diff.t | Binary_file [@@deriving sexp_of] + + val equal : t -> t -> bool end type t = @@ -46,6 +49,8 @@ module Change : sig ; num_stat : Num_stat.t } [@@deriving sexp_of] + + val equal : t -> t -> bool end type t = Change.t list [@@deriving sexp_of] @@ -57,5 +62,7 @@ module Changed : sig { src : Rev.t ; dst : Rev.t } - [@@deriving equal, sexp_of] + [@@deriving sexp_of] + + val equal : t -> t -> bool end diff --git a/lib/vcs/src/path_in_repo.ml b/lib/vcs/src/path_in_repo.ml index d0a3bc4..8999af7 100644 --- a/lib/vcs/src/path_in_repo.ml +++ b/lib/vcs/src/path_in_repo.ml @@ -44,15 +44,7 @@ *) open! Import - -module T = struct - [@@@coverage off] - - type t = Relative_path.t [@@deriving compare, hash, sexp_of] -end - -include T -include Comparable.Make (T) +include Relative_path let root = Relative_path.empty let to_fpath = Relative_path.to_fpath diff --git a/lib/vcs/src/path_in_repo.mli b/lib/vcs/src/path_in_repo.mli index c81ffe0..92fe7a8 100644 --- a/lib/vcs/src/path_in_repo.mli +++ b/lib/vcs/src/path_in_repo.mli @@ -47,9 +47,9 @@ This is a wrapper for a [Fpath.t] relative to the repo root, used for accrued type safety. *) -type t [@@deriving compare, equal, hash, sexp_of] +type t -include Comparable.S with type t := t +include Container_key.S with type t := t include Validated_string.S with type t := t val root : t diff --git a/lib/vcs/src/platform.ml b/lib/vcs/src/platform.ml index ea3faf0..3a85405 100644 --- a/lib/vcs/src/platform.ml +++ b/lib/vcs/src/platform.ml @@ -21,14 +21,12 @@ open! Import -module T = struct - [@@@coverage off] +type t = GitHub [@@deriving enumerate, sexp_of] - type t = GitHub [@@deriving compare, enumerate, hash, sexp_of] -end - -include T -include Comparable.Make (T) +let compare = (Stdlib.compare : t -> t -> int) +let equal = (Stdlib.( = ) : t -> t -> bool) +let seeded_hash = (Stdlib.Hashtbl.seeded_hash : int -> t -> int) +let hash = (Stdlib.Hashtbl.hash : t -> int) let to_string = function | GitHub -> "GitHub" diff --git a/lib/vcs/src/platform.mli b/lib/vcs/src/platform.mli index abf4b94..f82fe2e 100644 --- a/lib/vcs/src/platform.mli +++ b/lib/vcs/src/platform.mli @@ -25,9 +25,11 @@ This is used to implement convenient utils, such as utils to clone repositories from GitHub, etc. *) -type t = GitHub [@@deriving compare, equal, enumerate, hash, sexp_of] +type t = GitHub -include Comparable.S with type t := t +include Container_key.S with type t := t + +val all : t list (** A string representing the platform, using the styled capitalization of the variant constructor. For example, ["GitHub"] is typically spelled with an diff --git a/lib/vcs/src/ref_kind.ml b/lib/vcs/src/ref_kind.ml index 497961f..61b0888 100644 --- a/lib/vcs/src/ref_kind.ml +++ b/lib/vcs/src/ref_kind.ml @@ -21,19 +21,62 @@ open! Import -module T = struct - [@@@coverage off] +[@@@coverage off] - type t = - | Local_branch of { branch_name : Branch_name.t } - | Remote_branch of { remote_branch_name : Remote_branch_name.t } - | Tag of { tag_name : Tag_name.t } - | Other of { name : string } - [@@deriving compare, hash, sexp_of] -end +type t = + | Local_branch of { branch_name : Branch_name.t } + | Remote_branch of { remote_branch_name : Remote_branch_name.t } + | Tag of { tag_name : Tag_name.t } + | Other of { name : string } +[@@deriving sexp_of] -include T -include Comparable.Make (T) +let compare = + (fun a__001_ b__002_ -> + if Stdlib.( == ) a__001_ b__002_ + then 0 + else ( + match a__001_, b__002_ with + | Local_branch _a__003_, Local_branch _b__004_ -> + Branch_name.compare _a__003_.branch_name _b__004_.branch_name + | Local_branch _, _ -> -1 + | _, Local_branch _ -> 1 + | Remote_branch _a__005_, Remote_branch _b__006_ -> + Remote_branch_name.compare + _a__005_.remote_branch_name + _b__006_.remote_branch_name + | Remote_branch _, _ -> -1 + | _, Remote_branch _ -> 1 + | Tag _a__007_, Tag _b__008_ -> + Tag_name.compare _a__007_.tag_name _b__008_.tag_name + | Tag _, _ -> -1 + | _, Tag _ -> 1 + | Other _a__009_, Other _b__010_ -> compare_string _a__009_.name _b__010_.name) + : t -> t -> int) +;; + +let equal = + (fun a__011_ b__012_ -> + if Stdlib.( == ) a__011_ b__012_ + then true + else ( + match a__011_, b__012_ with + | Local_branch _a__013_, Local_branch _b__014_ -> + Branch_name.equal _a__013_.branch_name _b__014_.branch_name + | Local_branch _, _ -> false + | _, Local_branch _ -> false + | Remote_branch _a__015_, Remote_branch _b__016_ -> + Remote_branch_name.equal _a__015_.remote_branch_name _b__016_.remote_branch_name + | Remote_branch _, _ -> false + | _, Remote_branch _ -> false + | Tag _a__017_, Tag _b__018_ -> Tag_name.equal _a__017_.tag_name _b__018_.tag_name + | Tag _, _ -> false + | _, Tag _ -> false + | Other _a__019_, Other _b__020_ -> equal_string _a__019_.name _b__020_.name) + : t -> t -> bool) +;; + +let seeded_hash = (Stdlib.Hashtbl.seeded_hash : int -> t -> int) +let hash = (Stdlib.Hashtbl.hash : t -> int) let to_string = function | Local_branch { branch_name } -> "refs/heads/" ^ Branch_name.to_string branch_name diff --git a/lib/vcs/src/ref_kind.mli b/lib/vcs/src/ref_kind.mli index 73f155e..d8bccdf 100644 --- a/lib/vcs/src/ref_kind.mli +++ b/lib/vcs/src/ref_kind.mli @@ -24,8 +24,7 @@ type t = | Remote_branch of { remote_branch_name : Remote_branch_name.t } | Tag of { tag_name : Tag_name.t } | Other of { name : string } -[@@deriving compare, equal, hash, sexp_of] -include Comparable.S with type t := t +include Container_key.S with type t := t val to_string : t -> string diff --git a/lib/vcs/src/refs.ml b/lib/vcs/src/refs.ml index cbdbeac..ce7cdf4 100644 --- a/lib/vcs/src/refs.ml +++ b/lib/vcs/src/refs.ml @@ -28,13 +28,26 @@ module Line = struct { rev : Rev.t ; ref_kind : Ref_kind.t } - [@@deriving equal, sexp_of] + [@@deriving sexp_of] + + let equal = + (fun a__001_ b__002_ -> + if Stdlib.( == ) a__001_ b__002_ + then true + else + Stdlib.( && ) + (Rev.equal a__001_.rev b__002_.rev) + (Ref_kind.equal a__001_.ref_kind b__002_.ref_kind) + : t -> t -> bool) + ;; end module T = struct [@@@coverage off] - type t = Line.t list [@@deriving equal, sexp_of] + type t = Line.t list [@@deriving sexp_of] + + let equal a b = equal_list Line.equal a b end include T @@ -43,13 +56,14 @@ let tags (t : t) = List.filter_map t ~f:(function | { rev = _; ref_kind = Tag { tag_name } } -> Some tag_name | _ -> None) - |> Set.of_list (module Tag_name) + |> List.sort ~compare:Tag_name.compare ;; let local_branches (t : t) = List.filter_map t ~f:(function | { rev = _; ref_kind = Local_branch { branch_name } } -> Some branch_name | _ -> None) + |> List.sort ~compare:Branch_name.compare ;; let remote_branches (t : t) = @@ -57,11 +71,5 @@ let remote_branches (t : t) = | { rev = _; ref_kind = Remote_branch { remote_branch_name } } -> Some remote_branch_name | _ -> None) -;; - -let to_map (t : t) = - List.fold - t - ~init:(Map.empty (module Ref_kind)) - ~f:(fun acc { rev; ref_kind } -> Map.add_exn acc ~key:ref_kind ~data:rev) + |> List.sort ~compare:Remote_branch_name.compare ;; diff --git a/lib/vcs/src/refs.mli b/lib/vcs/src/refs.mli index 0e23bc9..e53c66a 100644 --- a/lib/vcs/src/refs.mli +++ b/lib/vcs/src/refs.mli @@ -33,21 +33,17 @@ module Line : sig { rev : Rev.t ; ref_kind : Ref_kind.t } - [@@deriving equal, sexp_of] + [@@deriving sexp_of] + + val equal : t -> t -> bool end -type t = Line.t list [@@deriving equal, sexp_of] +type t = Line.t list [@@deriving sexp_of] + +val equal : t -> t -> bool (** {1 Accessors} *) -val tags : t -> Set.M(Tag_name).t +val tags : t -> Tag_name.t list val local_branches : t -> Branch_name.t list val remote_branches : t -> Remote_branch_name.t list - -(** To lookup the revision of references (branch, tag, etc.), it is usually - quite cheap to get all refs using {!val:Vcs.refs}, turn the result into a - map with this function, and use the map for the lookups rather than trying - to run one git command per lookup. You may also use - {!val:Vcs.Graph.find_ref} if you build the complete graph with - {!val:Vcs.graph}. *) -val to_map : t -> Rev.t Map.M(Ref_kind).t diff --git a/lib/vcs/src/remote_branch_name.ml b/lib/vcs/src/remote_branch_name.ml index ad56ef1..65f476d 100644 --- a/lib/vcs/src/remote_branch_name.ml +++ b/lib/vcs/src/remote_branch_name.ml @@ -21,18 +21,40 @@ open! Import -module T = struct - [@@@coverage off] +[@@@coverage off] - type t = - { remote_name : Remote_name.t - ; branch_name : Branch_name.t - } - [@@deriving compare, hash, sexp_of] -end +type t = + { remote_name : Remote_name.t + ; branch_name : Branch_name.t + } +[@@deriving sexp_of] -include T -include Comparable.Make (T) +let compare = + (fun a__001_ b__002_ -> + if Stdlib.( == ) a__001_ b__002_ + then 0 + else ( + match Remote_name.compare a__001_.remote_name b__002_.remote_name with + | 0 -> Branch_name.compare a__001_.branch_name b__002_.branch_name + | n -> n) + : t -> t -> int) +;; + +let equal = + (fun a__003_ b__004_ -> + if Stdlib.( == ) a__003_ b__004_ + then true + else + Stdlib.( && ) + (Remote_name.equal a__003_.remote_name b__004_.remote_name) + (Branch_name.equal a__003_.branch_name b__004_.branch_name) + : t -> t -> bool) +;; + +[@@@coverage on] + +let seeded_hash = (Stdlib.Hashtbl.seeded_hash : int -> t -> int) +let hash = (Stdlib.Hashtbl.hash : t -> int) let to_string { remote_name; branch_name } = Printf.sprintf @@ -45,9 +67,10 @@ let of_string str = match String.lsplit2 str ~on:'/' with | None -> Error (`Msg (Printf.sprintf "%S: invalid remote_branch_name" str)) | Some (remote, branch) -> - let%bind.Result remote_name = Remote_name.of_string remote in - let%map.Result branch_name = Branch_name.of_string branch in - { remote_name; branch_name } + let ( let* ) = Stdlib.Result.bind in + let* remote_name = Remote_name.of_string remote in + let* branch_name = Branch_name.of_string branch in + Result.return { remote_name; branch_name } ;; let v str = diff --git a/lib/vcs/src/remote_branch_name.mli b/lib/vcs/src/remote_branch_name.mli index 810c0a6..d10aa45 100644 --- a/lib/vcs/src/remote_branch_name.mli +++ b/lib/vcs/src/remote_branch_name.mli @@ -23,7 +23,6 @@ type t = { remote_name : Remote_name.t ; branch_name : Branch_name.t } -[@@deriving compare, equal, hash, sexp_of] -include Comparable.S with type t := t +include Container_key.S with type t := t include Validated_string.S with type t := t diff --git a/lib/vcs/src/remote_name.ml b/lib/vcs/src/remote_name.ml index 43364ff..dc6f18b 100644 --- a/lib/vcs/src/remote_name.ml +++ b/lib/vcs/src/remote_name.ml @@ -20,15 +20,7 @@ (*******************************************************************************) open! Import - -module T = struct - [@@@coverage off] - - type t = string [@@deriving compare, hash, sexp_of] -end - -include T -include Comparable.Make (T) +include Container_key.String_impl let invariant t = (not (String.is_empty t)) diff --git a/lib/vcs/src/remote_name.mli b/lib/vcs/src/remote_name.mli index d19a2ea..416fd54 100644 --- a/lib/vcs/src/remote_name.mli +++ b/lib/vcs/src/remote_name.mli @@ -19,9 +19,9 @@ (*_ and , respectively. *) (*_******************************************************************************) -type t [@@deriving compare, equal, hash, sexp_of] +type t -include Comparable.S with type t := t +include Container_key.S with type t := t include Validated_string.S with type t := t (** {1 Some standard names} *) diff --git a/lib/vcs/src/repo_name.ml b/lib/vcs/src/repo_name.ml index 771c443..9773791 100644 --- a/lib/vcs/src/repo_name.ml +++ b/lib/vcs/src/repo_name.ml @@ -20,15 +20,7 @@ (*******************************************************************************) open! Import - -module T = struct - [@@@coverage off] - - type t = string [@@deriving compare, hash, sexp_of] -end - -include T -include Comparable.Make (T) +include Container_key.String_impl let invariant t = (not (String.is_empty t)) diff --git a/lib/vcs/src/repo_name.mli b/lib/vcs/src/repo_name.mli index 80a27e0..76f2ac2 100644 --- a/lib/vcs/src/repo_name.mli +++ b/lib/vcs/src/repo_name.mli @@ -36,7 +36,7 @@ repository. For this, the GitHub {!module:User_handle} must be added. See {!module:Url} for a complete url to a repository. *) -type t [@@deriving compare, equal, hash, sexp_of] +type t -include Comparable.S with type t := t +include Container_key.S with type t := t include Validated_string.S with type t := t diff --git a/lib/vcs/src/repo_root.ml b/lib/vcs/src/repo_root.ml index 9a5d0d0..ed993ec 100644 --- a/lib/vcs/src/repo_root.ml +++ b/lib/vcs/src/repo_root.ml @@ -43,15 +43,7 @@ *) open! Import - -module T = struct - [@@@coverage off] - - type t = Absolute_path.t [@@deriving compare, hash, sexp_of] -end - -include T -include Comparable.Make (T) +include Absolute_path let of_absolute_path t = t let to_absolute_path t = t diff --git a/lib/vcs/src/repo_root.mli b/lib/vcs/src/repo_root.mli index 21f1279..f4ebcb8 100644 --- a/lib/vcs/src/repo_root.mli +++ b/lib/vcs/src/repo_root.mli @@ -47,8 +47,9 @@ This is a wrapper around [Absolute_path.t] to increase type safety. *) -type t [@@deriving compare, equal, hash, sexp_of] +type t +include Container_key.S with type t := t include Validated_string.S with type t := t val of_absolute_path : Absolute_path.t -> t diff --git a/lib/vcs/src/rev.ml b/lib/vcs/src/rev.ml index c8bcbfb..02464e7 100644 --- a/lib/vcs/src/rev.ml +++ b/lib/vcs/src/rev.ml @@ -20,13 +20,7 @@ (*******************************************************************************) open! Import - -module T = struct - type t = string [@@deriving compare, hash, sexp_of] -end - -include T -include Comparable.Make (T) +include Container_key.String_impl let invariant t = Int.(String.length t = 40) diff --git a/lib/vcs/src/rev.mli b/lib/vcs/src/rev.mli index 0368e0b..15861f0 100644 --- a/lib/vcs/src/rev.mli +++ b/lib/vcs/src/rev.mli @@ -23,7 +23,7 @@ repository. The name was inherited from Mercurial. For git, this correspond to the commit-hash. In both systems, these are 40-chars hashes. *) -type t [@@deriving compare, equal, hash, sexp_of] +type t -include Comparable.S with type t := t +include Container_key.S with type t := t include Validated_string.S with type t := t diff --git a/lib/vcs/src/tag_name.ml b/lib/vcs/src/tag_name.ml index ae1380e..ef06593 100644 --- a/lib/vcs/src/tag_name.ml +++ b/lib/vcs/src/tag_name.ml @@ -20,15 +20,7 @@ (*******************************************************************************) open! Import - -module T = struct - [@@@coverage off] - - type t = string [@@deriving compare, hash, sexp_of] -end - -include T -include Comparable.Make (T) +include Container_key.String_impl let invariant t = (not (String.is_empty t)) diff --git a/lib/vcs/src/tag_name.mli b/lib/vcs/src/tag_name.mli index aa48f18..afa6f41 100644 --- a/lib/vcs/src/tag_name.mli +++ b/lib/vcs/src/tag_name.mli @@ -19,7 +19,7 @@ (*_ and , respectively. *) (*_******************************************************************************) -type t [@@deriving compare, equal, hash, sexp_of] +type t -include Comparable.S with type t := t +include Container_key.S with type t := t include Validated_string.S with type t := t diff --git a/lib/vcs/src/url.ml b/lib/vcs/src/url.ml index 2bb78ae..a04f99a 100644 --- a/lib/vcs/src/url.ml +++ b/lib/vcs/src/url.ml @@ -22,16 +22,20 @@ open! Import module Protocol = struct - module T = struct - [@@@coverage off] + [@@@coverage off] + + type t = + | Ssh + | Https + [@@deriving enumerate, sexp_of] - type t = - | Ssh - | Https - [@@deriving compare, equal, enumerate, hash, sexp_of] - end + let compare = (Stdlib.compare : t -> t -> int) + let equal = (Stdlib.( = ) : t -> t -> bool) - include T + [@@@coverage on] + + let seeded_hash = (Stdlib.Hashtbl.seeded_hash : int -> t -> int) + let hash = (Stdlib.Hashtbl.hash : t -> int) let to_string t ~(platform : Platform.t) = match platform, t with @@ -40,19 +44,52 @@ module Protocol = struct ;; end -module T = struct - [@@@coverage off] +[@@@coverage off] - type t = - { platform : Platform.t - ; protocol : Protocol.t - ; user_handle : User_handle.t - ; repo_name : Repo_name.t - } - [@@deriving compare, equal, hash, sexp_of] -end +type t = + { platform : Platform.t + ; protocol : Protocol.t + ; user_handle : User_handle.t + ; repo_name : Repo_name.t + } +[@@deriving sexp_of] + +let compare = + (fun a__005_ b__006_ -> + if Stdlib.( == ) a__005_ b__006_ + then 0 + else ( + match Platform.compare a__005_.platform b__006_.platform with + | 0 -> + (match Protocol.compare a__005_.protocol b__006_.protocol with + | 0 -> + (match User_handle.compare a__005_.user_handle b__006_.user_handle with + | 0 -> Repo_name.compare a__005_.repo_name b__006_.repo_name + | n -> n) + | n -> n) + | n -> n) + : t -> t -> int) +;; + +let equal = + (fun a__007_ b__008_ -> + if Stdlib.( == ) a__007_ b__008_ + then true + else + Stdlib.( && ) + (Platform.equal a__007_.platform b__008_.platform) + (Stdlib.( && ) + (Protocol.equal a__007_.protocol b__008_.protocol) + (Stdlib.( && ) + (User_handle.equal a__007_.user_handle b__008_.user_handle) + (Repo_name.equal a__007_.repo_name b__008_.repo_name))) + : t -> t -> bool) +;; + +[@@@coverage on] -include T +let seeded_hash = (Stdlib.Hashtbl.seeded_hash : int -> t -> int) +let hash = (Stdlib.Hashtbl.hash : t -> int) let to_string t = let { platform; protocol; user_handle; repo_name } = t in @@ -63,35 +100,33 @@ let to_string t = ;; let of_string (s : string) : (t, [ `Msg of string ]) Result.t = - let open Or_error.Let_syntax in + let ( let* ) = Stdlib.Result.bind in match List.find_map Platform.all ~f:(fun platform -> List.find_map Protocol.all ~f:(fun protocol -> let prefix = Protocol.to_string protocol ~platform in Option.map (String.chop_prefix s ~prefix) ~f:(fun rest -> - let%bind user_handle, rest = - String.lsplit2 rest ~on:'/' - |> Result.of_option ~error:(Error.of_string "missing user handle") + let* user_handle, rest = + String.lsplit2 rest ~on:'/' |> Result.of_option ~error:"missing user handle" in - let%bind repo_name = + let* repo_name = String.chop_suffix rest ~suffix:".git" - |> Result.of_option ~error:(Error.of_string "missing .git suffix") + |> Result.of_option ~error:"missing .git suffix" in - let%bind user_handle = + let* user_handle = match User_handle.of_string user_handle with | Ok _ as ok -> ok - | Error (`Msg m) -> Or_error.error_string m + | Error (`Msg m) -> Error m in - let%bind repo_name = + let* repo_name = match Repo_name.of_string repo_name with | Ok _ as ok -> ok - | Error (`Msg m) -> Or_error.error_string m + | Error (`Msg m) -> Error m in - return { platform; protocol; user_handle; repo_name }))) + Result.return { platform; protocol; user_handle; repo_name }))) with | Some (Ok _ as ok) -> ok - | Some (Error e) -> - Error (`Msg (Printf.sprintf "%S: invalid url. %s" s (Error.to_string_hum e))) + | Some (Error e) -> Error (`Msg (Printf.sprintf "%S: invalid url. %s" s e)) | None -> Error (`Msg (Printf.sprintf "%S: invalid url" s)) ;; diff --git a/lib/vcs/src/url.mli b/lib/vcs/src/url.mli index fea27d3..cb136c9 100644 --- a/lib/vcs/src/url.mli +++ b/lib/vcs/src/url.mli @@ -31,7 +31,10 @@ module Protocol : sig type t = | Ssh | Https - [@@deriving compare, equal, enumerate, hash, sexp_of] + + include Container_key.S with type t := t + + val all : t list end type t = @@ -40,7 +43,8 @@ type t = ; user_handle : User_handle.t ; repo_name : Repo_name.t } -[@@deriving compare, equal, hash, sexp_of] + +include Container_key.S with type t := t (** Create a complete string suitable for use with git commands, such as remote add, clone, etc. *) diff --git a/lib/vcs/src/user_email.ml b/lib/vcs/src/user_email.ml index d3d372f..c74f972 100644 --- a/lib/vcs/src/user_email.ml +++ b/lib/vcs/src/user_email.ml @@ -20,14 +20,7 @@ (*******************************************************************************) open! Import - -module T = struct - [@@@coverage off] - - type t = string [@@deriving compare, equal, hash, sexp_of] -end - -include T +include Container_key.String_impl let invariant t = (not (String.is_empty t)) diff --git a/lib/vcs/src/user_email.mli b/lib/vcs/src/user_email.mli index 35f078b..afa6f41 100644 --- a/lib/vcs/src/user_email.mli +++ b/lib/vcs/src/user_email.mli @@ -19,6 +19,7 @@ (*_ and , respectively. *) (*_******************************************************************************) -type t [@@deriving compare, equal, hash, sexp_of] +type t +include Container_key.S with type t := t include Validated_string.S with type t := t diff --git a/lib/vcs/src/user_handle.ml b/lib/vcs/src/user_handle.ml index 5e78365..a2c6549 100644 --- a/lib/vcs/src/user_handle.ml +++ b/lib/vcs/src/user_handle.ml @@ -20,15 +20,7 @@ (*******************************************************************************) open! Import - -module T = struct - [@@@coverage off] - - type t = string [@@deriving compare, hash, sexp_of] -end - -include T -include Comparable.Make (T) +include Container_key.String_impl let invariant t = (not (String.is_empty t)) diff --git a/lib/vcs/src/user_handle.mli b/lib/vcs/src/user_handle.mli index b0f0a21..a5376e2 100644 --- a/lib/vcs/src/user_handle.mli +++ b/lib/vcs/src/user_handle.mli @@ -32,7 +32,7 @@ which includes the full first name and last name, including spaces etc. This module is part of the [Vcs] library for convenience. *) -type t [@@deriving compare, equal, hash, sexp_of] +type t -include Comparable.S with type t := t +include Container_key.S with type t := t include Validated_string.S with type t := t diff --git a/lib/vcs/src/user_name.ml b/lib/vcs/src/user_name.ml index dba29c6..76a83ba 100644 --- a/lib/vcs/src/user_name.ml +++ b/lib/vcs/src/user_name.ml @@ -20,14 +20,7 @@ (*******************************************************************************) open! Import - -module T = struct - [@@@coverage off] - - type t = string [@@deriving compare, equal, hash, sexp_of] -end - -include T +include Container_key.String_impl let invariant t = (not (String.is_empty t)) diff --git a/lib/vcs/src/user_name.mli b/lib/vcs/src/user_name.mli index 29be187..94bc3e7 100644 --- a/lib/vcs/src/user_name.mli +++ b/lib/vcs/src/user_name.mli @@ -25,6 +25,7 @@ [User_name.v "John Doe"]. This is not to be conflated with the {!module:User_handle}, which are used as GitHub logins and other contexts. *) -type t [@@deriving compare, equal, hash, sexp_of] +type t +include Container_key.S with type t := t include Validated_string.S with type t := t diff --git a/lib/vcs/src/vcs0.ml b/lib/vcs/src/vcs0.ml index 8d07c74..dc0c8b1 100644 --- a/lib/vcs/src/vcs0.ml +++ b/lib/vcs/src/vcs0.ml @@ -24,6 +24,7 @@ open! Import type 'a t = 'a Provider.t let create provider = provider +let ( let* ) = Stdlib.Result.bind let of_result ~step = function | Ok r -> r @@ -106,7 +107,7 @@ let current_revision (Provider.T { t; handler }) ~repo_root = let commit (Provider.T { t; handler }) ~repo_root ~commit_message = let module R = (val Provider.Handler.lookup handler ~trait:Trait.Rev_parse) in let module C = (val Provider.Handler.lookup handler ~trait:Trait.Commit) in - (let%bind.Or_error () = C.commit t ~repo_root ~commit_message in + (let* () = C.commit t ~repo_root ~commit_message in R.current_revision t ~repo_root) |> of_result ~step:(lazy [%sexp "Vcs.commit", { repo_root : Repo_root.t }]) ;; @@ -167,12 +168,11 @@ let graph (Provider.T { t; handler }) ~repo_root = let module L = (val Provider.Handler.lookup handler ~trait:Trait.Log) in let module R = (val Provider.Handler.lookup handler ~trait:Trait.Refs) in let graph = Graph.create () in - (let open Or_error.Let_syntax in - let%bind log = L.all t ~repo_root in - let%bind refs = R.show_ref t ~repo_root in + (let* log = L.all t ~repo_root in + let* refs = R.show_ref t ~repo_root in Graph.add_nodes graph ~log; Graph.set_refs graph ~refs; - return graph) + Result.return graph) |> of_result ~step:(lazy [%sexp "Vcs.graph", { repo_root : Repo_root.t }]) ;; diff --git a/lib/vcs/test/dune b/lib/vcs/test/dune index e2010bd..6b514fc 100644 --- a/lib/vcs/test/dune +++ b/lib/vcs/test/dune @@ -28,6 +28,7 @@ fpath fpath-sexp0 vcs + vcs_base vcs_git_provider) (instrumentation (backend bisect_ppx)) diff --git a/lib/vcs/test/test__graph.ml b/lib/vcs/test/test__graph.ml index 7cd4e9c..154f4e5 100644 --- a/lib/vcs/test/test__graph.ml +++ b/lib/vcs/test/test__graph.ml @@ -557,7 +557,7 @@ let ancestors graph node = then loop acc to_visit else loop (Set.add acc node) (Vcs.Graph.prepend_parents graph node to_visit) in - loop (Set.empty (module Vcs.Graph.Node)) [ node ] + loop (Set.empty (module Vcs_base.Vcs.Graph.Node)) [ node ] ;; let%expect_test "debug graph" = @@ -681,7 +681,7 @@ let%expect_test "debug graph" = print_ancestors r4; [%expect {| (#0 #1 #2 #3 #4) |}]; (* Low level int indexing. *) - let node_index node = print_s [%sexp (Vcs.Graph.node_index graph node : int)] in + let node_index node = print_s [%sexp (Vcs.Graph.node_index node : int)] in node_index (node ~rev:r1); [%expect {| 0 |}]; node_index (node ~rev:r4); diff --git a/lib/vcs/test/test__name_status.ml b/lib/vcs/test/test__name_status.ml index 911a7d7..07b5d29 100644 --- a/lib/vcs/test/test__name_status.ml +++ b/lib/vcs/test/test__name_status.ml @@ -26,8 +26,14 @@ let%expect_test "parse_exn" = let contents = Eio.Path.load path in let lines = String.split_lines contents in let name_status = Vcs_git_provider.Name_status.parse_lines_exn ~lines in - let files_at_src = Vcs.Name_status.files_at_src name_status in - let files_at_dst = Vcs.Name_status.files_at_dst name_status in + let files_at_src = + Vcs.Name_status.files_at_src name_status + |> Set.of_list (module Vcs_base.Vcs.Path_in_repo) + in + let files_at_dst = + Vcs.Name_status.files_at_dst name_status + |> Set.of_list (module Vcs_base.Vcs.Path_in_repo) + in print_s [%sexp (Set.diff files_at_dst files_at_src : Set.M(Vcs.Path_in_repo).t)]; [%expect {| @@ -63,7 +69,7 @@ let%expect_test "files" = (dst new_renamed_file) (similarity 100))) |}]; let files = Vcs.Name_status.files name_status in - print_s [%sexp (files : Set.M(Vcs.Path_in_repo).t)]; + print_s [%sexp (files : Vcs.Path_in_repo.t list)]; [%expect {| (added_file @@ -73,12 +79,18 @@ let%expect_test "files" = original_copied_file original_renamed_file removed_file) |}]; - let files_at_src = Vcs.Name_status.files_at_src name_status in + let files_at_src = + Vcs.Name_status.files_at_src name_status + |> Set.of_list (module Vcs_base.Vcs.Path_in_repo) + in print_s [%sexp (files_at_src : Set.M(Vcs.Path_in_repo).t)]; [%expect {| (modified_file original_copied_file original_renamed_file removed_file) |}]; - let files_at_dst = Vcs.Name_status.files_at_dst name_status in + let files_at_dst = + Vcs.Name_status.files_at_dst name_status + |> Set.of_list (module Vcs_base.Vcs.Path_in_repo) + in print_s [%sexp (files_at_dst : Set.M(Vcs.Path_in_repo).t)]; [%expect {| (added_file modified_file new_copied_file new_renamed_file) |}]; diff --git a/lib/vcs/test/test__platform.ml b/lib/vcs/test/test__platform.ml index 54169e9..5a1b256 100644 --- a/lib/vcs/test/test__platform.ml +++ b/lib/vcs/test/test__platform.ml @@ -24,3 +24,17 @@ let%expect_test "to_string_hum" = [%expect {| GitHub |}]; () ;; + +let%expect_test "hash" = + List.iter Vcs.Platform.all ~f:(fun t -> + let stdlib_hash = Stdlib.Hashtbl.hash t in + let vcs_hash = Vcs.Platform.hash t in + print_s [%sexp (t : Vcs.Platform.t), { stdlib_hash : int; vcs_hash : int }]); + [%expect + {| + (GitHub ( + (stdlib_hash 129913994) + (vcs_hash 129913994))) + |}]; + () +;; diff --git a/lib/vcs_base/src/author.ml b/lib/vcs_base/src/author.ml new file mode 100644 index 0000000..6fdb8e6 --- /dev/null +++ b/lib/vcs_base/src/author.ml @@ -0,0 +1,27 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = Vcs.Author +include T +include Comparable.Make (T) + +let hash t = String.hash (T.to_string t) +let hash_fold_t state t = String.hash_fold_t state (T.to_string t) diff --git a/lib/vcs_base/src/author.mli b/lib/vcs_base/src/author.mli new file mode 100644 index 0000000..85bffb4 --- /dev/null +++ b/lib/vcs_base/src/author.mli @@ -0,0 +1,25 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.Author.t [@@deriving hash] + +include module type of Vcs.Author with type t := t +include Comparable.S with type t := t diff --git a/lib/vcs_base/src/branch_name.ml b/lib/vcs_base/src/branch_name.ml new file mode 100644 index 0000000..6a94f50 --- /dev/null +++ b/lib/vcs_base/src/branch_name.ml @@ -0,0 +1,27 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = Vcs.Branch_name +include T +include Comparable.Make (T) + +let hash t = String.hash (T.to_string t) +let hash_fold_t state t = String.hash_fold_t state (T.to_string t) diff --git a/lib/vcs_base/src/branch_name.mli b/lib/vcs_base/src/branch_name.mli new file mode 100644 index 0000000..17c220c --- /dev/null +++ b/lib/vcs_base/src/branch_name.mli @@ -0,0 +1,25 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.Branch_name.t [@@deriving hash] + +include module type of Vcs.Branch_name with type t := t +include Comparable.S with type t := t diff --git a/lib/vcs_base/src/commit_message.ml b/lib/vcs_base/src/commit_message.ml new file mode 100644 index 0000000..6e2a3c4 --- /dev/null +++ b/lib/vcs_base/src/commit_message.ml @@ -0,0 +1,26 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = Vcs.Commit_message +include T + +let hash t = String.hash (T.to_string t) +let hash_fold_t state t = String.hash_fold_t state (T.to_string t) diff --git a/lib/vcs_base/src/commit_message.mli b/lib/vcs_base/src/commit_message.mli new file mode 100644 index 0000000..c083b40 --- /dev/null +++ b/lib/vcs_base/src/commit_message.mli @@ -0,0 +1,24 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.Commit_message.t [@@deriving hash] + +include module type of Vcs.Commit_message with type t := t diff --git a/lib/vcs_base/src/file_contents.ml b/lib/vcs_base/src/file_contents.ml new file mode 100644 index 0000000..317596e --- /dev/null +++ b/lib/vcs_base/src/file_contents.ml @@ -0,0 +1,26 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = Vcs.File_contents +include T + +let hash t = String.hash (T.to_string t) +let hash_fold_t state t = String.hash_fold_t state (T.to_string t) diff --git a/lib/vcs_base/src/file_contents.mli b/lib/vcs_base/src/file_contents.mli new file mode 100644 index 0000000..21ef823 --- /dev/null +++ b/lib/vcs_base/src/file_contents.mli @@ -0,0 +1,24 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.File_contents.t [@@deriving hash] + +include module type of Vcs.File_contents with type t := t diff --git a/lib/vcs_base/src/graph.ml b/lib/vcs_base/src/graph.ml new file mode 100644 index 0000000..0b09012 --- /dev/null +++ b/lib/vcs_base/src/graph.ml @@ -0,0 +1,51 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module Node = struct + module T = Vcs.Graph.Node + include T + include Comparable.Make (T) + + let hash t = Int.hash (Vcs.Graph.node_index t) + let hash_fold_t state t = Int.hash_fold_t state (Vcs.Graph.node_index t) +end + +module Descendance = struct + module T0 = struct + type t = Vcs.Graph.Descendance.t = + | Same_node + | Strict_ancestor + | Strict_descendant + | Other + [@@deriving hash] + end + + include ( + Vcs.Graph.Descendance : module type of Vcs.Graph.Descendance with type t := T0.t) + + include T0 +end + +include ( + Vcs.Graph : + module type of Vcs.Graph + with module Node := Vcs.Graph.Node + and module Descendance := Vcs.Graph.Descendance) diff --git a/lib/vcs_base/src/graph.mli b/lib/vcs_base/src/graph.mli new file mode 100644 index 0000000..0d4b2d4 --- /dev/null +++ b/lib/vcs_base/src/graph.mli @@ -0,0 +1,43 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +module Node : sig + type t = Vcs.Graph.Node.t [@@deriving hash] + + include module type of Vcs.Graph.Node with type t := t + include Comparable.S with type t := t +end + +module Descendance : sig + type t = Vcs.Graph.Descendance.t = + | Same_node + | Strict_ancestor + | Strict_descendant + | Other + [@@deriving hash] + + include module type of Vcs.Graph.Descendance with type t := t +end + +include + module type of Vcs.Graph + with module Node := Vcs.Graph.Node + and module Descendance := Vcs.Graph.Descendance diff --git a/lib/vcs_base/src/name_status.ml b/lib/vcs_base/src/name_status.ml new file mode 100644 index 0000000..d4230a3 --- /dev/null +++ b/lib/vcs_base/src/name_status.ml @@ -0,0 +1,64 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module Change = struct + type t = Vcs.Name_status.Change.t = + | Added of Path_in_repo.t + | Removed of Path_in_repo.t + | Modified of Path_in_repo.t + | Copied of + { src : Path_in_repo.t + ; dst : Path_in_repo.t + ; similarity : int + } + | Renamed of + { src : Path_in_repo.t + ; dst : Path_in_repo.t + ; similarity : int + } + + include ( + Vcs.Name_status.Change : module type of Vcs.Name_status.Change with type t := t) +end + +module Changed = struct + type t = Vcs.Name_status.Changed.t = + | Between of + { src : Rev.t + ; dst : Rev.t + } + + include ( + Vcs.Name_status.Changed : module type of Vcs.Name_status.Changed with type t := t) +end + +type t = Change.t list + +include ( + Vcs.Name_status : + module type of Vcs.Name_status + with type t := t + and module Change := Vcs.Name_status.Change + and module Changed := Vcs.Name_status.Changed) + +let files t = Set.of_list (module Path_in_repo) (Vcs.Name_status.files t) +let files_at_src t = Set.of_list (module Path_in_repo) (Vcs.Name_status.files_at_src t) +let files_at_dst t = Set.of_list (module Path_in_repo) (Vcs.Name_status.files_at_dst t) diff --git a/lib/vcs_base/src/name_status.mli b/lib/vcs_base/src/name_status.mli new file mode 100644 index 0000000..59ca212 --- /dev/null +++ b/lib/vcs_base/src/name_status.mli @@ -0,0 +1,61 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +module Change : sig + type t = Vcs.Name_status.Change.t = + | Added of Path_in_repo.t + | Removed of Path_in_repo.t + | Modified of Path_in_repo.t + | Copied of + { src : Path_in_repo.t + ; dst : Path_in_repo.t + ; similarity : int + } + | Renamed of + { src : Path_in_repo.t + ; dst : Path_in_repo.t + ; similarity : int + } + + include module type of Vcs.Name_status.Change with type t := t +end + +module Changed : sig + type t = Vcs.Name_status.Changed.t = + | Between of + { src : Rev.t + ; dst : Rev.t + } + + include module type of Vcs.Name_status.Changed with type t := t +end + +type t = Change.t list + +include + module type of Vcs.Name_status + with type t := t + and module Change := Vcs.Name_status.Change + and module Changed := Vcs.Name_status.Changed + +val files : t -> Set.M(Path_in_repo).t +val files_at_src : t -> Set.M(Path_in_repo).t +val files_at_dst : t -> Set.M(Path_in_repo).t diff --git a/lib/vcs_base/src/num_lines_in_diff.ml b/lib/vcs_base/src/num_lines_in_diff.ml new file mode 100644 index 0000000..f8d897c --- /dev/null +++ b/lib/vcs_base/src/num_lines_in_diff.ml @@ -0,0 +1,36 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +include Vcs.Num_lines_in_diff + +let to_string_hum { insertions; deletions } = + let int_hum i = Int.to_string_hum ~delimiter:',' i in + match + [ (if insertions > 0 then Some ("+" ^ int_hum insertions) else None) + ; (if deletions > 0 then Some ("-" ^ int_hum deletions) else None) + ] + |> List.filter_opt + with + | [] -> "0" + | [ hd ] -> hd + | [ a; b ] -> a ^ ", " ^ b + | _ :: _ :: _ :: _ -> assert false +;; diff --git a/lib/vcs_base/src/num_lines_in_diff.mli b/lib/vcs_base/src/num_lines_in_diff.mli new file mode 100644 index 0000000..6b0dadf --- /dev/null +++ b/lib/vcs_base/src/num_lines_in_diff.mli @@ -0,0 +1,31 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.Num_lines_in_diff.t = + { insertions : int + ; deletions : int + } + +include module type of Vcs.Num_lines_in_diff with type t := t + +(** Returns a short string suitable for human consumption. + Some examples: [["0"; "+100"; "-15"; "+1,999, -13,898"]]. *) +val to_string_hum : t -> string diff --git a/lib/vcs_base/src/path_in_repo.ml b/lib/vcs_base/src/path_in_repo.ml new file mode 100644 index 0000000..c96cd5a --- /dev/null +++ b/lib/vcs_base/src/path_in_repo.ml @@ -0,0 +1,27 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = Vcs.Path_in_repo +include T +include Comparable.Make (T) + +let hash t = String.hash (T.to_string t) +let hash_fold_t state t = String.hash_fold_t state (T.to_string t) diff --git a/lib/vcs_base/src/path_in_repo.mli b/lib/vcs_base/src/path_in_repo.mli new file mode 100644 index 0000000..109ed83 --- /dev/null +++ b/lib/vcs_base/src/path_in_repo.mli @@ -0,0 +1,25 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.Path_in_repo.t [@@deriving hash] + +include module type of Vcs.Path_in_repo with type t := t +include Comparable.S with type t := t diff --git a/lib/vcs_base/src/platform.ml b/lib/vcs_base/src/platform.ml new file mode 100644 index 0000000..c052a4e --- /dev/null +++ b/lib/vcs_base/src/platform.ml @@ -0,0 +1,32 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = struct + module T0 = struct + type t = Vcs.Platform.t = GitHub [@@deriving hash] + end + + include (Vcs.Platform : module type of Vcs.Platform with type t := T0.t) + include T0 +end + +include T +include Comparable.Make (T) diff --git a/lib/vcs_base/src/platform.mli b/lib/vcs_base/src/platform.mli new file mode 100644 index 0000000..62127bf --- /dev/null +++ b/lib/vcs_base/src/platform.mli @@ -0,0 +1,25 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.Platform.t = GitHub [@@deriving hash] + +include module type of Vcs.Platform with type t := t +include Comparable.S with type t := t diff --git a/lib/vcs_base/src/ref_kind.ml b/lib/vcs_base/src/ref_kind.ml new file mode 100644 index 0000000..3e01038 --- /dev/null +++ b/lib/vcs_base/src/ref_kind.ml @@ -0,0 +1,37 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = struct + module T0 = struct + type t = Vcs.Ref_kind.t = + | Local_branch of { branch_name : Branch_name.t } + | Remote_branch of { remote_branch_name : Remote_branch_name.t } + | Tag of { tag_name : Tag_name.t } + | Other of { name : string } + [@@deriving hash] + end + + include (Vcs.Ref_kind : module type of Vcs.Ref_kind with type t := T0.t) + include T0 +end + +include T +include Comparable.Make (T) diff --git a/lib/vcs_base/src/ref_kind.mli b/lib/vcs_base/src/ref_kind.mli new file mode 100644 index 0000000..9cdbbbc --- /dev/null +++ b/lib/vcs_base/src/ref_kind.mli @@ -0,0 +1,30 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.Ref_kind.t = + | Local_branch of { branch_name : Branch_name.t } + | Remote_branch of { remote_branch_name : Remote_branch_name.t } + | Tag of { tag_name : Tag_name.t } + | Other of { name : string } +[@@deriving hash] + +include module type of Vcs.Ref_kind with type t := t +include Comparable.S with type t := t diff --git a/lib/vcs_base/src/refs.ml b/lib/vcs_base/src/refs.ml new file mode 100644 index 0000000..4001844 --- /dev/null +++ b/lib/vcs_base/src/refs.ml @@ -0,0 +1,48 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module Line = struct + type t = Vcs.Refs.Line.t = + { rev : Rev.t + ; ref_kind : Ref_kind.t + } + + include (Vcs.Refs.Line : module type of Vcs.Refs.Line with type t := t) +end + +type t = Line.t list + +include ( + Vcs.Refs : module type of Vcs.Refs with type t := t and module Line := Vcs.Refs.Line) + +let tags t = Set.of_list (module Tag_name) (Vcs.Refs.tags t) +let local_branches t = Set.of_list (module Branch_name) (Vcs.Refs.local_branches t) + +let remote_branches t = + Set.of_list (module Remote_branch_name) (Vcs.Refs.remote_branches t) +;; + +let to_map (t : t) = + List.fold + t + ~init:(Map.empty (module Ref_kind)) + ~f:(fun acc { rev; ref_kind } -> Map.add_exn acc ~key:ref_kind ~data:rev) +;; diff --git a/lib/vcs_base/src/refs.mli b/lib/vcs_base/src/refs.mli new file mode 100644 index 0000000..1244fc9 --- /dev/null +++ b/lib/vcs_base/src/refs.mli @@ -0,0 +1,45 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +module Line : sig + type t = Vcs.Refs.Line.t = + { rev : Rev.t + ; ref_kind : Ref_kind.t + } + + include module type of Vcs.Refs.Line with type t := t +end + +type t = Line.t list + +include module type of Vcs.Refs with type t := t and module Line := Vcs.Refs.Line + +val tags : t -> Set.M(Tag_name).t +val local_branches : t -> Set.M(Branch_name).t +val remote_branches : t -> Set.M(Remote_branch_name).t + +(** To lookup the revision of references (branch, tag, etc.), it is usually + quite cheap to get all refs using {!val:Vcs.refs}, turn the result into a + map with this function, and use the map for the lookups rather than trying + to run one git command per lookup. You may also use + {!val:Vcs.Graph.find_ref} if you build the complete graph with + {!val:Vcs.graph}. *) +val to_map : t -> Rev.t Map.M(Ref_kind).t diff --git a/lib/vcs_base/src/remote_branch_name.ml b/lib/vcs_base/src/remote_branch_name.ml new file mode 100644 index 0000000..b7f7c69 --- /dev/null +++ b/lib/vcs_base/src/remote_branch_name.ml @@ -0,0 +1,38 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = struct + module T0 = struct + type t = Vcs.Remote_branch_name.t = + { remote_name : Remote_name.t + ; branch_name : Branch_name.t + } + [@@deriving hash] + end + + include ( + Vcs.Remote_branch_name : module type of Vcs.Remote_branch_name with type t := T0.t) + + include T0 +end + +include T +include Comparable.Make (T) diff --git a/lib/vcs_base/src/remote_branch_name.mli b/lib/vcs_base/src/remote_branch_name.mli new file mode 100644 index 0000000..c38b160 --- /dev/null +++ b/lib/vcs_base/src/remote_branch_name.mli @@ -0,0 +1,29 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.Remote_branch_name.t = + { remote_name : Remote_name.t + ; branch_name : Branch_name.t + } +[@@deriving hash] + +include module type of Vcs.Remote_branch_name with type t := t +include Comparable.S with type t := t diff --git a/lib/vcs_base/src/remote_name.ml b/lib/vcs_base/src/remote_name.ml new file mode 100644 index 0000000..d27fbc6 --- /dev/null +++ b/lib/vcs_base/src/remote_name.ml @@ -0,0 +1,27 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = Vcs.Remote_name +include T +include Comparable.Make (T) + +let hash t = String.hash (T.to_string t) +let hash_fold_t state t = String.hash_fold_t state (T.to_string t) diff --git a/lib/vcs_base/src/remote_name.mli b/lib/vcs_base/src/remote_name.mli new file mode 100644 index 0000000..53bce6c --- /dev/null +++ b/lib/vcs_base/src/remote_name.mli @@ -0,0 +1,25 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.Remote_name.t [@@deriving hash] + +include module type of Vcs.Remote_name with type t := t +include Comparable.S with type t := t diff --git a/lib/vcs_base/src/repo_name.ml b/lib/vcs_base/src/repo_name.ml new file mode 100644 index 0000000..004663f --- /dev/null +++ b/lib/vcs_base/src/repo_name.ml @@ -0,0 +1,27 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = Vcs.Repo_name +include T +include Comparable.Make (T) + +let hash t = String.hash (T.to_string t) +let hash_fold_t state t = String.hash_fold_t state (T.to_string t) diff --git a/lib/vcs_base/src/repo_name.mli b/lib/vcs_base/src/repo_name.mli new file mode 100644 index 0000000..44becd8 --- /dev/null +++ b/lib/vcs_base/src/repo_name.mli @@ -0,0 +1,25 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.Repo_name.t [@@deriving hash] + +include module type of Vcs.Repo_name with type t := t +include Comparable.S with type t := t diff --git a/lib/vcs_base/src/repo_root.ml b/lib/vcs_base/src/repo_root.ml new file mode 100644 index 0000000..9b1461e --- /dev/null +++ b/lib/vcs_base/src/repo_root.ml @@ -0,0 +1,27 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = Vcs.Repo_root +include T +include Comparable.Make (T) + +let hash t = Absolute_path.hash (T.to_absolute_path t) +let hash_fold_t state t = Absolute_path.hash_fold_t state (T.to_absolute_path t) diff --git a/lib/vcs_base/src/repo_root.mli b/lib/vcs_base/src/repo_root.mli new file mode 100644 index 0000000..d672ddb --- /dev/null +++ b/lib/vcs_base/src/repo_root.mli @@ -0,0 +1,25 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.Repo_root.t [@@deriving hash] + +include module type of Vcs.Repo_root with type t := t +include Comparable.S with type t := t diff --git a/lib/vcs_base/src/rev.ml b/lib/vcs_base/src/rev.ml new file mode 100644 index 0000000..20a2c4b --- /dev/null +++ b/lib/vcs_base/src/rev.ml @@ -0,0 +1,27 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = Vcs.Rev +include T +include Comparable.Make (T) + +let hash t = String.hash (T.to_string t) +let hash_fold_t state t = String.hash_fold_t state (T.to_string t) diff --git a/lib/vcs_base/src/rev.mli b/lib/vcs_base/src/rev.mli new file mode 100644 index 0000000..3d863fa --- /dev/null +++ b/lib/vcs_base/src/rev.mli @@ -0,0 +1,25 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.Rev.t [@@deriving hash] + +include module type of Vcs.Rev with type t := t +include Comparable.S with type t := t diff --git a/lib/vcs_base/src/tag_name.ml b/lib/vcs_base/src/tag_name.ml new file mode 100644 index 0000000..85f7886 --- /dev/null +++ b/lib/vcs_base/src/tag_name.ml @@ -0,0 +1,27 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = Vcs.Tag_name +include T +include Comparable.Make (T) + +let hash t = String.hash (T.to_string t) +let hash_fold_t state t = String.hash_fold_t state (T.to_string t) diff --git a/lib/vcs_base/src/tag_name.mli b/lib/vcs_base/src/tag_name.mli new file mode 100644 index 0000000..a56f43c --- /dev/null +++ b/lib/vcs_base/src/tag_name.mli @@ -0,0 +1,25 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.Tag_name.t [@@deriving hash] + +include module type of Vcs.Tag_name with type t := t +include Comparable.S with type t := t diff --git a/lib/vcs_base/src/url.ml b/lib/vcs_base/src/url.ml new file mode 100644 index 0000000..e97cda1 --- /dev/null +++ b/lib/vcs_base/src/url.ml @@ -0,0 +1,47 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module Protocol = struct + module T0 = struct + type t = Vcs.Url.Protocol.t = + | Ssh + | Https + [@@deriving hash] + end + + include (Vcs.Url.Protocol : module type of Vcs.Url.Protocol with type t := T0.t) + include T0 +end + +module T0 = struct + type t = Vcs.Url.t = + { platform : Platform.t + ; protocol : Protocol.t + ; user_handle : User_handle.t + ; repo_name : Repo_name.t + } + [@@deriving hash] +end + +include ( + Vcs.Url : module type of Vcs.Url with type t := T0.t and module Protocol := Protocol) + +include T0 diff --git a/lib/vcs_base/src/url.mli b/lib/vcs_base/src/url.mli new file mode 100644 index 0000000..e10d51e --- /dev/null +++ b/lib/vcs_base/src/url.mli @@ -0,0 +1,39 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +module Protocol : sig + type t = Vcs.Url.Protocol.t = + | Ssh + | Https + [@@deriving hash] + + include module type of Vcs.Url.Protocol with type t := t +end + +type t = Vcs.Url.t = + { platform : Platform.t + ; protocol : Protocol.t + ; user_handle : User_handle.t + ; repo_name : Repo_name.t + } +[@@deriving hash] + +include module type of Vcs.Url with type t := t and module Protocol := Protocol diff --git a/lib/vcs_base/src/user_email.ml b/lib/vcs_base/src/user_email.ml new file mode 100644 index 0000000..be42e48 --- /dev/null +++ b/lib/vcs_base/src/user_email.ml @@ -0,0 +1,27 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = Vcs.User_email +include T +include Comparable.Make (T) + +let hash t = String.hash (T.to_string t) +let hash_fold_t state t = String.hash_fold_t state (T.to_string t) diff --git a/lib/vcs_base/src/user_email.mli b/lib/vcs_base/src/user_email.mli new file mode 100644 index 0000000..6f14a66 --- /dev/null +++ b/lib/vcs_base/src/user_email.mli @@ -0,0 +1,25 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.User_email.t [@@deriving hash] + +include module type of Vcs.User_email with type t := t +include Comparable.S with type t := t diff --git a/lib/vcs_base/src/user_handle.ml b/lib/vcs_base/src/user_handle.ml new file mode 100644 index 0000000..69a4ce2 --- /dev/null +++ b/lib/vcs_base/src/user_handle.ml @@ -0,0 +1,27 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = Vcs.User_handle +include T +include Comparable.Make (T) + +let hash t = String.hash (T.to_string t) +let hash_fold_t state t = String.hash_fold_t state (T.to_string t) diff --git a/lib/vcs_base/src/user_handle.mli b/lib/vcs_base/src/user_handle.mli new file mode 100644 index 0000000..9928c49 --- /dev/null +++ b/lib/vcs_base/src/user_handle.mli @@ -0,0 +1,25 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.User_handle.t [@@deriving hash] + +include module type of Vcs.User_handle with type t := t +include Comparable.S with type t := t diff --git a/lib/vcs_base/src/user_name.ml b/lib/vcs_base/src/user_name.ml new file mode 100644 index 0000000..4c91fa2 --- /dev/null +++ b/lib/vcs_base/src/user_name.ml @@ -0,0 +1,27 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module T = Vcs.User_name +include T +include Comparable.Make (T) + +let hash t = String.hash (T.to_string t) +let hash_fold_t state t = String.hash_fold_t state (T.to_string t) diff --git a/lib/vcs_base/src/user_name.mli b/lib/vcs_base/src/user_name.mli new file mode 100644 index 0000000..d981b2c --- /dev/null +++ b/lib/vcs_base/src/user_name.mli @@ -0,0 +1,25 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +type t = Vcs.User_name.t [@@deriving hash] + +include module type of Vcs.User_name with type t := t +include Comparable.S with type t := t diff --git a/lib/vcs_base/src/vcs_base.ml b/lib/vcs_base/src/vcs_base.ml new file mode 100644 index 0000000..a709d21 --- /dev/null +++ b/lib/vcs_base/src/vcs_base.ml @@ -0,0 +1,69 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module Vcs = struct + module Author = Author + module Branch_name = Branch_name + module Commit_message = Commit_message + module File_contents = File_contents + module Graph = Graph + module Name_status = Name_status + module Num_lines_in_diff = Num_lines_in_diff + module Path_in_repo = Path_in_repo + module Platform = Platform + module Ref_kind = Ref_kind + module Refs = Refs + module Remote_branch_name = Remote_branch_name + module Remote_name = Remote_name + module Repo_name = Repo_name + module Repo_root = Repo_root + module Rev = Rev + module Tag_name = Tag_name + module Url = Url + module User_email = User_email + module User_handle = User_handle + module User_name = User_name + + include ( + Vcs : + module type of Vcs + with module Author := Vcs.Author + and module Branch_name := Vcs.Branch_name + and module Commit_message := Vcs.Commit_message + and module File_contents := Vcs.File_contents + and module Graph := Vcs.Graph + and module Name_status := Vcs.Name_status + and module Num_lines_in_diff := Vcs.Num_lines_in_diff + and module Path_in_repo := Vcs.Path_in_repo + and module Platform := Vcs.Platform + and module Ref_kind := Vcs.Ref_kind + and module Refs := Vcs.Refs + and module Remote_branch_name := Vcs.Remote_branch_name + and module Remote_name := Vcs.Remote_name + and module Repo_name := Vcs.Repo_name + and module Repo_root := Vcs.Repo_root + and module Rev := Vcs.Rev + and module Tag_name := Vcs.Tag_name + and module Url := Vcs.Url + and module User_email := Vcs.User_email + and module User_handle := Vcs.User_handle + and module User_name := Vcs.User_name) +end diff --git a/lib/vcs_base/src/vcs_base.mli b/lib/vcs_base/src/vcs_base.mli new file mode 100644 index 0000000..e7345a7 --- /dev/null +++ b/lib/vcs_base/src/vcs_base.mli @@ -0,0 +1,70 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +module Vcs : sig + (** {1 Extended Vcs API} *) + + module Author = Author + module Branch_name = Branch_name + module Commit_message = Commit_message + module File_contents = File_contents + module Graph = Graph + module Name_status = Name_status + module Num_lines_in_diff = Num_lines_in_diff + module Path_in_repo = Path_in_repo + module Platform = Platform + module Ref_kind = Ref_kind + module Refs = Refs + module Remote_branch_name = Remote_branch_name + module Remote_name = Remote_name + module Repo_name = Repo_name + module Repo_root = Repo_root + module Rev = Rev + module Tag_name = Tag_name + module Url = Url + module User_email = User_email + module User_handle = User_handle + module User_name = User_name + + include + module type of Vcs + with module Author := Vcs.Author + and module Branch_name := Vcs.Branch_name + and module Commit_message := Vcs.Commit_message + and module File_contents := Vcs.File_contents + and module Graph := Vcs.Graph + and module Name_status := Vcs.Name_status + and module Num_lines_in_diff := Vcs.Num_lines_in_diff + and module Path_in_repo := Vcs.Path_in_repo + and module Platform := Vcs.Platform + and module Ref_kind := Vcs.Ref_kind + and module Refs := Vcs.Refs + and module Remote_branch_name := Vcs.Remote_branch_name + and module Remote_name := Vcs.Remote_name + and module Repo_name := Vcs.Repo_name + and module Repo_root := Vcs.Repo_root + and module Rev := Vcs.Rev + and module Tag_name := Vcs.Tag_name + and module Url := Vcs.Url + and module User_email := Vcs.User_email + and module User_handle := Vcs.User_handle + and module User_name := Vcs.User_name +end diff --git a/lib/vcs_base/test/dune b/lib/vcs_base/test/dune new file mode 100644 index 0000000..42d8180 --- /dev/null +++ b/lib/vcs_base/test/dune @@ -0,0 +1,42 @@ +(library + (name vcs_base_test) + (public_name vcs-tests.vcs_base_test) + (inline_tests) + (flags + :standard + -w + +a-4-40-41-42-44-45-48-66 + -warn-error + +a + -open + Base + -open + Fpath_sexp0 + -open + Expect_test_helpers_base) + (libraries + base + eio + eio_main + err + expect_test_helpers_core.expect_test_helpers_base + fpath + fpath-sexp0 + vcs + vcs_base + vcs_git_provider) + (instrumentation + (backend bisect_ppx)) + (lint + (pps ppx_js_style -check-doc-comments)) + (preprocess + (pps + -unused-code-warnings=force + ppx_compare + ppx_enumerate + ppx_expect + ppx_hash + ppx_here + ppx_let + ppx_sexp_conv + ppx_sexp_value))) diff --git a/lib/vcs_base/test/test__platform.ml b/lib/vcs_base/test/test__platform.ml new file mode 100644 index 0000000..a0902da --- /dev/null +++ b/lib/vcs_base/test/test__platform.ml @@ -0,0 +1,38 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let%expect_test "monitor-hashes" = + List.iter Vcs.Platform.all ~f:(fun t -> + let stdlib_hash = Stdlib.Hashtbl.hash t in + let vcs_hash = Vcs.Platform.hash t in + let vcs_base_hash = Vcs_base.Vcs.Platform.hash t in + print_s + [%sexp + (t : Vcs.Platform.t), { stdlib_hash : int; vcs_hash : int; vcs_base_hash : int }]); + [%expect + {| + (GitHub ( + (stdlib_hash 129913994) + (vcs_hash 129913994) + (vcs_base_hash 0))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__platform.mli b/lib/vcs_base/test/test__platform.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__platform.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_command/src/vcs_command.ml b/lib/vcs_command/src/vcs_command.ml index 4771c59..2754964 100644 --- a/lib/vcs_command/src/vcs_command.ml +++ b/lib/vcs_command/src/vcs_command.ml @@ -456,9 +456,12 @@ let branch_revision_cmd = | None -> Vcs.current_branch vcs ~repo_root in let rev = - let refs = Vcs.refs vcs ~repo_root |> Vcs.Refs.to_map in - match Map.find refs (Local_branch { branch_name }) with - | Some rev -> rev + let refs = Vcs.refs vcs ~repo_root in + match + List.find refs ~f:(fun { Vcs.Refs.Line.ref_kind; rev = _ } -> + Vcs.Ref_kind.equal ref_kind (Local_branch { branch_name })) + with + | Some ref -> ref.rev | None -> (* This line is covered in tests, but we need to disable coverage reporting here. The reason is that bisect_ppx inserts an unvisitable diff --git a/lib/vcs_git_blocking/test/test__hello_commit.ml b/lib/vcs_git_blocking/test/test__hello_commit.ml index 80f4185..a166750 100644 --- a/lib/vcs_git_blocking/test/test__hello_commit.ml +++ b/lib/vcs_git_blocking/test/test__hello_commit.ml @@ -26,7 +26,7 @@ let%expect_test "hello commit" = let vcs = Vcs_git_blocking.create () in let mock_revs = Vcs.Mock_revs.create () in let cwd = Unix.getcwd () |> Absolute_path.v in - let repo_root = Vcs.For_test.init vcs ~path:cwd |> Or_error.ok_exn in + let repo_root = Vcs.For_test.init vcs ~path:cwd in let hello_file = Vcs.Path_in_repo.v "hello.txt" in Vcs.save_file vcs diff --git a/lib/vcs_git_eio/test/test__init.ml b/lib/vcs_git_eio/test/test__init.ml index 2878fee..8f5d822 100644 --- a/lib/vcs_git_eio/test/test__init.ml +++ b/lib/vcs_git_eio/test/test__init.ml @@ -29,7 +29,7 @@ let%expect_test "init" = let repo_root = Eio.Switch.on_release sw (fun () -> Eio.Path.rmtree Eio.Path.(Eio.Stdenv.fs env / path)); - Vcs.For_test.init vcs ~path:(Absolute_path.v path) |> Or_error.ok_exn + Vcs.For_test.init vcs ~path:(Absolute_path.v path) in require_equal [%here] diff --git a/lib/vcs_git_provider/test/test__name_status.ml b/lib/vcs_git_provider/test/test__name_status.ml index 35d3130..bee7d56 100644 --- a/lib/vcs_git_provider/test/test__name_status.ml +++ b/lib/vcs_git_provider/test/test__name_status.ml @@ -101,7 +101,7 @@ let%expect_test "parse_exn" = (Modified lib/super_master_mind/test/test__opening_book.ml) (Modified super-master-mind.opam) (Modified test/maker.t)) |}]; - print_s [%sexp (Vcs.Name_status.files name_status : Set.M(Vcs.Path_in_repo).t)]; + print_s [%sexp (Vcs.Name_status.files name_status : Vcs.Path_in_repo.t list)]; [%expect {| (.github/workflows/ci.yml diff --git a/lib/vcs_git_provider/test/test__refs.ml b/lib/vcs_git_provider/test/test__refs.ml index ba28e3c..55b095f 100644 --- a/lib/vcs_git_provider/test/test__refs.ml +++ b/lib/vcs_git_provider/test/test__refs.ml @@ -36,7 +36,7 @@ let%expect_test "parse_exn" = let refs = Vcs_git_provider.Refs.parse_lines_exn ~lines in print_s [%sexp - { tags = (Vcs.Refs.tags refs : Set.M(Vcs.Tag_name).t) + { tags = (Vcs.Refs.tags refs : Vcs.Tag_name.t list) ; local_branches = (Vcs.Refs.local_branches refs : Vcs.Branch_name.t list) ; remote_branches = (Vcs.Refs.remote_branches refs : Vcs.Remote_branch_name.t list) }]; diff --git a/lib/vcs_test_helpers/src/vcs_test_helpers.ml b/lib/vcs_test_helpers/src/vcs_test_helpers.ml index c07c65b..274df8e 100644 --- a/lib/vcs_test_helpers/src/vcs_test_helpers.ml +++ b/lib/vcs_test_helpers/src/vcs_test_helpers.ml @@ -29,7 +29,7 @@ type 'a env = 'a let init_temp_repo ~env ~sw ~vcs = let path = Stdlib.Filename.temp_dir ~temp_dir:(Unix.getcwd ()) "vcs" "test" in Eio.Switch.on_release sw (fun () -> Eio.Path.rmtree Eio.Path.(Eio.Stdenv.fs env / path)); - Vcs.For_test.init vcs ~path:(Absolute_path.v path) |> Or_error.ok_exn + Vcs.For_test.init vcs ~path:(Absolute_path.v path) ;; let redact_sexp err ~fields = diff --git a/test/expect/dune b/test/expect/dune index 9a34872..b4cb92a 100644 --- a/test/expect/dune +++ b/test/expect/dune @@ -13,7 +13,9 @@ -open Fpath_sexp0 -open - Expect_test_helpers_base) + Expect_test_helpers_base + -open + Vcs_base) (libraries base eio @@ -22,6 +24,7 @@ fpath fpath-sexp0 vcs + vcs_base vcs_git_blocking vcs_git_eio vcs_test_helpers) From 81b03dd8d29e0db8a5c341ee09034862cdc69644 Mon Sep 17 00:00:00 2001 From: Mathieu Barbin Date: Sat, 19 Oct 2024 21:06:33 +0200 Subject: [PATCH 4/4] Add tests --- lib/vcs/src/graph.ml | 2 +- lib/vcs/test/test__log.ml | 2 +- lib/vcs/test/test__num_lines_in_diff.ml | 27 ++ lib/vcs/test/test__platform.ml | 14 - lib/vcs_base/test/dune | 25 +- lib/vcs_base/test/hash_test.ml | 57 ++++ lib/vcs_base/test/hash_test.mli | 34 +++ lib/vcs_base/test/test__author.ml | 58 ++++ lib/vcs_base/test/test__author.mli | 20 ++ lib/vcs_base/test/test__branch_name.ml | 58 ++++ lib/vcs_base/test/test__branch_name.mli | 22 ++ lib/vcs_base/test/test__commit_message.ml | 62 ++++ lib/vcs_base/test/test__commit_message.mli | 20 ++ lib/vcs_base/test/test__file_contents.ml | 58 ++++ lib/vcs_base/test/test__file_contents.mli | 20 ++ lib/vcs_base/test/test__graph.ml | 285 ++++++++++++++++++ lib/vcs_base/test/test__graph.mli | 20 ++ lib/vcs_base/test/test__name_status.ml | 75 +++++ lib/vcs_base/test/test__name_status.mli | 20 ++ lib/vcs_base/test/test__num_lines_in_diff.ml | 35 +++ lib/vcs_base/test/test__num_lines_in_diff.mli | 20 ++ lib/vcs_base/test/test__path_in_repo.ml | 58 ++++ lib/vcs_base/test/test__path_in_repo.mli | 20 ++ lib/vcs_base/test/test__platform.ml | 24 +- lib/vcs_base/test/test__ref_kind.ml | 231 ++++++++++++++ lib/vcs_base/test/test__ref_kind.mli | 20 ++ lib/vcs_base/test/test__refs.ml | 87 ++++++ lib/vcs_base/test/test__refs.mli | 20 ++ lib/vcs_base/test/test__remote_branch_name.ml | 141 +++++++++ .../test/test__remote_branch_name.mli | 22 ++ lib/vcs_base/test/test__remote_name.ml | 58 ++++ lib/vcs_base/test/test__remote_name.mli | 22 ++ lib/vcs_base/test/test__repo_name.ml | 58 ++++ lib/vcs_base/test/test__repo_name.mli | 20 ++ lib/vcs_base/test/test__repo_root.ml | 58 ++++ lib/vcs_base/test/test__repo_root.mli | 20 ++ lib/vcs_base/test/test__rev.ml | 59 ++++ lib/vcs_base/test/test__rev.mli | 20 ++ lib/vcs_base/test/test__tag_name.ml | 72 +++++ lib/vcs_base/test/test__tag_name.mli | 22 ++ lib/vcs_base/test/test__url.ml | 135 +++++++++ lib/vcs_base/test/test__url.mli | 20 ++ lib/vcs_base/test/test__user_email.ml | 58 ++++ lib/vcs_base/test/test__user_email.mli | 20 ++ lib/vcs_base/test/test__user_handle.ml | 58 ++++ lib/vcs_base/test/test__user_handle.mli | 20 ++ lib/vcs_base/test/test__user_name.ml | 58 ++++ lib/vcs_base/test/test__user_name.mli | 42 +++ lib/vcs_git_provider/test/dune | 1 + test/expect/user_config.ml | 94 ++++++ test/expect/user_config.mli | 20 ++ 51 files changed, 2465 insertions(+), 27 deletions(-) create mode 100644 lib/vcs_base/test/hash_test.ml create mode 100644 lib/vcs_base/test/hash_test.mli create mode 100644 lib/vcs_base/test/test__author.ml create mode 100644 lib/vcs_base/test/test__author.mli create mode 100644 lib/vcs_base/test/test__branch_name.ml create mode 100644 lib/vcs_base/test/test__branch_name.mli create mode 100644 lib/vcs_base/test/test__commit_message.ml create mode 100644 lib/vcs_base/test/test__commit_message.mli create mode 100644 lib/vcs_base/test/test__file_contents.ml create mode 100644 lib/vcs_base/test/test__file_contents.mli create mode 100644 lib/vcs_base/test/test__graph.ml create mode 100644 lib/vcs_base/test/test__graph.mli create mode 100644 lib/vcs_base/test/test__name_status.ml create mode 100644 lib/vcs_base/test/test__name_status.mli create mode 100644 lib/vcs_base/test/test__num_lines_in_diff.ml create mode 100644 lib/vcs_base/test/test__num_lines_in_diff.mli create mode 100644 lib/vcs_base/test/test__path_in_repo.ml create mode 100644 lib/vcs_base/test/test__path_in_repo.mli create mode 100644 lib/vcs_base/test/test__ref_kind.ml create mode 100644 lib/vcs_base/test/test__ref_kind.mli create mode 100644 lib/vcs_base/test/test__refs.ml create mode 100644 lib/vcs_base/test/test__refs.mli create mode 100644 lib/vcs_base/test/test__remote_branch_name.ml create mode 100644 lib/vcs_base/test/test__remote_branch_name.mli create mode 100644 lib/vcs_base/test/test__remote_name.ml create mode 100644 lib/vcs_base/test/test__remote_name.mli create mode 100644 lib/vcs_base/test/test__repo_name.ml create mode 100644 lib/vcs_base/test/test__repo_name.mli create mode 100644 lib/vcs_base/test/test__repo_root.ml create mode 100644 lib/vcs_base/test/test__repo_root.mli create mode 100644 lib/vcs_base/test/test__rev.ml create mode 100644 lib/vcs_base/test/test__rev.mli create mode 100644 lib/vcs_base/test/test__tag_name.ml create mode 100644 lib/vcs_base/test/test__tag_name.mli create mode 100644 lib/vcs_base/test/test__url.ml create mode 100644 lib/vcs_base/test/test__url.mli create mode 100644 lib/vcs_base/test/test__user_email.ml create mode 100644 lib/vcs_base/test/test__user_email.mli create mode 100644 lib/vcs_base/test/test__user_handle.ml create mode 100644 lib/vcs_base/test/test__user_handle.mli create mode 100644 lib/vcs_base/test/test__user_name.ml create mode 100644 lib/vcs_base/test/test__user_name.mli create mode 100644 test/expect/user_config.ml create mode 100644 test/expect/user_config.mli diff --git a/lib/vcs/src/graph.ml b/lib/vcs/src/graph.ml index 648674a..20afe17 100644 --- a/lib/vcs/src/graph.ml +++ b/lib/vcs/src/graph.ml @@ -26,7 +26,7 @@ module Node = struct let compare = Int.compare let equal = Int.equal - let hash = Int.hash + let hash = Stdlib.Int.hash let seeded_hash = Stdlib.Int.seeded_hash let sexp_of_t i = Sexp.Atom ("#" ^ Int.to_string_hum i) end diff --git a/lib/vcs/test/test__log.ml b/lib/vcs/test/test__log.ml index 75939a7..94c95ab 100644 --- a/lib/vcs/test/test__log.ml +++ b/lib/vcs/test/test__log.ml @@ -19,7 +19,7 @@ (* and , respectively. *) (*******************************************************************************) -(* More tests for the [Vcs.Log] module in [lib/vcs_git_cli/test/test__log.ml]. *) +(* More tests for the [Vcs.Log] module in [lib/vcs_git_provider/test/test__log.ml]. *) let%expect_test "parse_exn" = Eio_main.run diff --git a/lib/vcs/test/test__num_lines_in_diff.ml b/lib/vcs/test/test__num_lines_in_diff.ml index 86575c5..573619c 100644 --- a/lib/vcs/test/test__num_lines_in_diff.ml +++ b/lib/vcs/test/test__num_lines_in_diff.ml @@ -82,3 +82,30 @@ let%expect_test "to_string_hum" = [%expect {| +1,999, -13,898 |}]; () ;; + +let%expect_test "equal-and-compare" = + let t1 = { Vcs.Num_lines_in_diff.insertions = 1; deletions = 2 } in + let t2 = { Vcs.Num_lines_in_diff.insertions = 1; deletions = 2 } in + let t3 = { Vcs.Num_lines_in_diff.insertions = 1; deletions = 3 } in + let t4 = { Vcs.Num_lines_in_diff.insertions = 2; deletions = 2 } in + require_equal [%here] (module Vcs.Num_lines_in_diff) t1 t1; + [%expect {||}]; + require_equal [%here] (module Vcs.Num_lines_in_diff) t1 t2; + [%expect {||}]; + require_not_equal [%here] (module Vcs.Num_lines_in_diff) t1 t3; + [%expect {||}]; + require_not_equal [%here] (module Vcs.Num_lines_in_diff) t1 t4; + [%expect {||}]; + let cmp a b = + print_s [%sexp (Vcs.Num_lines_in_diff.compare a b |> Ordering.of_int : Ordering.t)] + in + cmp t1 t1; + [%expect {| Equal |}]; + cmp t1 t2; + [%expect {| Equal |}]; + cmp t1 t3; + [%expect {| Less |}]; + cmp t1 t4; + [%expect {| Less |}]; + () +;; diff --git a/lib/vcs/test/test__platform.ml b/lib/vcs/test/test__platform.ml index 5a1b256..54169e9 100644 --- a/lib/vcs/test/test__platform.ml +++ b/lib/vcs/test/test__platform.ml @@ -24,17 +24,3 @@ let%expect_test "to_string_hum" = [%expect {| GitHub |}]; () ;; - -let%expect_test "hash" = - List.iter Vcs.Platform.all ~f:(fun t -> - let stdlib_hash = Stdlib.Hashtbl.hash t in - let vcs_hash = Vcs.Platform.hash t in - print_s [%sexp (t : Vcs.Platform.t), { stdlib_hash : int; vcs_hash : int }]); - [%expect - {| - (GitHub ( - (stdlib_hash 129913994) - (vcs_hash 129913994))) - |}]; - () -;; diff --git a/lib/vcs_base/test/dune b/lib/vcs_base/test/dune index 42d8180..054b499 100644 --- a/lib/vcs_base/test/dune +++ b/lib/vcs_base/test/dune @@ -1,7 +1,12 @@ (library (name vcs_base_test) (public_name vcs-tests.vcs_base_test) - (inline_tests) + (inline_tests + (deps + (glob_files *.name-status) + (glob_files *.num-status) + (glob_files *.log) + (glob_files *.refs))) (flags :standard -w @@ -40,3 +45,21 @@ ppx_let ppx_sexp_conv ppx_sexp_value))) + +(rule + (copy + %{project_root}/test/data/super-master-mind.name-status + super-master-mind.name-status)) + +(rule + (copy + %{project_root}/test/data/super-master-mind.num-status + super-master-mind.num-status)) + +(rule + (copy + %{project_root}/test/data/super-master-mind.refs + super-master-mind.refs)) + +(rule + (copy %{project_root}/test/data/super-master-mind.log super-master-mind.log)) diff --git a/lib/vcs_base/test/hash_test.ml b/lib/vcs_base/test/hash_test.ml new file mode 100644 index 0000000..ff9f035 --- /dev/null +++ b/lib/vcs_base/test/hash_test.ml @@ -0,0 +1,57 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module type H = sig + type t + + val sexp_of_t : t -> Sexp.t + val hash : t -> int + val seeded_hash : int -> t -> int +end + +let run + (type a) + (module V : H with type t = a) + (module V_base : Ppx_hash_lib.Hashable.S with type t = a) + values + = + let test_hash (t : a) = + let stdlib_hash = Stdlib.Hashtbl.hash t in + let vcs_hash = V.hash t in + let vcs_base_hash = V_base.hash t in + print_s + [%sexp + { value = (t : V.t) }, { stdlib_hash : int; vcs_hash : int; vcs_base_hash : int }] + in + let test_fold (t : a) ~seed = + let stdlib_hash = Stdlib.Hashtbl.seeded_hash seed t in + let vcs_hash = V.seeded_hash seed t in + let vcs_base_hash = Hash.run ~seed V_base.hash_fold_t t in + print_s + [%sexp + { value = (t : V.t); seed : int } + , { stdlib_hash : int; vcs_hash : int; vcs_base_hash : int }] + in + List.iter values ~f:(fun t -> + test_hash t; + test_fold t ~seed:0; + test_fold t ~seed:42) +;; diff --git a/lib/vcs_base/test/hash_test.mli b/lib/vcs_base/test/hash_test.mli new file mode 100644 index 0000000..f5f76e8 --- /dev/null +++ b/lib/vcs_base/test/hash_test.mli @@ -0,0 +1,34 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +module type H = sig + type t + + val sexp_of_t : t -> Sexp.t + val hash : t -> int + val seeded_hash : int -> t -> int +end + +val run + : (module H with type t = 'a) + -> (module Ppx_hash_lib.Hashable.S with type t = 'a) + -> 'a list + -> unit diff --git a/lib/vcs_base/test/test__author.ml b/lib/vcs_base/test/test__author.ml new file mode 100644 index 0000000..5b7687a --- /dev/null +++ b/lib/vcs_base/test/test__author.ml @@ -0,0 +1,58 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let values = [ Vcs.Author.v "John Doe"; Vcs.Author.v "Jane Doe" ] + +let%expect_test "hash" = + Hash_test.run (module Vcs.Author) (module Vcs_base.Vcs.Author) values; + [%expect + {| + (((value "John Doe")) + ((stdlib_hash 719227130) + (vcs_hash 719227130) + (vcs_base_hash 719227130))) + (((value "John Doe") + (seed 0)) + ((stdlib_hash 719227130) + (vcs_hash 719227130) + (vcs_base_hash 719227130))) + (((value "John Doe") + (seed 42)) + ((stdlib_hash 81441934) + (vcs_hash 81441934) + (vcs_base_hash 81441934))) + (((value "Jane Doe")) + ((stdlib_hash 659235483) + (vcs_hash 659235483) + (vcs_base_hash 659235483))) + (((value "Jane Doe") + (seed 0)) + ((stdlib_hash 659235483) + (vcs_hash 659235483) + (vcs_base_hash 659235483))) + (((value "Jane Doe") + (seed 42)) + ((stdlib_hash 443135183) + (vcs_hash 443135183) + (vcs_base_hash 443135183))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__author.mli b/lib/vcs_base/test/test__author.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__author.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__branch_name.ml b/lib/vcs_base/test/test__branch_name.ml new file mode 100644 index 0000000..1ae7f52 --- /dev/null +++ b/lib/vcs_base/test/test__branch_name.ml @@ -0,0 +1,58 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let values = [ Vcs.Branch_name.main; Vcs.Branch_name.v "my-branch" ] + +let%expect_test "hash" = + Hash_test.run (module Vcs.Branch_name) (module Vcs_base.Vcs.Branch_name) values; + [%expect + {| + (((value main)) + ((stdlib_hash 763421968) + (vcs_hash 763421968) + (vcs_base_hash 763421968))) + (((value main) + (seed 0)) + ((stdlib_hash 763421968) + (vcs_hash 763421968) + (vcs_base_hash 763421968))) + (((value main) + (seed 42)) + ((stdlib_hash 1007953461) + (vcs_hash 1007953461) + (vcs_base_hash 1007953461))) + (((value my-branch)) + ((stdlib_hash 977970132) + (vcs_hash 977970132) + (vcs_base_hash 977970132))) + (((value my-branch) + (seed 0)) + ((stdlib_hash 977970132) + (vcs_hash 977970132) + (vcs_base_hash 977970132))) + (((value my-branch) + (seed 42)) + ((stdlib_hash 513500652) + (vcs_hash 513500652) + (vcs_base_hash 513500652))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__branch_name.mli b/lib/vcs_base/test/test__branch_name.mli new file mode 100644 index 0000000..f3826a2 --- /dev/null +++ b/lib/vcs_base/test/test__branch_name.mli @@ -0,0 +1,22 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +val values : Vcs.Branch_name.t list diff --git a/lib/vcs_base/test/test__commit_message.ml b/lib/vcs_base/test/test__commit_message.ml new file mode 100644 index 0000000..48b2876 --- /dev/null +++ b/lib/vcs_base/test/test__commit_message.ml @@ -0,0 +1,62 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let values = + [ Vcs.Commit_message.v "Add this awesome new feature" + ; Vcs.Commit_message.v "Fix this rather annoying bug" + ] +;; + +let%expect_test "hash" = + Hash_test.run (module Vcs.Commit_message) (module Vcs_base.Vcs.Commit_message) values; + [%expect + {| + (((value "Add this awesome new feature")) + ((stdlib_hash 340930455) + (vcs_hash 340930455) + (vcs_base_hash 340930455))) + (((value "Add this awesome new feature") + (seed 0)) + ((stdlib_hash 340930455) + (vcs_hash 340930455) + (vcs_base_hash 340930455))) + (((value "Add this awesome new feature") + (seed 42)) + ((stdlib_hash 655507996) + (vcs_hash 655507996) + (vcs_base_hash 655507996))) + (((value "Fix this rather annoying bug")) + ((stdlib_hash 410910191) + (vcs_hash 410910191) + (vcs_base_hash 410910191))) + (((value "Fix this rather annoying bug") + (seed 0)) + ((stdlib_hash 410910191) + (vcs_hash 410910191) + (vcs_base_hash 410910191))) + (((value "Fix this rather annoying bug") + (seed 42)) + ((stdlib_hash 813233200) + (vcs_hash 813233200) + (vcs_base_hash 813233200))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__commit_message.mli b/lib/vcs_base/test/test__commit_message.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__commit_message.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__file_contents.ml b/lib/vcs_base/test/test__file_contents.ml new file mode 100644 index 0000000..1108a78 --- /dev/null +++ b/lib/vcs_base/test/test__file_contents.ml @@ -0,0 +1,58 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let values = [ Vcs.File_contents.create ""; Vcs.File_contents.create "Hello" ] + +let%expect_test "hash" = + Hash_test.run (module Vcs.File_contents) (module Vcs_base.Vcs.File_contents) values; + [%expect + {| + (((value "")) + ((stdlib_hash 0) + (vcs_hash 0) + (vcs_base_hash 0))) + (((value "") + (seed 0)) + ((stdlib_hash 0) + (vcs_hash 0) + (vcs_base_hash 0))) + (((value "") + (seed 42)) + ((stdlib_hash 142593372) + (vcs_hash 142593372) + (vcs_base_hash 142593372))) + (((value Hello)) + ((stdlib_hash 200495445) + (vcs_hash 200495445) + (vcs_base_hash 200495445))) + (((value Hello) + (seed 0)) + ((stdlib_hash 200495445) + (vcs_hash 200495445) + (vcs_base_hash 200495445))) + (((value Hello) + (seed 42)) + ((stdlib_hash 825079905) + (vcs_hash 825079905) + (vcs_base_hash 825079905))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__file_contents.mli b/lib/vcs_base/test/test__file_contents.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__file_contents.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__graph.ml b/lib/vcs_base/test/test__graph.ml new file mode 100644 index 0000000..cae0177 --- /dev/null +++ b/lib/vcs_base/test/test__graph.ml @@ -0,0 +1,285 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let%expect_test "base int hash" = + (* In this test we monitor the hashes of some int values using [Base]. + + We note here that we would not have expected [Base.Int.hash] to sometimes + return negative values, nor encounter cases where [Base.Int.hash_fold_t] + applied to an empty state returns a result that differs from that of + [Base.Int.hash]. *) + let test i = + let h = Base.Int.hash i in + let h2 = Base.Hash.run Base.Int.hash_fold_t i in + print_s [%sexp (i : int), (h : int), (h2 : int), (h = h2 : bool)] + in + List.iter ~f:test [ 0; 1; 2; 4; 5; -123456789 ]; + [%expect + {| + (0 4316648529147585864 1058613066 false) + (1 -2609136240614377266 129913994 false) + (2 4005111014598772340 462777137 false) + (4 -1213116315786261967 607293368 false) + (5 -3822126110415902464 648017920 false) + (-123456789 -547221948126359607 131804527 false) + |}]; + () +;; + +let%expect_test "stdlib int hash" = + (* Using [Stdlib.Int.hash] the hash values are always positive. *) + let test i = + let h = Stdlib.Int.hash i in + let h2 = Stdlib.Int.seeded_hash 0 i in + print_s [%sexp (i : int), (h : int), (h2 : int), (h = h2 : bool)] + in + List.iter ~f:test [ 0; 1; 2; 4; 5; -123456789 ]; + [%expect + {| + (0 129913994 129913994 true) + (1 883721435 883721435 true) + (2 648017920 648017920 true) + (4 127382775 127382775 true) + (5 378313623 378313623 true) + (-123456789 470621265 470621265 true) + |}]; + () +;; + +let%expect_test "node hash" = + let mock_rev_gen = Vcs.Mock_rev_gen.create ~name:"test-graph" in + let rev () = Vcs.Mock_rev_gen.next mock_rev_gen in + let graph = Vcs.Graph.create () in + let node ~rev = Vcs.Graph.find_rev graph ~rev |> Option.value_exn ~here:[%here] in + let root () = + let rev = rev () in + Vcs.Graph.add_nodes graph ~log:[ Vcs.Log.Line.Root { rev } ]; + node ~rev, rev + in + let commit ~parent = + let rev = rev () in + Vcs.Graph.add_nodes graph ~log:[ Vcs.Log.Line.Commit { rev; parent } ]; + node ~rev, rev + in + let merge ~parent1 ~parent2 = + let rev = rev () in + Vcs.Graph.add_nodes graph ~log:[ Vcs.Log.Line.Merge { rev; parent1; parent2 } ]; + node ~rev, rev + in + let n1, r1 = root () in + let n2, r2 = commit ~parent:r1 in + let n3, r3 = commit ~parent:r1 in + let nm1, m1 = merge ~parent1:r2 ~parent2:r3 in + let n4, r4 = commit ~parent:m1 in + Vcs.Graph.set_refs + graph + ~refs: + [ { rev = r2 + ; ref_kind = + Remote_branch { remote_branch_name = Vcs.Remote_branch_name.v "origin/main" } + } + ; { rev = r4; ref_kind = Tag { tag_name = Vcs.Tag_name.v "0.1.0" } } + ; { rev = r4; ref_kind = Local_branch { branch_name = Vcs.Branch_name.main } } + ]; + print_s [%sexp (graph : Vcs.Graph.t)]; + [%expect + {| + ((nodes ( + (#4 ( + Commit + (rev 7216231cd107946841cc3eebe5da287b7216231c) + (parent #3))) + (#3 ( + Merge + (rev 9a81fba7a18f740120f1141b1ed109bb9a81fba7) + (parent1 #1) + (parent2 #2))) + (#2 ( + Commit + (rev 5deb4aaec51a75ef58765038b7c20b3f5deb4aae) + (parent #0))) + (#1 ( + Commit + (rev f453b802f640c6888df978c712057d17f453b802) + (parent #0))) + (#0 (Root (rev 5cd237e9598b11065c344d1eb33bc8c15cd237e9))))) + (revs ( + (#4 7216231cd107946841cc3eebe5da287b7216231c) + (#3 9a81fba7a18f740120f1141b1ed109bb9a81fba7) + (#2 5deb4aaec51a75ef58765038b7c20b3f5deb4aae) + (#1 f453b802f640c6888df978c712057d17f453b802) + (#0 5cd237e9598b11065c344d1eb33bc8c15cd237e9))) + (refs ( + (#4 ( + (Local_branch (branch_name main)) + (Tag (tag_name 0.1.0)))) + (#1 (( + Remote_branch ( + remote_branch_name ( + (remote_name origin) + (branch_name main))))))))) + |}]; + Hash_test.run + (module Vcs.Graph.Node) + (module Vcs_base.Vcs.Graph.Node) + [ n1; n2; n3; n4; nm1 ]; + [%expect + {| + (((value #0)) + ((stdlib_hash 129913994) + (vcs_hash 129913994) + (vcs_base_hash 4316648529147585864))) + (((value #0) + (seed 0)) + ((stdlib_hash 129913994) + (vcs_hash 129913994) + (vcs_base_hash 1058613066))) + (((value #0) + (seed 42)) + ((stdlib_hash 269061838) + (vcs_hash 269061838) + (vcs_base_hash 992140660))) + (((value #1)) + ((stdlib_hash 883721435) + (vcs_hash 883721435) + (vcs_base_hash -2609136240614377266))) + (((value #1) + (seed 0)) + ((stdlib_hash 883721435) + (vcs_hash 883721435) + (vcs_base_hash 129913994))) + (((value #1) + (seed 42)) + ((stdlib_hash 166027884) + (vcs_hash 166027884) + (vcs_base_hash 269061838))) + (((value #2)) + ((stdlib_hash 648017920) + (vcs_hash 648017920) + (vcs_base_hash 4005111014598772340))) + (((value #2) + (seed 0)) + ((stdlib_hash 648017920) + (vcs_hash 648017920) + (vcs_base_hash 462777137))) + (((value #2) + (seed 42)) + ((stdlib_hash 1013383106) + (vcs_hash 1013383106) + (vcs_base_hash 1005547790))) + (((value #4)) + ((stdlib_hash 127382775) + (vcs_hash 127382775) + (vcs_base_hash -1213116315786261967))) + (((value #4) + (seed 0)) + ((stdlib_hash 127382775) + (vcs_hash 127382775) + (vcs_base_hash 607293368))) + (((value #4) + (seed 42)) + ((stdlib_hash 688167720) + (vcs_hash 688167720) + (vcs_base_hash 1062720725))) + (((value #3)) + ((stdlib_hash 152507349) + (vcs_hash 152507349) + (vcs_base_hash 1396078460937419741))) + (((value #3) + (seed 0)) + ((stdlib_hash 152507349) + (vcs_hash 152507349) + (vcs_base_hash 883721435))) + (((value #3) + (seed 42)) + ((stdlib_hash 97476682) + (vcs_hash 97476682) + (vcs_base_hash 166027884))) + |}]; + () +;; + +let%expect_test "descendance-hash" = + Hash_test.run + (module Vcs.Graph.Descendance) + (module Vcs_base.Vcs.Graph.Descendance) + Vcs.Graph.Descendance.all; + [%expect + {| + (((value Same_node)) + ((stdlib_hash 129913994) + (vcs_hash 129913994) + (vcs_base_hash 1058613066))) + (((value Same_node) + (seed 0)) + ((stdlib_hash 129913994) + (vcs_hash 129913994) + (vcs_base_hash 1058613066))) + (((value Same_node) + (seed 42)) + ((stdlib_hash 269061838) + (vcs_hash 269061838) + (vcs_base_hash 992140660))) + (((value Strict_ancestor)) + ((stdlib_hash 883721435) + (vcs_hash 883721435) + (vcs_base_hash 129913994))) + (((value Strict_ancestor) + (seed 0)) + ((stdlib_hash 883721435) + (vcs_hash 883721435) + (vcs_base_hash 129913994))) + (((value Strict_ancestor) + (seed 42)) + ((stdlib_hash 166027884) + (vcs_hash 166027884) + (vcs_base_hash 269061838))) + (((value Strict_descendant)) + ((stdlib_hash 648017920) + (vcs_hash 648017920) + (vcs_base_hash 462777137))) + (((value Strict_descendant) + (seed 0)) + ((stdlib_hash 648017920) + (vcs_hash 648017920) + (vcs_base_hash 462777137))) + (((value Strict_descendant) + (seed 42)) + ((stdlib_hash 1013383106) + (vcs_hash 1013383106) + (vcs_base_hash 1005547790))) + (((value Other)) + ((stdlib_hash 152507349) + (vcs_hash 152507349) + (vcs_base_hash 883721435))) + (((value Other) + (seed 0)) + ((stdlib_hash 152507349) + (vcs_hash 152507349) + (vcs_base_hash 883721435))) + (((value Other) + (seed 42)) + ((stdlib_hash 97476682) + (vcs_hash 97476682) + (vcs_base_hash 166027884))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__graph.mli b/lib/vcs_base/test/test__graph.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__graph.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__name_status.ml b/lib/vcs_base/test/test__name_status.ml new file mode 100644 index 0000000..dfa4fa9 --- /dev/null +++ b/lib/vcs_base/test/test__name_status.ml @@ -0,0 +1,75 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module Vcs = Vcs_base.Vcs + +let%expect_test "files" = + let lines = + [ "A\tadded_file" + ; "D\tremoved_file" + ; "M\tmodified_file" + ; "C75\toriginal_copied_file\tnew_copied_file" + ; "R100\toriginal_renamed_file\tnew_renamed_file" + ] + in + let name_status = Vcs_git_provider.Name_status.parse_lines_exn ~lines in + print_s [%sexp (name_status : Vcs.Name_status.t)]; + [%expect + {| + ((Added added_file) + (Removed removed_file) + (Modified modified_file) + (Copied + (src original_copied_file) + (dst new_copied_file) + (similarity 75)) + (Renamed + (src original_renamed_file) + (dst new_renamed_file) + (similarity 100))) |}]; + let files = Vcs.Name_status.files name_status in + print_s [%sexp (files : Set.M(Vcs.Path_in_repo).t)]; + [%expect + {| + (added_file + modified_file + new_copied_file + new_renamed_file + original_copied_file + original_renamed_file + removed_file) |}]; + let files_at_src = Vcs.Name_status.files_at_src name_status in + print_s [%sexp (files_at_src : Set.M(Vcs.Path_in_repo).t)]; + [%expect + {| + (modified_file original_copied_file original_renamed_file removed_file) |}]; + let files_at_dst = Vcs.Name_status.files_at_dst name_status in + print_s [%sexp (files_at_dst : Set.M(Vcs.Path_in_repo).t)]; + [%expect {| + (added_file modified_file new_copied_file new_renamed_file) |}]; + print_s [%sexp (Set.diff files_at_dst files_at_src : Set.M(Vcs.Path_in_repo).t)]; + [%expect {| + (added_file new_copied_file new_renamed_file) |}]; + print_s [%sexp (Set.diff files_at_src files_at_dst : Set.M(Vcs.Path_in_repo).t)]; + [%expect {| + (original_copied_file original_renamed_file removed_file) |}]; + () +;; diff --git a/lib/vcs_base/test/test__name_status.mli b/lib/vcs_base/test/test__name_status.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__name_status.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__num_lines_in_diff.ml b/lib/vcs_base/test/test__num_lines_in_diff.ml new file mode 100644 index 0000000..357b280 --- /dev/null +++ b/lib/vcs_base/test/test__num_lines_in_diff.ml @@ -0,0 +1,35 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module Vcs = Vcs_base.Vcs + +let%expect_test "to_string_hum" = + let test t = print_endline (Vcs.Num_lines_in_diff.to_string_hum t) in + test { insertions = 0; deletions = 0 }; + [%expect {| 0 |}]; + test { insertions = 100; deletions = 0 }; + [%expect {| +100 |}]; + test { insertions = 0; deletions = 15 }; + [%expect {| -15 |}]; + test { insertions = 1999; deletions = 13898 }; + [%expect {| +1,999, -13,898 |}]; + () +;; diff --git a/lib/vcs_base/test/test__num_lines_in_diff.mli b/lib/vcs_base/test/test__num_lines_in_diff.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__num_lines_in_diff.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__path_in_repo.ml b/lib/vcs_base/test/test__path_in_repo.ml new file mode 100644 index 0000000..d59b9f6 --- /dev/null +++ b/lib/vcs_base/test/test__path_in_repo.ml @@ -0,0 +1,58 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let values = [ Vcs.Path_in_repo.v "foo.txt"; Vcs.Path_in_repo.v "bar/baz.ml" ] + +let%expect_test "hash" = + Hash_test.run (module Vcs.Path_in_repo) (module Vcs_base.Vcs.Path_in_repo) values; + [%expect + {| + (((value foo.txt)) + ((stdlib_hash 836355526) + (vcs_hash 836355526) + (vcs_base_hash 836355526))) + (((value foo.txt) + (seed 0)) + ((stdlib_hash 836355526) + (vcs_hash 836355526) + (vcs_base_hash 836355526))) + (((value foo.txt) + (seed 42)) + ((stdlib_hash 444099220) + (vcs_hash 444099220) + (vcs_base_hash 444099220))) + (((value bar/baz.ml)) + ((stdlib_hash 615308050) + (vcs_hash 615308050) + (vcs_base_hash 615308050))) + (((value bar/baz.ml) + (seed 0)) + ((stdlib_hash 615308050) + (vcs_hash 615308050) + (vcs_base_hash 615308050))) + (((value bar/baz.ml) + (seed 42)) + ((stdlib_hash 922480314) + (vcs_hash 922480314) + (vcs_base_hash 922480314))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__path_in_repo.mli b/lib/vcs_base/test/test__path_in_repo.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__path_in_repo.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__platform.ml b/lib/vcs_base/test/test__platform.ml index a0902da..7c6a81f 100644 --- a/lib/vcs_base/test/test__platform.ml +++ b/lib/vcs_base/test/test__platform.ml @@ -19,20 +19,24 @@ (* and , respectively. *) (*******************************************************************************) -let%expect_test "monitor-hashes" = - List.iter Vcs.Platform.all ~f:(fun t -> - let stdlib_hash = Stdlib.Hashtbl.hash t in - let vcs_hash = Vcs.Platform.hash t in - let vcs_base_hash = Vcs_base.Vcs.Platform.hash t in - print_s - [%sexp - (t : Vcs.Platform.t), { stdlib_hash : int; vcs_hash : int; vcs_base_hash : int }]); +let%expect_test "hash" = + Hash_test.run (module Vcs.Platform) (module Vcs_base.Vcs.Platform) Vcs.Platform.all; [%expect {| - (GitHub ( - (stdlib_hash 129913994) + (((value GitHub)) + ((stdlib_hash 129913994) (vcs_hash 129913994) (vcs_base_hash 0))) + (((value GitHub) + (seed 0)) + ((stdlib_hash 129913994) + (vcs_hash 129913994) + (vcs_base_hash 0))) + (((value GitHub) + (seed 42)) + ((stdlib_hash 269061838) + (vcs_hash 269061838) + (vcs_base_hash 142593372))) |}]; () ;; diff --git a/lib/vcs_base/test/test__ref_kind.ml b/lib/vcs_base/test/test__ref_kind.ml new file mode 100644 index 0000000..cb1040c --- /dev/null +++ b/lib/vcs_base/test/test__ref_kind.ml @@ -0,0 +1,231 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let values = + List.concat + [ List.map Test__branch_name.values ~f:(fun branch_name -> + Vcs.Ref_kind.Local_branch { branch_name }) + ; List.map Test__remote_branch_name.values ~f:(fun remote_branch_name -> + Vcs.Ref_kind.Remote_branch { remote_branch_name }) + ; List.map Test__tag_name.values ~f:(fun tag_name -> Vcs.Ref_kind.Tag { tag_name }) + ; List.map ~f:(fun name -> Vcs.Ref_kind.Other { name }) [ "HEAD"; "MERGE_HEAD" ] + ] +;; + +let%expect_test "hash" = + Hash_test.run (module Vcs.Ref_kind) (module Vcs_base.Vcs.Ref_kind) values; + [%expect + {| + (((value (Local_branch (branch_name main)))) + ((stdlib_hash 29025240) + (vcs_hash 29025240) + (vcs_base_hash 94735605))) + (((value (Local_branch (branch_name main))) (seed 0)) + ((stdlib_hash 29025240) + (vcs_hash 29025240) + (vcs_base_hash 94735605))) + (((value (Local_branch (branch_name main))) (seed 42)) + ((stdlib_hash 830500646) + (vcs_hash 830500646) + (vcs_base_hash 770880661))) + (((value (Local_branch (branch_name my-branch)))) + ((stdlib_hash 946168396) + (vcs_hash 946168396) + (vcs_base_hash 984439962))) + (((value (Local_branch (branch_name my-branch))) (seed 0)) + ((stdlib_hash 946168396) + (vcs_hash 946168396) + (vcs_base_hash 984439962))) + (((value (Local_branch (branch_name my-branch))) (seed 42)) + ((stdlib_hash 335838264) + (vcs_hash 335838264) + (vcs_base_hash 878689118))) + ((( + value ( + Remote_branch ( + remote_branch_name ( + (remote_name origin) + (branch_name main)))))) + ((stdlib_hash 258976199) + (vcs_hash 258976199) + (vcs_base_hash 242619430))) + (((value ( + Remote_branch ( + remote_branch_name ( + (remote_name origin) + (branch_name main))))) + (seed 0)) + ((stdlib_hash 258976199) + (vcs_hash 258976199) + (vcs_base_hash 242619430))) + (((value ( + Remote_branch ( + remote_branch_name ( + (remote_name origin) + (branch_name main))))) + (seed 42)) + ((stdlib_hash 343494517) + (vcs_hash 343494517) + (vcs_base_hash 999580363))) + ((( + value ( + Remote_branch ( + remote_branch_name ( + (remote_name origin) + (branch_name my-branch)))))) + ((stdlib_hash 397055407) + (vcs_hash 397055407) + (vcs_base_hash 276051467))) + (((value ( + Remote_branch ( + remote_branch_name ( + (remote_name origin) + (branch_name my-branch))))) + (seed 0)) + ((stdlib_hash 397055407) + (vcs_hash 397055407) + (vcs_base_hash 276051467))) + (((value ( + Remote_branch ( + remote_branch_name ( + (remote_name origin) + (branch_name my-branch))))) + (seed 42)) + ((stdlib_hash 181104236) + (vcs_hash 181104236) + (vcs_base_hash 918453922))) + ((( + value ( + Remote_branch ( + remote_branch_name ( + (remote_name upstream) + (branch_name main)))))) + ((stdlib_hash 359047634) + (vcs_hash 359047634) + (vcs_base_hash 718475039))) + (((value ( + Remote_branch ( + remote_branch_name ( + (remote_name upstream) + (branch_name main))))) + (seed 0)) + ((stdlib_hash 359047634) + (vcs_hash 359047634) + (vcs_base_hash 718475039))) + (((value ( + Remote_branch ( + remote_branch_name ( + (remote_name upstream) + (branch_name main))))) + (seed 42)) + ((stdlib_hash 969621201) + (vcs_hash 969621201) + (vcs_base_hash 409254382))) + ((( + value ( + Remote_branch ( + remote_branch_name ( + (remote_name upstream) + (branch_name my-branch)))))) + ((stdlib_hash 646234684) + (vcs_hash 646234684) + (vcs_base_hash 646359821))) + (((value ( + Remote_branch ( + remote_branch_name ( + (remote_name upstream) + (branch_name my-branch))))) + (seed 0)) + ((stdlib_hash 646234684) + (vcs_hash 646234684) + (vcs_base_hash 646359821))) + (((value ( + Remote_branch ( + remote_branch_name ( + (remote_name upstream) + (branch_name my-branch))))) + (seed 42)) + ((stdlib_hash 201067920) + (vcs_hash 201067920) + (vcs_base_hash 21348147))) + (((value (Tag (tag_name my-tag)))) + ((stdlib_hash 93827037) + (vcs_hash 93827037) + (vcs_base_hash 217296416))) + (((value (Tag (tag_name my-tag))) (seed 0)) + ((stdlib_hash 93827037) + (vcs_hash 93827037) + (vcs_base_hash 217296416))) + (((value (Tag (tag_name my-tag))) (seed 42)) + ((stdlib_hash 130085576) + (vcs_hash 130085576) + (vcs_base_hash 889889237))) + (((value (Tag (tag_name v0.0.1)))) + ((stdlib_hash 853378279) + (vcs_hash 853378279) + (vcs_base_hash 959412064))) + (((value (Tag (tag_name v0.0.1))) (seed 0)) + ((stdlib_hash 853378279) + (vcs_hash 853378279) + (vcs_base_hash 959412064))) + (((value (Tag (tag_name v0.0.1))) (seed 42)) + ((stdlib_hash 4011706) + (vcs_hash 4011706) + (vcs_base_hash 511371176))) + (((value (Tag (tag_name 1.2)))) + ((stdlib_hash 368157373) + (vcs_hash 368157373) + (vcs_base_hash 91233646))) + (((value (Tag (tag_name 1.2))) (seed 0)) + ((stdlib_hash 368157373) + (vcs_hash 368157373) + (vcs_base_hash 91233646))) + (((value (Tag (tag_name 1.2))) (seed 42)) + ((stdlib_hash 224592090) + (vcs_hash 224592090) + (vcs_base_hash 737977122))) + (((value (Other (name HEAD)))) + ((stdlib_hash 245238873) + (vcs_hash 245238873) + (vcs_base_hash 816863108))) + (((value (Other (name HEAD))) (seed 0)) + ((stdlib_hash 245238873) + (vcs_hash 245238873) + (vcs_base_hash 816863108))) + (((value (Other (name HEAD))) (seed 42)) + ((stdlib_hash 599545985) + (vcs_hash 599545985) + (vcs_base_hash 190479651))) + (((value (Other (name MERGE_HEAD)))) + ((stdlib_hash 1068385555) + (vcs_hash 1068385555) + (vcs_base_hash 645534583))) + (((value (Other (name MERGE_HEAD))) (seed 0)) + ((stdlib_hash 1068385555) + (vcs_hash 1068385555) + (vcs_base_hash 645534583))) + (((value (Other (name MERGE_HEAD))) (seed 42)) + ((stdlib_hash 681314370) + (vcs_hash 681314370) + (vcs_base_hash 121079498))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__ref_kind.mli b/lib/vcs_base/test/test__ref_kind.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__ref_kind.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__refs.ml b/lib/vcs_base/test/test__refs.ml new file mode 100644 index 0000000..8ae7b12 --- /dev/null +++ b/lib/vcs_base/test/test__refs.ml @@ -0,0 +1,87 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +module Vcs = Vcs_base.Vcs + +let%expect_test "parse_exn" = + Eio_main.run + @@ fun env -> + let path = Eio.Path.(Eio.Stdenv.fs env / "super-master-mind.refs") in + let contents = Eio.Path.load path in + let lines = String.split_lines contents in + let refs = Vcs_git_provider.Refs.parse_lines_exn ~lines in + print_s + [%sexp + { tags = (Vcs.Refs.tags refs : Set.M(Vcs.Tag_name).t) + ; local_branches = (Vcs.Refs.local_branches refs : Set.M(Vcs.Branch_name).t) + ; remote_branches = + (Vcs.Refs.remote_branches refs : Set.M(Vcs.Remote_branch_name).t) + }]; + [%expect + {| + ((tags (0.0.1 0.0.2 0.0.3 0.0.3-preview.1)) + (local_branches (gh-pages main subrepo)) + (remote_branches ( + ((remote_name origin) (branch_name 0.0.3-preview)) + ((remote_name origin) (branch_name gh-pages)) + ((remote_name origin) (branch_name main)) + ((remote_name origin) (branch_name progress-bar)) + ((remote_name origin) (branch_name progress-bar.2))))) |}]; + print_s [%sexp (Vcs.Refs.to_map refs : Vcs.Rev.t Map.M(Vcs.Ref_kind).t)]; + [%expect + {| + (((Local_branch (branch_name gh-pages)) + 7135b7f4790562e94d9122365478f0d39f5ffead) + ((Local_branch (branch_name main)) 2e4fbeae154ec896262decf1ab3bee5687b93f21) + ((Local_branch (branch_name subrepo)) + 2e4fbeae154ec896262decf1ab3bee5687b93f21) + ((Remote_branch ( + remote_branch_name ( + (remote_name origin) + (branch_name 0.0.3-preview)))) + 8e0e6821261f8baaff7bf4d6820c41417bab91eb) + ((Remote_branch ( + remote_branch_name ( + (remote_name origin) + (branch_name gh-pages)))) + 7135b7f4790562e94d9122365478f0d39f5ffead) + ((Remote_branch ( + remote_branch_name ( + (remote_name origin) + (branch_name main)))) + 2e4fbeae154ec896262decf1ab3bee5687b93f21) + ((Remote_branch ( + remote_branch_name ( + (remote_name origin) + (branch_name progress-bar)))) + a2cc521adbc8dcbd4855968698176e8af54f6550) + ((Remote_branch ( + remote_branch_name ( + (remote_name origin) + (branch_name progress-bar.2)))) + 7500919364fb176946e7598051ca7247addc3d15) + ((Tag (tag_name 0.0.1)) 1892d4980ee74945eb98f67be26b745f96c0f482) + ((Tag (tag_name 0.0.2)) 0d4750ff594236a4bd970e1c90b8bbad80fcadff) + ((Tag (tag_name 0.0.3)) fc8e67fbc47302b7da682e9a7da626790bb59eaa) + ((Tag (tag_name 0.0.3-preview.1)) 1887c81ebf9b84c548bc35038f7af82a18eb77bf)) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__refs.mli b/lib/vcs_base/test/test__refs.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__refs.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__remote_branch_name.ml b/lib/vcs_base/test/test__remote_branch_name.ml new file mode 100644 index 0000000..25386de --- /dev/null +++ b/lib/vcs_base/test/test__remote_branch_name.ml @@ -0,0 +1,141 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let values = + List.concat_map Test__remote_name.values ~f:(fun remote_name -> + List.map Test__branch_name.values ~f:(fun branch_name -> + { Vcs.Remote_branch_name.remote_name; branch_name })) +;; + +let%expect_test "hash" = + Hash_test.run + (module Vcs.Remote_branch_name) + (module Vcs_base.Vcs.Remote_branch_name) + values; + [%expect + {| + ((( + value ( + (remote_name origin) + (branch_name main)))) + ((stdlib_hash 310768421) + (vcs_hash 310768421) + (vcs_base_hash 299265207))) + (((value ( + (remote_name origin) + (branch_name main))) + (seed 0)) + ((stdlib_hash 310768421) + (vcs_hash 310768421) + (vcs_base_hash 299265207))) + (((value ( + (remote_name origin) + (branch_name main))) + (seed 42)) + ((stdlib_hash 1032210503) + (vcs_hash 1032210503) + (vcs_base_hash 701314591))) + ((( + value ( + (remote_name origin) + (branch_name my-branch)))) + ((stdlib_hash 598970259) + (vcs_hash 598970259) + (vcs_base_hash 239096173))) + (((value ( + (remote_name origin) + (branch_name my-branch))) + (seed 0)) + ((stdlib_hash 598970259) + (vcs_hash 598970259) + (vcs_base_hash 239096173))) + (((value ( + (remote_name origin) + (branch_name my-branch))) + (seed 42)) + ((stdlib_hash 46891672) + (vcs_hash 46891672) + (vcs_base_hash 1039200790))) + ((( + value ( + (remote_name upstream) + (branch_name main)))) + ((stdlib_hash 588793325) + (vcs_hash 588793325) + (vcs_base_hash 919801467))) + (((value ( + (remote_name upstream) + (branch_name main))) + (seed 0)) + ((stdlib_hash 588793325) + (vcs_hash 588793325) + (vcs_base_hash 919801467))) + (((value ( + (remote_name upstream) + (branch_name main))) + (seed 42)) + ((stdlib_hash 698319882) + (vcs_hash 698319882) + (vcs_base_hash 760806345))) + ((( + value ( + (remote_name upstream) + (branch_name my-branch)))) + ((stdlib_hash 925005510) + (vcs_hash 925005510) + (vcs_base_hash 470939564))) + (((value ( + (remote_name upstream) + (branch_name my-branch))) + (seed 0)) + ((stdlib_hash 925005510) + (vcs_hash 925005510) + (vcs_base_hash 470939564))) + (((value ( + (remote_name upstream) + (branch_name my-branch))) + (seed 42)) + ((stdlib_hash 990156454) + (vcs_hash 990156454) + (vcs_base_hash 260501276))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__remote_branch_name.mli b/lib/vcs_base/test/test__remote_branch_name.mli new file mode 100644 index 0000000..c99c94a --- /dev/null +++ b/lib/vcs_base/test/test__remote_branch_name.mli @@ -0,0 +1,22 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +val values : Vcs.Remote_branch_name.t list diff --git a/lib/vcs_base/test/test__remote_name.ml b/lib/vcs_base/test/test__remote_name.ml new file mode 100644 index 0000000..141b790 --- /dev/null +++ b/lib/vcs_base/test/test__remote_name.ml @@ -0,0 +1,58 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let values = [ Vcs.Remote_name.origin; Vcs.Remote_name.v "upstream" ] + +let%expect_test "hash" = + Hash_test.run (module Vcs.Remote_name) (module Vcs_base.Vcs.Remote_name) values; + [%expect + {| + (((value origin)) + ((stdlib_hash 340153502) + (vcs_hash 340153502) + (vcs_base_hash 340153502))) + (((value origin) + (seed 0)) + ((stdlib_hash 340153502) + (vcs_hash 340153502) + (vcs_base_hash 340153502))) + (((value origin) + (seed 42)) + ((stdlib_hash 84167816) + (vcs_hash 84167816) + (vcs_base_hash 84167816))) + (((value upstream)) + ((stdlib_hash 315569492) + (vcs_hash 315569492) + (vcs_base_hash 315569492))) + (((value upstream) + (seed 0)) + ((stdlib_hash 315569492) + (vcs_hash 315569492) + (vcs_base_hash 315569492))) + (((value upstream) + (seed 42)) + ((stdlib_hash 96936268) + (vcs_hash 96936268) + (vcs_base_hash 96936268))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__remote_name.mli b/lib/vcs_base/test/test__remote_name.mli new file mode 100644 index 0000000..711cf8b --- /dev/null +++ b/lib/vcs_base/test/test__remote_name.mli @@ -0,0 +1,22 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +val values : Vcs.Remote_name.t list diff --git a/lib/vcs_base/test/test__repo_name.ml b/lib/vcs_base/test/test__repo_name.ml new file mode 100644 index 0000000..fa25584 --- /dev/null +++ b/lib/vcs_base/test/test__repo_name.ml @@ -0,0 +1,58 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let values = [ Vcs.Repo_name.v "vcs"; Vcs.Repo_name.v "loc" ] + +let%expect_test "hash" = + Hash_test.run (module Vcs.Repo_name) (module Vcs_base.Vcs.Repo_name) values; + [%expect + {| + (((value vcs)) + ((stdlib_hash 416069169) + (vcs_hash 416069169) + (vcs_base_hash 416069169))) + (((value vcs) + (seed 0)) + ((stdlib_hash 416069169) + (vcs_hash 416069169) + (vcs_base_hash 416069169))) + (((value vcs) + (seed 42)) + ((stdlib_hash 363610390) + (vcs_hash 363610390) + (vcs_base_hash 363610390))) + (((value loc)) + ((stdlib_hash 41095261) + (vcs_hash 41095261) + (vcs_base_hash 41095261))) + (((value loc) + (seed 0)) + ((stdlib_hash 41095261) + (vcs_hash 41095261) + (vcs_base_hash 41095261))) + (((value loc) + (seed 42)) + ((stdlib_hash 683447793) + (vcs_hash 683447793) + (vcs_base_hash 683447793))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__repo_name.mli b/lib/vcs_base/test/test__repo_name.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__repo_name.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__repo_root.ml b/lib/vcs_base/test/test__repo_root.ml new file mode 100644 index 0000000..eeda169 --- /dev/null +++ b/lib/vcs_base/test/test__repo_root.ml @@ -0,0 +1,58 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let values = [ Vcs.Repo_root.v "/tmp/foo"; Vcs.Repo_root.v "/home/user/dev/repo" ] + +let%expect_test "hash" = + Hash_test.run (module Vcs.Repo_root) (module Vcs_base.Vcs.Repo_root) values; + [%expect + {| + (((value /tmp/foo)) + ((stdlib_hash 300202224) + (vcs_hash 300202224) + (vcs_base_hash 300202224))) + (((value /tmp/foo) + (seed 0)) + ((stdlib_hash 300202224) + (vcs_hash 300202224) + (vcs_base_hash 300202224))) + (((value /tmp/foo) + (seed 42)) + ((stdlib_hash 202387283) + (vcs_hash 202387283) + (vcs_base_hash 202387283))) + (((value /home/user/dev/repo)) + ((stdlib_hash 793408912) + (vcs_hash 793408912) + (vcs_base_hash 793408912))) + (((value /home/user/dev/repo) + (seed 0)) + ((stdlib_hash 793408912) + (vcs_hash 793408912) + (vcs_base_hash 793408912))) + (((value /home/user/dev/repo) + (seed 42)) + ((stdlib_hash 628866208) + (vcs_hash 628866208) + (vcs_base_hash 628866208))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__repo_root.mli b/lib/vcs_base/test/test__repo_root.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__repo_root.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__rev.ml b/lib/vcs_base/test/test__rev.ml new file mode 100644 index 0000000..6d9fff4 --- /dev/null +++ b/lib/vcs_base/test/test__rev.ml @@ -0,0 +1,59 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let%expect_test "hash" = + let mock_rev_gen = Vcs.Mock_rev_gen.create ~name:"test-graph" in + let rev () = Vcs.Mock_rev_gen.next mock_rev_gen in + let values = [ rev (); rev () ] in + Hash_test.run (module Vcs.Rev) (module Vcs_base.Vcs.Rev) values; + [%expect + {| + (((value f453b802f640c6888df978c712057d17f453b802)) + ((stdlib_hash 1067342185) + (vcs_hash 1067342185) + (vcs_base_hash 1067342185))) + (((value f453b802f640c6888df978c712057d17f453b802) + (seed 0)) + ((stdlib_hash 1067342185) + (vcs_hash 1067342185) + (vcs_base_hash 1067342185))) + (((value f453b802f640c6888df978c712057d17f453b802) + (seed 42)) + ((stdlib_hash 720223438) + (vcs_hash 720223438) + (vcs_base_hash 720223438))) + (((value 5cd237e9598b11065c344d1eb33bc8c15cd237e9)) + ((stdlib_hash 687820538) + (vcs_hash 687820538) + (vcs_base_hash 687820538))) + (((value 5cd237e9598b11065c344d1eb33bc8c15cd237e9) + (seed 0)) + ((stdlib_hash 687820538) + (vcs_hash 687820538) + (vcs_base_hash 687820538))) + (((value 5cd237e9598b11065c344d1eb33bc8c15cd237e9) + (seed 42)) + ((stdlib_hash 1058957186) + (vcs_hash 1058957186) + (vcs_base_hash 1058957186))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__rev.mli b/lib/vcs_base/test/test__rev.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__rev.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__tag_name.ml b/lib/vcs_base/test/test__tag_name.ml new file mode 100644 index 0000000..4646629 --- /dev/null +++ b/lib/vcs_base/test/test__tag_name.ml @@ -0,0 +1,72 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let values = [ Vcs.Tag_name.v "my-tag"; Vcs.Tag_name.v "v0.0.1"; Vcs.Tag_name.v "1.2" ] + +let%expect_test "hash" = + Hash_test.run (module Vcs.Tag_name) (module Vcs_base.Vcs.Tag_name) values; + [%expect + {| + (((value my-tag)) + ((stdlib_hash 865032536) + (vcs_hash 865032536) + (vcs_base_hash 865032536))) + (((value my-tag) + (seed 0)) + ((stdlib_hash 865032536) + (vcs_hash 865032536) + (vcs_base_hash 865032536))) + (((value my-tag) + (seed 42)) + ((stdlib_hash 809141036) + (vcs_hash 809141036) + (vcs_base_hash 809141036))) + (((value v0.0.1)) + ((stdlib_hash 803999042) + (vcs_hash 803999042) + (vcs_base_hash 803999042))) + (((value v0.0.1) + (seed 0)) + ((stdlib_hash 803999042) + (vcs_hash 803999042) + (vcs_base_hash 803999042))) + (((value v0.0.1) + (seed 42)) + ((stdlib_hash 682119237) + (vcs_hash 682119237) + (vcs_base_hash 682119237))) + (((value 1.2)) + ((stdlib_hash 968236532) + (vcs_hash 968236532) + (vcs_base_hash 968236532))) + (((value 1.2) + (seed 0)) + ((stdlib_hash 968236532) + (vcs_hash 968236532) + (vcs_base_hash 968236532))) + (((value 1.2) + (seed 42)) + ((stdlib_hash 285020915) + (vcs_hash 285020915) + (vcs_base_hash 285020915))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__tag_name.mli b/lib/vcs_base/test/test__tag_name.mli new file mode 100644 index 0000000..e3dc1bb --- /dev/null +++ b/lib/vcs_base/test/test__tag_name.mli @@ -0,0 +1,22 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +val values : Vcs.Tag_name.t list diff --git a/lib/vcs_base/test/test__url.ml b/lib/vcs_base/test/test__url.ml new file mode 100644 index 0000000..55f02ab --- /dev/null +++ b/lib/vcs_base/test/test__url.ml @@ -0,0 +1,135 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let%expect_test "protocol-hash" = + Hash_test.run + (module Vcs.Url.Protocol) + (module Vcs_base.Vcs.Url.Protocol) + Vcs.Url.Protocol.all; + [%expect + {| + (((value Ssh)) + ((stdlib_hash 129913994) + (vcs_hash 129913994) + (vcs_base_hash 1058613066))) + (((value Ssh) + (seed 0)) + ((stdlib_hash 129913994) + (vcs_hash 129913994) + (vcs_base_hash 1058613066))) + (((value Ssh) + (seed 42)) + ((stdlib_hash 269061838) + (vcs_hash 269061838) + (vcs_base_hash 992140660))) + (((value Https)) + ((stdlib_hash 883721435) + (vcs_hash 883721435) + (vcs_base_hash 129913994))) + (((value Https) + (seed 0)) + ((stdlib_hash 883721435) + (vcs_hash 883721435) + (vcs_base_hash 129913994))) + (((value Https) + (seed 42)) + ((stdlib_hash 166027884) + (vcs_hash 166027884) + (vcs_base_hash 269061838))) + |}]; + () +;; + +let values = + [ { Vcs.Url.platform = GitHub + ; protocol = Ssh + ; user_handle = Vcs.User_handle.v "jdoe" + ; repo_name = Vcs.Repo_name.v "vcs" + } + ; { Vcs.Url.platform = GitHub + ; protocol = Https + ; user_handle = Vcs.User_handle.v "jdoe" + ; repo_name = Vcs.Repo_name.v "vcs" + } + ] +;; + +let%expect_test "hash" = + Hash_test.run (module Vcs.Url) (module Vcs_base.Vcs.Url) values; + [%expect + {| + ((( + value ( + (platform GitHub) + (protocol Ssh) + (user_handle jdoe) + (repo_name vcs)))) + ((stdlib_hash 985339529) + (vcs_hash 985339529) + (vcs_base_hash 379123824))) + (((value ( + (platform GitHub) + (protocol Ssh) + (user_handle jdoe) + (repo_name vcs))) + (seed 0)) + ((stdlib_hash 985339529) + (vcs_hash 985339529) + (vcs_base_hash 379123824))) + (((value ( + (platform GitHub) + (protocol Ssh) + (user_handle jdoe) + (repo_name vcs))) + (seed 42)) + ((stdlib_hash 403159267) + (vcs_hash 403159267) + (vcs_base_hash 455185329))) + ((( + value ( + (platform GitHub) + (protocol Https) + (user_handle jdoe) + (repo_name vcs)))) + ((stdlib_hash 738318452) + (vcs_hash 738318452) + (vcs_base_hash 175273566))) + (((value ( + (platform GitHub) + (protocol Https) + (user_handle jdoe) + (repo_name vcs))) + (seed 0)) + ((stdlib_hash 738318452) + (vcs_hash 738318452) + (vcs_base_hash 175273566))) + (((value ( + (platform GitHub) + (protocol Https) + (user_handle jdoe) + (repo_name vcs))) + (seed 42)) + ((stdlib_hash 578334967) + (vcs_hash 578334967) + (vcs_base_hash 1022761584))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__url.mli b/lib/vcs_base/test/test__url.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__url.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__user_email.ml b/lib/vcs_base/test/test__user_email.ml new file mode 100644 index 0000000..9b2c52d --- /dev/null +++ b/lib/vcs_base/test/test__user_email.ml @@ -0,0 +1,58 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let values = [ Vcs.User_email.v "jdoe@jdoe.org"; Vcs.User_email.v "john-doe@email.com" ] + +let%expect_test "hash" = + Hash_test.run (module Vcs.User_email) (module Vcs_base.Vcs.User_email) values; + [%expect + {| + (((value jdoe@jdoe.org)) + ((stdlib_hash 505986774) + (vcs_hash 505986774) + (vcs_base_hash 505986774))) + (((value jdoe@jdoe.org) + (seed 0)) + ((stdlib_hash 505986774) + (vcs_hash 505986774) + (vcs_base_hash 505986774))) + (((value jdoe@jdoe.org) + (seed 42)) + ((stdlib_hash 249313671) + (vcs_hash 249313671) + (vcs_base_hash 249313671))) + (((value john-doe@email.com)) + ((stdlib_hash 641234243) + (vcs_hash 641234243) + (vcs_base_hash 641234243))) + (((value john-doe@email.com) + (seed 0)) + ((stdlib_hash 641234243) + (vcs_hash 641234243) + (vcs_base_hash 641234243))) + (((value john-doe@email.com) + (seed 42)) + ((stdlib_hash 810806416) + (vcs_hash 810806416) + (vcs_base_hash 810806416))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__user_email.mli b/lib/vcs_base/test/test__user_email.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__user_email.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__user_handle.ml b/lib/vcs_base/test/test__user_handle.ml new file mode 100644 index 0000000..e6284c7 --- /dev/null +++ b/lib/vcs_base/test/test__user_handle.ml @@ -0,0 +1,58 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let values = [ Vcs.User_handle.v "john-doe"; Vcs.User_handle.v "jane-doe" ] + +let%expect_test "hash" = + Hash_test.run (module Vcs.User_handle) (module Vcs_base.Vcs.User_handle) values; + [%expect + {| + (((value john-doe)) + ((stdlib_hash 152607077) + (vcs_hash 152607077) + (vcs_base_hash 152607077))) + (((value john-doe) + (seed 0)) + ((stdlib_hash 152607077) + (vcs_hash 152607077) + (vcs_base_hash 152607077))) + (((value john-doe) + (seed 42)) + ((stdlib_hash 80938851) + (vcs_hash 80938851) + (vcs_base_hash 80938851))) + (((value jane-doe)) + ((stdlib_hash 209935393) + (vcs_hash 209935393) + (vcs_base_hash 209935393))) + (((value jane-doe) + (seed 0)) + ((stdlib_hash 209935393) + (vcs_hash 209935393) + (vcs_base_hash 209935393))) + (((value jane-doe) + (seed 42)) + ((stdlib_hash 414759229) + (vcs_hash 414759229) + (vcs_base_hash 414759229))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__user_handle.mli b/lib/vcs_base/test/test__user_handle.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/lib/vcs_base/test/test__user_handle.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_base/test/test__user_name.ml b/lib/vcs_base/test/test__user_name.ml new file mode 100644 index 0000000..8e94cec --- /dev/null +++ b/lib/vcs_base/test/test__user_name.ml @@ -0,0 +1,58 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let values = [ Vcs.User_name.v "John Doe"; Vcs.User_name.v "Jane Doe" ] + +let%expect_test "hash" = + Hash_test.run (module Vcs.User_name) (module Vcs_base.Vcs.User_name) values; + [%expect + {| + (((value "John Doe")) + ((stdlib_hash 719227130) + (vcs_hash 719227130) + (vcs_base_hash 719227130))) + (((value "John Doe") + (seed 0)) + ((stdlib_hash 719227130) + (vcs_hash 719227130) + (vcs_base_hash 719227130))) + (((value "John Doe") + (seed 42)) + ((stdlib_hash 81441934) + (vcs_hash 81441934) + (vcs_base_hash 81441934))) + (((value "Jane Doe")) + ((stdlib_hash 659235483) + (vcs_hash 659235483) + (vcs_base_hash 659235483))) + (((value "Jane Doe") + (seed 0)) + ((stdlib_hash 659235483) + (vcs_hash 659235483) + (vcs_base_hash 659235483))) + (((value "Jane Doe") + (seed 42)) + ((stdlib_hash 443135183) + (vcs_hash 443135183) + (vcs_base_hash 443135183))) + |}]; + () +;; diff --git a/lib/vcs_base/test/test__user_name.mli b/lib/vcs_base/test/test__user_name.mli new file mode 100644 index 0000000..3ec9fcc --- /dev/null +++ b/lib/vcs_base/test/test__user_name.mli @@ -0,0 +1,42 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) + +val values : Vcs.User_name.t list +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************) diff --git a/lib/vcs_git_provider/test/dune b/lib/vcs_git_provider/test/dune index 814817a..f97bc98 100644 --- a/lib/vcs_git_provider/test/dune +++ b/lib/vcs_git_provider/test/dune @@ -22,6 +22,7 @@ eio eio_main expect_test_helpers_core.expect_test_helpers_base + vcs vcs_git_provider) (instrumentation (backend bisect_ppx)) diff --git a/test/expect/user_config.ml b/test/expect/user_config.ml new file mode 100644 index 0000000..9f34223 --- /dev/null +++ b/test/expect/user_config.ml @@ -0,0 +1,94 @@ +(*******************************************************************************) +(* Vcs - a Versatile OCaml Library for Git Operations *) +(* Copyright (C) 2024 Mathieu Barbin *) +(* *) +(* This file is part of Vcs. *) +(* *) +(* Vcs is free software; you can redistribute it and/or modify it under *) +(* the terms of the GNU Lesser General Public License as published by the *) +(* Free Software Foundation either version 3 of the License, or any later *) +(* version, with the LGPL-3.0 Linking Exception. *) +(* *) +(* Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(* the file `NOTICE.md` at the root of this repository for more details. *) +(* *) +(* You should have received a copy of the GNU Lesser General Public License *) +(* and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(* and , respectively. *) +(*******************************************************************************) + +let commit_file vcs ~repo_root ~path ~file_contents ~commit_message = + Vcs.save_file vcs ~path:(Vcs.Repo_root.append repo_root path) ~file_contents; + Vcs.add vcs ~repo_root ~path; + Vcs.commit vcs ~repo_root ~commit_message +;; + +let show_commit_metadata vcs ~repo_root ~rev = + Vcs.git + vcs + ~repo_root + ~args:[ "log"; "-n"; "1"; "--pretty=format:\"%an <%ae>\""; Vcs.Rev.to_string rev ] + ~f:Vcs.Git.exit0_and_stdout + |> print_endline +;; + +let%expect_test "set-user-config" = + Eio_main.run + @@ fun env -> + Eio.Switch.run + @@ fun sw -> + let vcs = Vcs_git_eio.create ~env in + let repo_root = Vcs_test_helpers.init_temp_repo ~env ~sw ~vcs in + let mock_revs = Vcs.Mock_revs.create () in + let hello_file = Vcs.Path_in_repo.v "hello.txt" in + let rev = + commit_file + vcs + ~repo_root + ~path:hello_file + ~file_contents:(Vcs.File_contents.create "Hello World!") + ~commit_message:(Vcs.Commit_message.v "hello commit") + in + let mock_rev = Vcs.Mock_revs.to_mock mock_revs ~rev in + print_s [%sexp (mock_rev : Vcs.Rev.t)]; + [%expect {| 1185512b92d612b25613f2e5b473e5231185512b |}]; + show_commit_metadata vcs ~repo_root ~rev; + [%expect {| "Test User " |}]; + Vcs.set_user_name vcs ~repo_root ~user_name:(Vcs.User_name.v "Other User"); + Vcs.set_user_email vcs ~repo_root ~user_email:(Vcs.User_email.v "other@other-user.org"); + let rev = + commit_file + vcs + ~repo_root + ~path:hello_file + ~file_contents:(Vcs.File_contents.create "Hello World!\nWe're adding a new line!") + ~commit_message:(Vcs.Commit_message.v "hello commit") + in + show_commit_metadata vcs ~repo_root ~rev; + [%expect {| "Other User " |}]; + let () = + Vcs.Result.set_user_name vcs ~repo_root ~user_name:(Vcs.User_name.v "Third User") + |> Stdlib.Result.get_ok + in + let () = + Vcs.Result.set_user_email + vcs + ~repo_root + ~user_email:(Vcs.User_email.v "third@third-user.org") + |> Stdlib.Result.get_ok + in + let rev = + commit_file + vcs + ~repo_root + ~path:hello_file + ~file_contents: + (Vcs.File_contents.create "Hello World!\nWe're adding an even better new line!") + ~commit_message:(Vcs.Commit_message.v "a commit by a third user") + in + show_commit_metadata vcs ~repo_root ~rev; + [%expect {| "Third User " |}]; + () +;; diff --git a/test/expect/user_config.mli b/test/expect/user_config.mli new file mode 100644 index 0000000..45af050 --- /dev/null +++ b/test/expect/user_config.mli @@ -0,0 +1,20 @@ +(*_******************************************************************************) +(*_ Vcs - a Versatile OCaml Library for Git Operations *) +(*_ Copyright (C) 2024 Mathieu Barbin *) +(*_ *) +(*_ This file is part of Vcs. *) +(*_ *) +(*_ Vcs is free software; you can redistribute it and/or modify it under *) +(*_ the terms of the GNU Lesser General Public License as published by the *) +(*_ Free Software Foundation either version 3 of the License, or any later *) +(*_ version, with the LGPL-3.0 Linking Exception. *) +(*_ *) +(*_ Vcs is distributed in the hope that it will be useful, but WITHOUT ANY *) +(*_ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) +(*_ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) +(*_ the file `NOTICE.md` at the root of this repository for more details. *) +(*_ *) +(*_ You should have received a copy of the GNU Lesser General Public License *) +(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *) +(*_ and , respectively. *) +(*_******************************************************************************)