Skip to content

Commit

Permalink
Merge pull request #2227 from samoht/conf
Browse files Browse the repository at this point in the history
Add Conf.pp and Conf.equal
  • Loading branch information
samoht committed Mar 28, 2023
2 parents 850dc4e + 1cfacce commit bc35f04
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
8 changes: 6 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### Added

- **irmin**
- Add `Conf.pp` and `Conf.equal` to print and compare configuration values
(#2227, @samoht)

- **irmin-pack**
- Add configuration option, `lower_root`, to specify a path for archiving data
during a GC. (#2177, @metanivek)
Expand Down Expand Up @@ -33,7 +37,7 @@
- Unhandled exceptions in GC worker process are now reported as a failure
(#2163, @metanivek)
- Fix the silent mode for the integrity checks. (#2179, @icristescu)

## 3.6.1 (2023-03-15)

### Fixed
Expand All @@ -47,7 +51,7 @@

- **irmin-pack**
- Clear LRU when calling `reload` after a GC (#2200, @metanivek)

## 3.6.0 (2023-02-16)

### Changed
Expand Down
19 changes: 19 additions & 0 deletions src/irmin/conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)
open! Import

module Univ = struct
type t = exn
Expand Down Expand Up @@ -141,6 +142,24 @@ let get (_, d) k =
let keys (_, conf) = M.to_seq conf |> Seq.map (fun (k, _) -> k)
let with_spec (_, conf) spec = (spec, conf)

let to_strings (_, conf) =
conf
|> M.to_seq
|> Seq.map (fun (K k, v) ->
( k.name,
match k.of_univ v with
| Some v -> Type.to_string k.ty v
| None -> assert false ))

let pp ppf t =
t |> to_strings |> List.of_seq |> Fmt.Dump.(list (pair string string)) ppf

let equal t1 t2 =
t1 == t2
|| Seq.for_all2
(fun (k1, v1) (k2, v2) -> String.equal k1 k2 && String.equal v1 v2)
(to_strings t1) (to_strings t2)

(* ~root *)
let root spec =
key ~spec ~docv:"ROOT" ~doc:"The location of the Irmin store on disk."
Expand Down
7 changes: 7 additions & 0 deletions src/irmin/conf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ val root : Spec.t -> string key
type t
(** The type for configurations. *)

val pp : t Fmt.t
(** [pp] is the pretty printer for configuration values. *)

val equal : t -> t -> bool
(** [equal] is the equality for configuration values. Two values are equal if
they have the same [pp] representation. *)

val spec : t -> Spec.t
(** [spec c] is the specification associated with [c] *)

Expand Down
9 changes: 9 additions & 0 deletions src/irmin/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ module Seq = struct
match seq1 () with
| Nil -> seq2 ()
| Cons (x, next) -> Cons (x, append next seq2)

(* Since 4.14 *)
let rec for_all2 f xs ys =
match xs () with
| Nil -> true
| Cons (x, xs) -> (
match ys () with
| Nil -> true
| Cons (y, ys) -> f x y && for_all2 f xs ys)
end

let shuffle state arr =
Expand Down

0 comments on commit bc35f04

Please sign in to comment.