Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opam-0install-cudf: Add support for the avoid-version flag #37

Closed
wants to merge 4 commits into from

Conversation

kit-ty-kate
Copy link
Collaborator

Take 2. Superseds #35

For some reason I hadn’t thought of this very simple solution in #35...

Copy link
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some fly-by comments as I happened to be working on something related in ocaml-ci!

Comment on lines 15 to 28
let version_rev_compare context pkg1 pkg2 =
let rev_cmp () =
if context.prefer_oldest then
Int.compare pkg1.Cudf.version pkg2.Cudf.version
else
Int.compare pkg2.Cudf.version pkg1.Cudf.version
in
if context.handle_avoid_version then
match tagged_with_avoid_version pkg1, tagged_with_avoid_version pkg2 with
| true, true | false, false -> rev_cmp ()
| true, false -> 1
| false, true -> -1
else
rev_cmp ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function may be hot enough for it to be worth unrolling all four versions and selecting having:

let version_rev_compare context = if context.handle_avoid_version && context.prefer_oldest then version_rev_compare_avoid_oldest else (* ... *)

but it's certainly worth removing the auxiliary function:

Suggested change
let version_rev_compare context pkg1 pkg2 =
let rev_cmp () =
if context.prefer_oldest then
Int.compare pkg1.Cudf.version pkg2.Cudf.version
else
Int.compare pkg2.Cudf.version pkg1.Cudf.version
in
if context.handle_avoid_version then
match tagged_with_avoid_version pkg1, tagged_with_avoid_version pkg2 with
| true, true | false, false -> rev_cmp ()
| true, false -> 1
| false, true -> -1
else
rev_cmp ()
let version_rev_compare context = pkg1 pkg2 =
let avoid_version_pkg1 = context.handle_avoid_version && tagged_with_avoid_version pkg1 in
let avoid_version_pkg2 = context.handle_avoid_version && tagged_with_avoid_version pkg2 in
if avoid_version_pkg1 <> avoid_version_pkg2 then
if avoid_version_pkg1 then 1 else -1
else if context.prefer_oldest then
Int.compare pkg1.Cudf.version pkg2.Cudf.version
else
Int.compare pkg2.Cudf.version pkg1.Cudf.version

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in ea571ba, what do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually i improved it further, the commit linked above is outdated

lib-cudf/model.ml Show resolved Hide resolved
@@ -6,16 +6,23 @@ type diagnostics

val create :
?prefer_oldest:bool ->
?handle_avoid_version:bool -> (* TODO: Make it true by default on the next major breaking release *)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to wait for this? Or it simply that opam itself can opt-in to enabling it immediately? It feels like a bug that it was ignoring it before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the parameter entirely

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've put it back but made it true by default

@kit-ty-kate kit-ty-kate marked this pull request as ready for review July 30, 2024 16:30
@kit-ty-kate kit-ty-kate requested a review from dra27 July 30, 2024 16:31
@kit-ty-kate
Copy link
Collaborator Author

Moved to ocaml-opam/opam-0install-cudf#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants