@@ -6,6 +6,8 @@ open Cosmetrics_utils
6
6
module Store = Git_unix. FS
7
7
module G = Git_unix.Sync. Make (Store )
8
8
9
+ let openfile_pool = Lwt_pool. create 100 (fun () -> return_unit)
10
+
9
11
let read_commit_exn t sha =
10
12
Store. read_exn t (Git.SHA. of_commit sha) >> = fun v ->
11
13
match v with
@@ -70,20 +72,23 @@ module Cache = struct
70
72
if version <> t.version || newer_dep then (
71
73
Lwt_io. close fh >> = fun () ->
72
74
log t " Update cache %s\n " t.fname >> = fun () ->
73
- update t
75
+ update t (* previous handle closed, thus only 1 in use *)
74
76
)
75
77
else (
76
78
Lwt_io. read_value fh >> = fun v ->
77
79
Lwt_io. close fh > |= fun () ->
78
80
v
79
81
)
80
82
83
+ let read_exn_pool t () =
84
+ Lwt_pool. use openfile_pool (read_exn t)
85
+
81
86
let read t =
82
- catch (read_exn t)
87
+ catch (read_exn_pool t)
83
88
(function Unix. Unix_error (Unix. ENOENT, _ , _ ) ->
84
89
(* Cache does not exist, create one *)
85
90
log t " Create cache %s\n " t.fname >> = fun () ->
86
- update t
91
+ Lwt_pool. use openfile_pool ( fun () -> update t)
87
92
| e -> fail e)
88
93
89
94
let default_log s =
@@ -344,7 +349,7 @@ module Tag = struct
344
349
name = String. sub s 10 (String. length s - 10 );
345
350
date = Calendar. from_unixfloat (Int64. to_float t) }
346
351
347
- let get_ref t r =
352
+ let get_ref t r () =
348
353
if String. starting ~w: " refs/tags/" (Git.Reference. to_raw r) then
349
354
Store. read_reference_exn t r >> = fun sha ->
350
355
Store. read_exn t (Git.SHA. of_commit sha) > |= fun v ->
@@ -358,13 +363,17 @@ module Tag = struct
358
363
| Git.Value. Blob _ | Git.Value. Tree _ -> None
359
364
else return_none
360
365
366
+ (* Like [get_ref] but wait if too many files are already opened. *)
367
+ let get_ref_pool t r =
368
+ Lwt_pool. use openfile_pool (get_ref t r)
369
+
361
370
let get t =
362
371
Store. references t >> = fun r ->
363
372
(* Because of the bug https://github.com/mirage/ocaml-git/issues/124
364
373
remove possible duplicates in the list. *)
365
374
let r = List. sort Git.Reference. compare r in
366
375
let r = List. remove_consecutive_duplicates Git.Reference. equal r in
367
- Lwt_list. filter_map_p (get_ref t) r
376
+ Lwt_list. filter_map_p (get_ref_pool t) r
368
377
end
369
378
370
379
0 commit comments