Skip to content

Commit

Permalink
expose records in comparison function to trigger record changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbou committed Nov 19, 2021
1 parent d10ed3d commit d006e15
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/core/opamFilename.ml
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,10 @@ let of_json = function
| `String x -> (try Some (of_string x) with _ -> None)
| _ -> None

let compare f g =
let dir = Dir.compare f.dirname g.dirname in
let compare {dirname; basename} f =
let dir = Dir.compare dirname f.dirname in
if dir <> 0 then dir else
Base.compare f.basename g.basename
Base.compare basename f.basename

let equal f g = compare f g = 0

Expand Down Expand Up @@ -574,12 +574,12 @@ module Attribute = struct
end
| _ -> None

let compare a b =
let base = Base.compare a.base b.base in
let compare {base; md5; perm} a =
let base = Base.compare base a.base in
if base <> 0 then base else
let md5 = OpamHash.compare a.md5 b.md5 in
let md5 = OpamHash.compare md5 a.md5 in
if md5 <> 0 then md5 else
OpamStd.Option.compare OpamCompat.Int.compare a.perm b.perm
OpamStd.Option.compare OpamCompat.Int.compare perm a.perm

let equal a b = compare a b = 0

Expand Down
10 changes: 5 additions & 5 deletions src/core/opamUrl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ let empty = {
hash = None;
}

let compare u v =
let transport = String.compare u.transport v.transport in
let compare {transport; path; hash; backend} u =
let transport = String.compare transport u.transport in
if transport <> 0 then transport else
let path = String.compare u.path v.path in
let path = String.compare path u.path in
if path <> 0 then path else
let hash = OpamStd.Option.compare String.compare u.hash v.hash in
let hash = OpamStd.Option.compare String.compare hash u.hash in
if hash <> 0 then hash else
compare u.backend v.backend
compare backend u.backend

let equal u v = compare u v = 0

Expand Down
8 changes: 4 additions & 4 deletions src/format/opamVariable.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ module Full = struct
| `String s -> (try Some (of_string s) with _ -> None)
| _ -> None

let compare f g =
match f.scope, g.scope with
let compare {scope; variable} fv =
match scope, fv.scope with
| Global, Global | Self, Self ->
String.compare f.variable g.variable
String.compare variable fv.variable
| Package n, Package m ->
let package = OpamPackage.Name.compare n m in
if package <> 0 then package else
String.compare f.variable g.variable
String.compare variable fv.variable
| Global, _ | _, Self -> 1
| Self, _ | _, Global -> -1

Expand Down

0 comments on commit d006e15

Please sign in to comment.