Skip to content

Commit 002e2f7

Browse files
authored
refactor(promote): move missing file handling to the command line (#13480)
Signed-off-by: Rudi Grinberg <[email protected]>
1 parent b4de6e5 commit 002e2f7

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

bin/promotion.ml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ let files_to_promote ~common files : Dune_rpc.Files_to_promote.t =
1111
These files
1212
;;
1313

14-
let on_missing fn =
15-
User_warning.emit
16-
[ Pp.paragraphf "Nothing to promote for %s." (Path.Source.to_string_maybe_quoted fn)
17-
|> Pp.tag User_message.Style.Warning
18-
]
14+
let on_missing missing =
15+
List.sort missing ~compare:Path.Source.compare
16+
|> List.iter ~f:(fun fn ->
17+
User_warning.emit
18+
[ Pp.paragraphf "Nothing to promote for %s." (Path.Source.to_string_maybe_quoted fn)
19+
|> Pp.tag User_message.Style.Warning
20+
])
1921
;;
2022

2123
module Apply = struct
@@ -51,10 +53,7 @@ module Apply = struct
5153
Scheduler_setup.go_without_rpc_server ~common ~config (fun () ->
5254
let open Fiber.O in
5355
let+ () = Fiber.return () in
54-
let missing =
55-
Diff_promotion.promote_files_registered_in_last_run files_to_promote
56-
in
57-
List.iter ~f:on_missing missing)
56+
Diff_promotion.promote_files_registered_in_last_run files_to_promote |> on_missing)
5857
| Error lock_held_by ->
5958
Scheduler_setup.no_build_no_rpc ~config (fun () ->
6059
let open Fiber.O in
@@ -84,11 +83,11 @@ module Diff = struct
8483
let files_to_promote = files_to_promote ~common files in
8584
(* CR-soon rgrinberg: remove pointless args *)
8685
Scheduler_setup.no_build_no_rpc ~config (fun () ->
87-
let open Fiber.O in
8886
let db = Diff_promotion.load_db () in
89-
let all = Diff_promotion.partition_db db files_to_promote in
90-
let* missing = Diff_promotion.missing all in
91-
List.iter ~f:on_missing missing;
87+
let ({ Diff_promotion.present = _; missing } as all) =
88+
Diff_promotion.partition_db db files_to_promote
89+
in
90+
on_missing missing;
9291
Diff_promotion.display_diffs all)
9392
;;
9493

@@ -112,8 +111,7 @@ module Files = struct
112111
let { Diff_promotion.present; missing } =
113112
Diff_promotion.partition_db db files_to_promote
114113
in
115-
let missing = List.sort missing ~compare:Path.Source.compare in
116-
List.iter ~f:on_missing missing;
114+
on_missing missing;
117115
List.sort present ~compare:(fun x y ->
118116
Path.Source.compare (Diff_promotion.File.source x) (Diff_promotion.File.source y))
119117
|> List.iter ~f:(fun file ->
@@ -153,11 +151,13 @@ module Show = struct
153151
let files_to_promote = files_to_promote ~common files in
154152
(* CR-soon rgrinberg: remove pointless args *)
155153
Scheduler_setup.no_build_no_rpc ~config (fun () ->
156-
let open Fiber.O in
157154
let db = Diff_promotion.load_db () in
158-
let all = Diff_promotion.partition_db db files_to_promote in
159-
let+ () = Diff_promotion.missing all >>| List.iter ~f:on_missing in
160-
display_corrected_contents db files_to_promote)
155+
let { Diff_promotion.present = _; missing } =
156+
Diff_promotion.partition_db db files_to_promote
157+
in
158+
on_missing missing;
159+
display_corrected_contents db files_to_promote;
160+
Fiber.return ())
161161
;;
162162

163163
let command = Cmd.v info term

src/dune_engine/diff_promotion.ml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,6 @@ let sort_for_display { present; missing } =
270270
sorted_diffs, sorted_missing
271271
;;
272272

273-
let missing all =
274-
let open Fiber.O in
275-
let+ _diffs, missing = sort_for_display all in
276-
missing
277-
;;
278-
279273
let display_diffs all =
280274
let open Fiber.O in
281275
let+ diffs, _missing = sort_for_display all in

src/dune_engine/diff_promotion.mli

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ type all =
5151
val partition_db : db -> Files_to_promote.t -> all
5252
val promote_files_registered_in_last_run : Files_to_promote.t -> Path.Source.t list
5353

54-
(** [missing db files] returns the list of files in [files] but not in [db]. *)
55-
val missing : all -> Path.Source.t list Fiber.t
56-
5754
(** [display_diffs db files] will only print the diffs of files that are both
5855
in [files] and in [db]. *)
5956
val display_diffs : all -> unit Fiber.t

0 commit comments

Comments
 (0)