Skip to content

Commit

Permalink
Start populating Vcs_base
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbin committed Oct 20, 2024
1 parent 06f5dd5 commit e624da9
Show file tree
Hide file tree
Showing 114 changed files with 2,269 additions and 328 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
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: 1 addition & 8 deletions lib/vcs/src/author.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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))
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
10 changes: 1 addition & 9 deletions lib/vcs/src/branch_name.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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))
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: 1 addition & 8 deletions lib/vcs/src/commit_message.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

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)))
9 changes: 1 addition & 8 deletions lib/vcs/src/file_contents.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
52 changes: 38 additions & 14 deletions lib/vcs/src/graph.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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)
Loading

0 comments on commit e624da9

Please sign in to comment.