@@ -159,37 +159,41 @@ let do_promote db files_to_promote =
159159 match files_to_promote with
160160 | Dune_rpc_private.Files_to_promote. All ->
161161 Path.Source.Map. iteri by_targets ~f: promote_one;
162- []
163- | These ( files , on_missing ) ->
164- let by_targets =
162+ [] , []
163+ | These files ->
164+ let by_targets, missing =
165165 let files = Path.Source.Set. of_list files in
166- Path.Source.Set. fold files ~init: by_targets ~f: (fun fn map ->
167- match Path.Source.Map. find by_targets fn with
168- | None ->
169- on_missing fn;
170- map
166+ Path.Source.Set. fold files ~init: (by_targets, [] ) ~f: (fun fn (map , missing ) ->
167+ match Path.Source.Map. find map fn with
168+ | None -> map, fn :: missing
171169 | Some srcs ->
172170 promote_one fn srcs;
173- Path.Source.Map. remove by_targets fn)
171+ Path.Source.Map. remove map fn, missing )
174172 in
175- Path.Source.Map. to_list by_targets
176- |> List. concat_map ~f: (fun (dst , srcs ) ->
177- List. map srcs ~f: (fun (src , staging ) -> { File. src; staging; dst }))
173+ ( Path.Source.Map. to_list by_targets
174+ |> List. concat_map ~f: (fun (dst , srcs ) ->
175+ List. map srcs ~f: (fun (src , staging ) -> { File. src; staging; dst }))
176+ , missing )
178177;;
179178
180179let finalize () =
181180 let db =
182181 match ! Dune_engine.Clflags. promote with
183- | Some Automatically -> do_promote ! File. db All
182+ | Some Automatically ->
183+ let _is_necessarily_empty = do_promote ! File. db All in
184+ []
184185 | Some Never | None -> ! File. db
185186 in
186187 dump_db db
187188;;
188189
190+ (* Returns the list of files that were in [files_to_promote]
191+ but not present in the promotion database. *)
189192let promote_files_registered_in_last_run files_to_promote =
190193 let db = load_db () in
191- let db = do_promote db files_to_promote in
192- dump_db db
194+ let remaining, missing = do_promote db files_to_promote in
195+ dump_db remaining;
196+ missing
193197;;
194198
195199let diff_for_file (file : File.t ) =
@@ -199,28 +203,50 @@ let diff_for_file (file : File.t) =
199203 Print_diff. get msg original correction
200204;;
201205
202- let filter_db files_to_promote db =
206+ (* * [partition_db files_to_promote db] splits [files_to_promote] into two lists
207+ - The files present in [db] as actual [File.t]s.
208+ - The files absent from [db] as [Path]s. *)
209+ let partition_db files_to_promote db =
203210 match files_to_promote with
204- | Dune_rpc_private.Files_to_promote. All -> db
205- | These (files , on_missing ) ->
206- List. filter_map files ~f: (fun file ->
207- let r = List. find db ~f: (fun (f : File.t ) -> Path.Source. equal f.dst file) in
208- if Option. is_none r then on_missing file;
209- r)
211+ | Dune_rpc_private.Files_to_promote. All -> db, []
212+ | These paths ->
213+ List. partition_map paths ~f: (fun path ->
214+ let res = List. find db ~f: (fun (f : File.t ) -> Path.Source. equal f.dst path) in
215+ match res with
216+ | Some file -> Left file
217+ | None -> Right path)
210218;;
211219
212- let display files_to_promote =
220+ let sort_for_display files_to_promote =
213221 let open Fiber.O in
214- let files = load_db () |> filter_db files_to_promote in
222+ let files, missing = load_db () |> partition_db files_to_promote in
215223 let + diff_opts =
216224 Fiber. parallel_map files ~f: (fun file ->
217225 let + diff_opt = diff_for_file file in
218226 match diff_opt with
219227 | Ok diff -> Some (file, diff)
220228 | Error _ -> None )
221229 in
222- diff_opts
223- |> List. filter_opt
224- |> List. sort ~compare: (fun (file , _ ) (file' , _ ) -> File. compare file file')
225- |> List. iter ~f: (fun (_file , diff ) -> Print_diff.Diff. print diff)
230+ let sorted_diffs =
231+ diff_opts
232+ |> List. filter_opt
233+ |> List. sort ~compare: (fun (file , _ ) (file' , _ ) -> File. compare file file')
234+ in
235+ let sorted_missing = List. sort missing ~compare: Path.Source. compare in
236+ sorted_diffs, sorted_missing
237+ ;;
238+
239+ let display_diffs ~on_missing files_to_promote =
240+ let open Fiber.O in
241+ let + diffs, missing = sort_for_display files_to_promote in
242+ List. iter missing ~f: on_missing;
243+ List. iter diffs ~f: (fun (_file , diff ) -> Print_diff.Diff. print diff)
244+ ;;
245+
246+ let display_files ~on_missing files_to_promote =
247+ let open Fiber.O in
248+ let + diffs, missing = sort_for_display files_to_promote in
249+ List. iter missing ~f: on_missing;
250+ List. iter diffs ~f: (fun (file , _diff ) ->
251+ Console. printf " %s" (File. source file |> Path.Source. to_string))
226252;;
0 commit comments