Persistent store with Git semantics: lazy reads, delayed writes, content-addressing
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Apply ocamlformat fixes in irmin/

Mechanical formatting changes from dune fmt.

+38 -41
+18 -15
lib/backend.ml
··· 168 168 mutable refs : 'hash String_map.t; 169 169 } 170 170 171 - module Memory (H : HASH) : S with type hash = H.t and type t = H.t mem_state = 172 - struct 171 + module Memory_of (H : HASH) : 172 + S with type hash = H.t and type t = H.t mem_state = struct 173 173 type hash = H.t 174 174 type t = hash mem_state 175 175 ··· 207 207 208 208 let empty_mem_state () = { objects = String_map.empty; refs = String_map.empty } 209 209 210 - let memory (type h) (to_hex : h -> string) (equal : h -> h -> bool) : h t = 210 + let pack_memory (type h) (to_hex : h -> string) (equal : h -> h -> bool) : h t = 211 211 let module H = struct 212 212 type t = h 213 213 214 214 let to_hex = to_hex 215 215 let equal = equal 216 216 end in 217 - let module B = Memory (H) in 217 + let module B = Memory_of (H) in 218 218 let module P = Make (B) in 219 219 P.v (empty_mem_state ()) 220 220 221 - let memory_sha1 () = memory Hash.to_hex Hash.equal 222 - let memory_sha256 () = memory Hash.to_hex Hash.equal 223 - let memory_cid () = memory Atp.Cid.to_string Atp.Cid.equal 221 + module Memory = struct 222 + let sha1 () = pack_memory Hash.to_hex Hash.equal 223 + let sha256 () = pack_memory Hash.to_hex Hash.equal 224 + let cid () = pack_memory Atp.Cid.to_string Atp.Cid.equal 225 + end 224 226 225 227 (* ===== Disk backend ===== *) 228 + 229 + module Pack = Make 226 230 227 231 module Disk = struct 228 232 module String_map = Map.Make (String) ··· 508 512 s.data_file <- None) 509 513 end 510 514 511 - let create_with_hash (type h) ~sw (root : Eio.Fs.dir_ty Eio.Path.t) 515 + let pack_disk (type h) ~sw (root : Eio.Fs.dir_ty Eio.Path.t) 512 516 (to_hex : h -> string) (of_hex : string -> (h, [ `Msg of string ]) result) 513 517 (equal : h -> h -> bool) : h t = 514 518 if not (Eio.Path.is_directory root) then ··· 529 533 let equal = equal 530 534 end in 531 535 let module B = Make (H) in 532 - let module P = Make (B) in 536 + let module P = Pack (B) in 533 537 P.v 534 538 { 535 539 root; ··· 544 548 mutex = Eio.Mutex.create (); 545 549 } 546 550 547 - let create_sha1 ~sw root = 548 - create_with_hash ~sw root Hash.to_hex Hash.sha1_of_hex Hash.equal 551 + let sha1 ~sw root = pack_disk ~sw root Hash.to_hex Hash.sha1_of_hex Hash.equal 549 552 550 - let create_sha256 ~sw root = 551 - create_with_hash ~sw root Hash.to_hex Hash.sha256_of_hex Hash.equal 553 + let sha256 ~sw root = 554 + pack_disk ~sw root Hash.to_hex Hash.sha256_of_hex Hash.equal 552 555 553 - let create_cid ~sw root = 554 - create_with_hash ~sw root Atp.Cid.to_string 556 + let cid ~sw root = 557 + pack_disk ~sw root Atp.Cid.to_string 555 558 (fun s -> 556 559 try Ok (Atp.Cid.of_string s) 557 560 with exn ->
+20 -26
lib/backend.mli
··· 2 2 3 3 (** {1 Backend Interface} *) 4 4 5 + module type HASH = sig 6 + type t 7 + 8 + val to_hex : t -> string 9 + val equal : t -> t -> bool 10 + end 11 + 5 12 module type S = sig 6 13 type t 7 14 type hash ··· 20 27 val flush : t -> unit 21 28 val close : t -> unit 22 29 end 30 + 31 + (** {1 Packed Backend} *) 23 32 24 33 type 'hash t 25 - (** A packed storage backend. *) 34 + (** An abstract storage backend. *) 26 35 27 36 module Make (B : S) : sig 28 37 val v : B.t -> B.hash t ··· 39 48 val flush : 'h t -> unit 40 49 val close : 'h t -> unit 41 50 42 - (** {1 Combinator Functors} 43 - 44 - Compose at the module level, then pack with {!Make}: 45 - {[ 46 - module My_backend = Backend.Cached (Backend.Disk.Impl (...)) 47 - module P = Backend.Make (My_backend) 48 - let backend = P.v state 49 - ]} *) 51 + (** {1 Combinator Functors} *) 50 52 51 53 module Cached (B : S) : S with type hash = B.hash 52 54 module Readonly (B : S) : S with type t = B.t and type hash = B.hash ··· 56 58 57 59 (** {1 Memory Backend} *) 58 60 61 + module Memory_of (H : HASH) : S with type hash = H.t 62 + 59 63 module Memory : sig 60 - val create_with_hash : ('h -> string) -> ('h -> 'h -> bool) -> 'h t 61 - val create_sha1 : unit -> Hash.sha1 t 62 - val create_sha256 : unit -> Hash.sha256 t 63 - val create_cid : unit -> Atp.Cid.t t 64 + val sha1 : unit -> Hash.sha1 t 65 + val sha256 : unit -> Hash.sha256 t 66 + val cid : unit -> Atp.Cid.t t 64 67 end 65 68 66 69 (** {1 Disk Backend} *) 67 70 68 71 module Disk : sig 69 - val create_with_hash : 70 - sw:Eio.Switch.t -> 71 - Eio.Fs.dir_ty Eio.Path.t -> 72 - ('h -> string) -> 73 - (string -> ('h, [ `Msg of string ]) result) -> 74 - ('h -> 'h -> bool) -> 75 - 'h t 72 + module Make (H : HASH) : S with type hash = H.t 76 73 77 - val create_sha1 : sw:Eio.Switch.t -> Eio.Fs.dir_ty Eio.Path.t -> Hash.sha1 t 78 - 79 - val create_sha256 : 80 - sw:Eio.Switch.t -> Eio.Fs.dir_ty Eio.Path.t -> Hash.sha256 t 81 - 82 - val create_cid : sw:Eio.Switch.t -> Eio.Fs.dir_ty Eio.Path.t -> Atp.Cid.t t 74 + val sha1 : sw:Eio.Switch.t -> Eio.Fs.dir_ty Eio.Path.t -> Hash.sha1 t 75 + val sha256 : sw:Eio.Switch.t -> Eio.Fs.dir_ty Eio.Path.t -> Hash.sha256 t 76 + val cid : sw:Eio.Switch.t -> Eio.Fs.dir_ty Eio.Path.t -> Atp.Cid.t t 83 77 end 84 78 85 79 (** {1 Statistics} *)