Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/stdlib/absolute_path0.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(*********************************************************************************)
(* Volgo - A Versatile OCaml Library for Git Operations *)
(* SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(* SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*********************************************************************************)

include Absolute_path

let to_dyn t = Dyn.string (Absolute_path.to_string t)
11 changes: 11 additions & 0 deletions src/stdlib/absolute_path0.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(*_********************************************************************************)
(*_ Volgo - A Versatile OCaml Library for Git Operations *)
(*_ SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(*_ SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*_********************************************************************************)

include module type of struct
include Absolute_path
end

val to_dyn : t -> Dyn.t
49 changes: 49 additions & 0 deletions src/stdlib/array0.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
(*********************************************************************************)
(* Volgo - A Versatile OCaml Library for Git Operations *)
(* SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(* SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*********************************************************************************)

include ArrayLabels

let sexp_of_t = Sexplib0.Sexp_conv.sexp_of_array
let create ~len a = make len a

let filter_mapi t ~f =
let out_count = ref 0 in
let out = ref [] in
iteri t ~f:(fun i a ->
match f i a with
| None -> ()
| Some e ->
incr out_count;
out := e :: !out);
match !out with
| [] -> [||]
| hd :: _ ->
let out_count = !out_count in
let res = create ~len:out_count hd in
List.iteri (fun i a -> res.(out_count - 1 - i) <- a) !out;
res
;;

let rev a =
let len = length a in
let res = create ~len a.(0) in
iteri a ~f:(fun i x -> res.(len - 1 - i) <- x);
res
;;

let sort t ~compare = sort t ~cmp:compare

let[@tail_mod_cons] rec to_list_mapi_aux t ~f ~index ~len =
if index >= len
then []
else (
let elt = Array.unsafe_get t index in
(* Coverage is off in the second part of the expression because the
instrumentation breaks [@tail_mod_cons], triggering warning 71. *)
f index elt :: (to_list_mapi_aux t ~f ~index:(index + 1) ~len [@coverage off]))
;;

let to_list_mapi t ~f = to_list_mapi_aux t ~f ~index:0 ~len:(Array.length t)
14 changes: 14 additions & 0 deletions src/stdlib/array0.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(*_********************************************************************************)
(*_ Volgo - A Versatile OCaml Library for Git Operations *)
(*_ SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(*_ SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*_********************************************************************************)

include module type of ArrayLabels

val to_list_mapi : 'a t -> f:(int -> 'a -> 'b) -> 'b list
val sexp_of_t : ('a -> Sexp.t) -> 'a t -> Sexp.t
val create : len:int -> 'a -> 'a array
val filter_mapi : 'a array -> f:(int -> 'a -> 'b option) -> 'b array
val rev : 'a array -> 'a array
val sort : 'a array -> compare:('a -> 'a -> int) -> unit
9 changes: 9 additions & 0 deletions src/stdlib/bool0.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(*********************************************************************************)
(* Volgo - A Versatile OCaml Library for Git Operations *)
(* SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(* SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*********************************************************************************)

include Bool

let to_dyn = Dyn.bool
11 changes: 11 additions & 0 deletions src/stdlib/bool0.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(*_********************************************************************************)
(*_ Volgo - A Versatile OCaml Library for Git Operations *)
(*_ SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(*_ SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*_********************************************************************************)

include module type of struct
include Stdlib.Bool
end

val to_dyn : t -> Dyn.t
17 changes: 17 additions & 0 deletions src/stdlib/char0.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(*********************************************************************************)
(* Volgo - A Versatile OCaml Library for Git Operations *)
(* SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(* SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*********************************************************************************)

include Char

let is_alphanum = function
| 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' -> true
| _ -> false
;;

let is_whitespace = function
| '\t' | '\n' | '\011' (* vertical tab *) | '\012' (* form feed *) | '\r' | ' ' -> true
| _ -> false
;;
10 changes: 10 additions & 0 deletions src/stdlib/char0.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(*_********************************************************************************)
(*_ Volgo - A Versatile OCaml Library for Git Operations *)
(*_ SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(*_ SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*_********************************************************************************)

include module type of Char

val is_alphanum : char -> bool
val is_whitespace : char -> bool
9 changes: 9 additions & 0 deletions src/stdlib/fsegment0.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(*********************************************************************************)
(* Volgo - A Versatile OCaml Library for Git Operations *)
(* SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(* SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*********************************************************************************)

include Fsegment

let to_dyn t = Dyn.string (Fsegment.to_string t)
11 changes: 11 additions & 0 deletions src/stdlib/fsegment0.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(*_********************************************************************************)
(*_ Volgo - A Versatile OCaml Library for Git Operations *)
(*_ SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(*_ SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*_********************************************************************************)

include module type of struct
include Fsegment
end

val to_dyn : t -> Dyn.t
59 changes: 59 additions & 0 deletions src/stdlib/hashtbl0.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
(*********************************************************************************)
(* Volgo - A Versatile OCaml Library for Git Operations *)
(* SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(* SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*********************************************************************************)

include (
MoreLabels.Hashtbl :
module type of MoreLabels.Hashtbl with module Make := MoreLabels.Hashtbl.Make)

module type S_extended = sig
include MoreLabels.Hashtbl.S

val add_exn : 'a t -> key:key -> data:'a -> unit
val add_multi : 'a list t -> key:key -> data:'a -> unit
val find : 'a t -> key -> 'a option
val set : 'a t -> key:key -> data:'a -> unit
end

exception E of Sexp.t

let () =
Sexplib0.Sexp_conv.Exn_converter.add [%extension_constructor E] (function
| E sexp -> sexp
| _ -> assert false)
;;

module Make (H : sig
include Hashtbl.HashedType

val sexp_of_t : t -> Sexp.t
end) =
struct
include MoreLabels.Hashtbl.Make (H)

let add_exn t ~key ~data =
if mem t key
then
raise
(E
(List
[ Atom "Hashtbl.add_exn: key already present"
; Sexp.List [ Atom "key"; H.sexp_of_t key ]
]))
else add t ~key ~data
;;

let add_multi t ~key ~data =
let data =
match find_opt t key with
| None -> [ data ]
| Some l -> data :: l
in
replace t ~key ~data
;;

let find = find_opt
let set = replace
end
22 changes: 22 additions & 0 deletions src/stdlib/hashtbl0.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(*_********************************************************************************)
(*_ Volgo - A Versatile OCaml Library for Git Operations *)
(*_ SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(*_ SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*_********************************************************************************)

include module type of MoreLabels.Hashtbl with module Make := MoreLabels.Hashtbl.Make

module type S_extended = sig
include MoreLabels.Hashtbl.S

val add_exn : 'a t -> key:key -> data:'a -> unit
val add_multi : 'a list t -> key:key -> data:'a -> unit
val find : 'a t -> key -> 'a option
val set : 'a t -> key:key -> data:'a -> unit
end

module Make (H : sig
include Hashtbl.HashedType

val sexp_of_t : t -> Sexp.t
end) : S_extended with type key = H.t
42 changes: 42 additions & 0 deletions src/stdlib/int0.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(*********************************************************************************)
(* Volgo - A Versatile OCaml Library for Git Operations *)
(* SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(* SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*********************************************************************************)

open! Stdlib_compat
include Int

let incr = incr
let max_value = max_int
let of_string_opt = int_of_string_opt

let to_string_hum n =
let s = string_of_int n in
let len = String.length s in
let is_negative = n < 0 in
let sign_count = if is_negative then 1 else 0 in
let absolute_digit_count = if is_negative then len - 1 else len in
let separator_count = absolute_digit_count / 3 in
let initial_skip_count =
let digit_skip = absolute_digit_count mod 3 in
sign_count + if digit_skip > 0 then digit_skip else 3
in
let buffer = Buffer.create (len + separator_count) in
let rec aux i count =
if i < len
then
if count = 0
then (
Buffer.add_char buffer '_';
aux i 3)
else (
Buffer.add_char buffer s.[i];
aux (i + 1) (count - 1))
in
aux 0 initial_skip_count;
Buffer.contents buffer
;;

let to_dyn t = Dyn.Int t
let sexp_of_t t = Sexp.Atom (to_string_hum t)
15 changes: 15 additions & 0 deletions src/stdlib/int0.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(*_********************************************************************************)
(*_ Volgo - A Versatile OCaml Library for Git Operations *)
(*_ SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(*_ SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*_********************************************************************************)

open! Stdlib_compat
include module type of Int

val sexp_of_t : t -> Sexp.t
val to_dyn : t -> Dyn.t
val incr : int ref -> unit
val max_value : int
val of_string_opt : string -> int option
val to_string_hum : int -> string
27 changes: 27 additions & 0 deletions src/stdlib/list0.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(*********************************************************************************)
(* Volgo - A Versatile OCaml Library for Git Operations *)
(* SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(* SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*********************************************************************************)

open! Stdlib_compat
include ListLabels

let sexp_of_t = Sexplib0.Sexp_conv.sexp_of_list
let concat_map t ~f = concat_map ~f t
let dedup_and_sort t ~compare = sort_uniq t ~cmp:compare

let hd = function
| [] -> None
| hd :: _ -> Some hd
;;

let filter_opt t = filter_map t ~f:Fun.id
let find t ~f = find_opt t ~f
let find_map t ~f = find_map ~f t
let fold t ~init ~f = fold_left ~f ~init t
let iter t ~f = iter t ~f
let map t ~f = map ~f t
let mapi t ~f = mapi ~f t
let sort t ~compare = sort t ~cmp:compare
let count t ~f = fold t ~init:0 ~f:(fun acc e -> acc + if f e then 1 else 0)
22 changes: 22 additions & 0 deletions src/stdlib/list0.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(*_********************************************************************************)
(*_ Volgo - A Versatile OCaml Library for Git Operations *)
(*_ SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(*_ SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*_********************************************************************************)

open! Stdlib_compat
include module type of ListLabels

val sexp_of_t : ('a -> Sexp.t) -> 'a t -> Sexp.t
val concat_map : 'a list -> f:('a -> 'b list) -> 'b list
val count : 'a list -> f:('a -> bool) -> int
val dedup_and_sort : 'a list -> compare:('a -> 'a -> int) -> 'a list
val filter_opt : 'a option list -> 'a list
val find : 'a list -> f:('a -> bool) -> 'a option
val find_map : 'a list -> f:('a -> 'b option) -> 'b option
val fold : 'a list -> init:'b -> f:('b -> 'a -> 'b) -> 'b
val hd : 'a list -> 'a option
val iter : 'a list -> f:('a -> unit) -> unit
val map : 'a list -> f:('a -> 'b) -> 'b list
val mapi : 'a list -> f:(int -> 'a -> 'b) -> 'b list
val sort : 'a list -> compare:('a -> 'a -> int) -> 'a list
12 changes: 12 additions & 0 deletions src/stdlib/option0.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(*********************************************************************************)
(* Volgo - A Versatile OCaml Library for Git Operations *)
(* SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(* SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*********************************************************************************)

include Option

let sexp_of_t = Sexplib0.Sexp_conv.sexp_of_option
let iter t ~f = iter f t
let map t ~f = map f t
let some_if cond a = if cond then Some a else None
12 changes: 12 additions & 0 deletions src/stdlib/option0.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(*_********************************************************************************)
(*_ Volgo - A Versatile OCaml Library for Git Operations *)
(*_ SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(*_ SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*_********************************************************************************)

include module type of Option

val sexp_of_t : ('a -> Sexp.t) -> 'a t -> Sexp.t
val iter : 'a t -> f:('a -> unit) -> unit
val map : 'a option -> f:('a -> 'b) -> 'b option
val some_if : bool -> 'a -> 'a option
13 changes: 13 additions & 0 deletions src/stdlib/ordering0.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(*********************************************************************************)
(* Volgo - A Versatile OCaml Library for Git Operations *)
(* SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(* SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *)
(*********************************************************************************)

include Ordering

let to_dyn = function
| Lt -> Dyn.Variant ("Lt", [])
| Eq -> Dyn.Variant ("Eq", [])
| Gt -> Dyn.Variant ("Gt", [])
;;
Loading