Skip to content

Commit

Permalink
Merge pull request #31 from mbarbin/init-base-refactor
Browse files Browse the repository at this point in the history
Initialize vcs-base refactor
  • Loading branch information
mbarbin authored Oct 20, 2024
2 parents 1dba267 + 81b03dd commit 4cbb832
Show file tree
Hide file tree
Showing 196 changed files with 5,123 additions and 315 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
57 changes: 57 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion example/hello_blocking.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions headache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 2 additions & 7 deletions lib/vcs/src/author.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@
(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
(*******************************************************************************)

module T = struct
[@@@coverage off]

type t = string [@@deriving compare, equal, hash, sexp_of]
end

include T
open! Import
include Container_key.String_impl

let invariant t =
(not (String.is_empty t))
Expand Down
3 changes: 2 additions & 1 deletion lib/vcs/src/author.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
For example: [Author.v "John Doe <[email protected]>"]. *)

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
2 changes: 2 additions & 0 deletions lib/vcs/src/bit_vector.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
(*******************************************************************************)

open! Import

type t = bool array

let sexp_of_t t =
Expand Down
10 changes: 2 additions & 8 deletions lib/vcs/src/branch_name.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@
(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
(*******************************************************************************)

module T = struct
[@@@coverage off]

type t = string [@@deriving compare, hash, sexp_of]
end

include T
include Comparable.Make (T)
open! Import
include Container_key.String_impl

let invariant t =
(not (String.is_empty t))
Expand Down
4 changes: 2 additions & 2 deletions lib/vcs/src/branch_name.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
(*_ <http://www.gnu.org/licenses/> and <https://spdx.org>, 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} *)
Expand Down
9 changes: 2 additions & 7 deletions lib/vcs/src/commit_message.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@
(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
(*******************************************************************************)

module T = struct
[@@@coverage off]

type t = string [@@deriving compare, equal, hash, sexp_of]
end

include T
open! Import
include Container_key.String_impl

let invariant t = (not (String.is_empty t)) && String.length t <= 512

Expand Down
3 changes: 2 additions & 1 deletion lib/vcs/src/commit_message.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 42 additions & 0 deletions lib/vcs/src/container_key.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(*******************************************************************************)
(* Vcs - a Versatile OCaml Library for Git Operations *)
(* Copyright (C) 2024 Mathieu Barbin <[email protected]> *)
(* *)
(* 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 *)
(* <http://www.gnu.org/licenses/> and <https://spdx.org>, 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
32 changes: 32 additions & 0 deletions lib/vcs/src/container_key.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(*_******************************************************************************)
(*_ Vcs - a Versatile OCaml Library for Git Operations *)
(*_ Copyright (C) 2024 Mathieu Barbin <[email protected]> *)
(*_ *)
(*_ 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 *)
(*_ <http://www.gnu.org/licenses/> and <https://spdx.org>, 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
6 changes: 1 addition & 5 deletions lib/vcs/src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))
2 changes: 2 additions & 0 deletions lib/vcs/src/err.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
(*******************************************************************************)

open! Import

type t =
{ steps : Info.t list
; error : Error.t
Expand Down
9 changes: 2 additions & 7 deletions lib/vcs/src/file_contents.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@
(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
(*******************************************************************************)

module T = struct
[@@@coverage off]

type t = string [@@deriving compare, equal, hash, sexp_of]
end

include T
open! Import
include Container_key.String_impl

let create t = t
let to_string t = t
4 changes: 3 additions & 1 deletion lib/vcs/src/file_contents.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions lib/vcs/src/for_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]")
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 "[email protected]");
repo_root
;;
5 changes: 1 addition & 4 deletions lib/vcs/src/for_test.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 4cbb832

Please sign in to comment.