Skip to content

Commit

Permalink
Stop using polymorphic comparison when comparing switch_selections
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Jul 17, 2024
1 parent a1c9c34 commit 07dade1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/format/opamTypesBase.ml
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,16 @@ let string_of_path_format = function
let char_of_separator = function
| SSemiColon -> ';'
| SColon -> ':'

let switch_selections_compare x
{sel_installed; sel_roots; sel_compiler; sel_pinned} =
let cmp = OpamPackage.Set.compare x.sel_installed sel_installed in
if cmp <> 0 then cmp else
let cmp = OpamPackage.Set.compare x.sel_roots sel_roots in
if cmp <> 0 then cmp else
let cmp = OpamPackage.Set.compare x.sel_compiler sel_compiler in
if cmp <> 0 then cmp else
OpamPackage.Set.compare x.sel_pinned sel_pinned

let switch_selections_equal x y =
switch_selections_compare x y = 0
3 changes: 3 additions & 0 deletions src/format/opamTypesBase.mli
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,6 @@ val raw_of_op: euok_writeable env_update_op_kind -> OpamParserTypes.FullPos.env_
(* Path transformers & separator functions *)
val string_of_path_format: path_format -> string
val char_of_separator: separator -> char

val switch_selections_compare : switch_selections -> switch_selections -> int
val switch_selections_equal : switch_selections -> switch_selections -> bool
5 changes: 4 additions & 1 deletion src/state/opamSwitchAction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ let update_switch_state ?installed ?installed_roots ?reinstall ?pinned st =
in
let st = { st with compiler_packages } in
if not OpamStateConfig.(!r.dryrun) then (
if OpamSwitchState.selections st <> old_selections then write_selections st;
if not (OpamTypesBase.switch_selections_equal
(OpamSwitchState.selections st)
old_selections) then
write_selections st;
if not (OpamPackage.Set.equal reinstall0 reinstall) then
OpamFile.PkgList.write
(OpamPath.Switch.reinstall st.switch_global.root st.switch)
Expand Down
2 changes: 1 addition & 1 deletion src/state/opamUpdate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ let dev_packages st ?autolock ?(working_dir=OpamPackage.Set.empty) packages =
(* The following is needed for pinned packages that may have changed
version *)
let selections1 = OpamSwitchState.selections st in
if selections0 <> selections1 then
if not (OpamTypesBase.switch_selections_equal selections0 selections1) then
OpamFile.SwitchSelections.write
(OpamPath.Switch.selections st.switch_global.root st.switch)
selections1;
Expand Down

0 comments on commit 07dade1

Please sign in to comment.