Skip to content

Commit c87bde9

Browse files
authored
ocaml: format using make format with ocamlformat 0.28.1 (#6831)
We're changing the formatting of the ifs because of a bug in ocamlformat, but otherwise the changes to jump to the newest version are needed anyway
2 parents d516d10 + 7e207d2 commit c87bde9

File tree

411 files changed

+7349
-4930
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

411 files changed

+7349
-4930
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ b12cf444edea15da6274975e1b2ca6a7fce2a090
3434
d8b4de9076531dd13bdffa20cc10c72290a52356
3535
bdf06bca7534fbc0c4fc3cee3408a51a22615226
3636
eefc649e17086fbc200e4da114ea673825e79864
37+
eb801de661df21e5f4837db12e9c4a90198f7136
3738

3839
# ocp-indent
3940
d018d26d6acd4707a23288b327b49e44f732725e

.ocamlformat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
profile=ocamlformat
22
indicate-multiline-delimiters=closing-on-separate-line
3-
if-then-else=fit-or-vertical
3+
if-then-else=k-r
44
dock-collection-brackets=true
55
break-struct=natural
66
break-separators=before

ocaml/alerts/certificate/certificate_check.ml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ let get_expiry = function
6868
let alert rpc session_id =
6969
get_certificates rpc session_id
7070
|> List.map (fun cert ->
71-
let cls, obj_uuid =
72-
alert_message_cls_and_obj_uuid rpc session_id cert
73-
in
74-
let obj_description = certificate_description cert in
75-
let alert_conditions = alert_conditions cert in
76-
let expiry = get_expiry cert in
77-
Expiry_alert.{cls; obj_uuid; obj_description; alert_conditions; expiry}
78-
)
71+
let cls, obj_uuid = alert_message_cls_and_obj_uuid rpc session_id cert in
72+
let obj_description = certificate_description cert in
73+
let alert_conditions = alert_conditions cert in
74+
let expiry = get_expiry cert in
75+
Expiry_alert.{cls; obj_uuid; obj_description; alert_conditions; expiry}
76+
)
7977
|> Expiry_alert.alert ~rpc ~session_id
8078

8179
let maybe_generate_alert = Expiry_alert.maybe_generate_alert

ocaml/alerts/expiry_alert.ml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ let filter_messages msg_name_list msg_obj_uuid alert all_msgs =
7777
let msg_body, (msg_name, msg_prio) = alert in
7878
all_msgs
7979
|> List.filter (fun (_ref, record) ->
80-
record.API.message_obj_uuid = msg_obj_uuid
81-
&& List.mem record.API.message_name msg_name_list
82-
)
80+
record.API.message_obj_uuid = msg_obj_uuid
81+
&& List.mem record.API.message_name msg_name_list
82+
)
8383
|> List.partition (fun (_ref, record) ->
84-
record.API.message_body <> msg_body
85-
|| record.API.message_name <> msg_name
86-
|| record.API.message_priority <> msg_prio
87-
)
84+
record.API.message_body <> msg_body
85+
|| record.API.message_name <> msg_name
86+
|| record.API.message_priority <> msg_prio
87+
)
8888

8989
let alert ~rpc ~session_id raw_alerts =
9090
let now = Clock.Date.now () in
@@ -93,20 +93,20 @@ let alert ~rpc ~session_id raw_alerts =
9393
(fun {cls; obj_uuid; obj_description; alert_conditions; expiry} ->
9494
maybe_generate_alert now obj_description alert_conditions expiry
9595
|> Option.map (fun alert ->
96-
let msg_name_list =
97-
List.map (fun (_, (msg_name, _)) -> msg_name) alert_conditions
98-
in
99-
all_msgs |> filter_messages msg_name_list obj_uuid alert
100-
|> fun (outdated, current) ->
101-
List.iter
102-
(fun (self, _) -> XenAPI.Message.destroy ~rpc ~session_id ~self)
103-
outdated ;
104-
if current = [] then
105-
let body, (name, priority) = alert in
106-
XenAPI.Message.create ~rpc ~session_id ~name ~priority ~cls
107-
~obj_uuid ~body
108-
|> ignore
109-
)
96+
let msg_name_list =
97+
List.map (fun (_, (msg_name, _)) -> msg_name) alert_conditions
98+
in
99+
all_msgs |> filter_messages msg_name_list obj_uuid alert
100+
|> fun (outdated, current) ->
101+
List.iter
102+
(fun (self, _) -> XenAPI.Message.destroy ~rpc ~session_id ~self)
103+
outdated ;
104+
if current = [] then
105+
let body, (name, priority) = alert in
106+
XenAPI.Message.create ~rpc ~session_id ~name ~priority ~cls
107+
~obj_uuid ~body
108+
|> ignore
109+
)
110110
|> ignore
111111
)
112112
raw_alerts

ocaml/cdrommon/cdrommon.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ let check interval name =
4040
| _ ->
4141
()
4242
) ;
43-
if !oldnotify then
44-
disc_inserted name
43+
if !oldnotify then disc_inserted name
4544
) else
4645
match status with
4746
| Cdrom.DISC_OK ->

ocaml/database/block_device_io.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,10 @@ let action_writedb block_dev_fd client datasock target_response_time =
518518
(* If there's space, write some ASCII NULs over the next few bytes so that we trample on any data which may already exist on the block device *)
519519
let remaining_space = remaining_space - min_space_needed in
520520
let trample_size =
521-
if size_size > remaining_space then remaining_space else size_size
521+
if size_size > remaining_space then
522+
remaining_space
523+
else
524+
size_size
522525
in
523526
Unixext.time_limited_write block_dev_fd trample_size
524527
(Bytes.make trample_size '\000')
@@ -606,7 +609,10 @@ let action_writedelta block_dev_fd client _datasock target_response_time =
606609
(* If there's space, write some ASCII NULs over the next few bytes so that we trample on any data which may already exist on the block device *)
607610
let available_space = available_space - str_len in
608611
let trample_size =
609-
if size_size > available_space then available_space else size_size
612+
if size_size > available_space then
613+
available_space
614+
else
615+
size_size
610616
in
611617
let str = Bytes.concat Bytes.empty [str; Bytes.make trample_size '\000'] in
612618
(* Write the delta *)

ocaml/database/database_test.ml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,10 @@ functor
294294
(fun name _ table acc ->
295295
Db_cache_types.Table.fold_over_recent g
296296
(fun r {Db_cache_types.Stat.created; _} _ acc ->
297-
if created >= g then (name, r) :: acc else acc
297+
if created >= g then
298+
(name, r) :: acc
299+
else
300+
acc
298301
)
299302
table acc
300303
)
@@ -321,7 +324,10 @@ functor
321324
(fun _ _ table acc ->
322325
Db_cache_types.Table.fold_over_deleted g
323326
(fun r {Db_cache_types.Stat.deleted; _} acc ->
324-
if deleted > g then r :: acc else acc
327+
if deleted > g then
328+
r :: acc
329+
else
330+
acc
325331
)
326332
table acc
327333
)
@@ -730,11 +736,9 @@ functor
730736
()
731737
) ;
732738
let xs = Client.read_records_where t "VM" Db_filter_types.True in
733-
if List.length xs <> 1 then
734-
failwith "read_records_where <valid table> 2" ;
739+
if List.length xs <> 1 then failwith "read_records_where <valid table> 2" ;
735740
let xs = Client.read_records_where t "VM" Db_filter_types.False in
736-
if xs <> [] then
737-
failwith "read_records_where <valid table> 3" ;
741+
if xs <> [] then failwith "read_records_where <valid table> 3" ;
738742
expect_missing_tbl "Vm" (fun () ->
739743
let _ = Client.find_refs_with_filter t "Vm" Db_filter_types.True in
740744
failwith "find_refs_with_filter <invalid table>"
@@ -743,8 +747,7 @@ functor
743747
if List.length xs <> 1 then
744748
failwith "find_refs_with_filter <valid table> 1" ;
745749
let xs = Client.find_refs_with_filter t "VM" Db_filter_types.False in
746-
if xs <> [] then
747-
failwith "find_refs_with_filter <valid table> 2" ;
750+
if xs <> [] then failwith "find_refs_with_filter <valid table> 2" ;
748751
expect_missing_tbl "Vm" (fun () ->
749752
Client.process_structured_field t ("", "") "Vm" "wibble" invalid_ref
750753
Db_cache_types.AddSet ;

ocaml/database/database_test.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@
1313
*)
1414

1515
module Tests : functor (_ : Db_interface.DB_ACCESS) -> sig
16-
val main : bool -> unit
17-
end
16+
val main : bool -> unit end

ocaml/database/db_cache_impl.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ let read_field t tblname fldname objref =
6868
let ensure_utf8_xml string =
6969
let length = String.length string in
7070
let prefix = Xapi_stdext_encodings.Utf8.XML.longest_valid_prefix string in
71-
if length > String.length prefix then
72-
warn "string truncated to: '%s'." prefix ;
71+
if length > String.length prefix then warn "string truncated to: '%s'." prefix ;
7372
prefix
7473

7574
let ensure_utf8_xml_and_share string = string |> ensure_utf8_xml |> Share.merge

ocaml/database/db_cache_types.ml

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ module StringMap = struct
7070
let add key v t = add (Share.merge key) v t
7171
end
7272

73-
module type VAL = sig
74-
type t
75-
end
73+
module type VAL = sig type t end
7674

7775
module type MAP = sig
7876
type t
@@ -152,7 +150,10 @@ functor
152150
let fold_over_recent since f t initial =
153151
StringMap.fold
154152
(fun x y z ->
155-
if y.stat.Stat.modified > since then f x y.stat y.v z else z
153+
if y.stat.Stat.modified > since then
154+
f x y.stat y.v z
155+
else
156+
z
156157
)
157158
t initial
158159
end
@@ -275,7 +276,10 @@ module Table = struct
275276
else
276277
acc
277278
in
278-
if deleted <= since then new_acc else loop xs new_acc
279+
if deleted <= since then
280+
new_acc
281+
else
282+
loop xs new_acc
279283
| [] ->
280284
acc
281285
in
@@ -523,7 +527,12 @@ end
523527
(* Helper functions to deal with Sets and Maps *)
524528
let add_to_set key t =
525529
let t = Schema.Value.Unsafe_cast.set t in
526-
Schema.Value.Set (if List.mem key t then t else key :: t)
530+
Schema.Value.Set
531+
( if List.mem key t then
532+
t
533+
else
534+
key :: t
535+
)
527536

528537
let remove_from_set key t =
529538
let t = Schema.Value.Unsafe_cast.set t in
@@ -704,15 +713,14 @@ let add_row tblname objref newval db =
704713
let g = db.Database.manifest.Manifest.generation_count in
705714
db
706715
|> Database.update_keymap (fun m ->
707-
if Row.mem Db_names.uuid newval then
708-
KeyMap.add_unique tblname Db_names.uuid
709-
(Uuid
710-
(Schema.Value.Unsafe_cast.string (Row.find Db_names.uuid newval))
711-
)
712-
(tblname, objref) m
713-
else
714-
m
715-
)
716+
if Row.mem Db_names.uuid newval then
717+
KeyMap.add_unique tblname Db_names.uuid
718+
(Uuid (Schema.Value.Unsafe_cast.string (Row.find Db_names.uuid newval))
719+
)
720+
(tblname, objref) m
721+
else
722+
m
723+
)
716724
|> Database.update_keymap
717725
(KeyMap.add_unique tblname Db_names.ref (Ref objref) (tblname, objref))
718726
|> ((fun _ -> newval)
@@ -731,8 +739,8 @@ let remove_row tblname objref db =
731739
let g = db.Database.manifest.Manifest.generation_count in
732740
db
733741
|> Database.update_keymap (fun m ->
734-
match uuid with Some u -> KeyMap.remove (Uuid u) m | None -> m
735-
)
742+
match uuid with Some u -> KeyMap.remove (Uuid u) m | None -> m
743+
)
736744
|> Database.update_keymap (KeyMap.remove (Ref objref))
737745
|> update_many_to_many g tblname objref remove_from_set
738746
(* Update foreign (Set(Ref _)) fields *)

0 commit comments

Comments
 (0)